@seamapi/react 2.3.0 → 2.5.0

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 (45) hide show
  1. package/README.md +1 -1
  2. package/dist/elements.js +2775 -2687
  3. package/dist/elements.js.map +1 -1
  4. package/dist/index.css +0 -8
  5. package/dist/index.css.map +1 -1
  6. package/dist/index.min.css +1 -1
  7. package/dist/index.min.css.map +1 -1
  8. package/lib/seam/components/DeviceDetails/ThermostatDeviceDetails.js +28 -14
  9. package/lib/seam/components/DeviceDetails/ThermostatDeviceDetails.js.map +1 -1
  10. package/lib/seam/components/SupportedDeviceTable/SupportedDeviceContent.js +0 -5
  11. package/lib/seam/components/SupportedDeviceTable/SupportedDeviceContent.js.map +1 -1
  12. package/lib/seam/thermostats/use-cool-thermostat.d.ts +6 -0
  13. package/lib/seam/thermostats/use-cool-thermostat.js +50 -0
  14. package/lib/seam/thermostats/use-cool-thermostat.js.map +1 -0
  15. package/lib/seam/thermostats/use-heat-cool-thermostat.d.ts +6 -0
  16. package/lib/seam/thermostats/use-heat-cool-thermostat.js +45 -0
  17. package/lib/seam/thermostats/use-heat-cool-thermostat.js.map +1 -0
  18. package/lib/seam/thermostats/use-heat-thermostat.d.ts +6 -0
  19. package/lib/seam/thermostats/use-heat-thermostat.js +50 -0
  20. package/lib/seam/thermostats/use-heat-thermostat.js.map +1 -0
  21. package/lib/seam/thermostats/use-set-thermostat-off.d.ts +6 -0
  22. package/lib/seam/thermostats/use-set-thermostat-off.js +48 -0
  23. package/lib/seam/thermostats/use-set-thermostat-off.js.map +1 -0
  24. package/lib/seam/thermostats/use-update-thermostat.js +2 -2
  25. package/lib/seam/thermostats/use-update-thermostat.js.map +1 -1
  26. package/lib/ui/Switch/Switch.d.ts +1 -2
  27. package/lib/ui/Switch/Switch.js +1 -2
  28. package/lib/ui/Switch/Switch.js.map +1 -1
  29. package/lib/version.d.ts +1 -1
  30. package/lib/version.js +1 -1
  31. package/package.json +3 -3
  32. package/src/lib/seam/components/DeviceDetails/ThermostatDeviceDetails.tsx +70 -24
  33. package/src/lib/seam/components/SupportedDeviceTable/SupportedDeviceContent.tsx +0 -16
  34. package/src/lib/seam/thermostats/use-cool-thermostat.ts +90 -0
  35. package/src/lib/seam/thermostats/use-heat-cool-thermostat.ts +83 -0
  36. package/src/lib/seam/thermostats/use-heat-thermostat.ts +90 -0
  37. package/src/lib/seam/thermostats/use-set-thermostat-off.ts +83 -0
  38. package/src/lib/seam/thermostats/use-update-thermostat.ts +2 -2
  39. package/src/lib/ui/Switch/Switch.tsx +1 -3
  40. package/src/lib/version.ts +1 -1
  41. package/src/styles/_supported-device-table.scss +0 -12
  42. package/lib/seam/components/SupportedDeviceTable/SupportedDeviceFilterResultRow.d.ts +0 -8
  43. package/lib/seam/components/SupportedDeviceTable/SupportedDeviceFilterResultRow.js +0 -10
  44. package/lib/seam/components/SupportedDeviceTable/SupportedDeviceFilterResultRow.js.map +0 -1
  45. package/src/lib/seam/components/SupportedDeviceTable/SupportedDeviceFilterResultRow.tsx +0 -47
