@switchbot/homebridge-switchbot 3.5.1-beta.12 → 3.5.1-beta.3

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 (75) hide show
  1. package/dist/device/blindtilt.js.map +1 -1
  2. package/dist/device/bot.js.map +1 -1
  3. package/dist/device/ceilinglight.d.ts.map +1 -1
  4. package/dist/device/ceilinglight.js +9 -6
  5. package/dist/device/ceilinglight.js.map +1 -1
  6. package/dist/device/colorbulb.d.ts.map +1 -1
  7. package/dist/device/colorbulb.js +3 -7
  8. package/dist/device/colorbulb.js.map +1 -1
  9. package/dist/device/curtain.js.map +1 -1
  10. package/dist/device/device.js +9 -9
  11. package/dist/device/device.js.map +1 -1
  12. package/dist/device/fan.js.map +1 -1
  13. package/dist/device/waterdetector.d.ts.map +1 -1
  14. package/dist/device/waterdetector.js +3 -5
  15. package/dist/device/waterdetector.js.map +1 -1
  16. package/dist/irdevice/airconditioner.d.ts +3 -1
  17. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  18. package/dist/irdevice/airconditioner.js +103 -44
  19. package/dist/irdevice/airconditioner.js.map +1 -1
  20. package/dist/irdevice/airpurifier.d.ts +1 -0
  21. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  22. package/dist/irdevice/airpurifier.js +49 -18
  23. package/dist/irdevice/airpurifier.js.map +1 -1
  24. package/dist/irdevice/camera.d.ts.map +1 -1
  25. package/dist/irdevice/camera.js +9 -9
  26. package/dist/irdevice/camera.js.map +1 -1
  27. package/dist/irdevice/fan.d.ts.map +1 -1
  28. package/dist/irdevice/fan.js +19 -19
  29. package/dist/irdevice/fan.js.map +1 -1
  30. package/dist/irdevice/irdevice.d.ts +10 -22
  31. package/dist/irdevice/irdevice.d.ts.map +1 -1
  32. package/dist/irdevice/irdevice.js +67 -89
  33. package/dist/irdevice/irdevice.js.map +1 -1
  34. package/dist/irdevice/light.d.ts.map +1 -1
  35. package/dist/irdevice/light.js +17 -15
  36. package/dist/irdevice/light.js.map +1 -1
  37. package/dist/irdevice/other.d.ts.map +1 -1
  38. package/dist/irdevice/other.js +76 -76
  39. package/dist/irdevice/other.js.map +1 -1
  40. package/dist/irdevice/tv.d.ts.map +1 -1
  41. package/dist/irdevice/tv.js +35 -35
  42. package/dist/irdevice/tv.js.map +1 -1
  43. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  44. package/dist/irdevice/vacuumcleaner.js +9 -9
  45. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  46. package/dist/irdevice/waterheater.d.ts.map +1 -1
  47. package/dist/irdevice/waterheater.js +9 -9
  48. package/dist/irdevice/waterheater.js.map +1 -1
  49. package/dist/platform.d.ts +12 -14
  50. package/dist/platform.d.ts.map +1 -1
  51. package/dist/platform.js +245 -245
  52. package/dist/platform.js.map +1 -1
  53. package/dist/types/devicewebhookstatus.d.ts +1 -1
  54. package/dist/types/devicewebhookstatus.d.ts.map +1 -1
  55. package/package.json +1 -1
  56. package/src/device/blindtilt.ts +1 -1
  57. package/src/device/bot.ts +1 -1
  58. package/src/device/ceilinglight.ts +15 -7
  59. package/src/device/colorbulb.ts +11 -8
  60. package/src/device/curtain.ts +1 -1
  61. package/src/device/device.ts +9 -9
  62. package/src/device/fan.ts +1 -1
  63. package/src/device/waterdetector.ts +3 -5
  64. package/src/irdevice/airconditioner.ts +97 -53
  65. package/src/irdevice/airpurifier.ts +45 -23
  66. package/src/irdevice/camera.ts +9 -9
  67. package/src/irdevice/fan.ts +19 -19
  68. package/src/irdevice/irdevice.ts +68 -92
  69. package/src/irdevice/light.ts +17 -15
  70. package/src/irdevice/other.ts +76 -76
  71. package/src/irdevice/tv.ts +35 -35
  72. package/src/irdevice/vacuumcleaner.ts +9 -9
  73. package/src/irdevice/waterheater.ts +9 -9
  74. package/src/platform.ts +247 -247
  75. package/src/types/devicewebhookstatus.ts +1 -1
