@seamapi/react 2.4.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.
- package/README.md +1 -1
- package/dist/elements.js +1803 -1815
- package/dist/elements.js.map +1 -1
- package/dist/index.css +0 -8
- package/dist/index.css.map +1 -1
- package/dist/index.min.css +1 -1
- package/dist/index.min.css.map +1 -1
- package/lib/seam/components/DeviceDetails/ThermostatDeviceDetails.js +24 -18
- package/lib/seam/components/DeviceDetails/ThermostatDeviceDetails.js.map +1 -1
- package/lib/seam/components/SupportedDeviceTable/SupportedDeviceContent.js +0 -5
- package/lib/seam/components/SupportedDeviceTable/SupportedDeviceContent.js.map +1 -1
- package/lib/seam/thermostats/use-cool-thermostat.d.ts +6 -0
- package/lib/seam/thermostats/use-cool-thermostat.js +50 -0
- package/lib/seam/thermostats/use-cool-thermostat.js.map +1 -0
- package/lib/seam/thermostats/use-heat-cool-thermostat.d.ts +6 -0
- package/lib/seam/thermostats/use-heat-cool-thermostat.js +45 -0
- package/lib/seam/thermostats/use-heat-cool-thermostat.js.map +1 -0
- package/lib/seam/thermostats/use-heat-thermostat.d.ts +6 -0
- package/lib/seam/thermostats/use-heat-thermostat.js +50 -0
- package/lib/seam/thermostats/use-heat-thermostat.js.map +1 -0
- package/lib/seam/thermostats/use-set-thermostat-off.d.ts +6 -0
- package/lib/seam/thermostats/use-set-thermostat-off.js +48 -0
- package/lib/seam/thermostats/use-set-thermostat-off.js.map +1 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +2 -2
- package/src/lib/seam/components/DeviceDetails/ThermostatDeviceDetails.tsx +56 -44
- package/src/lib/seam/components/SupportedDeviceTable/SupportedDeviceContent.tsx +0 -16
- package/src/lib/seam/thermostats/use-cool-thermostat.ts +90 -0
- package/src/lib/seam/thermostats/use-heat-cool-thermostat.ts +83 -0
- package/src/lib/seam/thermostats/use-heat-thermostat.ts +90 -0
- package/src/lib/seam/thermostats/use-set-thermostat-off.ts +83 -0
- package/src/lib/version.ts +1 -1
- package/src/styles/_supported-device-table.scss +0 -12
- package/lib/seam/components/SupportedDeviceTable/SupportedDeviceFilterResultRow.d.ts +0 -8
- package/lib/seam/components/SupportedDeviceTable/SupportedDeviceFilterResultRow.js +0 -10
- package/lib/seam/components/SupportedDeviceTable/SupportedDeviceFilterResultRow.js.map +0 -1
- package/src/lib/seam/components/SupportedDeviceTable/SupportedDeviceFilterResultRow.tsx +0 -47
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SupportedDeviceContent.js","sourceRoot":"","sources":["../../../../src/lib/seam/components/SupportedDeviceTable/SupportedDeviceContent.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAE/B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"SupportedDeviceContent.js","sourceRoot":"","sources":["../../../../src/lib/seam/components/SupportedDeviceTable/SupportedDeviceContent.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAE/B,OAAO,EAAE,kCAAkC,EAAE,MAAM,gFAAgF,CAAA;AAEnI,OAAO,EAEL,uBAAuB,GACxB,MAAM,wEAAwE,CAAA;AAC/E,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAUzC,MAAM,UAAU,sBAAsB,CAAC,EACrC,gBAAgB,EAChB,WAAW,EACX,OAAO,EACP,aAAa,EACb,qBAAqB,GACO;IAC5B,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,uBAAuB,CAC3E;QACE,WAAW;QACX,OAAO;QACP,aAAa;QACb,qBAAqB;KACtB,CACF,CAAA;IAED,MAAM,mBAAmB,GAAG,OAAO,CACjC,GAAG,EAAE,CAAC,+BAA+B,CAAC,YAAY,IAAI,EAAE,CAAC,EACzD,CAAC,YAAY,CAAC,CACf,CAAA;IAED,IAAI,SAAS,EA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EACnB,WAAW,EACX,gBAAgB,GAIjB;IACC,MAAM,cAAc,GAAG,CACrB,8BACE,sBAAI,CAAC,CAAC,OAAO,GAAK,EAClB,KAAC,MAAM,IACL,OAAO,EAAC,SAAS,EACjB,IAAI,EAAC,OAAO,EACZ,OAAO,EAAE,gBAAgB,EACzB,SAAS,EAAC,0DAA0D,YAEnE,CAAC,CAAC,KAAK,GACD,IACR,CACJ,CAAA;IAED,OAAO,CACL,cAAK,SAAS,EAAC,iDAAiD,YAC9D,wBACE,cAAK,SAAS,EAAC,6CAA6C,YACzD,WAAW,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,sBAAI,CAAC,CAAC,SAAS,GAAK,CAAC,CAAC,CAAC,cAAc,GAC7D,GACF,GACF,CACP,CAAA;AACH,CAAC;AAED,MAAM,+BAA+B,GAAG,CACtC,YAAiC,EACA,EAAE;IACnC,MAAM,MAAM,GAAoC,EAAE,CAAA;IAElD,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE;QAChC,MAAM,EAAE,YAAY,EAAE,GAAG,KAAK,CAAA;QAC9B,MAAM,IAAI,GAAG,MAAM,CAAC,YAAY,CAAC,eAAe,CAAC,IAAI,EAAE,CAAA;QACvD,MAAM,CAAC,YAAY,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,CAAA;KACxD;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,MAAM,CAAC,GAAG;IACR,OAAO,EAAE,0BAA0B;IACnC,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,4CAA4C;IACnD,SAAS,EAAE,yBAAyB;IACpC,OAAO,EAAE,uCAAuC;IAChD,KAAK,EAAE,oBAAoB;CAC5B,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type UseMutationResult } from '@tanstack/react-query';
|
|
2
|
+
import type { SeamError, ThermostatCoolRequest } from 'seamapi';
|
|
3
|
+
type UseCoolThermostatData = Record<string, unknown>;
|
|
4
|
+
type UseCoolThermostatMutationParams = ThermostatCoolRequest;
|
|
5
|
+
export declare function useCoolThermostat(): UseMutationResult<UseCoolThermostatData, SeamError, UseCoolThermostatMutationParams>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useMutation, useQueryClient, } from '@tanstack/react-query';
|
|
2
|
+
import { NullSeamClientError, useSeamClient } from '../../../lib/seam/use-seam-client.js';
|
|
3
|
+
export function useCoolThermostat() {
|
|
4
|
+
const { client } = useSeamClient();
|
|
5
|
+
const queryClient = useQueryClient();
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutationFn: async (mutationParams) => {
|
|
8
|
+
if (client === null)
|
|
9
|
+
throw new NullSeamClientError();
|
|
10
|
+
return await client.thermostats.cool(mutationParams);
|
|
11
|
+
},
|
|
12
|
+
onSuccess: (_data, variables) => {
|
|
13
|
+
queryClient.setQueryData(['devices', 'get', { device_id: variables.device_id }], (thermostat) => {
|
|
14
|
+
if (thermostat == null) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
return getUpdatedThermostat(thermostat, variables);
|
|
18
|
+
});
|
|
19
|
+
queryClient.setQueryData(['devices', 'list', { device_id: variables.device_id }], (thermostats) => {
|
|
20
|
+
if (thermostats == null) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
return thermostats.map((thermostat) => {
|
|
24
|
+
if (thermostat.device_id === variables.device_id) {
|
|
25
|
+
return getUpdatedThermostat(thermostat, variables);
|
|
26
|
+
}
|
|
27
|
+
return thermostat;
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function getUpdatedThermostat(thermostat, variables) {
|
|
34
|
+
return {
|
|
35
|
+
...thermostat,
|
|
36
|
+
properties: {
|
|
37
|
+
...thermostat.properties,
|
|
38
|
+
current_climate_setting: {
|
|
39
|
+
...thermostat.properties.current_climate_setting,
|
|
40
|
+
cooling_set_point_fahrenheit: variables.cooling_set_point_fahrenheit ??
|
|
41
|
+
thermostat.properties.current_climate_setting
|
|
42
|
+
.cooling_set_point_fahrenheit,
|
|
43
|
+
cooling_set_point_celsius: variables.cooling_set_point_celsius ??
|
|
44
|
+
thermostat.properties.current_climate_setting
|
|
45
|
+
.cooling_set_point_celsius,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=use-cool-thermostat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-cool-thermostat.js","sourceRoot":"","sources":["../../../src/lib/seam/thermostats/use-cool-thermostat.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EAEX,cAAc,GACf,MAAM,uBAAuB,CAAA;AAQ9B,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAMhF,MAAM,UAAU,iBAAiB;IAK/B,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE,CAAA;IAClC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IAEpC,OAAO,WAAW,CAIhB;QACA,UAAU,EAAE,KAAK,EAAE,cAA+C,EAAE,EAAE;YACpE,IAAI,MAAM,KAAK,IAAI;gBAAE,MAAM,IAAI,mBAAmB,EAAE,CAAA;YAEpD,OAAO,MAAM,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;QACtD,CAAC;QACD,SAAS,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;YAC9B,WAAW,CAAC,YAAY,CACtB,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,SAAS,CAAC,SAAS,EAAE,CAAC,EACtD,CAAC,UAAU,EAAE,EAAE;gBACb,IAAI,UAAU,IAAI,IAAI,EAAE;oBACtB,OAAM;iBACP;gBAED,OAAO,oBAAoB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAA;YACpD,CAAC,CACF,CAAA;YAED,WAAW,CAAC,YAAY,CACtB,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,SAAS,CAAC,SAAS,EAAE,CAAC,EACvD,CAAC,WAAW,EAAsB,EAAE;gBAClC,IAAI,WAAW,IAAI,IAAI,EAAE;oBACvB,OAAO,EAAE,CAAA;iBACV;gBAED,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;oBACpC,IAAI,UAAU,CAAC,SAAS,KAAK,SAAS,CAAC,SAAS,EAAE;wBAChD,OAAO,oBAAoB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAA;qBACnD;oBAED,OAAO,UAAU,CAAA;gBACnB,CAAC,CAAC,CAAA;YACJ,CAAC,CACF,CAAA;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,oBAAoB,CAC3B,UAA4B,EAC5B,SAA0C;IAE1C,OAAO;QACL,GAAG,UAAU;QACb,UAAU,EAAE;YACV,GAAG,UAAU,CAAC,UAAU;YACxB,uBAAuB,EAAE;gBACvB,GAAG,UAAU,CAAC,UAAU,CAAC,uBAAuB;gBAChD,4BAA4B,EAC1B,SAAS,CAAC,4BAA4B;oBACtC,UAAU,CAAC,UAAU,CAAC,uBAAuB;yBAC1C,4BAA4B;gBACjC,yBAAyB,EACvB,SAAS,CAAC,yBAAyB;oBACnC,UAAU,CAAC,UAAU,CAAC,uBAAuB;yBAC1C,yBAAyB;aAC/B;SACF;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type UseMutationResult } from '@tanstack/react-query';
|
|
2
|
+
import type { SeamError, ThermostatHeatCoolRequest } from 'seamapi';
|
|
3
|
+
type UseHeatCoolThermostatData = Record<string, unknown>;
|
|
4
|
+
type UseHeatCoolThermostatMutationParams = ThermostatHeatCoolRequest;
|
|
5
|
+
export declare function useHeatCoolThermostat(): UseMutationResult<UseHeatCoolThermostatData, SeamError, UseHeatCoolThermostatMutationParams>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useMutation, useQueryClient, } from '@tanstack/react-query';
|
|
2
|
+
import { NullSeamClientError, useSeamClient } from '../../../lib/seam/use-seam-client.js';
|
|
3
|
+
export function useHeatCoolThermostat() {
|
|
4
|
+
const { client } = useSeamClient();
|
|
5
|
+
const queryClient = useQueryClient();
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutationFn: async (mutationParams) => {
|
|
8
|
+
if (client === null)
|
|
9
|
+
throw new NullSeamClientError();
|
|
10
|
+
return await client.thermostats.heatCool(mutationParams);
|
|
11
|
+
},
|
|
12
|
+
onSuccess: (_data, variables) => {
|
|
13
|
+
queryClient.setQueryData(['devices', 'get', { device_id: variables.device_id }], (thermostat) => {
|
|
14
|
+
if (thermostat == null) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
return getUpdatedThermostat(thermostat, variables);
|
|
18
|
+
});
|
|
19
|
+
queryClient.setQueryData(['devices', 'list', { device_id: variables.device_id }], (thermostats) => {
|
|
20
|
+
if (thermostats == null) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
return thermostats.map((thermostat) => {
|
|
24
|
+
if (thermostat.device_id === variables.device_id) {
|
|
25
|
+
return getUpdatedThermostat(thermostat, variables);
|
|
26
|
+
}
|
|
27
|
+
return thermostat;
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function getUpdatedThermostat(thermostat, variables) {
|
|
34
|
+
return {
|
|
35
|
+
...thermostat,
|
|
36
|
+
properties: {
|
|
37
|
+
...thermostat.properties,
|
|
38
|
+
current_climate_setting: {
|
|
39
|
+
...thermostat.properties.current_climate_setting,
|
|
40
|
+
...variables,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=use-heat-cool-thermostat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-heat-cool-thermostat.js","sourceRoot":"","sources":["../../../src/lib/seam/thermostats/use-heat-cool-thermostat.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EAEX,cAAc,GACf,MAAM,uBAAuB,CAAA;AAQ9B,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAMhF,MAAM,UAAU,qBAAqB;IAKnC,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE,CAAA;IAClC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IAEpC,OAAO,WAAW,CAIhB;QACA,UAAU,EAAE,KAAK,EAAE,cAAmD,EAAE,EAAE;YACxE,IAAI,MAAM,KAAK,IAAI;gBAAE,MAAM,IAAI,mBAAmB,EAAE,CAAA;YAEpD,OAAO,MAAM,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAA;QAC1D,CAAC;QACD,SAAS,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;YAC9B,WAAW,CAAC,YAAY,CACtB,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,SAAS,CAAC,SAAS,EAAE,CAAC,EACtD,CAAC,UAAU,EAAE,EAAE;gBACb,IAAI,UAAU,IAAI,IAAI,EAAE;oBACtB,OAAM;iBACP;gBAED,OAAO,oBAAoB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAA;YACpD,CAAC,CACF,CAAA;YAED,WAAW,CAAC,YAAY,CACtB,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,SAAS,CAAC,SAAS,EAAE,CAAC,EACvD,CAAC,WAAW,EAAsB,EAAE;gBAClC,IAAI,WAAW,IAAI,IAAI,EAAE;oBACvB,OAAO,EAAE,CAAA;iBACV;gBAED,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;oBACpC,IAAI,UAAU,CAAC,SAAS,KAAK,SAAS,CAAC,SAAS,EAAE;wBAChD,OAAO,oBAAoB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAA;qBACnD;oBAED,OAAO,UAAU,CAAA;gBACnB,CAAC,CAAC,CAAA;YACJ,CAAC,CACF,CAAA;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,oBAAoB,CAC3B,UAA4B,EAC5B,SAA8C;IAE9C,OAAO;QACL,GAAG,UAAU;QACb,UAAU,EAAE;YACV,GAAG,UAAU,CAAC,UAAU;YACxB,uBAAuB,EAAE;gBACvB,GAAG,UAAU,CAAC,UAAU,CAAC,uBAAuB;gBAChD,GAAG,SAAS;aACb;SACF;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type UseMutationResult } from '@tanstack/react-query';
|
|
2
|
+
import type { SeamError, ThermostatHeatRequest } from 'seamapi';
|
|
3
|
+
type UseHeatThermostatData = Record<string, unknown>;
|
|
4
|
+
type UseHeatThermostatMutationParams = ThermostatHeatRequest;
|
|
5
|
+
export declare function useHeatThermostat(): UseMutationResult<UseHeatThermostatData, SeamError, UseHeatThermostatMutationParams>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useMutation, useQueryClient, } from '@tanstack/react-query';
|
|
2
|
+
import { NullSeamClientError, useSeamClient } from '../../../lib/seam/use-seam-client.js';
|
|
3
|
+
export function useHeatThermostat() {
|
|
4
|
+
const { client } = useSeamClient();
|
|
5
|
+
const queryClient = useQueryClient();
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutationFn: async (mutationParams) => {
|
|
8
|
+
if (client === null)
|
|
9
|
+
throw new NullSeamClientError();
|
|
10
|
+
return await client.thermostats.heat(mutationParams);
|
|
11
|
+
},
|
|
12
|
+
onSuccess: (_data, variables) => {
|
|
13
|
+
queryClient.setQueryData(['devices', 'get', { device_id: variables.device_id }], (thermostat) => {
|
|
14
|
+
if (thermostat == null) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
return getUpdatedThermostat(thermostat, variables);
|
|
18
|
+
});
|
|
19
|
+
queryClient.setQueryData(['devices', 'list', { device_id: variables.device_id }], (thermostats) => {
|
|
20
|
+
if (thermostats == null) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
return thermostats.map((thermostat) => {
|
|
24
|
+
if (thermostat.device_id === variables.device_id) {
|
|
25
|
+
return getUpdatedThermostat(thermostat, variables);
|
|
26
|
+
}
|
|
27
|
+
return thermostat;
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function getUpdatedThermostat(thermostat, variables) {
|
|
34
|
+
return {
|
|
35
|
+
...thermostat,
|
|
36
|
+
properties: {
|
|
37
|
+
...thermostat.properties,
|
|
38
|
+
current_climate_setting: {
|
|
39
|
+
...thermostat.properties.current_climate_setting,
|
|
40
|
+
heating_set_point_fahrenheit: variables.heating_set_point_fahrenheit ??
|
|
41
|
+
thermostat.properties.current_climate_setting
|
|
42
|
+
.heating_set_point_fahrenheit,
|
|
43
|
+
heating_set_point_celsius: variables.heating_set_point_celsius ??
|
|
44
|
+
thermostat.properties.current_climate_setting
|
|
45
|
+
.heating_set_point_celsius,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=use-heat-thermostat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-heat-thermostat.js","sourceRoot":"","sources":["../../../src/lib/seam/thermostats/use-heat-thermostat.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EAEX,cAAc,GACf,MAAM,uBAAuB,CAAA;AAQ9B,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAMhF,MAAM,UAAU,iBAAiB;IAK/B,MAAM,EAAE,MAAM,EAAE,GAAG,aAA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AAC,UAAU;YACxB,uBAAuB,EAAE;gBACvB,GAAG,UAAU,CAAC,UAAU,CAAC,uBAAuB;gBAChD,4BAA4B,EAC1B,SAAS,CAAC,4BAA4B;oBACtC,UAAU,CAAC,UAAU,CAAC,uBAAuB;yBAC1C,4BAA4B;gBACjC,yBAAyB,EACvB,SAAS,CAAC,yBAAyB;oBACnC,UAAU,CAAC,UAAU,CAAC,uBAAuB;yBAC1C,yBAAyB;aAC/B;SACF;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type UseMutationResult } from '@tanstack/react-query';
|
|
2
|
+
import type { SeamError, ThermostatOffRequest } from 'seamapi';
|
|
3
|
+
type UseSetThermostatOffData = Record<string, unknown>;
|
|
4
|
+
type UseSetThermostatOffMutationParams = ThermostatOffRequest;
|
|
5
|
+
export declare function useSetThermostatOff(): UseMutationResult<UseSetThermostatOffData, SeamError, UseSetThermostatOffMutationParams>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useMutation, useQueryClient, } from '@tanstack/react-query';
|
|
2
|
+
import { NullSeamClientError, useSeamClient } from '../../../lib/seam/use-seam-client.js';
|
|
3
|
+
export function useSetThermostatOff() {
|
|
4
|
+
const { client } = useSeamClient();
|
|
5
|
+
const queryClient = useQueryClient();
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutationFn: async (mutationParams) => {
|
|
8
|
+
if (client === null)
|
|
9
|
+
throw new NullSeamClientError();
|
|
10
|
+
return await client.thermostats.off(mutationParams);
|
|
11
|
+
},
|
|
12
|
+
onSuccess: (_data, variables) => {
|
|
13
|
+
queryClient.setQueryData(['devices', 'get', { device_id: variables.device_id }], (thermostat) => {
|
|
14
|
+
if (thermostat == null) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
return getUpdatedThermostat(thermostat);
|
|
18
|
+
});
|
|
19
|
+
queryClient.setQueryData(['devices', 'list', { device_id: variables.device_id }], (thermostats) => {
|
|
20
|
+
if (thermostats == null) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
return thermostats.map((thermostat) => {
|
|
24
|
+
if (thermostat.device_id === variables.device_id) {
|
|
25
|
+
return getUpdatedThermostat(thermostat);
|
|
26
|
+
}
|
|
27
|
+
return thermostat;
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function getUpdatedThermostat(thermostat) {
|
|
34
|
+
return {
|
|
35
|
+
...thermostat,
|
|
36
|
+
properties: {
|
|
37
|
+
...thermostat.properties,
|
|
38
|
+
is_fan_running: false,
|
|
39
|
+
current_climate_setting: {
|
|
40
|
+
...thermostat.properties.current_climate_setting,
|
|
41
|
+
automatic_cooling_enabled: false,
|
|
42
|
+
automatic_heating_enabled: false,
|
|
43
|
+
hvac_mode_setting: 'off',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=use-set-thermostat-off.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-set-thermostat-off.js","sourceRoot":"","sources":["../../../src/lib/seam/thermostats/use-set-thermostat-off.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EAEX,cAAc,GACf,MAAM,uBAAuB,CAAA;AAQ9B,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAMhF,MAAM,UAAU,mBAAmB;IAKjC,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE,CAAA;IAClC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IAEpC,OAAO,WAAW,CAIhB;QACA,UAAU,EAAE,KAAK,EAAE,cAAiD,EAAE,EAAE;YACtE,IAAI,MAAM,KAAK,IAAI;gBAAE,MAAM,IAAI,mBAAmB,EAAE,CAAA;YAEpD,OAAO,MAAM,MAAM,CAAC,WAAW,CAAC,GAAG,CAA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"2.
|
|
1
|
+
declare const seamapiReactVersion = "2.5.0";
|
|
2
2
|
export default seamapiReactVersion;
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seamapi/react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "Seam Components.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -132,7 +132,7 @@
|
|
|
132
132
|
"luxon": "^3.3.0",
|
|
133
133
|
"queue": "^7.0.0",
|
|
134
134
|
"react-hook-form": "^7.46.1",
|
|
135
|
-
"seamapi": "^8.
|
|
135
|
+
"seamapi": "^8.19.0",
|
|
136
136
|
"uuid": "^9.0.0"
|
|
137
137
|
},
|
|
138
138
|
"devDependencies": {
|
|
@@ -44,18 +44,6 @@ export function ThermostatDeviceDetails({
|
|
|
44
44
|
device_id: device.device_id,
|
|
45
45
|
})
|
|
46
46
|
|
|
47
|
-
const {
|
|
48
|
-
mutate: updateFanMode,
|
|
49
|
-
isError: isFanModeError,
|
|
50
|
-
isSuccess: isFanModeSuccess,
|
|
51
|
-
} = useUpdateFanMode()
|
|
52
|
-
|
|
53
|
-
const {
|
|
54
|
-
mutate: updateThermostat,
|
|
55
|
-
isSuccess: isThermostatUpdateSuccess,
|
|
56
|
-
isError: isThermostatUpdateError,
|
|
57
|
-
} = useUpdateThermostat()
|
|
58
|
-
|
|
59
47
|
if (climateSettingsOpen) {
|
|
60
48
|
return (
|
|
61
49
|
<NestedClimateSettingScheduleTable
|
|
@@ -123,17 +111,7 @@ export function ThermostatDeviceDetails({
|
|
|
123
111
|
temperatureUnit='fahrenheit'
|
|
124
112
|
/>
|
|
125
113
|
</DetailRow>
|
|
126
|
-
<
|
|
127
|
-
<FanModeMenu
|
|
128
|
-
mode={device.properties.fan_mode_setting}
|
|
129
|
-
onChange={(fanMode) => {
|
|
130
|
-
updateFanMode({
|
|
131
|
-
device_id: device.device_id,
|
|
132
|
-
fan_mode_setting: fanMode,
|
|
133
|
-
})
|
|
134
|
-
}}
|
|
135
|
-
/>
|
|
136
|
-
</DetailRow>
|
|
114
|
+
<FanModeRow device={device} />
|
|
137
115
|
</DetailSection>
|
|
138
116
|
|
|
139
117
|
<DetailSection
|
|
@@ -150,22 +128,8 @@ export function ThermostatDeviceDetails({
|
|
|
150
128
|
<p>{t.none}</p>
|
|
151
129
|
)}
|
|
152
130
|
</DetailRow>
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
checked={
|
|
156
|
-
device.properties.default_climate_setting
|
|
157
|
-
?.manual_override_allowed ?? true
|
|
158
|
-
}
|
|
159
|
-
onChange={(checked) => {
|
|
160
|
-
updateThermostat({
|
|
161
|
-
device_id: device.device_id,
|
|
162
|
-
default_climate_setting: {
|
|
163
|
-
manual_override_allowed: checked,
|
|
164
|
-
},
|
|
165
|
-
})
|
|
166
|
-
}}
|
|
167
|
-
/>
|
|
168
|
-
</DetailRow>
|
|
131
|
+
|
|
132
|
+
<ManualOverrideRow device={device} />
|
|
169
133
|
</DetailSection>
|
|
170
134
|
|
|
171
135
|
<DetailSection label={t.deviceDetails}>
|
|
@@ -189,25 +153,73 @@ export function ThermostatDeviceDetails({
|
|
|
189
153
|
</DetailSectionGroup>
|
|
190
154
|
</div>
|
|
191
155
|
</div>
|
|
156
|
+
</div>
|
|
157
|
+
)
|
|
158
|
+
}
|
|
192
159
|
|
|
160
|
+
function ManualOverrideRow({
|
|
161
|
+
device,
|
|
162
|
+
}: {
|
|
163
|
+
device: ThermostatDevice
|
|
164
|
+
}): JSX.Element {
|
|
165
|
+
const { mutate, isSuccess, isError } = useUpdateThermostat()
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<>
|
|
169
|
+
<DetailRow label={t.allowManualOverride}>
|
|
170
|
+
<Switch
|
|
171
|
+
checked={
|
|
172
|
+
device.properties.default_climate_setting
|
|
173
|
+
?.manual_override_allowed ?? true
|
|
174
|
+
}
|
|
175
|
+
onChange={(checked) => {
|
|
176
|
+
mutate({
|
|
177
|
+
device_id: device.device_id,
|
|
178
|
+
default_climate_setting: {
|
|
179
|
+
manual_override_allowed: checked,
|
|
180
|
+
},
|
|
181
|
+
})
|
|
182
|
+
}}
|
|
183
|
+
/>
|
|
184
|
+
</DetailRow>
|
|
193
185
|
<Snackbar
|
|
194
186
|
message={t.manualOverrideSuccess}
|
|
195
187
|
variant='success'
|
|
196
|
-
visible={
|
|
188
|
+
visible={isSuccess}
|
|
197
189
|
automaticVisibility
|
|
198
190
|
/>
|
|
199
191
|
|
|
200
192
|
<Snackbar
|
|
201
193
|
message={t.manualOverrideError}
|
|
202
194
|
variant='error'
|
|
203
|
-
visible={
|
|
195
|
+
visible={isError}
|
|
204
196
|
automaticVisibility
|
|
205
197
|
/>
|
|
198
|
+
</>
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function FanModeRow({ device }: { device: ThermostatDevice }): JSX.Element {
|
|
203
|
+
const { mutate, isSuccess, isError } = useUpdateFanMode()
|
|
204
|
+
|
|
205
|
+
return (
|
|
206
|
+
<>
|
|
207
|
+
<DetailRow label={t.fanMode}>
|
|
208
|
+
<FanModeMenu
|
|
209
|
+
mode={device.properties.fan_mode_setting}
|
|
210
|
+
onChange={(fanMode) => {
|
|
211
|
+
mutate({
|
|
212
|
+
device_id: device.device_id,
|
|
213
|
+
fan_mode_setting: fanMode,
|
|
214
|
+
})
|
|
215
|
+
}}
|
|
216
|
+
/>
|
|
217
|
+
</DetailRow>
|
|
206
218
|
|
|
207
219
|
<Snackbar
|
|
208
220
|
message={t.fanModeSuccess}
|
|
209
221
|
variant='success'
|
|
210
|
-
visible={
|
|
222
|
+
visible={isSuccess}
|
|
211
223
|
automaticVisibility
|
|
212
224
|
autoDismiss
|
|
213
225
|
/>
|
|
@@ -215,10 +227,10 @@ export function ThermostatDeviceDetails({
|
|
|
215
227
|
<Snackbar
|
|
216
228
|
message={t.fanModeError}
|
|
217
229
|
variant='error'
|
|
218
|
-
visible={
|
|
230
|
+
visible={isError}
|
|
219
231
|
automaticVisibility
|
|
220
232
|
/>
|
|
221
|
-
|
|
233
|
+
</>
|
|
222
234
|
)
|
|
223
235
|
}
|
|
224
236
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { DeviceModelV1 } from '@seamapi/types/devicedb'
|
|
2
2
|
import { useMemo } from 'react'
|
|
3
3
|
|
|
4
|
-
import { SupportedDeviceFilterResultRow } from 'lib/seam/components/SupportedDeviceTable/SupportedDeviceFilterResultRow.js'
|
|
5
4
|
import { SupportedDeviceManufacturerSection } from 'lib/seam/components/SupportedDeviceTable/SupportedDeviceManufacturerSection.js'
|
|
6
5
|
import type { UseDeviceModelsData } from 'lib/seam/components/SupportedDeviceTable/use-device-models.js'
|
|
7
6
|
import {
|
|
@@ -80,21 +79,6 @@ export function SupportedDeviceContent({
|
|
|
80
79
|
)
|
|
81
80
|
}
|
|
82
81
|
|
|
83
|
-
const hasFilters = filterValue.trim() !== '' || filters.manufacturer !== null
|
|
84
|
-
|
|
85
|
-
if (hasFilters) {
|
|
86
|
-
return (
|
|
87
|
-
<div className='seam-supported-device-table-content'>
|
|
88
|
-
{deviceModels.map((deviceModel) => (
|
|
89
|
-
<SupportedDeviceFilterResultRow
|
|
90
|
-
key={deviceModel.device_model_id}
|
|
91
|
-
deviceModel={deviceModel}
|
|
92
|
-
/>
|
|
93
|
-
))}
|
|
94
|
-
</div>
|
|
95
|
-
)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
82
|
return (
|
|
99
83
|
<>
|
|
100
84
|
{Object.entries(groupedDeviceModels)
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useMutation,
|
|
3
|
+
type UseMutationResult,
|
|
4
|
+
useQueryClient,
|
|
5
|
+
} from '@tanstack/react-query'
|
|
6
|
+
import type {
|
|
7
|
+
SeamError,
|
|
8
|
+
ThermostatCoolRequest,
|
|
9
|
+
ThermostatDevice,
|
|
10
|
+
ThermostatsListResponse,
|
|
11
|
+
} from 'seamapi'
|
|
12
|
+
|
|
13
|
+
import { NullSeamClientError, useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
14
|
+
|
|
15
|
+
// UPSTREAM: Missing ThermostatCoolResponse in seamapi.
|
|
16
|
+
type UseCoolThermostatData = Record<string, unknown>
|
|
17
|
+
type UseCoolThermostatMutationParams = ThermostatCoolRequest
|
|
18
|
+
|
|
19
|
+
export function useCoolThermostat(): UseMutationResult<
|
|
20
|
+
UseCoolThermostatData,
|
|
21
|
+
SeamError,
|
|
22
|
+
UseCoolThermostatMutationParams
|
|
23
|
+
> {
|
|
24
|
+
const { client } = useSeamClient()
|
|
25
|
+
const queryClient = useQueryClient()
|
|
26
|
+
|
|
27
|
+
return useMutation<
|
|
28
|
+
UseCoolThermostatData,
|
|
29
|
+
SeamError,
|
|
30
|
+
UseCoolThermostatMutationParams
|
|
31
|
+
>({
|
|
32
|
+
mutationFn: async (mutationParams: UseCoolThermostatMutationParams) => {
|
|
33
|
+
if (client === null) throw new NullSeamClientError()
|
|
34
|
+
|
|
35
|
+
return await client.thermostats.cool(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: UseCoolThermostatMutationParams
|
|
72
|
+
): ThermostatDevice {
|
|
73
|
+
return {
|
|
74
|
+
...thermostat,
|
|
75
|
+
properties: {
|
|
76
|
+
...thermostat.properties,
|
|
77
|
+
current_climate_setting: {
|
|
78
|
+
...thermostat.properties.current_climate_setting,
|
|
79
|
+
cooling_set_point_fahrenheit:
|
|
80
|
+
variables.cooling_set_point_fahrenheit ??
|
|
81
|
+
thermostat.properties.current_climate_setting
|
|
82
|
+
.cooling_set_point_fahrenheit,
|
|
83
|
+
cooling_set_point_celsius:
|
|
84
|
+
variables.cooling_set_point_celsius ??
|
|
85
|
+
thermostat.properties.current_climate_setting
|
|
86
|
+
.cooling_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
|
+
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
|
+
}
|