@@ -0,0 +1,83 @@
1
+ import {
2
+ useMutation,
3
+ type UseMutationResult,
4
+ useQueryClient,
5
+ } from '@tanstack/react-query'
6
+ import type {
7
+ SeamError,
8
+ ThermostatDevice,
9
+ ThermostatHeatCoolRequest,
10
+ ThermostatsListResponse,
11
+ } from 'seamapi'
12
+
13
+ import { NullSeamClientError, useSeamClient } from 'lib/seam/use-seam-client.js'
14
+
15
+ // UPSTREAM: Missing ThermostatHeatCoolResponse in seamapi.
16
+ type UseHeatCoolThermostatData = Record<string, unknown>
17
+ type UseHeatCoolThermostatMutationParams = ThermostatHeatCoolRequest
18
+
19
+ export function useHeatCoolThermostat(): UseMutationResult<
20
+ UseHeatCoolThermostatData,
21
+ SeamError,
22
+ UseHeatCoolThermostatMutationParams
23
+ > {
24
+ const { client } = useSeamClient()
25
+ const queryClient = useQueryClient()
26
+
27
+ return useMutation<
28
+ UseHeatCoolThermostatData,
29
+ SeamError,
30
+ UseHeatCoolThermostatMutationParams
31
+ >({
32
+ mutationFn: async (mutationParams: UseHeatCoolThermostatMutationParams) => {
33
+ if (client === null) throw new NullSeamClientError()
34
+
35
+ return await client.thermostats.heatCool(mutationParams)
36
+ },
37
+ onSuccess: (_data, variables) => {
38
+ queryClient.setQueryData<ThermostatDevice | null>(
39
+ ['devices', 'get', { device_id: variables.device_id }],
40
+ (thermostat) => {
41
+ if (thermostat == null) {
42
+ return
43
+ }
44
+
45
+ return getUpdatedThermostat(thermostat, variables)
46
+ }
47
+ )
48
+
49
+ queryClient.setQueryData<ThermostatsListResponse['thermostats']>(
50
+ ['devices', 'list', { device_id: variables.device_id }],
51
+ (thermostats): ThermostatDevice[] => {
52
+ if (thermostats == null) {
53
+ return []
54
+ }
55
+
56
+ return thermostats.map((thermostat) => {
57
+ if (thermostat.device_id === variables.device_id) {
58
+ return getUpdatedThermostat(thermostat, variables)
59
+ }
60
+
61
+ return thermostat
62
+ })
63
+ }
64
+ )
65
+ },
66
+ })
67
+ }
68
+
69
+ function getUpdatedThermostat(
70
+ thermostat: ThermostatDevice,
71
+ variables: UseHeatCoolThermostatMutationParams
72
+ ): ThermostatDevice {
73
+ return {
74
+ ...thermostat,
75
+ properties: {
76
+ ...thermostat.properties,
77
+ current_climate_setting: {
78
+ ...thermostat.properties.current_climate_setting,
79
+ ...variables,
80
+ },
81
+ },
82
+ }
83
+ }
@@ -0,0 +1,90 @@
1
+ import {
2
+ useMutation,
3
+ type UseMutationResult,
4
+ useQueryClient,
5
+ } from '@tanstack/react-query'
6
+ import type {
7
+ SeamError,
8
+ ThermostatDevice,
9
+ ThermostatHeatRequest,
10
+ ThermostatsListResponse,
11
+ } from 'seamapi'
12
+
13
+ import { NullSeamClientError, useSeamClient } from 'lib/seam/use-seam-client.js'
14
+
15
+ // UPSTREAM: Missing ThermostatHeatResponse in seamapi.
16
+ type UseHeatThermostatData = Record<string, unknown>
17
+ type UseHeatThermostatMutationParams = ThermostatHeatRequest
18
+
19
+ export function useHeatThermostat(): UseMutationResult<
20
+ UseHeatThermostatData,
21
+ SeamError,
22
+ UseHeatThermostatMutationParams
23
+ > {
24
+ const { client } = useSeamClient()
25
+ const queryClient = useQueryClient()
26
+
27
+ return useMutation<
28
+ UseHeatThermostatData,
29
+ SeamError,
30
+ UseHeatThermostatMutationParams
31
+ >({
32
+ mutationFn: async (mutationParams: UseHeatThermostatMutationParams) => {
33
+ if (client === null) throw new NullSeamClientError()
34
+
35
+ return await client.thermostats.heat(mutationParams)
36
+ },
37
+ onSuccess: (_data, variables) => {
38
+ queryClient.setQueryData<ThermostatDevice | null>(
39
+ ['devices', 'get', { device_id: variables.device_id }],
40
+ (thermostat) => {
41
+ if (thermostat == null) {
42
+ return
43
+ }
44
+
45
+ return getUpdatedThermostat(thermostat, variables)
46
+ }
47
+ )
48
+
49
+ queryClient.setQueryData<ThermostatsListResponse['thermostats']>(
50
+ ['devices', 'list', { device_id: variables.device_id }],
51
+ (thermostats): ThermostatDevice[] => {
52
+ if (thermostats == null) {
53
+ return []
54
+ }
55
+
56
+ return thermostats.map((thermostat) => {
57
+ if (thermostat.device_id === variables.device_id) {
58
+ return getUpdatedThermostat(thermostat, variables)
59
+ }
60
+
61
+ return thermostat
62
+ })
63
+ }
64
+ )
65
+ },
66
+ })
67
+ }
68
+
69
+ function getUpdatedThermostat(
70
+ thermostat: ThermostatDevice,
71
+ variables: UseHeatThermostatMutationParams
72
+ ): ThermostatDevice {
73
+ return {
74
+ ...thermostat,
75
+ properties: {
76
+ ...thermostat.properties,
77
+ current_climate_setting: {
78
+ ...thermostat.properties.current_climate_setting,
79
+ heating_set_point_fahrenheit:
80
+ variables.heating_set_point_fahrenheit ??
81
+ thermostat.properties.current_climate_setting
82
+ .heating_set_point_fahrenheit,
83
+ heating_set_point_celsius:
84
+ variables.heating_set_point_celsius ??
85
+ thermostat.properties.current_climate_setting
86
+ .heating_set_point_celsius,
87
+ },
88
+ },
89
+ }
90
+ }
@@ -0,0 +1,83 @@
1
+ import {
2
+ useMutation,
3
+ type UseMutationResult,
4
+ useQueryClient,
5
+ } from '@tanstack/react-query'
6
+ import type {
7
+ SeamError,
8
+ ThermostatDevice,
9
+ ThermostatOffRequest,
10
+ ThermostatsListResponse,
11
+ } from 'seamapi'
12
+
13
+ import { NullSeamClientError, useSeamClient } from 'lib/seam/use-seam-client.js'
14
+
15
+ // UPSTREAM: Missing ThermostatOffResponse in seamapi.
16
+ type UseSetThermostatOffData = Record<string, unknown>
17
+ type UseSetThermostatOffMutationParams = ThermostatOffRequest
18
+
19
+ export function useSetThermostatOff(): UseMutationResult<
20
+ UseSetThermostatOffData,
21
+ SeamError,
22
+ UseSetThermostatOffMutationParams
23
+ > {
24
+ const { client } = useSeamClient()
25
+ const queryClient = useQueryClient()
26
+
27
+ return useMutation<
28
+ UseSetThermostatOffData,
29
+ SeamError,
30
+ UseSetThermostatOffMutationParams
31
+ >({
32
+ mutationFn: async (mutationParams: UseSetThermostatOffMutationParams) => {
33
+ if (client === null) throw new NullSeamClientError()
34
+
35
+ return await client.thermostats.off(mutationParams)
36
+ },
37
+ onSuccess: (_data, variables) => {
38
+ queryClient.setQueryData<ThermostatDevice | null>(
39
+ ['devices', 'get', { device_id: variables.device_id }],
40
+ (thermostat) => {
41
+ if (thermostat == null) {
42
+ return
43
+ }
44
+
45
+ return getUpdatedThermostat(thermostat)
46
+ }
47
+ )
48
+
49
+ queryClient.setQueryData<ThermostatsListResponse['thermostats']>(
50
+ ['devices', 'list', { device_id: variables.device_id }],
51
+ (thermostats): ThermostatDevice[] => {
52
+ if (thermostats == null) {
53
+ return []
54
+ }
55
+
56
+ return thermostats.map((thermostat) => {
57
+ if (thermostat.device_id === variables.device_id) {
58
+ return getUpdatedThermostat(thermostat)
59
+ }
60
+
61
+ return thermostat
62
+ })
63
+ }
64
+ )
65
+ },
66
+ })
67
+ }
68
+
69
+ function getUpdatedThermostat(thermostat: ThermostatDevice): ThermostatDevice {
70
+ return {
71
+ ...thermostat,
72
+ properties: {
73
+ ...thermostat.properties,
74
+ is_fan_running: false,
75
+ current_climate_setting: {
76
+ ...thermostat.properties.current_climate_setting,
77
+ automatic_cooling_enabled: false,
78
+ automatic_heating_enabled: false,
79
+ hvac_mode_setting: 'off',
80
+ },
81
+ },
82
+ }
83
+ }
@@ -36,7 +36,7 @@ export function useUpdateThermostat(): UseMutationResult<
36
36
  },
