@switchbot/homebridge-switchbot 1.3.1-beta.1 → 1.3.1-beta.13

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 (94) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/config.schema.json +12 -25
  3. package/dist/devices/bots.d.ts +2 -0
  4. package/dist/devices/bots.d.ts.map +1 -1
  5. package/dist/devices/bots.js +136 -95
  6. package/dist/devices/bots.js.map +1 -1
  7. package/dist/devices/colorbulb.d.ts +1 -0
  8. package/dist/devices/colorbulb.d.ts.map +1 -1
  9. package/dist/devices/colorbulb.js +18 -4
  10. package/dist/devices/colorbulb.js.map +1 -1
  11. package/dist/devices/contact.js +1 -1
  12. package/dist/devices/contact.js.map +1 -1
  13. package/dist/devices/curtains.d.ts.map +1 -1
  14. package/dist/devices/curtains.js +6 -1
  15. package/dist/devices/curtains.js.map +1 -1
  16. package/dist/devices/humidifiers.d.ts +1 -0
  17. package/dist/devices/humidifiers.d.ts.map +1 -1
  18. package/dist/devices/humidifiers.js +15 -2
  19. package/dist/devices/humidifiers.js.map +1 -1
  20. package/dist/devices/indoorcam.d.ts.map +1 -1
  21. package/dist/devices/indoorcam.js +12 -1
  22. package/dist/devices/indoorcam.js.map +1 -1
  23. package/dist/devices/meters.d.ts +5 -11
  24. package/dist/devices/meters.d.ts.map +1 -1
  25. package/dist/devices/meters.js +49 -47
  26. package/dist/devices/meters.js.map +1 -1
  27. package/dist/devices/plugs.d.ts +2 -0
  28. package/dist/devices/plugs.d.ts.map +1 -1
  29. package/dist/devices/plugs.js +41 -16
  30. package/dist/devices/plugs.js.map +1 -1
  31. package/dist/irdevices/airconditioners.d.ts +2 -0
  32. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  33. package/dist/irdevices/airconditioners.js +17 -1
  34. package/dist/irdevices/airconditioners.js.map +1 -1
  35. package/dist/irdevices/airpurifiers.d.ts +2 -0
  36. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  37. package/dist/irdevices/airpurifiers.js +17 -0
  38. package/dist/irdevices/airpurifiers.js.map +1 -1
  39. package/dist/irdevices/cameras.d.ts +1 -0
  40. package/dist/irdevices/cameras.d.ts.map +1 -1
  41. package/dist/irdevices/cameras.js +9 -0
  42. package/dist/irdevices/cameras.js.map +1 -1
  43. package/dist/irdevices/fans.d.ts +1 -0
  44. package/dist/irdevices/fans.d.ts.map +1 -1
  45. package/dist/irdevices/fans.js +9 -0
  46. package/dist/irdevices/fans.js.map +1 -1
  47. package/dist/irdevices/lights.d.ts +1 -0
  48. package/dist/irdevices/lights.d.ts.map +1 -1
  49. package/dist/irdevices/lights.js +9 -0
  50. package/dist/irdevices/lights.js.map +1 -1
  51. package/dist/irdevices/others.d.ts +1 -0
  52. package/dist/irdevices/others.d.ts.map +1 -1
  53. package/dist/irdevices/others.js +9 -0
  54. package/dist/irdevices/others.js.map +1 -1
  55. package/dist/irdevices/tvs.d.ts +1 -0
  56. package/dist/irdevices/tvs.d.ts.map +1 -1
  57. package/dist/irdevices/tvs.js +9 -0
  58. package/dist/irdevices/tvs.js.map +1 -1
  59. package/dist/irdevices/vacuumcleaners.d.ts +1 -0
  60. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  61. package/dist/irdevices/vacuumcleaners.js +9 -0
  62. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  63. package/dist/irdevices/waterheaters.d.ts +1 -0
  64. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  65. package/dist/irdevices/waterheaters.js +9 -0
  66. package/dist/irdevices/waterheaters.js.map +1 -1
  67. package/dist/platform.d.ts +2 -0
  68. package/dist/platform.d.ts.map +1 -1
  69. package/dist/platform.js +106 -20
  70. package/dist/platform.js.map +1 -1
  71. package/dist/settings.d.ts +6 -5
  72. package/dist/settings.d.ts.map +1 -1
  73. package/dist/settings.js.map +1 -1
  74. package/homebridge-ui/public/index.html +5 -1
  75. package/package.json +7 -7
  76. package/src/devices/bots.ts +124 -85
  77. package/src/devices/colorbulb.ts +18 -4
  78. package/src/devices/contact.ts +1 -1
  79. package/src/devices/curtains.ts +7 -2
  80. package/src/devices/humidifiers.ts +17 -3
  81. package/src/devices/indoorcam.ts +13 -2
  82. package/src/devices/meters.ts +50 -48
  83. package/src/devices/plugs.ts +45 -18
  84. package/src/irdevices/airconditioners.ts +17 -1
  85. package/src/irdevices/airpurifiers.ts +18 -0
  86. package/src/irdevices/cameras.ts +10 -0
  87. package/src/irdevices/fans.ts +10 -0
  88. package/src/irdevices/lights.ts +10 -0
  89. package/src/irdevices/others.ts +10 -0
  90. package/src/irdevices/tvs.ts +10 -0
  91. package/src/irdevices/vacuumcleaners.ts +10 -0
  92. package/src/irdevices/waterheaters.ts +10 -0
  93. package/src/platform.ts +104 -20
  94. package/src/settings.ts +7 -5
