@@ -105,17 +105,20 @@ class Govee {
105
105
}
106
106
if ( ( accessory = this . devicesInHB . get ( device . device ) ) ) {
107
107
accessory . context . controllable = device . controllable
108
+ accessory . context . retrievable = device . retrievable
108
109
accessory . context . supportedCmds = device . supportCmds
109
110
const res = await this . httpClient . getDevice ( accessory . context )
110
- this . refreshAccessory ( accessory , Object . assign ( { } , ...res ) )
111
+ if ( accessory . context . retrievable ) {
112
+ this . refreshAccessory ( accessory , Object . assign ( { } , ...res ) )
113
+ } else {
114
+ throw new Error ( 'requesting status is unsupported for the ' + device . model )
115
+ }
111
116
} else {
112
- this . log . warn ( "[%s] could not be initialised as it wasn't found in Homebridge.", device . deviceName )
117
+ throw new Error ( " it wasn't found in Homebridge.")
113
118
}
114
119
} catch ( err ) {
115
120
if ( this . debug ) {
116
- let str = err . message
117
- if ( str === 'Request failed with status code 400' ) str += '. This error can often be safely ignored if device control is working as expected'
118
- this . log . warn ( '[%s] could not be updated as %s.' , device . deviceName , str )
121
+ this . log . warn ( '[%s] could not be updated as %s.' , device . deviceName , err . message )
119
122
}
120
123
}
121
124
}
@@ -209,6 +212,12 @@ class Govee {
209
212
async internalOnOffUpdate ( accessory , value , callback ) {
210
213
callback ( )
211
214
try {
215
+ if ( ! (
216
+ accessory . context . controllable &&
217
+ accessory . context . supportedCmds . includes ( 'turn' )
218
+ ) ) {
219
+ throw new Error ( 'model [' + accessory . context . gvModel + '] does not support command [turn]' )
220
+ }
212
221
await this . httpClient . updateDevice ( accessory . context , {
213
222
name : 'turn' ,
214
223
value : value ? 'on' : 'off'
@@ -218,13 +227,19 @@ class Govee {
218
227
}
219
228
this . ignoreNextSync = true
220
229
} catch ( err ) {
221
- this . log . warn ( '[%s] could not be updated and its status will be reverted soon. Error: \n %s.' , accessory . displayName , err )
230
+ this . log . warn ( '[%s] could not be updated and its status will be reverted soon. Error: %s.' , accessory . displayName , err . message )
222
231
}
223
232
}
224
233
225
234
async internalBrightnessUpdate ( accessory , value , callback ) {
226
235
callback ( )
227
236
try {
237
+ if ( ! (
238
+ accessory . context . controllable &&
239
+ accessory . context . supportedCmds . includes ( 'brightness' )
240
+ ) ) {
241
+ throw new Error ( 'model [' + accessory . context . gvModel + '] does not support command [brightness]' )
242
+ }
228
243
await this . httpClient . updateDevice ( accessory . context , {
229
244
name : 'brightness' ,
230
245
value : value
@@ -234,13 +249,19 @@ class Govee {
234
249
}
235
250
this . ignoreNextSync = true
236
251
} catch ( err ) {
237
- this . log . warn ( '[%s] could not be updated and its status will be reverted soon. Error: \n %s.' , accessory . displayName , err )
252
+ this . log . warn ( '[%s] could not be updated and its status will be reverted soon. Error: %s.' , accessory . displayName , err . message )
238
253
}
239
254
}
240
255
241
256
async internalColourUpdate ( accessory , value , callback ) {
242
257
callback ( )
243
258
try {
259
+ if ( ! (
260
+ accessory . context . controllable &&
261
+ accessory . context . supportedCmds . includes ( 'color' )
262
+ ) ) {
263
+ throw new Error ( 'model [' + accessory . context . gvModel + '] does not support command [color]' )
264
+ }
244
265
const lightService = accessory . getService ( Service . Lightbulb )
245
266
const curSat = lightService . getCharacteristic ( Characteristic . Saturation ) . value
246
267
const newRGB = cConvert . hsv . rgb ( value , curSat , 100 )
@@ -258,7 +279,7 @@ class Govee {
258
279
}
259
280
this . ignoreNextSync = true
260
281
} catch ( err ) {
261
- this . log . warn ( '[%s] could not be updated and its status will be reverted soon. Error: \n %s.' , accessory . displayName , err )
282
+ this . log . warn ( '[%s] could not be updated and its status will be reverted soon. Error: %s.' , accessory . displayName , err . message )
262
283
}
263
284
}
264
285
}
0 commit comments