@seamapi/react 3.1.1 → 4.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/README.md +2 -2
  2. package/dist/elements.js +9897 -10374
  3. package/dist/elements.js.map +1 -1
  4. package/lib/seam/components/AccessCodeDetails/AccessCodeDetails.d.ts +1 -1
  5. package/lib/seam/components/AccessCodeDetails/AccessCodeDetails.js +3 -3
  6. package/lib/seam/components/AccessCodeDetails/AccessCodeDetails.js.map +1 -1
  7. package/lib/seam/components/AccessCodeTable/AccessCodeTable.d.ts +1 -1
  8. package/lib/seam/components/AccessCodeTable/AccessCodeTable.js +4 -4
  9. package/lib/seam/components/AccessCodeTable/AccessCodeTable.js.map +1 -1
  10. package/lib/seam/components/DeviceDetails/DeviceDetails.d.ts +1 -1
  11. package/lib/seam/components/DeviceDetails/DeviceDetails.js +1 -2
  12. package/lib/seam/components/DeviceDetails/DeviceDetails.js.map +1 -1
  13. package/lib/seam/components/DeviceDetails/LockDeviceDetails.d.ts +1 -1
  14. package/lib/seam/components/DeviceDetails/LockDeviceDetails.js +2 -2
  15. package/lib/seam/components/DeviceDetails/LockDeviceDetails.js.map +1 -1
  16. package/lib/seam/components/DeviceDetails/ThermostatDeviceDetails.d.ts +1 -1
  17. package/lib/seam/components/DeviceDetails/ThermostatDeviceDetails.js +2 -40
  18. package/lib/seam/components/DeviceDetails/ThermostatDeviceDetails.js.map +1 -1
  19. package/lib/seam/components/DeviceTable/DeviceTable.d.ts +1 -1
  20. package/lib/seam/components/DeviceTable/DeviceTable.js +2 -2
  21. package/lib/seam/components/DeviceTable/DeviceTable.js.map +1 -1
  22. package/lib/seam/components/common-props.d.ts +0 -1
  23. package/lib/seam/components/common-props.js.map +1 -1
  24. package/lib/seam/components/index.d.ts +0 -2
  25. package/lib/seam/components/index.js +0 -2
  26. package/lib/seam/components/index.js.map +1 -1
  27. package/lib/seam/index.d.ts +0 -2
  28. package/lib/seam/index.js +0 -2
  29. package/lib/seam/index.js.map +1 -1
  30. package/lib/ui/AccessCodeForm/AccessCodeForm.js +3 -3
  31. package/lib/ui/AccessCodeForm/AccessCodeForm.js.map +1 -1
  32. package/lib/ui/thermostat/FanModeMenu.js +1 -0
  33. package/lib/ui/thermostat/FanModeMenu.js.map +1 -1
  34. package/lib/version.d.ts +1 -1
  35. package/lib/version.js +1 -1
  36. package/lib/version.js.map +1 -1
  37. package/package.json +3 -3
  38. package/src/lib/element.tsx +0 -1
  39. package/src/lib/seam/components/AccessCodeDetails/AccessCodeDetails.tsx +0 -3
  40. package/src/lib/seam/components/AccessCodeTable/AccessCodeTable.tsx +0 -4
  41. package/src/lib/seam/components/DeviceDetails/DeviceDetails.tsx +0 -2
  42. package/src/lib/seam/components/DeviceDetails/LockDeviceDetails.tsx +0 -2
  43. package/src/lib/seam/components/DeviceDetails/ThermostatDeviceDetails.tsx +0 -137
  44. package/src/lib/seam/components/DeviceTable/DeviceTable.tsx +0 -2
  45. package/src/lib/seam/components/common-props.tsx +0 -1
  46. package/src/lib/seam/components/elements.ts +0 -2
  47. package/src/lib/seam/components/index.ts +0 -2
  48. package/src/lib/seam/index.ts +0 -2
  49. package/src/lib/ui/AccessCodeForm/AccessCodeForm.tsx +3 -4
  50. package/src/lib/ui/thermostat/FanModeMenu.tsx +1 -0
  51. package/src/lib/version.ts +1 -1
  52. package/lib/seam/components/ClimateSettingScheduleDetails/ClimateSettingScheduleCard.d.ts +0 -7
  53. package/lib/seam/components/ClimateSettingScheduleDetails/ClimateSettingScheduleCard.js +0 -43
  54. package/lib/seam/components/ClimateSettingScheduleDetails/ClimateSettingScheduleCard.js.map +0 -1
  55. package/lib/seam/components/ClimateSettingScheduleDetails/ClimateSettingScheduleDetails.d.ts +0 -7
  56. package/lib/seam/components/ClimateSettingScheduleDetails/ClimateSettingScheduleDetails.js +0 -55
  57. package/lib/seam/components/ClimateSettingScheduleDetails/ClimateSettingScheduleDetails.js.map +0 -1
  58. package/lib/seam/components/ClimateSettingScheduleDetails/ClimateSettingScheduleDeviceBar.d.ts +0 -5
  59. package/lib/seam/components/ClimateSettingScheduleDetails/ClimateSettingScheduleDeviceBar.js +0 -31
  60. package/lib/seam/components/ClimateSettingScheduleDetails/ClimateSettingScheduleDeviceBar.js.map +0 -1
  61. package/lib/seam/components/ClimateSettingScheduleDetails/dates.d.ts +0 -1
  62. package/lib/seam/components/ClimateSettingScheduleDetails/dates.js +0 -9
  63. package/lib/seam/components/ClimateSettingScheduleDetails/dates.js.map +0 -1
  64. package/lib/seam/components/ClimateSettingScheduleTable/ClimateSettingScheduleRow.d.ts +0 -8
  65. package/lib/seam/components/ClimateSettingScheduleTable/ClimateSettingScheduleRow.js +0 -10
  66. package/lib/seam/components/ClimateSettingScheduleTable/ClimateSettingScheduleRow.js.map +0 -1
  67. package/lib/seam/components/ClimateSettingScheduleTable/ClimateSettingScheduleRowDetails.d.ts +0 -5
  68. package/lib/seam/components/ClimateSettingScheduleTable/ClimateSettingScheduleRowDetails.js +0 -28
  69. package/lib/seam/components/ClimateSettingScheduleTable/ClimateSettingScheduleRowDetails.js.map +0 -1
  70. package/lib/seam/components/ClimateSettingScheduleTable/ClimateSettingScheduleTable.d.ts +0 -14
  71. package/lib/seam/components/ClimateSettingScheduleTable/ClimateSettingScheduleTable.js +0 -80
  72. package/lib/seam/components/ClimateSettingScheduleTable/ClimateSettingScheduleTable.js.map +0 -1
  73. package/lib/seam/components/CreateClimateSettingScheduleForm/CreateClimateSettingScheduleForm.d.ts +0 -5
  74. package/lib/seam/components/CreateClimateSettingScheduleForm/CreateClimateSettingScheduleForm.js +0 -29
  75. package/lib/seam/components/CreateClimateSettingScheduleForm/CreateClimateSettingScheduleForm.js.map +0 -1
  76. package/lib/seam/thermostats/climate-setting-schedules/use-climate-setting-schedule.d.ts +0 -6
  77. package/lib/seam/thermostats/climate-setting-schedules/use-climate-setting-schedule.js +0 -16
  78. package/lib/seam/thermostats/climate-setting-schedules/use-climate-setting-schedule.js.map +0 -1
  79. package/lib/seam/thermostats/climate-setting-schedules/use-climate-setting-schedules.d.ts +0 -6
  80. package/lib/seam/thermostats/climate-setting-schedules/use-climate-setting-schedules.js +0 -28
  81. package/lib/seam/thermostats/climate-setting-schedules/use-climate-setting-schedules.js.map +0 -1
  82. package/lib/seam/thermostats/climate-setting-schedules/use-create-climate-setting-schedule.d.ts +0 -7
  83. package/lib/seam/thermostats/climate-setting-schedules/use-create-climate-setting-schedule.js +0 -25
  84. package/lib/seam/thermostats/climate-setting-schedules/use-create-climate-setting-schedule.js.map +0 -1
  85. package/lib/seam/thermostats/climate-setting-schedules/use-delete-climate-setting-schedule.d.ts +0 -6
  86. package/lib/seam/thermostats/climate-setting-schedules/use-delete-climate-setting-schedule.js +0 -27
  87. package/lib/seam/thermostats/climate-setting-schedules/use-delete-climate-setting-schedule.js.map +0 -1
  88. package/lib/seam/thermostats/climate-setting-schedules/use-update-climate-setting-schedule.d.ts +0 -6
  89. package/lib/seam/thermostats/climate-setting-schedules/use-update-climate-setting-schedule.js +0 -46
  90. package/lib/seam/thermostats/climate-setting-schedules/use-update-climate-setting-schedule.js.map +0 -1
  91. package/lib/seam/thermostats/use-update-thermostat.d.ts +0 -6
  92. package/lib/seam/thermostats/use-update-thermostat.js +0 -51
  93. package/lib/seam/thermostats/use-update-thermostat.js.map +0 -1
  94. package/lib/ui/ClimateSettingForm/ClimateSettingScheduleForm.d.ts +0 -32
  95. package/lib/ui/ClimateSettingForm/ClimateSettingScheduleForm.js +0 -85
  96. package/lib/ui/ClimateSettingForm/ClimateSettingScheduleForm.js.map +0 -1
  97. package/lib/ui/ClimateSettingForm/ClimateSettingScheduleFormClimateSetting.d.ts +0 -13
  98. package/lib/ui/ClimateSettingForm/ClimateSettingScheduleFormClimateSetting.js +0 -44
  99. package/lib/ui/ClimateSettingForm/ClimateSettingScheduleFormClimateSetting.js.map +0 -1
  100. package/lib/ui/ClimateSettingForm/ClimateSettingScheduleFormDefaultClimateSetting.d.ts +0 -10
  101. package/lib/ui/ClimateSettingForm/ClimateSettingScheduleFormDefaultClimateSetting.js +0 -24
  102. package/lib/ui/ClimateSettingForm/ClimateSettingScheduleFormDefaultClimateSetting.js.map +0 -1
  103. package/lib/ui/ClimateSettingForm/ClimateSettingScheduleFormDeviceSelect.d.ts +0 -10
  104. package/lib/ui/ClimateSettingForm/ClimateSettingScheduleFormDeviceSelect.js +0 -10
  105. package/lib/ui/ClimateSettingForm/ClimateSettingScheduleFormDeviceSelect.js.map +0 -1
  106. package/lib/ui/ClimateSettingForm/ClimateSettingScheduleFormNameAndSchedule.d.ts +0 -15
  107. package/lib/ui/ClimateSettingForm/ClimateSettingScheduleFormNameAndSchedule.js +0 -30
  108. package/lib/ui/ClimateSettingForm/ClimateSettingScheduleFormNameAndSchedule.js.map +0 -1
  109. package/lib/ui/ClimateSettingForm/ClimateSettingScheduleFormTimeZonePicker.d.ts +0 -9
  110. package/lib/ui/ClimateSettingForm/ClimateSettingScheduleFormTimeZonePicker.js +0 -16
  111. package/lib/ui/ClimateSettingForm/ClimateSettingScheduleFormTimeZonePicker.js.map +0 -1
  112. package/lib/ui/ClimateSettingForm/set-point-bounds.d.ts +0 -4
  113. package/lib/ui/ClimateSettingForm/set-point-bounds.js +0 -17
  114. package/lib/ui/ClimateSettingForm/set-point-bounds.js.map +0 -1
  115. package/src/lib/seam/components/ClimateSettingScheduleDetails/ClimateSettingScheduleCard.tsx +0 -107
  116. package/src/lib/seam/components/ClimateSettingScheduleDetails/ClimateSettingScheduleDetails.element.ts +0 -11
  117. package/src/lib/seam/components/ClimateSettingScheduleDetails/ClimateSettingScheduleDetails.tsx +0 -175
  118. package/src/lib/seam/components/ClimateSettingScheduleDetails/ClimateSettingScheduleDeviceBar.tsx +0 -72
  119. package/src/lib/seam/components/ClimateSettingScheduleDetails/dates.ts +0 -10
  120. package/src/lib/seam/components/ClimateSettingScheduleTable/ClimateSettingScheduleRow.tsx +0 -35
  121. package/src/lib/seam/components/ClimateSettingScheduleTable/ClimateSettingScheduleRowDetails.tsx +0 -60
  122. package/src/lib/seam/components/ClimateSettingScheduleTable/ClimateSettingScheduleTable.element.ts +0 -17
  123. package/src/lib/seam/components/ClimateSettingScheduleTable/ClimateSettingScheduleTable.tsx +0 -220
  124. package/src/lib/seam/components/CreateClimateSettingScheduleForm/CreateClimateSettingScheduleForm.element.ts +0 -9
  125. package/src/lib/seam/components/CreateClimateSettingScheduleForm/CreateClimateSettingScheduleForm.tsx +0 -56
  126. package/src/lib/seam/thermostats/climate-setting-schedules/use-climate-setting-schedule.ts +0 -34
  127. package/src/lib/seam/thermostats/climate-setting-schedules/use-climate-setting-schedules.ts +0 -53
  128. package/src/lib/seam/thermostats/climate-setting-schedules/use-create-climate-setting-schedule.ts +0 -53
  129. package/src/lib/seam/thermostats/climate-setting-schedules/use-delete-climate-setting-schedule.ts +0 -51
  130. package/src/lib/seam/thermostats/climate-setting-schedules/use-update-climate-setting-schedule.ts +0 -83
  131. package/src/lib/seam/thermostats/use-update-thermostat.ts +0 -90
  132. package/src/lib/ui/ClimateSettingForm/ClimateSettingScheduleForm.tsx +0 -189
  133. package/src/lib/ui/ClimateSettingForm/ClimateSettingScheduleFormClimateSetting.tsx +0 -118
  134. package/src/lib/ui/ClimateSettingForm/ClimateSettingScheduleFormDefaultClimateSetting.tsx +0 -79
  135. package/src/lib/ui/ClimateSettingForm/ClimateSettingScheduleFormDeviceSelect.tsx +0 -36
  136. package/src/lib/ui/ClimateSettingForm/ClimateSettingScheduleFormNameAndSchedule.tsx +0 -120
  137. package/src/lib/ui/ClimateSettingForm/ClimateSettingScheduleFormTimeZonePicker.tsx +0 -43
  138. package/src/lib/ui/ClimateSettingForm/set-point-bounds.ts +0 -31
