8
8
} from 'seamapi'
9
9
10
10
import { getSystemTimeZone } from 'lib/dates.js'
11
- import { useDevice } from 'lib/index.js'
11
+ import { useSeamClient } from 'lib/index.js'
12
12
import { ClimateSettingScheduleFormClimateSetting } from 'lib/ui/ClimateSettingForm/ClimateSettingScheduleFormClimateSetting.js'
13
13
import { ClimateSettingScheduleFormDefaultClimateSetting } from 'lib/ui/ClimateSettingForm/ClimateSettingScheduleFormDefaultClimateSetting.js'
14
14
import { ClimateSettingScheduleFormDeviceSelect } from 'lib/ui/ClimateSettingForm/ClimateSettingScheduleFormDeviceSelect.js'
@@ -61,6 +61,7 @@ export function ClimateSettingScheduleForm({
61
61
function Content ( {
62
62
onBack,
63
63
} : Omit < ClimateSettingScheduleFormProps , 'className' > ) : JSX . Element {
64
+ const { client } = useSeamClient ( )
64
65
const { control, watch, resetField } =
65
66
useForm < ClimateSettingScheduleFormFields > ( {
66
67
defaultValues : {
@@ -80,10 +81,6 @@ function Content({
80
81
const deviceId = watch ( 'deviceId' )
81
82
const timeZone = watch ( 'timeZone' )
82
83
83
- const { device } = useDevice ( {
84
- device_id : deviceId ,
85
- } )
86
-
87
84
const [ page , setPage ] = useState <
88
85
| 'device_select'
89
86
| 'default_setting'
@@ -98,13 +95,22 @@ function Content({
98
95
}
99
96
100
97
useEffect ( ( ) => {
101
- if ( page === 'device_select' && device != null ) {
102
- if ( ! isThermostatDevice ( device ) ) return
103
- const defaultSetting = device . properties . default_climate_setting
104
- if ( defaultSetting != null ) setPage ( 'name_and_schedule' )
105
- else setPage ( 'default_setting' )
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 ( ( ) => { } )
106
112
}
107
- } , [ device , page , setPage ] )
113
+ } , [ client , deviceId , page , setPage ] )
108
114
109
115
if ( page === 'device_select' ) {
110
116
return (
0 commit comments