@@ -3,7 +3,7 @@ import { interval, Subject } from 'rxjs';
3
3
  import { skipWhile } from 'rxjs/operators';
4
4
  import { SwitchBotPlatform } from '../platform';
5
5
  import { Service, PlatformAccessory, Units, CharacteristicValue } from 'homebridge';
6
- import { DeviceURL, device, devicesConfig, serviceData, ad, switchbot, deviceStatusResponse } from '../settings';
6
+ import { DeviceURL, device, devicesConfig, serviceData, ad, switchbot, deviceStatusResponse, temperature } from '../settings';
7
7
 
8
8
  /**
9
9
  * Platform Accessory
@@ -18,8 +18,11 @@ export class Meter {
18
18
 
19
19
  // Characteristic Values
20
20
  CurrentRelativeHumidity!: CharacteristicValue;
21
+ CurrentRelativeHumidityCached!: CharacteristicValue;
21
22
  CurrentTemperature!: CharacteristicValue;
23
+ CurrentTemperatureCached!: CharacteristicValue;
22
24
  BatteryLevel!: CharacteristicValue;
25
+ BatteryLevelCached!: CharacteristicValue;
23
26
  ChargingState!: CharacteristicValue;
24
27
  StatusLowBattery!: CharacteristicValue;
25
28
  Active!: CharacteristicValue;
@@ -32,10 +35,9 @@ export class Meter {
32
35
  connected?: boolean;
33
36
  switchbot!: switchbot;
34
37
  serviceData!: serviceData;
38
+ temperature!: temperature['c'];
35
39
  battery!: serviceData['battery'];
36
40
  humidity!: serviceData['humidity'];
37
- fahrenheit!: serviceData['fahrenheit'];
38
- temperature!: serviceData['temperature'];
39
41
 
40
42
  // Config
41
43
  private readonly deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
@@ -51,15 +53,31 @@ export class Meter {
51
53
  public device: device & devicesConfig,
52
54
  ) {
53
55
  // Meter Config
54
- this.platform.device(`Meter: ${this.accessory.displayName} Config: (ble: ${device.ble}, unit: ${device.meter?.unit},`
55
- + ` hide_temperature: ${device.meter?.hide_temperature}, hide_humidity: ${device.meter?.hide_humidity})`);
56
+ this.platform.device(`Meter: ${this.accessory.displayName} Config: (ble: ${device.ble}, hide_temperature: ${device.meter?.hide_temperature},`
57
+ + ` hide_humidity: ${device.meter?.hide_humidity})`);
56
58
 
57
59
  // default placeholders
58
- this.BatteryLevel = 0;
59
- this.ChargingState = 2;
60
- this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
61
- this.CurrentRelativeHumidity = 0;
62
- this.CurrentTemperature = 0;
60
+ if (this.BatteryLevel === undefined) {
61
+ this.BatteryLevel = 100;
62
+ } else {
63
+ this.BatteryLevel = this.accessory.context.BatteryLevel;
64
+ }
65
+ if (this.BatteryLevel < 15) {
66
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
67
+ } else {
68
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
69
+ }
70
+ this.ChargingState = this.platform.Characteristic.ChargingState.NOT_CHARGEABLE;
71
+ if (this.CurrentRelativeHumidity === undefined) {
72
+ this.CurrentRelativeHumidity = 0;
73
+ } else {
74
+ this.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity;
75
+ }
76
+ if (this.CurrentTemperature === undefined) {
77
+ this.CurrentTemperature = 0;
78
+ } else {
79
+ this.CurrentTemperature = this.accessory.context.CurrentTemperature;
80
+ }
63
81
 
64
82
  // this is subject we use to track when we need to POST changes to the SwitchBot API
65
83
  this.doMeterUpdate = new Subject();
@@ -177,9 +195,9 @@ export class Meter {
177
195
  // Battery
178
196
  this.BatteryLevel = Number(this.battery);
179
197
  if (this.BatteryLevel < 15) {
180
- this.StatusLowBattery = 1;
198
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
181
199
  } else {
182
- this.StatusLowBattery = 0;
200
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
183
201
  }
184
202
  this.platform.debug(`${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
185
203
 
@@ -191,13 +209,8 @@ export class Meter {
191
209
 
192
210
  // Current Temperature
193
211
  if (!this.device.meter?.hide_temperature) {
194
- if (this.device.meter?.unit === 1) {
195
- this.CurrentTemperature = this.toFahrenheit(this.temperature!.c);
196
- } else if (this.device.meter?.unit === 0) {
197
- this.CurrentTemperature = this.toCelsius(this.temperature!.c);
198
- } else {
199
- this.CurrentTemperature = Number(this.temperature?.c);
200
- }
212
+ this.temperature < 0 ? 0 : this.temperature > 100 ? 100 : this.temperature;
213
+ this.CurrentTemperature = this.temperature;
201
214
  this.platform.debug(`Meter: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
202
215
  }
203
216
  }
@@ -211,9 +224,9 @@ export class Meter {
211
224
  this.BatteryLevel = 10;
212
225
  }
213
226
  if (this.BatteryLevel < 15) {
214
- this.StatusLowBattery = 1;
227
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
215
228
  } else {
216
- this.StatusLowBattery = 0;
229
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
217
230
  }
218
231
  // Current Relative Humidity
219
232
  if (!this.device.meter?.hide_humidity) {
@@ -223,13 +236,7 @@ export class Meter {
223
236
 
224
237
  // Current Temperature
225
238
  if (!this.device.meter?.hide_temperature) {
226
- if (this.device.meter?.unit === 1) {
227
- this.CurrentTemperature = this.toFahrenheit(this.deviceStatus.body.temperature!);
228
- } else if (this.device.meter?.unit === 0) {
229
- this.CurrentTemperature = this.toCelsius(this.deviceStatus.body.temperature!);
230
- } else {
231
- this.CurrentTemperature = Number(this.deviceStatus.body.temperature);
232
- }
239
+ this.CurrentTemperature = Number(this.deviceStatus.body.temperature);
233
240
  this.platform.debug(`Meter: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
234
241
  }
235
242
  }
@@ -259,20 +266,18 @@ export class Meter {
259
266
  const switchbot = this.connectBLE();
260
267
  // Start to monitor advertisement packets
261
268
  switchbot.startScan({
262
- model: 'T',
263
269
  id: this.device.bleMac,
264
270
  }).then(() => {
265
271
  // Set an event hander
266
272
  switchbot.onadvertisement = (ad: ad) => {
267
273
  this.serviceData = ad.serviceData;
268
- this.temperature = ad.serviceData.temperature;
269
- this.fahrenheit = ad.serviceData.fahrenheit;
274
+ this.temperature = ad.serviceData.temperature!.c;
270
275
  this.humidity = ad.serviceData.humidity;
271
276
  this.battery = ad.serviceData.battery;
272
277
  this.platform.device(`Meter: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
273
278
  this.platform.device(`Meter: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, `
274
- + `temperature: ${JSON.stringify(ad.serviceData.temperature)}, fahrenheit: ${ad.serviceData.fahrenheit}, `
275
- + `humidity: ${ad.serviceData.humidity}, battery: ${ad.serviceData.battery}`);
279
+ + `temperature: ${JSON.stringify(ad.serviceData.temperature?.c)}, humidity: ${ad.serviceData.humidity}, `
280
+ + `battery: ${ad.serviceData.battery}`);
276
281
 
277
282
  if (this.serviceData) {
278
283
  this.connected = true;
@@ -288,6 +293,12 @@ export class Meter {
288
293
  // Stop to monitor
289
294
  switchbot.stopScan();
290
295
  if (this.connected) {
296
+ this.CurrentTemperatureCached = this.temperature;
297
+ this.accessory.context.CurrentTemperature = this.CurrentTemperatureCached;
298
+ this.CurrentRelativeHumidityCached = this.humidity!;
299
+ this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidityCached;
300
+ this.BatteryLevelCached = this.battery!;
301
+ this.accessory.context.BatteryLevel = this.BatteryLevelCached;
291
302
  this.parseStatus();
292
303
  this.updateHomeKitCharacteristics();
293
304
  } else {
@@ -321,6 +332,12 @@ export class Meter {
321
332
  try {
322
333
  this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
323
334
  this.platform.debug(`Meter: ${this.accessory.displayName} openAPIRefreshStatus: ${JSON.stringify(this.deviceStatus)}`);
335
+ this.CurrentTemperatureCached = this.deviceStatus.body.humidity!;
336
+ this.accessory.context.CurrentTemperature = this.CurrentTemperatureCached;
337
+ this.CurrentRelativeHumidityCached = this.deviceStatus.body.humidity!;
338
+ this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidityCached;
339
+ this.BatteryLevelCached = 100;
340
+ this.accessory.context.BatteryLevel = this.BatteryLevelCached;
324
341
  this.parseStatus();
325
342
  this.updateHomeKitCharacteristics();
326
343
  } catch (e: any) {
@@ -382,19 +399,4 @@ export class Meter {
382
399
  this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
383
400
  }
384
401
  }
385
-
386
- /**
387
- * Converts the value to celsius if the temperature units are in Fahrenheit
388
- */
389
- toCelsius(value: number) {
390
- // celsius should be to the nearest 0.5 degree
391
- return Math.round((5 / 9) * (value - 32) * 2) / 2;
392
- }
393
-
394
- /**
395
- * Converts the value to fahrenheit if the temperature units are in Fahrenheit
396
- */
397
- toFahrenheit(value: number) {
398
- return Math.round((value * 9) / 5 + 32);
399
- }
400
402
  }
