@switchbot/homebridge-switchbot 1.3.1-beta.8 → 1.4.1-beta.1

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 (102) hide show
  1. package/CHANGELOG.md +5 -2
  2. package/config.schema.json +0 -22
  3. package/dist/devices/bots.d.ts +3 -1
  4. package/dist/devices/bots.d.ts.map +1 -1
  5. package/dist/devices/bots.js +114 -103
  6. package/dist/devices/bots.js.map +1 -1
  7. package/dist/devices/colorbulb.d.ts +2 -1
  8. package/dist/devices/colorbulb.d.ts.map +1 -1
  9. package/dist/devices/colorbulb.js +25 -21
  10. package/dist/devices/colorbulb.js.map +1 -1
  11. package/dist/devices/contact.d.ts +1 -1
  12. package/dist/devices/contact.d.ts.map +1 -1
  13. package/dist/devices/contact.js +5 -15
  14. package/dist/devices/contact.js.map +1 -1
  15. package/dist/devices/curtains.d.ts +1 -1
  16. package/dist/devices/curtains.d.ts.map +1 -1
  17. package/dist/devices/curtains.js +7 -16
  18. package/dist/devices/curtains.js.map +1 -1
  19. package/dist/devices/humidifiers.d.ts +2 -1
  20. package/dist/devices/humidifiers.d.ts.map +1 -1
  21. package/dist/devices/humidifiers.js +18 -26
  22. package/dist/devices/humidifiers.js.map +1 -1
  23. package/dist/devices/indoorcam.d.ts +1 -1
  24. package/dist/devices/indoorcam.d.ts.map +1 -1
  25. package/dist/devices/indoorcam.js +5 -5
  26. package/dist/devices/indoorcam.js.map +1 -1
  27. package/dist/devices/meters.d.ts +6 -12
  28. package/dist/devices/meters.d.ts.map +1 -1
  29. package/dist/devices/meters.js +58 -62
  30. package/dist/devices/meters.js.map +1 -1
  31. package/dist/devices/motion.d.ts +1 -1
  32. package/dist/devices/motion.d.ts.map +1 -1
  33. package/dist/devices/motion.js +4 -9
  34. package/dist/devices/motion.js.map +1 -1
  35. package/dist/devices/plugs.d.ts +3 -1
  36. package/dist/devices/plugs.d.ts.map +1 -1
  37. package/dist/devices/plugs.js +39 -26
  38. package/dist/devices/plugs.js.map +1 -1
  39. package/dist/irdevices/airconditioners.d.ts +3 -1
  40. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  41. package/dist/irdevices/airconditioners.js +20 -9
  42. package/dist/irdevices/airconditioners.js.map +1 -1
  43. package/dist/irdevices/airpurifiers.d.ts +3 -1
  44. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  45. package/dist/irdevices/airpurifiers.js +20 -6
  46. package/dist/irdevices/airpurifiers.js.map +1 -1
  47. package/dist/irdevices/cameras.d.ts +2 -1
  48. package/dist/irdevices/cameras.d.ts.map +1 -1
  49. package/dist/irdevices/cameras.js +12 -3
  50. package/dist/irdevices/cameras.js.map +1 -1
  51. package/dist/irdevices/fans.d.ts +2 -1
  52. package/dist/irdevices/fans.d.ts.map +1 -1
  53. package/dist/irdevices/fans.js +12 -5
  54. package/dist/irdevices/fans.js.map +1 -1
  55. package/dist/irdevices/lights.d.ts +2 -1
  56. package/dist/irdevices/lights.d.ts.map +1 -1
  57. package/dist/irdevices/lights.js +12 -3
  58. package/dist/irdevices/lights.js.map +1 -1
  59. package/dist/irdevices/others.d.ts +2 -1
  60. package/dist/irdevices/others.d.ts.map +1 -1
  61. package/dist/irdevices/others.js +12 -3
  62. package/dist/irdevices/others.js.map +1 -1
  63. package/dist/irdevices/tvs.d.ts +2 -1
  64. package/dist/irdevices/tvs.d.ts.map +1 -1
  65. package/dist/irdevices/tvs.js +12 -4
  66. package/dist/irdevices/tvs.js.map +1 -1
  67. package/dist/irdevices/vacuumcleaners.d.ts +2 -1
  68. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  69. package/dist/irdevices/vacuumcleaners.js +12 -3
  70. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  71. package/dist/irdevices/waterheaters.d.ts +2 -1
  72. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  73. package/dist/irdevices/waterheaters.js +12 -3
  74. package/dist/irdevices/waterheaters.js.map +1 -1
  75. package/dist/platform.d.ts +1 -0
  76. package/dist/platform.d.ts.map +1 -1
  77. package/dist/platform.js +50 -46
  78. package/dist/platform.js.map +1 -1
  79. package/dist/settings.d.ts +5 -5
  80. package/dist/settings.d.ts.map +1 -1
  81. package/dist/settings.js.map +1 -1
  82. package/package.json +7 -7
  83. package/src/devices/bots.ts +95 -83
  84. package/src/devices/colorbulb.ts +26 -22
  85. package/src/devices/contact.ts +6 -16
  86. package/src/devices/curtains.ts +8 -17
  87. package/src/devices/humidifiers.ts +20 -27
  88. package/src/devices/indoorcam.ts +6 -6
  89. package/src/devices/meters.ts +60 -64
  90. package/src/devices/motion.ts +5 -10
  91. package/src/devices/plugs.ts +43 -28
  92. package/src/irdevices/airconditioners.ts +21 -10
  93. package/src/irdevices/airpurifiers.ts +22 -7
  94. package/src/irdevices/cameras.ts +14 -4
  95. package/src/irdevices/fans.ts +14 -6
  96. package/src/irdevices/lights.ts +14 -4
  97. package/src/irdevices/others.ts +14 -4
  98. package/src/irdevices/tvs.ts +14 -5
  99. package/src/irdevices/vacuumcleaners.ts +14 -4
  100. package/src/irdevices/waterheaters.ts +14 -4
  101. package/src/platform.ts +43 -37
  102. package/src/settings.ts +6 -5
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { SwitchBotPlatform } from '../platform';
3
3
  import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