37
37
  onSuccess: (_data, variables) => {
38
38
  queryClient.setQueryData<ThermostatDevice | null>(
39
- ['thermostats', 'get', { device_id: variables.device_id }],
39
+ ['devices', 'get', { device_id: variables.device_id }],
40
40
  (thermostat) => {
41
41
  if (thermostat == null) {
42
42
  return
@@ -47,7 +47,7 @@ export function useUpdateThermostat(): UseMutationResult<
47
47
  )
48
48
 
49
49
  queryClient.setQueryData<ThermostatsListResponse['thermostats']>(
50
- ['thermostats', 'list', { device_id: variables.device_id }],
50
+ ['devices', 'list', { device_id: variables.device_id }],
51
51
  (thermostats): ThermostatDevice[] => {
52
52
  if (thermostats == null) {
53
53
  return []
@@ -6,7 +6,7 @@ export interface SwitchProps {
6
6
  enableLabel?: boolean
7
7
  }
8
8
 
9
- function Switch({
9
+ export function Switch({
10
10
  checked,
11
11
  onChange,
12
12
  enableLabel = false,
@@ -34,5 +34,3 @@ const t = {
34
34
  on: 'On',
35
35
  off: 'Off',
36
36
  }
37
-
38
- export default Switch
@@ -1,3 +1,3 @@
1
- const seamapiReactVersion = '2.3.0'
1
+ const seamapiReactVersion = '2.5.0'
2
2
 
3
3
  export default seamapiReactVersion
@@ -248,18 +248,6 @@ $row-padding: 8px;
248
248
  display: flex;
249
249
  padding: 8px;
250
250
  }
251
-
252
- &.filter-result-row {
253
- .seam-model-name {
254
- display: flex;
255
- align-items: center;
256
-
257
- .seam-manufacturer-image {
258
- width: 32px;
259
- margin-right: 4px;
260
- }
261
- }
262
- }
263
251
  }
264
252
 
265
253
  .seam-status-pill {
@@ -1,8 +0,0 @@
1
- /// <reference types="react" resolution-mode="require"/>
2
- import type { DeviceModelV1 } from '@seamapi/types/devicedb';
3
- interface SupportedDeviceFilterResultRowProps {
4
- deviceModel: DeviceModelV1;
5
- }
6
- export declare function SupportedDeviceFilterResultRow({ deviceModel, }: SupportedDeviceFilterResultRowProps): JSX.Element;
7
- export declare function ModelColumn({ deviceModel, }: SupportedDeviceFilterResultRowProps): JSX.Element;
8
- export {};
@@ -1,10 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { ImageColumn, StatusColumn, } from '../../../../lib/seam/components/SupportedDeviceTable/SupportedDeviceRow.js';
3
- import { DotDivider } from '../../../../lib/ui/layout/DotDivider.js';
4
- export function SupportedDeviceFilterResultRow({ deviceModel, }) {
5
- return (_jsxs("div", { className: 'seam-row filter-result-row', children: [_jsx(ImageColumn, { deviceModel: deviceModel }), _jsx(ModelColumn, { deviceModel: deviceModel }), _jsx(StatusColumn, { deviceModel: deviceModel })] }));
6
- }
7
- export function ModelColumn({ deviceModel, }) {
8
- return (_jsxs("div", { className: 'seam-col seam-model-col', children: [_jsxs("div", { className: 'seam-model-name', children: [_jsx("img", { src: deviceModel.manufacturer.logo?.url, alt: deviceModel.manufacturer.display_name, className: 'seam-manufacturer-image' }), ' ', _jsx("div", { className: 'seam-truncated-text', children: deviceModel.display_name })] }), _jsx("div", { className: 'seam-model-id', children: _jsxs("div", { className: 'seam-truncated-text', children: [deviceModel.device_model_id, _jsx(DotDivider, {}), deviceModel.main_connection_type] }) })] }));
9
- }
10
- //# sourceMappingURL=SupportedDeviceFilterResultRow.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SupportedDeviceFilterResultRow.js","sourceRoot":"","sources":["../../../../src/lib/seam/components/SupportedDeviceTable/SupportedDeviceFilterResultRow.tsx"],"names":[],"mappings":";AAEA,OAAO,EACL,WAAW,EACX,YAAY,GACb,MAAM,gEAAgE,CAAA;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAMxD,MAAM,UAAU,8BAA8B,CAAC,EAC7C,WAAW,GACyB;IACpC,OAAO,CACL,eAAK,SAAS,EAAC,4BAA4B,aACzC,KAAC,WAAW,IAAC,WAAW,EAAE,WAAW,GAAI,EACzC,KAAC,WAAW,IAAC,WAAW,EAAE,WAAW,GAAI,EACzC,KAAC,YAAY,IAAC,WAAW,EAAE,WAAW,GAAI,IACtC,CACP,CAAA;AACH,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,EAC1B,WAAW,GACyB;IACpC,OAAO,CACL,eAAK,SAAS,EAAC,yBAAyB,aACtC,eAAK,SAAS,EAAC,iBAAiB,aAC9B,cACE,GAAG,EAAE,WAAW,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,EACvC,GAAG,EAAE,WAAW,CAAC,YAAY,CAAC,YAAY,EAC1C,SAAS,EAAC,yBAAyB,GACnC,EAAC,GAAG,EACN,cAAK,SAAS,EAAC,qBAAqB,YAAE,WAAW,CAAC,YAAY,GAAO,IACjE,EACN,cAAK,SAAS,EAAC,eAAe,YAC5B,eAAK,SAAS,EAAC,qBAAqB,aACjC,WAAW,CAAC,eAAe,EAC5B,KAAC,UAAU,KAAG,EACb,WAAW,CAAC,oBAAoB,IAC7B,GACF,IACF,CACP,CAAA;AACH,CAAC"}
@@ -1,47 +0,0 @@
1
- import type { DeviceModelV1 } from '@seamapi/types/devicedb'
2
-
3
- import {
4
- ImageColumn,
5
- StatusColumn,
6
- } from 'lib/seam/components/SupportedDeviceTable/SupportedDeviceRow.js'
7
- import { DotDivider } from 'lib/ui/layout/DotDivider.js'
8
-
9
- interface SupportedDeviceFilterResultRowProps {
10
- deviceModel: DeviceModelV1
11
- }
12
-
13
- export function SupportedDeviceFilterResultRow({
14
- deviceModel,
15
- }: SupportedDeviceFilterResultRowProps): JSX.Element {
16
- return (
17
- <div className='seam-row filter-result-row'>
18
- <ImageColumn deviceModel={deviceModel} />
19
- <ModelColumn deviceModel={deviceModel} />
20
- <StatusColumn deviceModel={deviceModel} />
21
- </div>
22
- )
23
- }
24
-
25
- export function ModelColumn({
26
- deviceModel,
27
- }: SupportedDeviceFilterResultRowProps): JSX.Element {
28
- return (
29
- <div className='seam-col seam-model-col'>
30
- <div className='seam-model-name'>
31
- <img
32
- src={deviceModel.manufacturer.logo?.url}
33
- alt={deviceModel.manufacturer.display_name}
34
- className='seam-manufacturer-image'
35
- />{' '}
36
- <div className='seam-truncated-text'>{deviceModel.display_name}</div>
37
- </div>
38
- <div className='seam-model-id'>
39
- <div className='seam-truncated-text'>
40
- {deviceModel.device_model_id}
41
- <DotDivider />
42
- {deviceModel.main_connection_type}
43
- </div>
44
- </div>
45
- </div>
46
- )
47
- }