@@ -2,7 +2,7 @@
2
2
  import { AxiosResponse } from 'axios';
3
3
  import { interval, Subject } from 'rxjs';
4
4
  import { SwitchBotPlatform } from '../platform';
5
- import { debounceTime, skipWhile, tap } from 'rxjs/operators';
5
+ import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
6
6
  import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
7
7
  import { DeviceURL, device, devicesConfig, deviceStatusResponse, payload } from '../settings';
8
8
 
@@ -12,6 +12,7 @@ export class Plug {
12
12
 
13
13
  // Characteristic Values
14
14
  On!: CharacteristicValue;
15
+ OnCached!: CharacteristicValue;
15
16
 
16
17
  // OpenAPI Others
17
18
  deviceStatus!: deviceStatusResponse;
@@ -29,8 +30,15 @@ export class Plug {
29
30
  private accessory: PlatformAccessory,
30
31
  public device: device & devicesConfig,
31
32
  ) {
33
+ // Bot Config
34
+ this.platform.device(`Plug: ${this.accessory.displayName} Config: (offline: ${device.offline})`);
35
+
32
36
  // default placeholders
33
- this.On = false;
37
+ if (this.On === undefined) {
38
+ this.On = false;
39
+ } else {
40
+ this.On = this.accessory.context.On;
41
+ }
34
42
 
35
43
  // this is subject we use to track when we need to POST changes to the SwitchBot API
36
44
  this.doPlugUpdate = new Subject();
@@ -142,24 +150,34 @@ export class Plug {
142
150
  * Plug - "command" "turnOn" "default" = set to ON state
143
151
  */
144
152
  async pushChanges() {
145
- const payload = {
146
- commandType: 'command',
147
- parameter: 'default',
148
- } as payload;
149
-
150
- if (this.On) {
151
- payload.command = 'turnOn';
152
- } else {
153
- payload.command = 'turnOff';
154
- }
153
+ if (this.On !== this.OnCached) {
154
+ const payload = {
155
+ commandType: 'command',
156
+ parameter: 'default',
157
+ } as payload;
158
+
159
+ if (this.On) {
160
+ payload.command = 'turnOn';
161
+ } else {
162
+ payload.command = 'turnOff';
163
+ }
155
164
 
156
- this.platform.log.info(`Plug: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
157
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
165
+ this.platform.log.info(`Plug: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
166
+ + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
158
167
 
159
- // Make the API request
160
- const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
161
- this.platform.debug(`Plug: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
162
- this.statusCode(push);
168
+ // Make the API request
169
+ const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
170
+ this.platform.debug(`Plug: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
171
+ this.statusCode(push);
172
+ this.OnCached = this.On;
173
+ this.accessory.context.On = this.OnCached;
174
+ }
175
+ interval(5000)
176
+ .pipe(skipWhile(() => this.plugUpdateInProgress))
177
+ .pipe(take(1))
178
+ .subscribe(() => {
179
+ this.refreshStatus();
180
+ });
163
181
  }
164
182
 
165
183
  updateHomeKitCharacteristics() {
@@ -188,9 +206,11 @@ export class Plug {
188
206
  break;
189
207
  case 161:
190
208
  this.platform.log.error(`Plug: ${this.accessory.displayName} Device is offline.`);
209
+ this.offlineOff();
191
210
  break;
192
211
  case 171:
193
212
  this.platform.log.error(`Plug: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
213
+ this.offlineOff();
194
214
  break;
195
215
  case 190:
196
216
  this.platform.log.error(`Plug: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
@@ -204,6 +224,13 @@ export class Plug {
204
224
  }
205
225
  }
206
226
 
227
+ private offlineOff() {
228
+ if (this.device.offline) {
229
+ this.On = false;
230
+ this.service.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
231
+ }
232
+ }
233
+
207
234
  /**
208
235
  * Handle requests to set the value of the "On" characteristic
209
236
  */
@@ -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`);
@@ -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) {
@@ -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) {
@@ -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
  /**
@@ -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`);
@@ -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() {
@@ -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
 
@@ -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`);
@@ -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() {