+ import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -14,9 +14,11 @@ export class AirConditioner {
14
14
 
15
15
  // Characteristic Values
16
16
  Active!: CharacteristicValue;
17
+ ActiveCached!: CharacteristicValue;
17
18
  RotationSpeed!: CharacteristicValue;
18
19
  LastTemperature!: CharacteristicValue;
19
20
  CurrentTemperature!: CharacteristicValue;
21
+ CurrentTemperatureCached!: CharacteristicValue;
20
22
  TargetHeaterCoolerState?: CharacteristicValue;
21
23
  CurrentHeaterCoolerState!: CharacteristicValue;
22
24
  HeatingThresholdTemperature?: CharacteristicValue;
@@ -41,7 +43,17 @@ export class AirConditioner {
41
43
  private accessory: PlatformAccessory,
42
44
  public device: irdevice & irDevicesConfig,
43
45
  ) {
44
- this.CurrentTemperature = 24;
46
+ // default placeholders
47
+ if (this.Active === undefined) {
48
+ this.Active = this.platform.Characteristic.Active.INACTIVE;
49
+ } else {
50
+ this.Active = this.accessory.context.Active;
51
+ }
52
+ if (this.CurrentTemperature === undefined) {
53
+ this.CurrentTemperature = 24;
54
+ } else {
55
+ this.CurrentTemperature = this.accessory.context.CurrentTemperature;
56
+ }
45
57
 
46
58
  // set accessory information
47
59
  accessory
@@ -161,6 +173,8 @@ export class AirConditioner {
161
173
  this.platform.device(`Air Conditioner: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
162
174
  }
163
175
  this.Active = value;
176
+ this.ActiveCached = this.Active;
177
+ this.accessory.context.Active = this.ActiveCached;
164
178
  }
165
179
 
166
180
  private updateHomeKitCharacteristics() {
@@ -349,6 +363,8 @@ export class AirConditioner {
349
363
  const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
350
364
  this.platform.log.error(`Air Conditioner: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
351
365
  this.statusCode(push);
366
+ this.CurrentTemperatureCached = this.CurrentTemperature;
367
+ this.accessory.context.CurrentTemperature = this.CurrentTemperatureCached;
352
368
  this.updateHomeKitCharacteristics();
353
369
  } catch (e: any) {
354
370
  this.platform.log.error(`Air Conditioner: ${this.accessory.displayName} failed pushChanges`);
@@ -360,7 +376,7 @@ export class AirConditioner {
360
376
  this.platform.log.error(`Air Conditioner: ${this.accessory.displayName} failed pushChanges,`
361
377
  + ` Error: ${JSON.stringify(e)}`);
362
378
  }
363
- this.apiError(e);
379
+ this.apiError();
364
380
  }
365
381
  }
366
382
 
@@ -393,12 +409,7 @@ export class AirConditioner {
393
409
  }
394
410
  }
395
411
 
396
- public apiError(e: any) {
397
- this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
398
- this.service.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
399
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
400
- this.service.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, e);
401
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, e);
402
- this.service.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, e);
412
+ public apiError() {
413
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
403
414
  }