@@ -200,13 +200,22 @@ export class CeilingLight extends deviceBase {
200
200
  // On
201
201
  this.LightBulb.On = deviceStatus.power;
202
202
  await this.debugLog(`On: ${this.LightBulb.On}`);
203
+
203
204
  // Brightness
204
205
  this.LightBulb.Brightness = deviceStatus.brightness;
205
206
  await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
207
+
206
208
  // ColorTemperature
207
- const miredColorTemperature = Math.round(1000000 / deviceStatus.colorTemperature);
208
- this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140);
209
- await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
209
+ if (!Number.isNaN(deviceStatus.colorTemperature)) {
210
+ await this.debugLog(`OpenAPI ColorTemperature: ${deviceStatus.colorTemperature}`);
211
+ const mired = Math.round(1000000 / deviceStatus.colorTemperature);
212
+
213
+ this.LightBulb.ColorTemperature = Number(mired);
214
+
215
+ this.LightBulb.ColorTemperature = Math.max(Math.min(this.LightBulb.ColorTemperature, 500), 140);
216
+ await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
217
+ }
218
+
210
219
  // Firmware Version
211
220
  const version = deviceStatus.version.toString();
212
221
  await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
@@ -234,8 +243,7 @@ export class CeilingLight extends deviceBase {
234
243
  this.LightBulb.Brightness = context.brightness;
235
244
  await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
236
245
  // ColorTemperature
237
- const miredColorTemperature = Math.round(1000000 / context.colorTemperature);
238
- this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140);
246
+ this.LightBulb.ColorTemperature = context.colorTemperature;
239
247
  await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
240
248
  }
241
249
 