@@ -1,34 +0,0 @@
1
- import type {
2
- SeamHttpApiError,
3
- ThermostatsClimateSettingSchedulesGetParams,
4
- } from '@seamapi/http/connect'
5
- import type { ClimateSettingSchedule } from '@seamapi/types/connect'
6
- import { useQuery } from '@tanstack/react-query'
7
-
8
- import { useSeamClient } from 'lib/seam/use-seam-client.js'
9
- import type { UseSeamQueryResult } from 'lib/seam/use-seam-query-result.js'
10
-
11
- export type UseClimateSettingScheduleParams =
12
- ThermostatsClimateSettingSchedulesGetParams
13
-
14
- export type UseClimateSettingScheduleData = ClimateSettingSchedule | null
15
-
16
- export function useClimateSettingSchedule(
17
- params: UseClimateSettingScheduleParams
18
- ): UseSeamQueryResult<'climateSettingSchedule', UseClimateSettingScheduleData> {
19
- const { client } = useSeamClient()
20
-
21
- const { data, ...rest } = useQuery<
22
- UseClimateSettingScheduleData,
23
- SeamHttpApiError
24
- >({
25
- enabled: client != null,
26
- queryKey: ['thermostats', 'climate_setting_schedules', 'get', params],
27
- queryFn: async () => {
28
- if (client == null) return null
29
- return await client.thermostats.climateSettingSchedules.get(params)
30
- },
31
- })
32
-
33
- return { ...rest, climateSettingSchedule: data }
34
- }
@@ -1,53 +0,0 @@
1
- import type {
2
- SeamHttpApiError,
3
- ThermostatsClimateSettingSchedulesListParams,
4
- } from '@seamapi/http/connect'
5
- import type { ClimateSettingSchedule } from '@seamapi/types/connect'
6
- import { useQuery, useQueryClient } from '@tanstack/react-query'
7
-
8
- import { useSeamClient } from 'lib/seam/use-seam-client.js'
9
- import type { UseSeamQueryResult } from 'lib/seam/use-seam-query-result.js'
10
-
11
- export type UseClimateSettingSchedulesParams =
12
- ThermostatsClimateSettingSchedulesListParams
13
-
14
- export type UseClimateSettingSchedulesData = ClimateSettingSchedule[]
15
-
16
- export function useClimateSettingSchedules(
17
- params: UseClimateSettingSchedulesParams
18
- ): UseSeamQueryResult<
19
- 'climateSettingSchedules',
20
- UseClimateSettingSchedulesData
21
- > {
22
- const { client } = useSeamClient()
23
- const queryClient = useQueryClient()
24
-
25
- const { data, ...rest } = useQuery<
26
- UseClimateSettingSchedulesData,
27
- SeamHttpApiError
28
- >({
29
- enabled: client != null,
30
- queryKey: ['thermostats', 'climate_setting_schedules', 'list', params],
31
- queryFn: async () => {
32
- if (client == null) return []
33
- const climateSettingSchedules =
34
- await client.thermostats.climateSettingSchedules.list(params)
35
- for (const schedule of climateSettingSchedules) {
36
- queryClient.setQueryData(
37
- [
38
- 'thermostats',
39
- 'climate_setting_schedules',
40
- 'get',
41
- {
42
- climate_setting_schedule_id: schedule.climate_setting_schedule_id,
43
- },
44
- ],
45
- schedule
46
- )
47
- }
48
- return climateSettingSchedules
49
- },
50
- })
51
-
52
- return { ...rest, climateSettingSchedules: data }
53
- }
@@ -1,53 +0,0 @@
1
- import type {
2
- SeamHttpApiError,
3
- ThermostatsClimateSettingSchedulesCreateBody,
4
- } from '@seamapi/http/connect'
5
- import type { ClimateSettingSchedule } from '@seamapi/types/connect'
6
- import {
7
- useMutation,
8
- type UseMutationResult,
9
- useQueryClient,
10
- } from '@tanstack/react-query'
11
-
12
- import { NullSeamClientError, useSeamClient } from 'lib/seam/use-seam-client.js'
13
-
14
- export type UseCreateClimateSettingScheduleParams = never
15
-
16
- export type UseCreateClimateSettingScheduleData = ClimateSettingSchedule
17
-
18
- export type UseCreateClimateSettingScheduleMutationVariables =
19
- ThermostatsClimateSettingSchedulesCreateBody
20
-
21
- export function useCreateClimateSettingSchedule(): UseMutationResult<
22
- UseCreateClimateSettingScheduleData,
23
- SeamHttpApiError,
24
- UseCreateClimateSettingScheduleMutationVariables
25
- > {
26
- const { client } = useSeamClient()
27
- const queryClient = useQueryClient()
28
-
29
- return useMutation<
30
- UseCreateClimateSettingScheduleData,
31
- SeamHttpApiError,
32
- UseCreateClimateSettingScheduleMutationVariables
33
- >({
34
- mutationFn: async (variables) => {
35
- if (client === null) throw new NullSeamClientError()
36
- return await client.thermostats.climateSettingSchedules.create(variables)
37
- },
38
- onSuccess: (data) => {
39
- queryClient.setQueryData(
40
- [
41
- 'thermostats',
42
- 'climate_setting_schedules',
43
- 'get',
44
- { climate_setting_schedules: data.climate_setting_schedule_id },
45
- ],
46
- data
47
- )
48
- void queryClient.invalidateQueries({
49
- queryKey: ['thermostats', 'climate_setting_schedules', 'list'],
50
- })
51
- },
52
- })
53
- }
@@ -1,51 +0,0 @@
1
- import type {
2
- SeamHttpApiError,
3
- ThermostatsClimateSettingSchedulesDeleteParams,
4
- } from '@seamapi/http/connect'
5
- import {
6
- useMutation,
7
- type UseMutationResult,
8
- useQueryClient,
9
- } from '@tanstack/react-query'
10
-
11
- import { NullSeamClientError, useSeamClient } from 'lib/seam/use-seam-client.js'
12
-
13
- export type UseDeleteClimateSettingScheduleParams = never
14
-
15
- export type UseDeleteClimateSettingScheduleData = undefined
16
-
17
- export type UseDeleteClimateSettingScheduleMutationVariables =
18
- ThermostatsClimateSettingSchedulesDeleteParams
19
-
20
- export function useDeleteClimateSettingSchedule(): UseMutationResult<
21
- UseDeleteClimateSettingScheduleData,
22
- SeamHttpApiError,
23
- UseDeleteClimateSettingScheduleMutationVariables
24
- > {
25
- const { client } = useSeamClient()
26
- const queryClient = useQueryClient()
27
-
28
- return useMutation<
29
- UseDeleteClimateSettingScheduleData,
30
- SeamHttpApiError,
31
- UseDeleteClimateSettingScheduleMutationVariables
32
- >({
33
- mutationFn: async (variables) => {
34
- if (client === null) throw new NullSeamClientError()
35
- await client.thermostats.climateSettingSchedules.delete(variables)
36
- },
37
- onSuccess: (_data, variables) => {
38
- void queryClient.invalidateQueries({
39
- queryKey: [
40
- 'thermostats',
41
- 'climate_setting_schedules',
42
- 'get',
43
- { climate_setting_schedules: variables.climate_setting_schedule_id },
44
- ],
45
- })
46
- void queryClient.invalidateQueries({
47
- queryKey: ['thermostats', 'climate_setting_schedules', 'list'],
48
- })
49
- },
50
- })
51
- }
@@ -1,83 +0,0 @@
1
- import type {
2
- SeamHttpApiError,
3
- ThermostatsClimateSettingSchedulesUpdateBody,
4
- } from '@seamapi/http/connect'
5
- import type { ClimateSettingSchedule } from '@seamapi/types/connect'
6
- import {
7
- useMutation,
8
- type UseMutationResult,
9
- useQueryClient,
10
- } from '@tanstack/react-query'
11
-
12
- import { shake } from 'lib/object.js'
13
- import { NullSeamClientError, useSeamClient } from 'lib/seam/use-seam-client.js'
14
-
15
- export type UseUpdateClimateSettingScheduleParams = never
16
-
17
- export type UseUpdateClimateSettingScheduleData = undefined
18
-
19
- export type UseUpdateClimateSettingScheduleMutationVariables =
20
- ThermostatsClimateSettingSchedulesUpdateBody
21
-
22
- export function useUpdateClimateSettingSchedule(): UseMutationResult<
23
- UseUpdateClimateSettingScheduleData,
24
- SeamHttpApiError,
25
- UseUpdateClimateSettingScheduleMutationVariables
26
- > {
27
- const { client } = useSeamClient()
28
- const queryClient = useQueryClient()
29
-
30
- return useMutation<
31
- UseUpdateClimateSettingScheduleData,
32
- SeamHttpApiError,
33
- UseUpdateClimateSettingScheduleMutationVariables
34
- >({
35
- mutationFn: async (variables) => {
36
- if (client === null) throw new NullSeamClientError()
37
- await client.thermostats.climateSettingSchedules.update(variables)
38
- },
39
- onSuccess: (_data, variables) => {
40
- queryClient.setQueryData<ClimateSettingSchedule | null>(
41
- [
42
- 'thermostats',
43
- 'climate_setting_schedules',
44
- 'get',
45
- { climate_setting_schedules: variables.climate_setting_schedule_id },
46
- ],
47
- (climateSettingSchedule) => {
48
- if (climateSettingSchedule == null) {
49
- return
50
- }
51
-
52
- return {
53
- ...climateSettingSchedule,
54
- ...shake(variables),
55
- }
56
- }
57
- )
58
-
59
- queryClient.setQueryData<ClimateSettingSchedule[]>(
60
- ['thermostats', 'climate_setting_schedules', 'list'],
61
- (climateSettingSchedules) => {
62
- if (climateSettingSchedules == null) {
63
- return climateSettingSchedules
64
- }
65
-
66
- return climateSettingSchedules.map((climateSettingSchedule) => {
67
- if (
68
- climateSettingSchedule.climate_setting_schedule_id ===
69
- variables.climate_setting_schedule_id
70
- ) {
71
- return {
72
- ...climateSettingSchedule,
73
- ...shake(variables),
74
- }
75
- }
76
-
77
- return climateSettingSchedule
78
- })
79
- }
80
- )
81
- },
82
- })
83
- }
@@ -1,90 +0,0 @@
1
- import type {
2
- SeamHttpApiError,
3
- ThermostatsUpdateBody,
4
- } from '@seamapi/http/connect'
5
- import type { Device } from '@seamapi/types/connect'
6
- import {
7
- useMutation,
8
- type UseMutationResult,
9
- useQueryClient,
10
- } from '@tanstack/react-query'
11
-
12
- import { shake } from 'lib/object.js'
13
- import { NullSeamClientError, useSeamClient } from 'lib/seam/use-seam-client.js'
14
-
15
- export type UseUpdateThermostatParams = never
16
-
17
- export type UseUpdateThermostatData = undefined
18
-
19
- export type UseUpdateThermostatMutationVariables = ThermostatsUpdateBody
20
-
21
- export function useUpdateThermostat(): UseMutationResult<
22
- UseUpdateThermostatData,
23
- SeamHttpApiError,
24
- UseUpdateThermostatMutationVariables
25
- > {
26
- const { client } = useSeamClient()
27
- const queryClient = useQueryClient()
28
-
29
- return useMutation<
30
- UseUpdateThermostatData,
31
- SeamHttpApiError,
32
- UseUpdateThermostatMutationVariables
33
- >({
34
- mutationFn: async (variables) => {
35
- if (client === null) throw new NullSeamClientError()
36
- await client.thermostats.update(variables)
37
- },
38
- onSuccess: (_data, variables) => {
39
- queryClient.setQueryData<Device | null>(
40
- ['devices', 'get', { device_id: variables.device_id }],
41
- (device) => {
42
- if (device == null) {
43
- return
44
- }
45
- return getUpdatedDevice(device, variables)
46
- }
47
- )
48
-
49
- queryClient.setQueryData<Device[]>(
50
- ['devices', 'list', { device_id: variables.device_id }],
51
- (devices): Device[] => {
52
- if (devices == null) {
53
- return []
54
- }
55
-
56
- return devices.map((device) => {
57
- if (device.device_id === variables.device_id) {
58
- return getUpdatedDevice(device, variables)
59
- }
60
-
61
- return device
62
- })
63
- }
64
- )
65
- },
66
- })
67
- }
68
-
69
- const getUpdatedDevice = (
70
- device: Device,
71
- variables: UseUpdateThermostatMutationVariables
72
- ): Device => {
73
- const { properties } = device
74
- if (
75
- 'default_climate_setting' in properties &&
76
- properties.default_climate_setting != null
77
- ) {
78
- return {
79
- ...device,
80
- properties: {
81
- ...properties,
82
- default_climate_setting: {
83
- ...properties.default_climate_setting,
84
- ...shake(variables.default_climate_setting),
85
- },
86
- },
87
- }
88
- }
89
- return device
90
- }
@@ -1,189 +0,0 @@
1
- import classNames from 'classnames'
2
- import { useEffect, useState } from 'react'
3
- import { useForm } from 'react-hook-form'
4
-
5
- import { getSystemTimeZone } from 'lib/dates.js'
6
- import { useSeamClient } from 'lib/index.js'
7
- import {
8
- type ClimateSetting,
9
- type HvacModeSetting,
10
- isThermostatDevice,
11
- } from 'lib/seam/thermostats/thermostat-device.js'
12
- import { ClimateSettingScheduleFormClimateSetting } from 'lib/ui/ClimateSettingForm/ClimateSettingScheduleFormClimateSetting.js'
13
- import { ClimateSettingScheduleFormDefaultClimateSetting } from 'lib/ui/ClimateSettingForm/ClimateSettingScheduleFormDefaultClimateSetting.js'
14
- import { ClimateSettingScheduleFormDeviceSelect } from 'lib/ui/ClimateSettingForm/ClimateSettingScheduleFormDeviceSelect.js'
15
- import { ClimateSettingScheduleFormNameAndSchedule } from 'lib/ui/ClimateSettingForm/ClimateSettingScheduleFormNameAndSchedule.js'
16
- import { ClimateSettingScheduleFormTimeZonePicker } from 'lib/ui/ClimateSettingForm/ClimateSettingScheduleFormTimeZonePicker.js'
17
-
18
- export interface ClimateSettingScheduleFormSubmitData {
19
- name: string
20
- deviceId: string
21
- startDate: string
22
- endDate: string
23
- timeZone: string
24
- climateSetting: ClimateSetting
25
- }
26
-
27
- export interface ClimateSettingScheduleFormProps {
28
- className?: string
29
- onBack?: () => void
30
- isSubmitting: boolean
31
- onSubmit: (data: ClimateSettingScheduleFormSubmitData) => void
32
- }
33
-
34
- export interface ClimateSettingScheduleFormFields {
35
- name: string
36
- deviceId: string
37
- startDate: string
38
- endDate: string
39
- timeZone: string
40
- climateSetting: {
41
- hvacModeSetting: HvacModeSetting
42
- // may have to ignore one or the other fields here on submit
43
- heatingSetPoint: number
44
- coolingSetPoint: number
45
- }
46
- }
47
-
48
- export function ClimateSettingScheduleForm({
49
- className,
50
- ...props
51
- }: ClimateSettingScheduleFormProps): JSX.Element | null {
52
- return (
53
- <div
54
- className={classNames('seam-climate-setting-schedule-form', className)}
55
- >
56
- <Content {...props} />
57
- </div>
58
- )
59
- }
60
-
61
- function Content({
62
- onBack,
63
- }: Omit<ClimateSettingScheduleFormProps, 'className'>): JSX.Element {
64
- const { client } = useSeamClient()
65
- const { control, watch, resetField } =
66
- useForm<ClimateSettingScheduleFormFields>({
67
- defaultValues: {
68
- deviceId: '',
69
- name: '',
70
- startDate: '',
71
- endDate: '',
72
- timeZone: getSystemTimeZone(),
73
- climateSetting: {
74
- hvacModeSetting: 'heat_cool',
75
- heatingSetPoint: 70,
76
- coolingSetPoint: 75,
77
- },
78
- },
79
- })
80
-
81
- const deviceId = watch('deviceId')
82
- const timeZone = watch('timeZone')
83
-
84
- const [page, setPage] = useState<
85
- | 'device_select'
86
- | 'default_setting'
87
- | 'name_and_schedule'
88
- | 'time_zone_select'
89
- | 'climate_setting'
90
- >('device_select')
91
-
92
- const returnToDeviceSelect = (): void => {
93
- resetField('deviceId')
94
- setPage('device_select')
95
- }
96
-
97
- useEffect(() => {
98
- if (page === 'device_select' && deviceId !== '' && client != null) {
99
- client.devices
100
- .get({ device_id: deviceId })
101
- .then((device) => {
102
- if (!isThermostatDevice(device)) return
103
-
104
- if (device.properties.default_climate_setting != null) {
105
- setPage('name_and_schedule')
106
- return
107
- }
108
-
109
- setPage('default_setting')
110
- })
111
- .catch(() => {})
112
- }
113
- }, [client, deviceId, page, setPage])
114
-
115
- if (page === 'device_select') {
116
- return (
117
- <ClimateSettingScheduleFormDeviceSelect
118
- title={t.addNewClimateSettingSchedule}
119
- control={control}
120
- onBack={onBack}
121
- />
122
- )
123
- }
124
-
125
- if (page === 'default_setting') {
126
- return (
127
- <ClimateSettingScheduleFormDefaultClimateSetting
128
- title={t.addNewClimateSettingSchedule}
129
- deviceId={deviceId}
130
- onBack={returnToDeviceSelect}
131
- onCancel={onBack}
132
- onSave={() => {
133
- setPage('name_and_schedule')
134
- }}
135
- />
136
- )
137
- }
138
-
139
- if (page === 'name_and_schedule') {
140
- return (
141
- <ClimateSettingScheduleFormNameAndSchedule
142
- title={t.addNewClimateSettingSchedule}
143
- control={control}
144
- deviceId={deviceId}
145
- onBack={returnToDeviceSelect}
146
- onCancel={onBack}
147
- onNext={() => {
148
- setPage('climate_setting')
149
- }}
150
- onChangeTimeZone={() => {
151
- setPage('time_zone_select')
152
- }}
153
- timeZone={timeZone}
154
- />
155
- )
156
- }
157
-
158
- if (page === 'time_zone_select') {
159
- return (
160
- <ClimateSettingScheduleFormTimeZonePicker
161
- control={control}
162
- onClose={() => {
163
- setPage('name_and_schedule')
164
- }}
165
- />
166
- )
167
- }
168
-
169
- if (page === 'climate_setting') {
170
- return (
171
- <ClimateSettingScheduleFormClimateSetting
172
- title={t.addNewClimateSettingSchedule}
173
- control={control}
174
- deviceId={deviceId}
175
- onBack={() => {
176
- setPage('name_and_schedule')
177
- }}
178
- onCancel={onBack}
179
- onSave={() => {}}
180
- />
181
- )
182
- }
183
-
184
- return <></>
185
- }
186
-
187
- export const t = {
188
- addNewClimateSettingSchedule: 'Add a climate setting schedule',
189
- }
@@ -1,118 +0,0 @@
1
- import { type Control, Controller } from 'react-hook-form'
2
-
3
- import { useDevice } from 'lib/seam/devices/use-device.js'
4
- import { isThermostatDevice } from 'lib/seam/thermostats/thermostat-device.js'
5
- import { Button } from 'lib/ui/Button.js'
6
- import type { ClimateSettingScheduleFormFields } from 'lib/ui/ClimateSettingForm/ClimateSettingScheduleForm.js'
7
- import {
8
- getSetPointBounds,
9
- type SetPointBounds,
10
- } from 'lib/ui/ClimateSettingForm/set-point-bounds.js'
11
- import { FormField } from 'lib/ui/FormField.js'
12
- import { InputLabel } from 'lib/ui/InputLabel.js'
13
- import { ContentHeader } from 'lib/ui/layout/ContentHeader.js'
14
- import { ClimateSettingControlGroup } from 'lib/ui/thermostat/ClimateSettingControlGroup.js'
15
-
16
- interface ClimateSettingScheduleFormClimateSettingProps {
17
- title: string
18
- control: Control<ClimateSettingScheduleFormFields>
19
- deviceId: string
20
- onBack: () => void
21
- onCancel: (() => void) | undefined
22
- onSave: () => void
23
- }
24
-
25
- export function ClimateSettingScheduleFormClimateSetting({
26
- title,
27
- control,
28
- deviceId,
29
- onBack,
30
- onCancel,
31
- onSave,
32
- }: ClimateSettingScheduleFormClimateSettingProps): JSX.Element {
33
- const { device } = useDevice({
34
- device_id: deviceId,
35
- })
36
-
37
- if (device == null) return <></>
38
- if (!isThermostatDevice(device)) return <></>
39
-
40
- const setPointBounds = getSetPointBounds(device)
41
-
42
- return (
43
- <>
44
- <ContentHeader
45
- title={title}
46
- onBack={onBack}
47
- subheading={device?.properties.name}
48
- />
49
- <div className='seam-main'>
50
- <div className='seam-climate-setting-schedule-form-climate-setting'>
51
- <div className='seam-content'>
52
- <div>
53
- <InputLabel>{t.climateSetting}</InputLabel>
54
- <span className='seam-label'>{t.climateSettingSubHeading}</span>
55
- </div>
56
- <FormContent control={control} setPointBounds={setPointBounds} />
57
- </div>
58
- </div>
59
- <div className='seam-actions'>
60
- <Button onClick={onCancel}>{t.cancel}</Button>
61
- <Button variant='solid' onClick={onSave}>
62
- {t.save}
63
- </Button>
64
- </div>
65
- </div>
66
- </>
67
- )
68
- }
69
-
70
- interface FormContentProps {
71
- control: Control<ClimateSettingScheduleFormFields>
72
- setPointBounds: SetPointBounds
73
- }
74
-
75
- function FormContent({
76
- control,
77
- setPointBounds,
78
- }: FormContentProps): JSX.Element {
79
- return (
80
- <FormField>
81
- <Controller
82
- name='climateSetting'
83
- control={control}
84
- render={({ field: { value, onChange } }) => (
85
- <ClimateSettingControlGroup
86
- mode={value.hvacModeSetting}
87
- onModeChange={(mode) => {
88
- onChange({ ...value, hvacModeSetting: mode })
89
- }}
90
- coolValue={value.coolingSetPoint}
91
- heatValue={value.heatingSetPoint}
92
- {...setPointBounds}
93
- onCoolValueChange={(coolingSetPoint) => {
94
- onChange({
95
- ...value,
96
- coolingSetPoint,
97
- })
98
- }}
99
- onHeatValueChange={(heatingSetPoint) => {
100
- onChange({
101
- ...value,
102
- heatingSetPoint,
103
- })
104
- }}
105
- />
106
- )}
107
- />
108
- </FormField>
109
- )
110
- }
111
-
112
- const t = {
113
- climateSetting: 'Climate setting',
114
- climateSettingSubHeading: 'Choose mode and adjust the climate',
115
- cancel: 'Cancel',
116
- save: 'Save',
117
- next: 'Next',
118
- }