404
415
  }
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { SwitchBotPlatform } from '../platform';
3
3
  import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
+ import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -15,11 +15,13 @@ export class AirPurifier {
15
15
  // Characteristic Values
16
16
  Active!: CharacteristicValue;
17
17
  APActive!: CharacteristicValue;
18
+ ActiveCached!: CharacteristicValue;
18
19
  CurrentAPTemp!: CharacteristicValue;
19
20
  CurrentAPMode!: CharacteristicValue;
20
21
  RotationSpeed!: CharacteristicValue;
21
22
  CurrentAPFanSpeed!: CharacteristicValue;
22
23
  CurrentTemperature!: CharacteristicValue;
24
+ CurrentTemperatureCached!: CharacteristicValue;
23
25
  CurrentAirPurifierState!: CharacteristicValue;
24
26
  CurrentHeaterCoolerState!: CharacteristicValue;
25
27
 
@@ -42,6 +44,18 @@ export class AirPurifier {
42
44
  private accessory: PlatformAccessory,
43
45
  public device: irdevice & irDevicesConfig,
44
46
  ) {
47
+ // default placeholders
48
+ if (this.Active === undefined) {
49
+ this.Active = this.platform.Characteristic.Active.INACTIVE;
50
+ } else {
51
+ this.Active = this.accessory.context.Active;
52
+ }
53
+ if (this.CurrentTemperature === undefined) {
54
+ this.CurrentTemperature = 24;
55
+ } else {
56
+ this.CurrentTemperature = this.accessory.context.CurrentTemperature;
57
+ }
58
+
45
59
  // set accessory information
46
60
  accessory
47
61
  .getService(this.platform.Service.AccessoryInformation)!
@@ -81,6 +95,8 @@ export class AirPurifier {
81
95
  this.pushAirConditionerOnChanges();
82
96
  }
83
97
  this.Active = value;
98
+ this.ActiveCached = this.Active;
99
+ this.accessory.context.Active = this.ActiveCached;
84
100
  }
85
101
 
86
102
  private updateHomeKitCharacteristics() {
@@ -210,6 +226,8 @@ export class AirPurifier {
210
226
  this.platform.debug(`Air Purifier: ${this.accessory.displayName} pushChanges: ${push.data}`);
211
227
  this.statusCode(push);
212
228
  this.updateHomeKitCharacteristics();
229
+ this.CurrentTemperatureCached = this.CurrentTemperature;
230
+ this.accessory.context.CurrentTemperature = this.CurrentTemperatureCached;
213
231
  } catch (e: any) {
214
232
  this.platform.log.error(`Air Purifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
215
233
  if (this.deviceDebug) {
@@ -220,7 +238,7 @@ export class AirPurifier {
220
238
  this.platform.log.error(`Air Purifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
221
239
  + ` Error: ${JSON.stringify(e)}`);
222
240
  }
223
- this.apiError(e);
241
+ this.apiError();
224
242
  }
225
243
  }