@@ -301,7 +309,7 @@ export class CeilingLight extends deviceBase {
301
309
  async registerWebhook() {
302
310
  if (this.device.webhook) {
303
311
  await this.debugLog('is listening webhook.');
304
- this.platform.webhookEventHandler[this.device.deviceId] = async (context: ceilingLightWebhookContext | ceilingLightProWebhookContext) => {
312
+ this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
305
313
  try {
306
314
  await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
307
315
  await this.parseStatusWebhook(context);
@@ -468,7 +476,7 @@ export class CeilingLight extends deviceBase {
468
476
  async pushColorTemperatureChanges(): Promise<void> {
469
477
  await this.debugLog('pushColorTemperatureChanges');
470
478
  if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
471
- const kelvin = Math.round(1000000 * Number(this.LightBulb.ColorTemperature));
479
+ const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature));
472
480
  this.accessory.context.kelvin = kelvin;
473
481
  const bodyChange = JSON.stringify({
474
482
  command: 'setColorTemperature',
@@ -200,8 +200,7 @@ export class ColorBulb extends deviceBase {
200
200
  this.LightBulb.Saturation = saturation;
201
201
  await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
202
202
  // ColorTemperature
203
- const miredColorTemperature = Math.round(1000000 / serviceData.color_temperature);
204
- this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140);
203
+ this.LightBulb.ColorTemperature = Math.max(Math.min(serviceData.color_temperature, 500), 140);
205
204
  await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
206
205
  }
207
206
 
@@ -210,28 +209,35 @@ export class ColorBulb extends deviceBase {
210
209
  */
211
210
  async openAPIparseStatus(deviceStatus: colorBulbStatus): Promise<void> {
212
211
  await this.debugLog('openAPIparseStatus');
212
+
213
213
  // On
214
214
  this.LightBulb.On = deviceStatus.power === 'on' ? true : false;
215
215
  await this.debugLog(`On: ${this.LightBulb.On}`);
216
+
216
217
  // Brightness
217
218
  this.LightBulb.Brightness = deviceStatus.brightness;
218
219
  await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
220
+
219
221
  // Color, Hue & Brightness
220
222
  await this.debugLog(`color: ${JSON.stringify(deviceStatus.color)}`);
221
223
  const [red, green, blue] = deviceStatus.color.split(':');
222
224
  await this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`);
223
225
  const [hue, saturation] = rgb2hs(red, green, blue);
224
226
  await this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`);
227
+
225
228
  // Hue
226
229
  this.LightBulb.Hue = hue;
227
230
  await this.debugLog(`Hue: ${this.LightBulb.Hue}`);
231
+
228
232
  // Saturation
229
233
  this.LightBulb.Saturation = saturation;
230
234
  await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
235
+
231
236
  // ColorTemperature
232
237
  const miredColorTemperature = Math.round(1000000 / deviceStatus.colorTemperature);
233
238
  this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140);
234
239
  await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
240
+
235
241
  // Firmware Version
236
242
  const version = deviceStatus.version.toString();
237
243
  await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
@@ -272,8 +278,7 @@ export class ColorBulb extends deviceBase {
272
278
  this.LightBulb.Saturation = saturation;
273
279
  await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
274
280
  // ColorTemperature
275
- const miredColorTemperature = Math.round(1000000 / context.colorTemperature);
276
- this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140);
281
+ this.LightBulb.ColorTemperature = context.colorTemperature;
277
282
  await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
278
283
  }
279
284
 
@@ -339,7 +344,7 @@ export class ColorBulb extends deviceBase {
339
344
  async registerWebhook() {
340
345
  if (this.device.webhook) {
341
346
  await this.debugLog('is listening webhook.');
342
- this.platform.webhookEventHandler[this.device.deviceId] = async (context: colorBulbWebhookContext) => {
347
+ this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
343
348
  try {
344
349
  await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
345
350
  await this.parseStatusWebhook(context);
@@ -484,8 +489,6 @@ export class ColorBulb extends deviceBase {
484
489
  async BLEpushColorTemperatureChanges(): Promise<void> {
485
490
  await this.debugLog('BLEpushColorTemperatureChanges');
486
491
  if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
487
- const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature));
488
- this.accessory.context.kelvin = kelvin;
489
492
  const switchbot = await this.platform.connectBLE(this.accessory, this.device);
490
493
  await this.convertBLEAddress();
491
494
  if (switchbot !== false) {
@@ -493,7 +496,7 @@ export class ColorBulb extends deviceBase {
493
496
  .discover({ model: this.device.bleModel, id: this.device.bleMac })
494
497
  .then(async (device_list: any) => {
495
498
  await this.infoLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
496
- return await device_list[0].setColorTemperature(kelvin);
499
+ return await device_list[0].setColorTemperature(this.LightBulb.ColorTemperature);
497
500
  })
498
501
  .then(async () => {
499
502
  await this.successLog(`ColorTemperature: ${this.LightBulb.ColorTemperature} sent over SwitchBot BLE, sent successfully`);
@@ -462,7 +462,7 @@ export class Curtain extends deviceBase {
462
462
  async registerWebhook() {
463
463
  if (this.device.webhook) {
464
464
  await this.debugLog('is listening webhook.');
465
- this.platform.webhookEventHandler[this.device.deviceId] = async (context: curtainWebhookContext | curtain3WebhookContext) => {
465
+ this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
466
466
  try {
467
467
  await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
468
468
  await this.parseStatusWebhook(context);
@@ -841,48 +841,48 @@ export abstract class deviceBase {
841
841
  */
842
842
  async infoLog(...log: any[]): Promise<void> {
843
843
  if (await this.enablingDeviceLogging()) {
844
- this.log.info(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log));
844
+ this.log.info(`${this.device.deviceType}: ${this.accessory.displayName} `, String(...log));
845
845
  }
846
846
  }
847
847
 
848
848
  async successLog(...log: any[]): Promise<void> {
849
849
  if (await this.enablingDeviceLogging()) {
850
- this.log.success(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log));
850
+ this.log.success(`${this.device.deviceType}: ${this.accessory.displayName} `, String(...log));
851
851
  }
852
852
  }
853
853
 
854
854
  async debugSuccessLog(...log: any[]): Promise<void> {
855
855
  if (await this.enablingDeviceLogging()) {
856
856
  if (this.deviceLogging?.includes('debug')) {
857
- this.log.success(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log));
857
+ this.log.success(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName} `, String(...log));
858
858
  }
859
859
  }
860
860
  }
861
861
 
862
862
  async warnLog(...log: any[]): Promise<void> {
863
863
  if (await this.enablingDeviceLogging()) {
864
- this.log.warn(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log));
864
+ this.log.warn(`${this.device.deviceType}: ${this.accessory.displayName} `, String(...log));
865
865
  }
866
866
  }
867
867
 
868
868
  async debugWarnLog(...log: any[]): Promise<void> {
869
869
  if (await this.enablingDeviceLogging()) {
870
870
  if (this.deviceLogging?.includes('debug')) {
871
- this.log.warn(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log));
871
+ this.log.warn(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName} `, String(...log));
872
872
  }
873
873
  }
874
874
  }
875
875
 
876
876
  async errorLog(...log: any[]): Promise<void> {
877
877
  if (await this.enablingDeviceLogging()) {
878
- this.log.error(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log));
878
+ this.log.error(`${this.device.deviceType}: ${this.accessory.displayName} `, String(...log));
879
879
  }
880
880
  }
881
881
 
882
882
  async debugErrorLog(...log: any[]): Promise<void> {
883
883
  if (await this.enablingDeviceLogging()) {
884
884
  if (this.deviceLogging?.includes('debug')) {
885
- this.log.error(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log));
885
+ this.log.error(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName} `, String(...log));
886
886
  }
887
887
  }
888
888
  }
@@ -890,9 +890,9 @@ export abstract class deviceBase {
890
890
  async debugLog(...log: any[]): Promise<void> {
891
891
  if (await this.enablingDeviceLogging()) {
892
892
  if (this.deviceLogging === 'debug') {
893
- this.log.info(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log));
893
+ this.log.info(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName} `, String(...log));
894
894
  } else {
895
- this.log.debug(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log));
895
+ this.log.debug(`${this.device.deviceType}: ${this.accessory.displayName} `, String(...log));
896
896
  }
897
897
  }
898
898
  }
package/src/device/fan.ts CHANGED
@@ -339,7 +339,7 @@ export class Fan extends deviceBase {
339
339
  async registerWebhook() {
340
340
  if (this.device.webhook) {
341
341
  await this.debugLog('is listening webhook.');
342
- this.platform.webhookEventHandler[this.device.deviceId] = async (context: batteryCirculatorFanWebhookContext) => {
342
+ this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
343
343
  try {
344
344
  await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
345
345
  await this.parseStatusWebhook(context);
@@ -106,11 +106,10 @@ export class WaterDetector extends deviceBase {
106
106
  }
107
107
 
108
108
  // Retrieve initial values and updateHomekit
109
- this.debugLog('retrieve initial values and Update Homekit');
110
109
  this.refreshStatus();
111
110
 
112
111
  // Retrieve initial values and updateHomekit
113
- // this.updateHomeKitCharacteristics();
112
+ this.updateHomeKitCharacteristics();
114
113
 
115
114
  //regisiter webhook event handler
116
115
  this.registerWebhook();
@@ -119,7 +118,6 @@ export class WaterDetector extends deviceBase {
119
118
  interval(this.deviceRefreshRate * 1000)
120
119
  .pipe(skipWhile(() => this.WaterDetectorUpdateInProgress))
121
120
  .subscribe(async () => {
122
- await this.debugLog(`update interval: ${this.deviceRefreshRate * 1000} seconds`);
123
121
  await this.refreshStatus();
124
122
  });
125
123
  }
@@ -147,7 +145,7 @@ export class WaterDetector extends deviceBase {
147
145
  await this.debugLog('openAPIparseStatus');
148
146
  if (!this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
149
147
  // StatusActive
150
- this.LeakSensor.StatusActive = deviceStatus.battery === 0 ? false : true;
148
+ this.LeakSensor.StatusActive = deviceStatus.status ? true : false;
151
149
  await this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`);
152
150
  // LeakDetected
153
151
  this.LeakSensor.LeakDetected = deviceStatus.status;
@@ -162,7 +160,7 @@ export class WaterDetector extends deviceBase {
162
160
  await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
163
161
  // FirmwareVersion
164
162
  const version = deviceStatus.version.toString();
165
- await this.debugLog(`FirmwareVersion: ${version.replace(/^V|-.*$/g, '')}`);
163
+ await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
166
164
  if (deviceStatus.version) {
167
165
  const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
168
166
  this.accessory
@@ -28,7 +28,6 @@ export class AirConditioner extends irdeviceBase {
28
28
  };
29
29
 
30
30
  meter?: PlatformAccessory;
31
-
32
31
  private HumiditySensor?: {
33
32
  Name: CharacteristicValue;
34
33
  Service: Service;
@@ -182,7 +181,7 @@ export class AirConditioner extends irdeviceBase {
182
181
  * AirConditioner: "command" "highSpeed" "default" = fan speed to high
183
182
  */
184
183
  async pushAirConditionerOnChanges(): Promise<void> {
185
- await this.debugLog(`pushAirConditionerOnChanges Active: ${this.HeaterCooler.Active},`
184
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOnChanges Active: ${this.HeaterCooler.Active},`
186
185
  + ` disablePushOn: ${this.disablePushOn}`);
187
186
  if (this.HeaterCooler.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
188
187
  const commandType: string = await this.commandType();
@@ -197,7 +196,7 @@ export class AirConditioner extends irdeviceBase {
197
196
  }
198
197
 
199
198
  async pushAirConditionerOffChanges(): Promise<void> {
200
- await this.debugLog(`pushAirConditionerOffChanges Active: ${this.HeaterCooler.Active},`
199
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOffChanges Active: ${this.HeaterCooler.Active},`
201
200
  + ` disablePushOff: ${this.disablePushOff}`);
202
201
  if (this.HeaterCooler.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
203
202
  const commandType: string = await this.commandType();
@@ -212,7 +211,7 @@ export class AirConditioner extends irdeviceBase {
212
211
  }
213
212
 
214
213
  async pushAirConditionerStatusChanges(): Promise<void> {
215
- await this.debugLog(`pushAirConditionerStatusChanges Active: ${this.HeaterCooler.Active},`
214
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerStatusChanges Active: ${this.HeaterCooler.Active},`
216
215
  + ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
217
216
  if (!this.Busy) {
218
217
  this.Busy = true;
@@ -225,7 +224,7 @@ export class AirConditioner extends irdeviceBase {
225
224
  }
226
225
 
227
226
  async pushAirConditionerDetailsChanges(): Promise<void> {
228
- await this.debugLog(`pushAirConditionerDetailsChanges Active: ${this.HeaterCooler.Active},`
227
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerDetailsChanges Active: ${this.HeaterCooler.Active},`
229
228
  + ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
230
229
  //await this.deviceContext();
231
230
  if (this.CurrentMode === undefined) {
@@ -242,7 +241,7 @@ export class AirConditioner extends irdeviceBase {
242
241
  if (this.CurrentMode === 1) {
243
242
  // Remove or make configurable?
244
243
  this.HeaterCooler.ThresholdTemperature = 25;
245
- await this.debugLog(`CurrentMode: ${this.CurrentMode},`
244
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentMode: ${this.CurrentMode},`
246
245
  + ` ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`);
247
246
  }
248
247
  const parameter = `${this.HeaterCooler.ThresholdTemperature},${this.CurrentMode},${this.CurrentFanSpeed},${this.state}`;
@@ -345,9 +344,9 @@ export class AirConditioner extends irdeviceBase {
345
344
  }
346
345
 
347
346
  async pushChanges(bodyChange: any): Promise<void> {
348
- await this.debugLog('pushChanges');
347
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
349
348
  if (this.device.connectionType === 'OpenAPI' && !this.disablePushDetail) {
350
- await this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`);
349
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
351
350
  try {
352
351
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
353
352
  const deviceStatus: any = await body.json();
@@ -364,33 +363,35 @@ export class AirConditioner extends irdeviceBase {
364
363
  await this.pushChangeError(e);
365
364
  }
366
365
  } else {
367
- await this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
368
- await this.debugLog(`Connection Type: ${this.device.connectionType}, disablePushDetails: ${this.disablePushDetail}`);
369
- await this.updateHomeKitCharacteristics();
366
+ this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
367
+ + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
368
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
369
+ + ` Connection Type: ${this.device.connectionType}, disablePushDetails: ${this.disablePushDetail}`);
370
+ this.updateHomeKitCharacteristics();
370
371
  }
371
372
  }
372
373
 
373
374
  async CurrentTemperatureGet(): Promise<CharacteristicValue> {
374
375
  if (this.meter?.context?.CurrentTemperature) {
375
376
  this.accessory.context.CurrentTemperature = this.meter.context.CurrentTemperature;
376
- await this.debugLog(''
377
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} `
377
378
  + `Using CurrentTemperature from ${this.meter.context.deviceType} (${this.meter.context.deviceID})`);
378
379
  }
379
380
 
380
381
  this.HeaterCooler.CurrentTemperature = this.accessory.context.CurrentTemperature || 24;
381
- await this.debugLog(`Get CurrentTemperature: ${this.HeaterCooler.CurrentTemperature}`);
382
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get CurrentTemperature: ${this.HeaterCooler.CurrentTemperature}`);
382
383
  return this.HeaterCooler.CurrentTemperature;
383
384
  }
384
385
 
385
386
  async CurrentRelativeHumidityGet(): Promise<CharacteristicValue> {
386
387
  if (this.meter?.context?.CurrentRelativeHumidity) {
387
388
  this.accessory.context.CurrentRelativeHumidity = this.meter.context.CurrentRelativeHumidity;
388
- await this.debugLog(''
389
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} `
389
390
  + `Using CurrentRelativeHumidity from ${this.meter.context.deviceType} (${this.meter.context.deviceID})`);
390
391
  }
391
392
 
392
393
  this.HumiditySensor!.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity || 0;
393
- await this.debugLog('Get'
394
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get`
394
395
  + ` CurrentRelativeHumidity: ${this.HumiditySensor!.CurrentRelativeHumidity}`);
395
396
  return this.HumiditySensor!.CurrentRelativeHumidity as CharacteristicValue;
396
397
  }
@@ -401,7 +402,7 @@ export class AirConditioner extends irdeviceBase {
401
402
  } else {
402
403
  this.HeaterCooler.RotationSpeed = this.CurrentFanSpeed - 1;
403
404
  }
404
- await this.debugLog(`Get RotationSpeed: ${this.HeaterCooler.RotationSpeed}`);
405
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get RotationSpeed: ${this.HeaterCooler.RotationSpeed}`);
405
406
  return this.HeaterCooler.RotationSpeed;
406
407
  }
407
408
 
@@ -412,23 +413,24 @@ export class AirConditioner extends irdeviceBase {
412
413
  this.CurrentFanSpeed = Number(value) + 1;
413
414
  }
414
415
  this.HeaterCooler.RotationSpeed = value;
415
- await this.debugLog(`Set RotationSpeed: ${this.HeaterCooler.RotationSpeed}, CurrentFanSpeed: ${this.CurrentFanSpeed}`);
416
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
417
+ + `Set RotationSpeed: ${this.HeaterCooler.RotationSpeed}, CurrentFanSpeed: ${this.CurrentFanSpeed}`);
416
418
  this.pushAirConditionerStatusChanges();
417
419
  }
418
420
 
419
421
  async ActiveSet(value: CharacteristicValue): Promise<void> {
420
- await this.debugLog(`Set Active: ${value}`);
422
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
421
423
 
422
424
  this.HeaterCooler.Active = value;
423
425
  if (this.HeaterCooler.Active === this.hap.Characteristic.Active.ACTIVE) {
424
- await this.debugLog(`pushAirConditionerOnChanges, Active: ${this.HeaterCooler.Active}`);
426
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOnChanges, Active: ${this.HeaterCooler.Active}`);
425
427
  if (this.disablePushOn) {
426
428
  this.pushAirConditionerStatusChanges();
427
429
  } else {
428
430
  this.pushAirConditionerOnChanges();
429
431
  }
430
432
  } else {
431
- await this.debugLog(`pushAirConditionerOffChanges, Active: ${this.HeaterCooler.Active}`);
433
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.HeaterCooler.Active}`);
432
434
  this.pushAirConditionerOffChanges();
433
435
  }
434
436
  }
@@ -436,7 +438,7 @@ export class AirConditioner extends irdeviceBase {
436
438
  async TargetHeaterCoolerStateGet(): Promise<CharacteristicValue> {
437
439
  const targetState = this.HeaterCooler.TargetHeaterCoolerState || this.accessory.context.TargetHeaterCoolerState;
438
440
  this.HeaterCooler.TargetHeaterCoolerState = this.ValidValues.includes(targetState) ? targetState : this.ValidValues[0];
439
- await this.debugLog(`Get (${this.getTargetHeaterCoolerStateName()}) TargetHeaterCoolerState:`
441
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get (${this.getTargetHeaterCoolerStateName()}) TargetHeaterCoolerState:`
440
442
  + ` ${this.HeaterCooler.TargetHeaterCoolerState}, ValidValues: ${this.ValidValues}, hide_automode: ${this.hide_automode}`);
441
443
  return this.HeaterCooler.TargetHeaterCoolerState;
442
444
  }
@@ -449,7 +451,7 @@ export class AirConditioner extends irdeviceBase {
449
451
  } else if (value === this.hap.Characteristic.TargetHeaterCoolerState.COOL) {
450
452
  this.TargetHeaterCoolerStateCOOL();
451
453
  } else {
452
- this.errorLog('Set TargetHeaterCoolerState: '
454
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Set TargetHeaterCoolerState: `
453
455
  + `${this.HeaterCooler.TargetHeaterCoolerState}, hide_automode: ${this.hide_automode} `);
454
456
  }
455
457
  this.pushAirConditionerStatusChanges();
@@ -458,30 +460,31 @@ export class AirConditioner extends irdeviceBase {
458
460
  async TargetHeaterCoolerStateAUTO(): Promise<void> {
459
461
  this.HeaterCooler.TargetHeaterCoolerState = this.hap.Characteristic.TargetHeaterCoolerState.AUTO;
460
462
  this.CurrentMode = 1;
461
- await this.debugLog('Set (AUTO)'
463
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (AUTO)`
462
464
  + ` TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`);
463
- await this.debugLog(`Switchbot CurrentMode: ${this.CurrentMode}`);
465
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
464
466
  }
465
467
 
466
468
  async TargetHeaterCoolerStateCOOL(): Promise<void> {
467
469
  this.HeaterCooler.TargetHeaterCoolerState = this.hap.Characteristic.TargetHeaterCoolerState.COOL;
468
470
  this.CurrentMode = 2;
469
- await this.debugLog('Set (COOL)'
471
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (COOL)`
470
472
  + ` TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`);
471
- await this.debugLog(`Switchbot CurrentMode: ${this.CurrentMode}`);
473
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
472
474
  }
473
475
 
474
476
  async TargetHeaterCoolerStateHEAT(): Promise<void> {
475
477
  this.HeaterCooler.TargetHeaterCoolerState = this.hap.Characteristic.TargetHeaterCoolerState.HEAT;
476
478
  this.CurrentMode = 5;
477
- await this.debugLog('Set (HEAT)'
479
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (HEAT)`
478
480
  + ` TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`);
479
- await this.debugLog(`Switchbot CurrentMode: ${this.CurrentMode}`);
481
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
480
482
  }
481
483
 
482
484
  async CurrentHeaterCoolerStateGet(): Promise<CharacteristicValue> {
483
485
  await this.UpdateCurrentHeaterCoolerState();
484
- await this.debugLog(`Get (${this.getTargetHeaterCoolerStateName()}) CurrentHeaterCoolerState: ${this.HeaterCooler.CurrentHeaterCoolerState}`);
486
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
487
+ + ` Get (${this.getTargetHeaterCoolerStateName()}) CurrentHeaterCoolerState: ${this.HeaterCooler.CurrentHeaterCoolerState}`);
485
488
 
486
489
  return this.HeaterCooler.CurrentHeaterCoolerState;
487
490
  }
@@ -535,48 +538,89 @@ export class AirConditioner extends irdeviceBase {
535
538
  this.HumiditySensor!.CurrentRelativeHumidity = this.HumiditySensor!.CurrentRelativeHumidity || this.accessory.context.CurrentRelativeHumidity;
536
539
  }
537
540
  }
538
- await this.debugLog(`Get ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`);
541
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`);
539
542
  return this.HeaterCooler.ThresholdTemperature;
540
543
  }
541
544
 
542
545
  async ThresholdTemperatureSet(value: CharacteristicValue): Promise<void> {
543
546
  this.HeaterCooler.ThresholdTemperature = value;
544
- await this.debugLog(`Set ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature},`
547
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature},`
545
548
  + ` ThresholdTemperatureCached: ${this.accessory.context.ThresholdTemperature}`);
546
549
  this.pushAirConditionerStatusChanges();
547
550
  }
548
551
 
549
552
  async updateHomeKitCharacteristics(): Promise<void> {
550
- await this.debugLog('updateHomeKitCharacteristics');
551
553
  // Active
552
- await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.Active,
553
- this.HeaterCooler.Active, 'Active');
554
+ if (this.HeaterCooler.Active === undefined) {
555
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.HeaterCooler.Active}`);
556
+ } else {
557
+ this.accessory.context.Active = this.HeaterCooler.Active;
558
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.Active, this.HeaterCooler.Active);
559
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.HeaterCooler.Active}`);
560
+ }
554
561
  // RotationSpeed
555
- await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.RotationSpeed,
556
- this.HeaterCooler.RotationSpeed, 'RotationSpeed');
562
+ if (this.HeaterCooler.RotationSpeed === undefined) {
563
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} RotationSpeed: ${this.HeaterCooler.RotationSpeed}`);
564
+ } else {
565
+ this.accessory.context.RotationSpeed = this.HeaterCooler.RotationSpeed;
566
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, this.HeaterCooler.RotationSpeed);
567
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
568
+ + ` RotationSpeed: ${this.HeaterCooler.RotationSpeed}`);
569
+ }
557
570
  // CurrentTemperature
558
- await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.CurrentTemperature,
559
- this.HeaterCooler.CurrentTemperature, 'CurrentTemperature');
571
+ if (this.HeaterCooler.CurrentTemperature === undefined) {
572
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentTemperature: ${this.HeaterCooler.CurrentTemperature}`);
573
+ } else {
574
+ this.accessory.context.CurrentTemperature = this.HeaterCooler.CurrentTemperature;
575
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.HeaterCooler.CurrentTemperature);
576
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
577
+ + ` CurrentTemperature: ${this.HeaterCooler.CurrentTemperature}`);
578
+ }
579
+ // CurrentRelativeHumidity
580
+ if (this.meter) {
581
+ if (this.HumiditySensor!.CurrentRelativeHumidity === undefined) {
582
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
583
+ + ` CurrentRelativeHumidity: ${this.HumiditySensor!.CurrentRelativeHumidity}`);
584
+ } else {
585
+ this.accessory.context.CurrentRelativeHumidity = this.HumiditySensor!.CurrentRelativeHumidity;
586
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity,
587
+ this.HumiditySensor!.CurrentRelativeHumidity);
588
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
589
+ + ` CurrentRelativeHumidity: ${this.HumiditySensor!.CurrentRelativeHumidity}`);
590
+ }
591
+ }
560
592
  // TargetHeaterCoolerState
561
- await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.TargetHeaterCoolerState,
562
- this.HeaterCooler.TargetHeaterCoolerState, 'TargetHeaterCoolerState');
593
+ if (this.HeaterCooler.TargetHeaterCoolerState === undefined) {
594
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`);
595
+ } else {
596
+ this.accessory.context.TargetHeaterCoolerState = this.HeaterCooler.TargetHeaterCoolerState;
597
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.TargetHeaterCoolerState, this.HeaterCooler.TargetHeaterCoolerState);
598
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
599
+ + ` TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`);
600
+ }
563
601
  // CurrentHeaterCoolerState
564
- await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.CurrentHeaterCoolerState,
565
- this.HeaterCooler.CurrentHeaterCoolerState, 'CurrentHeaterCoolerState');
566
- // HeatingThresholdTemperature
567
- await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.HeatingThresholdTemperature,
568
- this.HeaterCooler.ThresholdTemperature, 'ThresholdTemperature');
569
- // CoolingThresholdTemperature
570
- await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.CoolingThresholdTemperature,
571
- this.HeaterCooler.ThresholdTemperature, 'ThresholdTemperature');
572
- if (this.meter && this.HumiditySensor?.Service) {
573
- // CurrentRelativeHumidity
574
- await this.updateCharacteristic(this.HumiditySensor.Service, this.hap.Characteristic.CurrentRelativeHumidity,
575
- this.HumiditySensor.CurrentRelativeHumidity, 'CurrentRelativeHumidity');
602
+ if (this.HeaterCooler.CurrentHeaterCoolerState === undefined) {
603
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
604
+ + ` CurrentHeaterCoolerState: ${this.HeaterCooler.CurrentHeaterCoolerState}`);
605
+ } else {
606
+ this.accessory.context.CurrentHeaterCoolerState = this.HeaterCooler.CurrentHeaterCoolerState;
607
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, this.HeaterCooler.CurrentHeaterCoolerState);
608
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
609
+ + ` updateCharacteristic CurrentHeaterCoolerState: ${this.HeaterCooler.CurrentHeaterCoolerState}`);
610
+ }
611
+ // ThresholdTemperature
612
+ if (this.HeaterCooler.ThresholdTemperature === undefined) {
613
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`);
614
+ } else {
615
+ this.accessory.context.ThresholdTemperature = this.HeaterCooler.ThresholdTemperature;
616
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.HeatingThresholdTemperature, this.HeaterCooler.ThresholdTemperature);
617
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CoolingThresholdTemperature, this.HeaterCooler.ThresholdTemperature);
618
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
619
+ + ` ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`);
576
620
  }
577
621
  }
578
622
 
579
- async apiError(e: any): Promise<void> {
623
+ async apiError({ e }: { e: any }): Promise<void> {
580
624
  this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
581
625
  this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, e);
582
626
  this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);