1- import type {
2- SeamActionAttemptFailedError ,
3- SeamActionAttemptTimeoutError ,
4- SeamHttpApiError ,
5- ThermostatsHeatParameters ,
6- } from '@seamapi/http/connect'
7- import type { ActionAttempt , Device } from '@seamapi/types/connect'
8- import {
9- useMutation ,
10- type UseMutationResult ,
11- useQueryClient ,
12- } from '@tanstack/react-query'
1+ import type { ThermostatsHeatParameters } from '@seamapi/http/connect'
2+ import type { Device } from '@seamapi/types/connect'
3+ import { useQueryClient } from '@tanstack/react-query'
134
145import {
156 getHeatingSetPointCelsius ,
167 getHeatingSetPointFahrenheit ,
178} from 'lib/seam/thermostats/unit-conversion.js'
18- import { NullSeamClientError , useSeamClient } from 'lib/seam/use-seam-client.js'
9+
10+ import {
11+ useSeamMutation ,
12+ type UseSeamMutationResult ,
13+ } from '../use-seam-mutation.js'
1914
2015export type UseHeatThermostatParams = never
2116
@@ -26,34 +21,13 @@ export type UseHeatThermostatMutationVariables = Pick<
2621 'device_id' | 'heating_set_point_celsius' | 'heating_set_point_fahrenheit'
2722>
2823
29- type HeatThermostatActionAttempt = Extract <
30- ActionAttempt ,
31- { action_type : 'SET_HEAT' }
32- >
33-
34- type MutationError =
35- | SeamHttpApiError
36- | SeamActionAttemptFailedError < HeatThermostatActionAttempt >
37- | SeamActionAttemptTimeoutError < HeatThermostatActionAttempt >
38-
39- export function useHeatThermostat ( ) : UseMutationResult <
40- UseHeatThermostatData ,
41- MutationError ,
42- UseHeatThermostatMutationVariables
43- > {
44- const { client } = useSeamClient ( )
24+ export function useHeatThermostat ( ) : UseSeamMutationResult < '/thermostats/heat' > {
4525 const queryClient = useQueryClient ( )
4626
47- return useMutation <
48- UseHeatThermostatData ,
49- MutationError ,
50- UseHeatThermostatMutationVariables
51- > ( {
52- mutationFn : async ( variables ) => {
53- if ( client === null ) throw new NullSeamClientError ( )
54- await client . thermostats . heat ( variables )
55- } ,
27+ return useSeamMutation ( '/thermostats/heat' , {
5628 onSuccess : ( _data , variables ) => {
29+ if ( variables == null ) return
30+
5731 queryClient . setQueryData < Device | null > (
5832 [ 'devices' , 'get' , { device_id : variables . device_id } ] ,
5933 ( device ) => {
0 commit comments