226
244
 
@@ -253,10 +271,7 @@ export class AirPurifier {
253
271
  }
254
272
  }
255
273
 
256
- public apiError(e: any) {
257
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, e);
258
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, e);
259
- this.service.updateCharacteristic(this.platform.Characteristic.TargetAirPurifierState, e);
260
- this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
274
+ public apiError() {
275
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
261
276
  }
262
277
  }
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { SwitchBotPlatform } from '../platform';
3
3
  import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
+ import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -14,6 +14,7 @@ export class Camera {
14
14
 
15
15
  // Characteristic Values
16
16
  On!: CharacteristicValue;
17
+ OnCached!: CharacteristicValue;
17
18
 
18
19
  // Config
19
20
  private readonly deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
@@ -24,6 +25,13 @@ export class Camera {
24
25
  private accessory: PlatformAccessory,
25
26
  public device: irdevice & irDevicesConfig,
26
27
  ) {
28
+ // default placeholders
29
+ if (this.On === undefined) {
30
+ this.On = false;
31
+ } else {
32
+ this.On = this.accessory.context.On;
33
+ }
34
+
27
35
  // set accessory information
28
36
  accessory
29
37
  .getService(this.platform.Service.AccessoryInformation)!
@@ -110,6 +118,8 @@ export class Camera {
110
118
  this.platform.debug(`Camera: ${this.accessory.displayName} pushChanges: ${push.data}`);
111
119
  this.statusCode(push);
112
120
  this.updateHomeKitCharacteristics();
121
+ this.OnCached = this.On;
122
+ this.accessory.context.On = this.OnCached;
113
123
  } catch (e: any) {
114
124
  this.platform.log.error(`Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
115
125
  if (this.deviceDebug) {
@@ -120,7 +130,7 @@ export class Camera {
120
130
  this.platform.log.error(`Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
121
131
  + ` Error: ${JSON.stringify(e)}`);
122
132
  }
123
- this.apiError(e);
133
+ this.apiError();
124
134
  }
125
135
  }
126
136
 
@@ -153,7 +163,7 @@ export class Camera {
153
163
  }
154
164
  }
155
165
 
156
- public apiError(e: any) {
157
- this.service.updateCharacteristic(this.platform.Characteristic.On, e);
166
+ public apiError() {
167
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
158
168
  }
159
169
  }
@@ -1,6 +1,6 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { SwitchBotPlatform } from '../platform';
3
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
3
+ import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
4
4
  import { DeviceURL, irdevice, deviceStatusResponse, irDevicesConfig, payload } from '../settings';
5
5
 
6
6
  /**
@@ -14,6 +14,7 @@ export class Fan {
14
14
 
15
15
  // Characteristic Values
16
16
  Active!: CharacteristicValue;
17
+ ActiveCached!: CharacteristicValue;
17
18
  ActiveIdentifier!: CharacteristicValue;
18
19
  RotationSpeed!: CharacteristicValue;
19
20
  SwingMode!: CharacteristicValue;
@@ -34,6 +35,13 @@ export class Fan {
34
35
  private accessory: PlatformAccessory,
35
36
  public device: irdevice & irDevicesConfig,
36
37
  ) {
38
+ // default placeholders
39
+ if (this.Active === undefined) {
40
+ this.Active = this.platform.Characteristic.Active.INACTIVE;
41
+ } else {
42
+ this.Active = this.accessory.context.Active;
43
+ }
44
+
37
45
  // set accessory information
38
46
  accessory
39
47
  .getService(this.platform.Service.AccessoryInformation)!
@@ -164,6 +172,8 @@ export class Fan {
164
172
  this.pushFanOnChanges();
165
173
  }
166
174
  this.Active = value;
175
+ this.ActiveCached = this.Active;
176
+ this.accessory.context.Active = this.ActiveCached;
167
177
  }
168
178
 
169
179
  /**
@@ -242,7 +252,7 @@ export class Fan {
242
252
  this.platform.log.error(`Fan: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
243
253
  + ` Error: ${JSON.stringify(e)}`);
244
254
  }
245
- this.apiError(e);
255
+ this.apiError();
246
256
  }
247
257
  }
248
258
 
@@ -275,9 +285,7 @@ export class Fan {
275
285
  }
276
286
  }
277
287
 
278
- public apiError(e: any) {
279
- this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
280
- this.service.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
281
- this.service.updateCharacteristic(this.platform.Characteristic.SwingMode, e);
288
+ public apiError() {
289
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
282
290
  }
283
291
  }
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { SwitchBotPlatform } from '../platform';
3
3
  import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
+ import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -14,6 +14,7 @@ export class Light {
14
14
 
15
15
  // Characteristic Values
16
16
  On!: CharacteristicValue;
17
+ OnCached!: CharacteristicValue;
17
18
 
18
19
  // Config
19
20
  private readonly deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
@@ -24,6 +25,13 @@ export class Light {
24
25
  private accessory: PlatformAccessory,
25
26
  public device: irdevice & irDevicesConfig,
26
27
  ) {
28
+ // default placeholders
29
+ if (this.On === undefined) {
30
+ this.On = false;
31
+ } else {
32
+ this.On = this.accessory.context.On;
33
+ }
34
+
27
35
  // set accessory information
28
36
  accessory
29
37
  .getService(this.platform.Service.AccessoryInformation)!
@@ -142,6 +150,8 @@ export class Light {
142
150
  const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
143
151
  this.platform.debug(`Light: ${this.accessory.displayName} pushChanges: ${push.data}`);
144
152
  this.statusCode(push);
153
+ this.OnCached = this.On;
154
+ this.accessory.context.On = this.OnCached;
145
155
  this.updateHomeKitCharacteristics();
146
156
  } catch (e: any) {
147
157
  this.platform.log.error(`Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
@@ -153,7 +163,7 @@ export class Light {
153
163
  this.platform.log.error(`Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
154
164
  + ` Error: ${JSON.stringify(e)}`);
155
165
  }
156
- this.apiError(e);
166
+ this.apiError();
157
167
  }
158
168
  }
159
169
 
@@ -187,7 +197,7 @@ export class Light {
187
197
  }
188
198
  }
189
199
 
190
- public apiError(e: any) {
191
- this.service.updateCharacteristic(this.platform.Characteristic.On, e);
200
+ public apiError() {
201
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
192
202
  }
193
203
  }
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { SwitchBotPlatform } from '../platform';
3
3
  import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
+ import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -14,6 +14,7 @@ export class Others {
14
14
 
15
15
  // Characteristic Values
16
16
  Active!: CharacteristicValue;
17
+ ActiveCached!: CharacteristicValue;
17
18
 
18
19
  // Config
19
20
  private readonly deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
@@ -24,6 +25,13 @@ export class Others {
24
25
  private accessory: PlatformAccessory,
25
26
  public device: irdevice & irDevicesConfig,
26
27
  ) {
28
+ // default placeholders
29
+ if (this.Active === undefined) {
30
+ this.Active = this.platform.Characteristic.Active.INACTIVE;
31
+ } else {
32
+ this.Active = this.accessory.context.Active;
33
+ }
34
+
27
35
  // set accessory information
28
36
  accessory
29
37
  .getService(this.platform.Service.AccessoryInformation)!
@@ -54,6 +62,8 @@ export class Others {
54
62
  this.pushOffChanges();
55
63
  }
56
64
  this.Active = value;
65
+ this.ActiveCached = this.Active;
66
+ this.accessory.context.Active = this.ActiveCached;
57
67
  }
58
68
 
59
69
  private updateHomeKitCharacteristics() {
@@ -141,7 +151,7 @@ export class Others {
141
151
  this.platform.log.error(`Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
142
152
  + ` Error: ${JSON.stringify(e)}`);
143
153
  }
144
- this.apiError(e);
154
+ this.apiError();
145
155
  }
146
156
  }
147
157
 
@@ -174,7 +184,7 @@ export class Others {
174
184
  }
175
185
  }
176
186
 
177
- public apiError(e: any) {
178
- this.service?.updateCharacteristic(this.platform.Characteristic.Active, e);
187
+ public apiError() {
188
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
179
189
  }
180
190
  }
@@ -1,6 +1,6 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { SwitchBotPlatform } from '../platform';
3
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
3
+ import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
4
4
  import { DeviceURL, irdevice, deviceStatusResponse, irDevicesConfig, payload } from '../settings';
5
5
 
6
6
  /**
@@ -15,6 +15,7 @@ export class TV {
15
15
 
16
16
  // Characteristic Values
17
17
  Active!: CharacteristicValue;
18
+ ActiveCached!: CharacteristicValue;
18
19
  ActiveIdentifier!: CharacteristicValue;
19
20
 
20
21
  // Others
@@ -29,6 +30,13 @@ export class TV {
29
30
  private accessory: PlatformAccessory,
30
31
  public device: irdevice & irDevicesConfig,
31
32
  ) {
33
+ // default placeholders
34
+ if (this.Active === undefined) {
35
+ this.Active = this.platform.Characteristic.Active.INACTIVE;
36
+ } else {
37
+ this.Active = this.accessory.context.Active;
38
+ }
39
+
32
40
  // set accessory information
33
41
  accessory
34
42
  .getService(this.platform.Service.AccessoryInformation)!
@@ -207,6 +215,8 @@ export class TV {
207
215
  this.pushTvOnChanges();
208
216
  }
209
217
  this.Active = value;
218
+ this.ActiveCached = this.Active;
219
+ this.accessory.context.Active = this.ActiveCached;
210
220
  }
211
221
  }
212
222
 
@@ -357,7 +367,7 @@ export class TV {
357
367
  this.platform.log.error(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
358
368
  + ` Error: ${JSON.stringify(e)}`);
359
369
  }
360
- this.apiError(e);
370
+ this.apiError();
361
371
  }
362
372
  }
363
373
 
@@ -392,8 +402,7 @@ export class TV {
392
402
  }
393
403
  }
394
404
 
395
- public apiError(e: any) {
396
- this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
397
- this.service.updateCharacteristic(this.platform.Characteristic.ActiveIdentifier, e);
405
+ public apiError() {
406
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
398
407
  }
399
408
  }
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { SwitchBotPlatform } from '../platform';
3
3
  import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
+ import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -14,6 +14,7 @@ export class VacuumCleaner {
14
14
 
15
15
  // Characteristic Values
16
16
  On!: CharacteristicValue;
17
+ OnCached!: CharacteristicValue;
17
18
 
18
19
  // Config
19
20
  private readonly deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
@@ -24,6 +25,13 @@ export class VacuumCleaner {
24
25
  private accessory: PlatformAccessory,
25
26
  public device: irdevice & irDevicesConfig,
26
27
  ) {
28
+ // default placeholders
29
+ if (this.On === undefined) {
30
+ this.On = false;
31
+ } else {
32
+ this.On = this.accessory.context.On;
33
+ }
34
+
27
35
  // set accessory information
28
36
  accessory
29
37
  .getService(this.platform.Service.AccessoryInformation)!
@@ -109,6 +117,8 @@ export class VacuumCleaner {
109
117
  const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
110
118
  this.platform.debug(`Vacuum Cleaner: ${this.accessory.displayName} pushChanges: ${push.data}`);
111
119
  this.statusCode(push);
120
+ this.OnCached = this.On;
121
+ this.accessory.context.On = this.OnCached;
112
122
  this.updateHomeKitCharacteristics();
113
123
  } catch (e: any) {
114
124
  this.platform.log.error(`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
@@ -120,7 +130,7 @@ export class VacuumCleaner {
120
130
  this.platform.log.error(`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
121
131
  + ` Error: ${JSON.stringify(e)}`);
122
132
  }
123
- this.apiError(e);
133
+ this.apiError();
124
134
  }
125
135
  }
126
136
 
@@ -153,7 +163,7 @@ export class VacuumCleaner {
153
163
  }
154
164
  }
155
165
 
156
- public apiError(e: any) {
157
- this.service.updateCharacteristic(this.platform.Characteristic.On, e);
166
+ public apiError() {
167
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
158
168
  }
159
169
  }
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { SwitchBotPlatform } from '../platform';
3
3
  import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
+ import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -14,6 +14,7 @@ export class WaterHeater {
14
14
 
15
15
  // Characteristic Values
16
16
  Active!: CharacteristicValue;
17
+ ActiveCached!: CharacteristicValue;
17
18
 
18
19
  // Config
19
20
  private readonly deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
@@ -24,6 +25,13 @@ export class WaterHeater {
24
25
  private accessory: PlatformAccessory,
25
26
  public device: irdevice & irDevicesConfig,
26
27
  ) {
28
+ // default placeholders
29
+ if (this.Active === undefined) {
30
+ this.Active = this.platform.Characteristic.Active.INACTIVE;
31
+ } else {
32
+ this.Active = this.accessory.context.Active;
33
+ }
34
+
27
35
  // set accessory information
28
36
  accessory
29
37
  .getService(this.platform.Service.AccessoryInformation)!
@@ -71,6 +79,8 @@ export class WaterHeater {
71
79
  this.service.setCharacteristic(this.platform.Characteristic.InUse, this.platform.Characteristic.InUse.IN_USE);
72
80
  }
73
81
  this.Active = value;
82
+ this.ActiveCached = this.Active;
83
+ this.accessory.context.Active = this.ActiveCached;
74
84
  }
75
85
 
76
86
  private updateHomeKitCharacteristics() {
@@ -134,7 +144,7 @@ export class WaterHeater {
134
144
  this.platform.log.error(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
135
145
  + ` Error: ${JSON.stringify(e)}`);
136
146
  }
137
- this.apiError(e);
147
+ this.apiError();
138
148
  }
139
149
  }
140
150
 
@@ -167,7 +177,7 @@ export class WaterHeater {
167
177
  }
168
178
  }
169
179
 
170
- public apiError(e: any) {
171
- this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
180
+ public apiError() {
181
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
172
182
  }
173
183
  }
package/src/platform.ts CHANGED
@@ -50,6 +50,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
50
50
  return;
51
51
  }
52
52
 
53
+ this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
54
+
53
55
  // HOOBS notice
54
56
  if (__dirname.includes('hoobs')) {
55
57
  this.log.warn('This plugin has not been tested under HOOBS, it is highly recommended that ' +
@@ -267,43 +269,47 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
267
269
  this.log.error('Neither SwitchBot OpenToken or Device Config are not set.');
268
270
  }
269
271
  } catch (e: any) {
270
- if (e.message.includes('400')) {
271
- this.log.error('Failed to Discover Devices: Bad Request');
272
- this.debug('The client has issued an invalid request. This is commonly used to specify validation errors in a request payload.');
273
- } else if (e.message.includes('401')) {
274
- this.log.error('Failed to Discover Devices: Unauthorized Request');
275
- this.debug('Authorization for the API is required, but the request has not been authenticated.');
276
- } else if (e.message.includes('403')) {
277
- this.log.error('Failed to Discover Devices: Forbidden Request');
278
- this.debug('The request has been authenticated but does not have appropriate permissions, or a requested resource is not found.');
279
- } else if (e.message.includes('404')) {
280
- this.log.error('Failed to Discover Devices: Requst Not Found');
281
- this.debug('Specifies the requested path does not exist.');
282
- } else if (e.message.includes('406')) {
283
- this.log.error('Failed to Discover Devices: Request Not Acceptable');
284
- this.debug('The client has requested a MIME type via the Accept header for a value not supported by the server.');
285
- } else if (e.message.includes('415')) {
286
- this.log.error('Failed to Discover Devices: Unsupported Requst Header');
287
- this.debug('The client has defined a contentType header that is not supported by the server.');
288
- } else if (e.message.includes('422')) {
289
- this.log.error('Failed to Discover Devices: Unprocessable Entity');
290
- this.debug('The client has made a valid request, but the server cannot process it.'
291
- + ' This is often used for APIs for which certain limits have been exceeded.');
292
- } else if (e.message.includes('429')) {
293
- this.log.error('Failed to Discover Devices: Too Many Requests');
294
- this.debug('The client has exceeded the number of requests allowed for a given time window.');
295
- } else if (e.message.includes('500')) {
296
- this.log.error('Failed to Discover Devices: Internal Server Error');
297
- this.debug('An unexpected error on the SmartThings servers has occurred. These errors should be rare.');
298
- } else {
299
- this.log.error('Failed to Discover Devices');
300
- }
301
- if (this.config.options?.debug === 'device') {
302
- this.log.error(`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}`);
303
- }
304
- if (this.config.options?.debug === 'debug' || this.debugMode) {
305
- this.log.error(`Failed to Discover Devices, Error: ${JSON.stringify(e)}`);
306
- }
272
+ this.deviceError(e);
273
+ }
274
+ }
275
+
276
+ deviceError(e: any) {
277
+ if (e.message.includes('400')) {
278
+ this.log.error('Failed to Discover Devices: Bad Request');
279
+ this.debug('The client has issued an invalid request. This is commonly used to specify validation errors in a request payload.');
280
+ } else if (e.message.includes('401')) {
281
+ this.log.error('Failed to Discover Devices: Unauthorized Request');
282
+ this.debug('Authorization for the API is required, but the request has not been authenticated.');
283
+ } else if (e.message.includes('403')) {
284
+ this.log.error('Failed to Discover Devices: Forbidden Request');
285
+ this.debug('The request has been authenticated but does not have appropriate permissions, or a requested resource is not found.');
286
+ } else if (e.message.includes('404')) {
287
+ this.log.error('Failed to Discover Devices: Requst Not Found');
288
+ this.debug('Specifies the requested path does not exist.');
289
+ } else if (e.message.includes('406')) {
290
+ this.log.error('Failed to Discover Devices: Request Not Acceptable');
291
+ this.debug('The client has requested a MIME type via the Accept header for a value not supported by the server.');
292
+ } else if (e.message.includes('415')) {
293
+ this.log.error('Failed to Discover Devices: Unsupported Requst Header');
294
+ this.debug('The client has defined a contentType header that is not supported by the server.');
295
+ } else if (e.message.includes('422')) {
296
+ this.log.error('Failed to Discover Devices: Unprocessable Entity');
297
+ this.debug('The client has made a valid request, but the server cannot process it.'
298
+ + ' This is often used for APIs for which certain limits have been exceeded.');
299
+ } else if (e.message.includes('429')) {
300
+ this.log.error('Failed to Discover Devices: Too Many Requests');
301
+ this.debug('The client has exceeded the number of requests allowed for a given time window.');
302
+ } else if (e.message.includes('500')) {
303
+ this.log.error('Failed to Discover Devices: Internal Server Error');
304
+ this.debug('An unexpected error on the SmartThings servers has occurred. These errors should be rare.');
305
+ } else {
306
+ this.log.error('Failed to Discover Devices');
307
+ }
308
+ if (this.config.options?.debug === 'device') {
309
+ this.log.error(`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}`);
310
+ }
311
+ if (this.config.options?.debug === 'debug' || this.debugMode) {
312
+ this.log.error(`Failed to Discover Devices, Error: ${JSON.stringify(e)}`);
307
313
  }
308
314
  }
309
315