@switchbot/homebridge-switchbot 2.0.0-beta.9 → 2.0.1-beta.0

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 (119) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/README.md +3 -2
  3. package/config.schema.json +119 -19
  4. package/dist/device/bot.d.ts +34 -28
  5. package/dist/device/bot.d.ts.map +1 -1
  6. package/dist/device/bot.js +657 -648
  7. package/dist/device/bot.js.map +1 -1
  8. package/dist/device/ceilinglight.d.ts +137 -0
  9. package/dist/device/ceilinglight.d.ts.map +1 -0
  10. package/dist/device/ceilinglight.js +1127 -0
  11. package/dist/device/ceilinglight.js.map +1 -0
  12. package/dist/device/colorbulb.d.ts +36 -14
  13. package/dist/device/colorbulb.d.ts.map +1 -1
  14. package/dist/device/colorbulb.js +472 -297
  15. package/dist/device/colorbulb.js.map +1 -1
  16. package/dist/device/contact.d.ts +18 -8
  17. package/dist/device/contact.d.ts.map +1 -1
  18. package/dist/device/contact.js +306 -237
  19. package/dist/device/contact.js.map +1 -1
  20. package/dist/device/curtain.d.ts +23 -16
  21. package/dist/device/curtain.d.ts.map +1 -1
  22. package/dist/device/curtain.js +566 -502
  23. package/dist/device/curtain.js.map +1 -1
  24. package/dist/device/humidifier.d.ts +24 -18
  25. package/dist/device/humidifier.d.ts.map +1 -1
  26. package/dist/device/humidifier.js +453 -369
  27. package/dist/device/humidifier.js.map +1 -1
  28. package/dist/device/lock.d.ts +27 -8
  29. package/dist/device/lock.d.ts.map +1 -1
  30. package/dist/device/lock.js +305 -148
  31. package/dist/device/lock.js.map +1 -1
  32. package/dist/device/meter.d.ts +22 -16
  33. package/dist/device/meter.d.ts.map +1 -1
  34. package/dist/device/meter.js +367 -267
  35. package/dist/device/meter.js.map +1 -1
  36. package/dist/device/meterplus.d.ts +24 -12
  37. package/dist/device/meterplus.d.ts.map +1 -1
  38. package/dist/device/meterplus.js +381 -213
  39. package/dist/device/meterplus.js.map +1 -1
  40. package/dist/device/motion.d.ts +18 -8
  41. package/dist/device/motion.d.ts.map +1 -1
  42. package/dist/device/motion.js +279 -216
  43. package/dist/device/motion.js.map +1 -1
  44. package/dist/device/plug.d.ts +27 -17
  45. package/dist/device/plug.d.ts.map +1 -1
  46. package/dist/device/plug.js +295 -251
  47. package/dist/device/plug.js.map +1 -1
  48. package/dist/device/striplight.d.ts +43 -19
  49. package/dist/device/striplight.d.ts.map +1 -1
  50. package/dist/device/striplight.js +506 -262
  51. package/dist/device/striplight.js.map +1 -1
  52. package/dist/irdevice/airconditioner.d.ts +12 -12
  53. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  54. package/dist/irdevice/airconditioner.js +316 -234
  55. package/dist/irdevice/airconditioner.js.map +1 -1
  56. package/dist/irdevice/airpurifier.d.ts +5 -3
  57. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  58. package/dist/irdevice/airpurifier.js +154 -104
  59. package/dist/irdevice/airpurifier.js.map +1 -1
  60. package/dist/irdevice/camera.d.ts +11 -8
  61. package/dist/irdevice/camera.d.ts.map +1 -1
  62. package/dist/irdevice/camera.js +133 -86
  63. package/dist/irdevice/camera.js.map +1 -1
  64. package/dist/irdevice/fan.d.ts +10 -7
  65. package/dist/irdevice/fan.d.ts.map +1 -1
  66. package/dist/irdevice/fan.js +160 -109
  67. package/dist/irdevice/fan.js.map +1 -1
  68. package/dist/irdevice/light.d.ts +11 -8
  69. package/dist/irdevice/light.d.ts.map +1 -1
  70. package/dist/irdevice/light.js +137 -103
  71. package/dist/irdevice/light.js.map +1 -1
  72. package/dist/irdevice/other.d.ts +11 -8
  73. package/dist/irdevice/other.d.ts.map +1 -1
  74. package/dist/irdevice/other.js +145 -98
  75. package/dist/irdevice/other.js.map +1 -1
  76. package/dist/irdevice/tv.d.ts +12 -9
  77. package/dist/irdevice/tv.d.ts.map +1 -1
  78. package/dist/irdevice/tv.js +143 -93
  79. package/dist/irdevice/tv.js.map +1 -1
  80. package/dist/irdevice/vacuumcleaner.d.ts +9 -10
  81. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  82. package/dist/irdevice/vacuumcleaner.js +132 -89
  83. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  84. package/dist/irdevice/waterheater.d.ts +8 -9
  85. package/dist/irdevice/waterheater.d.ts.map +1 -1
  86. package/dist/irdevice/waterheater.js +132 -89
  87. package/dist/irdevice/waterheater.js.map +1 -1
  88. package/dist/platform.d.ts +13 -12
  89. package/dist/platform.d.ts.map +1 -1
  90. package/dist/platform.js +530 -421
  91. package/dist/platform.js.map +1 -1
  92. package/dist/settings.d.ts +22 -11
  93. package/dist/settings.d.ts.map +1 -1
  94. package/dist/settings.js.map +1 -1
  95. package/homebridge-ui/public/index.html +1 -0
  96. package/package.json +11 -9
  97. package/src/device/bot.ts +656 -659
  98. package/src/device/ceilinglight.ts +1208 -0
  99. package/src/device/colorbulb.ts +482 -334
  100. package/src/device/contact.ts +309 -241
  101. package/src/device/curtain.ts +571 -516
  102. package/src/device/humidifier.ts +456 -403
  103. package/src/device/lock.ts +314 -149
  104. package/src/device/meter.ts +378 -280
  105. package/src/device/meterplus.ts +391 -219
  106. package/src/device/motion.ts +285 -222
  107. package/src/device/plug.ts +299 -260
  108. package/src/device/striplight.ts +522 -289
  109. package/src/irdevice/airconditioner.ts +322 -245
  110. package/src/irdevice/airpurifier.ts +151 -103
  111. package/src/irdevice/camera.ts +131 -85
  112. package/src/irdevice/fan.ts +157 -106
  113. package/src/irdevice/light.ts +135 -103
  114. package/src/irdevice/other.ts +143 -97
  115. package/src/irdevice/tv.ts +142 -93
  116. package/src/irdevice/vacuumcleaner.ts +131 -89
  117. package/src/irdevice/waterheater.ts +130 -89
  118. package/src/platform.ts +528 -449
  119. package/src/settings.ts +23 -11
@@ -1,6 +1,7 @@
1
1
  import https from 'https';
2
2
  import crypto from 'crypto';
3
3
  import { IncomingMessage } from 'http';
4
+ import superStringify from 'super-stringify';
4
5
  import { SwitchBotPlatform } from '../platform';
5
6
  import { irDevicesConfig, irdevice, HostDomain, DevicePath } from '../settings';
6
7
  import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
@@ -16,19 +17,12 @@ export class AirConditioner {
16
17
 
17
18
  // Characteristic Values
18
19
  Active!: CharacteristicValue;
19
- ActiveCached!: CharacteristicValue;
20
20
  RotationSpeed!: CharacteristicValue;
21
- RotationSpeedCached!: CharacteristicValue;
22
21
  CurrentTemperature!: CharacteristicValue;
23
- CurrentTemperatureCached!: CharacteristicValue;
24
22
  TargetHeaterCoolerState!: CharacteristicValue;
25
- TargetHeaterCoolerStateCached!: CharacteristicValue;
26
23
  CurrentHeaterCoolerState!: CharacteristicValue;
27
- CurrentHeaterCoolerStateCached!: CharacteristicValue;
28
24
  HeatingThresholdTemperature!: CharacteristicValue;
29
- HeatingThresholdTemperatureCached!: CharacteristicValue;
30
25
  CoolingThresholdTemperature!: CharacteristicValue;
31
- CoolingThresholdTemperatureCached!: CharacteristicValue;
32
26
 
33
27
  // Others
34
28
  state!: string;
@@ -54,30 +48,17 @@ export class AirConditioner {
54
48
  this.logs(device);
55
49
  this.config(device);
56
50
  this.pushOnChanges(device);
57
- if (this.Active === undefined) {
58
- this.Active = this.platform.Characteristic.Active.INACTIVE;
59
- } else {
60
- this.Active = this.accessory.context.Active;
61
- }
62
- if (this.CurrentTemperature === undefined) {
63
- this.CurrentTemperature = 24;
64
- } else {
65
- this.CurrentTemperature = this.accessory.context.CurrentTemperature;
66
- }
67
- if (device.irair?.hide_automode) {
68
- this.hide_automode = device.irair?.hide_automode;
69
- this.accessory.context.hide_automode = this.hide_automode;
70
- } else {
71
- this.hide_automode = device.irair?.hide_automode;
72
- this.accessory.context.hide_automode = this.hide_automode;
73
- }
51
+ this.context(device);
74
52
 
75
53
  // set accessory information
76
54
  accessory
77
55
  .getService(this.platform.Service.AccessoryInformation)!
78
56
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
79
57
  .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
80
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
58
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
59
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
60
+ .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
61
+ .updateValue(this.FirmwareRevision(accessory, device));
81
62
 
82
63
  // get the Television service if it exists, otherwise create a new Television service
83
64
  // you can create multiple services for each accessory
@@ -110,14 +91,14 @@ export class AirConditioner {
110
91
  this.TargetHeaterCoolerState = 1 || 2;
111
92
  this.ValidValues = [1, 2];
112
93
  this.debugLog(
113
- `Air Conditioner: ${this.accessory.displayName} ValidValues: ${JSON.stringify(this.ValidValues)},` +
94
+ `${this.device.remoteType}: ${this.accessory.displayName} ValidValues: ${superStringify(this.ValidValues)},` +
114
95
  ` hide_automode: ${this.hide_automode}, TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`,
115
96
  );
116
97
  } else {
117
98
  this.TargetHeaterCoolerState = 0 || 1 || 2;
118
99
  this.ValidValues = [0, 1, 2];
119
100
  this.debugLog(
120
- `Air Conditioner: ${this.accessory.displayName} ValidValues: ${JSON.stringify(this.ValidValues)},` +
101
+ `${this.device.remoteType}: ${this.accessory.displayName} ValidValues: ${superStringify(this.ValidValues)},` +
121
102
  ` hide_automode: ${this.hide_automode}, TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`,
122
103
  );
123
104
  }
@@ -183,20 +164,26 @@ export class AirConditioner {
183
164
  */
184
165
  async pushAirConditionerOnChanges(): Promise<void> {
185
166
  if (this.Active !== this.platform.Characteristic.Active.ACTIVE || this.pushOn) {
186
- const body = JSON.stringify({
187
- 'command': 'turnOn',
167
+ const commandType: string = await this.commandType();
168
+ const command: string = await this.commandOn();
169
+
170
+ const body = superStringify({
171
+ 'command': command,
188
172
  'parameter': 'default',
189
- 'commandType': 'command',
173
+ 'commandType': commandType,
190
174
  });
191
175
  await this.pushChanges(body);
192
176
  }
193
177
  }
194
178
 
195
179
  async pushAirConditionerOffChanges(): Promise<void> {
196
- const body = JSON.stringify({
197
- 'command': 'turnOff',
180
+ const commandType: string = await this.commandType();
181
+ const command: string = await this.commandOff();
182
+
183
+ const body = superStringify({
184
+ 'command': command,
198
185
  'parameter': 'default',
199
- 'commandType': 'command',
186
+ 'commandType': commandType,
200
187
  });
201
188
  await this.pushChanges(body);
202
189
  }
@@ -228,22 +215,23 @@ export class AirConditioner {
228
215
  if (this.CurrentMode === 1) {
229
216
  this.CurrentTemperature = 25;
230
217
  this.debugLog(
231
- `Air Conditioner: ${this.accessory.displayName} CurrentMode: ${this.CurrentMode},` + ` CurrentTemperature: ${this.CurrentTemperature}`,
218
+ `${this.device.remoteType}: ${this.accessory.displayName} CurrentMode: ${this.CurrentMode},`
219
+ + ` CurrentTemperature: ${this.CurrentTemperature}`,
232
220
  );
233
221
  }
234
222
  const parameter = `${this.CurrentTemperature},${this.CurrentMode},${this.CurrentFanSpeed},${this.state}`;
235
223
 
236
224
  if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
237
225
  this.CurrentTemperatureUndefined();
238
- if (this.CurrentTemperature < this.CurrentTemperatureCached) {
226
+ if (this.CurrentTemperature < this.accessory.context.CurrentTemperature) {
239
227
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
240
- } else if (this.CurrentTemperature > this.CurrentTemperatureCached) {
228
+ } else if (this.CurrentTemperature > this.accessory.context.CurrentTemperature) {
241
229
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
242
230
  }
243
231
  } else {
244
232
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
245
233
  }
246
- const body = JSON.stringify({
234
+ const body = superStringify({
247
235
  'command': 'setAll',
248
236
  'parameter': `${parameter}`,
249
237
  'commandType': 'command',
@@ -253,166 +241,72 @@ export class AirConditioner {
253
241
  }
254
242
 
255
243
  async pushChanges(body): Promise<void> {
256
- try {
244
+ if (this.device.connectionType === 'OpenAPI') {
245
+ try {
257
246
  // Make Push On request to the API
258
- const t = Date.now();
259
- const nonce = 'requestID';
260
- const data = this.platform.config.credentials?.token + t + nonce;
261
- const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
262
- .update(Buffer.from(data, 'utf-8'))
263
- .digest();
264
- const sign = signTerm.toString('base64');
265
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} sign: ${sign}`);
266
- this.infoLog(`Air Conditioner: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
267
- const options = {
268
- hostname: HostDomain,
269
- port: 443,
270
- path: `${DevicePath}/${this.device.deviceId}/commands`,
271
- method: 'POST',
272
- headers: {
273
- 'Authorization': this.platform.config.credentials?.token,
274
- 'sign': sign,
275
- 'nonce': nonce,
276
- 't': t,
277
- 'Content-Type': 'application/json',
278
- 'Content-Length': body.length,
279
- },
280
- };
281
- const req = https.request(options, res => {
282
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
283
- this.statusCode({ res });
284
- res.on('data', d => {
285
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} d: ${d}`);
247
+ const t = Date.now();
248
+ const nonce = 'requestID';
249
+ const data = this.platform.config.credentials?.token + t + nonce;
250
+ const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
251
+ .update(Buffer.from(data, 'utf-8'))
252
+ .digest();
253
+ const sign = signTerm.toString('base64');
254
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} sign: ${sign}`);
255
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
256
+ const options = {
257
+ hostname: HostDomain,
258
+ port: 443,
259
+ path: `${DevicePath}/${this.device.deviceId}/commands`,
260
+ method: 'POST',
261
+ headers: {
262
+ 'Authorization': this.platform.config.credentials?.token,
263
+ 'sign': sign,
264
+ 'nonce': nonce,
265
+ 't': t,
266
+ 'Content-Type': 'application/json',
267
+ 'Content-Length': body.length,
268
+ },
269
+ };
270
+ const req = https.request(options, res => {
271
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges statusCode: ${res.statusCode}`);
272
+ this.statusCode({ res });
273
+ res.on('data', d => {
274
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} d: ${d}`);
275
+ });
286
276
  });
287
- });
288
- req.on('error', (e: any) => {
289
- this.errorLog(`Air Conditioner: ${this.accessory.displayName} error message: ${e.message}`);
290
- });
291
- req.write(body);
292
- req.end();
293
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
294
- this.CurrentTemperatureCached = this.CurrentTemperature;
295
- this.accessory.context.CurrentTemperature = this.CurrentTemperatureCached;
296
- this.HeatingThresholdTemperature = this.CurrentTemperatureCached;
297
- this.HeatingThresholdTemperatureCached = this.CurrentTemperatureCached;
298
- this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperatureCached;
299
- this.CoolingThresholdTemperature = this.CurrentTemperatureCached;
300
- this.CoolingThresholdTemperatureCached = this.CurrentTemperatureCached;
301
- this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperatureCached;
302
- this.updateHomeKitCharacteristics();
303
- } catch (e: any) {
304
- this.errorLog(`Air Conditioner: ${this.accessory.displayName} failed pushChanges`);
305
- if (this.deviceLogging.includes('debug')) {
306
- this.errorLog(`Air Conditioner: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
307
- }
308
- this.apiError(e);
309
- }
310
- }
311
-
312
- async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
313
- switch (res.statusCode) {
314
- case 151:
315
- this.errorLog(`Air Conditioner: ${this.accessory.displayName} Command not supported by this device type.`);
316
- break;
317
- case 152:
318
- this.errorLog(`Air Conditioner: ${this.accessory.displayName} Device not found.`);
319
- break;
320
- case 160:
321
- this.errorLog(`Air Conditioner: ${this.accessory.displayName} Command is not supported.`);
322
- break;
323
- case 161:
324
- this.errorLog(`Air Conditioner: ${this.accessory.displayName} Device is offline.`);
325
- break;
326
- case 171:
327
- this.errorLog(`Air Conditioner: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
328
- break;
329
- case 190:
330
- this.errorLog(
331
- `Air Conditioner: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
332
- ` with server, Or command: ${JSON.stringify(res)} format is invalid`,
277
+ req.on('error', (e: any) => {
278
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} error message: ${e.message}`);
279
+ });
280
+ req.write(body);
281
+ req.end();
282
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
283
+ this.accessory.context.CurrentTemperature = this.CurrentTemperature;
284
+ this.HeatingThresholdTemperature = this.CurrentTemperature;
285
+ this.CoolingThresholdTemperature = this.CurrentTemperature;
286
+ this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
287
+ this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
288
+ this.updateHomeKitCharacteristics();
289
+ } catch (e: any) {
290
+ this.apiError(e);
291
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
292
+ + ` Error Message: ${superStringify(e.message)}`,
333
293
  );
334
- break;
335
- case 100:
336
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Command successfully sent.`);
337
- break;
338
- default:
339
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Unknown statusCode.`);
340
- }
341
- }
342
-
343
- async updateHomeKitCharacteristics(): Promise<void> {
344
- if (this.Active === undefined) {
345
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Active: ${this.Active}`);
346
- } else {
347
- this.coolerService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
348
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
349
- }
350
- if (this.RotationSpeed === undefined) {
351
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
352
- } else {
353
- this.coolerService?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
354
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
355
- }
356
- if (this.CurrentTemperature === undefined) {
357
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
358
- } else {
359
- this.coolerService?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
360
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
361
- }
362
- if (this.TargetHeaterCoolerState === undefined) {
363
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
364
- } else {
365
- this.coolerService?.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.TargetHeaterCoolerState);
366
- this.debugLog(
367
- `Air Conditioner: ${this.accessory.displayName}` + ` updateCharacteristic TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`,
368
- );
369
- }
370
- if (this.CurrentHeaterCoolerState === undefined) {
371
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
294
+ }
372
295
  } else {
373
- this.coolerService?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
374
- this.debugLog(
375
- `Air Conditioner: ${this.accessory.displayName}` + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
376
- );
296
+ this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
297
+ + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
377
298
  }
378
- if (this.HeatingThresholdTemperature === undefined) {
379
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
380
- } else {
381
- this.coolerService?.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, this.HeatingThresholdTemperature);
382
- this.debugLog(
383
- `Air Conditioner: ${this.accessory.displayName}` + ` updateCharacteristic HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`,
384
- );
385
- }
386
- if (this.CoolingThresholdTemperature === undefined) {
387
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`);
388
- } else {
389
- this.coolerService?.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, this.CoolingThresholdTemperature);
390
- this.debugLog(
391
- `Air Conditioner: ${this.accessory.displayName}` + ` updateCharacteristic CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`,
392
- );
393
- }
394
- }
395
-
396
- async apiError(e: any): Promise<void> {
397
- this.coolerService.updateCharacteristic(this.platform.Characteristic.Active, e);
398
- this.coolerService.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
399
- this.coolerService.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
400
- this.coolerService.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, e);
401
- this.coolerService.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, e);
402
- this.coolerService.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, e);
403
- this.coolerService.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, e);
404
- //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
405
299
  }
406
300
 
407
301
  async CurrentTemperatureGet(): Promise<CharacteristicValue> {
408
302
  if (this.CurrentTemperature === undefined) {
409
303
  this.CurrentTemperature = 24;
410
- this.CurrentTemperatureCached = this.CurrentTemperature;
304
+ this.accessory.context.CurrentTemperature = this.CurrentTemperature;
411
305
  } else {
412
- this.CurrentTemperatureCached = this.CurrentTemperature;
306
+ this.accessory.context.CurrentTemperature = this.CurrentTemperature;
413
307
  }
414
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get CurrentTemperature: ${this.CurrentTemperature}`);
415
- this.accessory.context.CurrentTemperature = this.CurrentTemperatureCached;
308
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get CurrentTemperature: ${this.CurrentTemperature}`);
309
+ this.accessory.context.CurrentTemperature = this.CurrentTemperature;
416
310
  return this.CurrentTemperature;
417
311
  }
418
312
 
@@ -424,9 +318,8 @@ export class AirConditioner {
424
318
  } else {
425
319
  this.RotationSpeed = this.CurrentFanSpeed - 1;
426
320
  }
427
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get RotationSpeed: ${this.RotationSpeed}`);
428
- this.RotationSpeedCached = this.RotationSpeed;
429
- this.accessory.context.RotationSpeed = this.RotationSpeedCached;
321
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get RotationSpeed: ${this.RotationSpeed}`);
322
+ this.accessory.context.RotationSpeed = this.RotationSpeed;
430
323
  return this.RotationSpeed;
431
324
  }
432
325
 
@@ -437,23 +330,19 @@ export class AirConditioner {
437
330
  this.CurrentFanSpeed = Number(value) + 1;
438
331
  }
439
332
  this.RotationSpeed = this.CurrentFanSpeed;
440
- this.RotationSpeedCached = this.RotationSpeed;
441
- this.accessory.context.RotationSpeed = this.RotationSpeedCached;
333
+ this.accessory.context.RotationSpeed = this.RotationSpeed;
442
334
  this.pushAirConditionerStatusChanges();
443
335
  }
444
336
 
445
337
  async ActiveSet(value: CharacteristicValue): Promise<void> {
446
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set Active: ${value}`);
447
-
338
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
448
339
  this.Active = value;
449
- this.ActiveCached = this.Active;
450
- this.accessory.context.Active = this.ActiveCached;
451
-
340
+ this.accessory.context.Active = this.Active;
452
341
  if (value === this.platform.Characteristic.Active.INACTIVE) {
453
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
342
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
454
343
  this.pushAirConditionerOffChanges();
455
344
  } else {
456
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} pushAirConditionerOnChanges, Active: ${this.Active}`);
345
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOnChanges, Active: ${this.Active}`);
457
346
  if (this.pushOn) {
458
347
  this.pushAirConditionerOnChanges();
459
348
  } else {
@@ -466,24 +355,23 @@ export class AirConditioner {
466
355
  if (this.ValidValues === this.valid012) {
467
356
  this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
468
357
  this.debugLog(
469
- `Air Conditioner: ${this.accessory.displayName} Get (AUTO) TargetHeaterCoolerState: ${this.CurrentHeaterCoolerState},` +
358
+ `${this.device.remoteType}: ${this.accessory.displayName} Get (AUTO) TargetHeaterCoolerState: ${this.CurrentHeaterCoolerState},` +
470
359
  ` ValidValues: ${this.ValidValues}`,
471
360
  );
472
361
  } else if (this.ValidValues === this.valid12) {
473
362
  this.TargetHeaterCoolerState =
474
363
  this.platform.Characteristic.TargetHeaterCoolerState.COOL || this.platform.Characteristic.TargetHeaterCoolerState.HEAT;
475
364
  this.debugLog(
476
- `Air Conditioner: ${this.accessory.displayName} Get (COOL/HEAT) TargetHeaterCoolerState: ${this.CurrentHeaterCoolerState},` +
365
+ `${this.device.remoteType}: ${this.accessory.displayName} Get (COOL/HEAT) TargetHeaterCoolerState: ${this.CurrentHeaterCoolerState},` +
477
366
  ` ValidValues: ${this.ValidValues}`,
478
367
  );
479
368
  } else {
480
369
  this.debugLog(
481
- `Air Conditioner: ${this.accessory.displayName} Get TargetHeaterCoolerState: ${this.CurrentHeaterCoolerState},` +
370
+ `${this.device.remoteType}: ${this.accessory.displayName} Get TargetHeaterCoolerState: ${this.CurrentHeaterCoolerState},` +
482
371
  ` ValidValues: ${this.ValidValues}`,
483
372
  );
484
373
  }
485
- this.TargetHeaterCoolerStateCached = this.TargetHeaterCoolerState;
486
- this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerStateCached;
374
+ this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerState;
487
375
  return this.TargetHeaterCoolerState;
488
376
  }
489
377
 
@@ -495,7 +383,7 @@ export class AirConditioner {
495
383
  this.TargetHeaterCoolerStateCOOL();
496
384
  } else {
497
385
  this.errorLog(
498
- `Air Conditioner: ${this.accessory.displayName} Set TargetHeaterCoolerState: ${this.TargetHeaterCoolerState},` +
386
+ `${this.device.remoteType}: ${this.accessory.displayName} Set TargetHeaterCoolerState: ${this.TargetHeaterCoolerState},` +
499
387
  ` hide_automode: ${this.hide_automode} `,
500
388
  );
501
389
  }
@@ -508,96 +396,93 @@ export class AirConditioner {
508
396
  this.TargetHeaterCoolerStateCOOL();
509
397
  } else {
510
398
  this.errorLog(
511
- `Air Conditioner: ${this.accessory.displayName} Set TargetHeaterCoolerState: ${this.TargetHeaterCoolerState},` +
399
+ `${this.device.remoteType}: ${this.accessory.displayName} Set TargetHeaterCoolerState: ${this.TargetHeaterCoolerState},` +
512
400
  ` hide_automode: ${this.hide_automode} `,
513
401
  );
514
402
  }
515
403
  }
516
- this.TargetHeaterCoolerStateCached = this.TargetHeaterCoolerState;
517
- this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerStateCached;
404
+ this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerState;
518
405
  this.pushAirConditionerStatusChanges();
519
406
  }
520
407
 
521
408
  async TargetHeaterCoolerStateAUTO(): Promise<void> {
522
409
  this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
523
410
  this.CurrentMode = 1;
524
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set (AUTO) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
525
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
411
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (AUTO) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
412
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
526
413
  }
527
414
 
528
415
  async TargetHeaterCoolerStateCOOL(): Promise<void> {
529
416
  this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.COOL;
530
417
  this.CurrentMode = 2;
531
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set (COOL) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
532
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
418
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (COOL) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
419
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
533
420
  }
534
421
 
535
422
  async TargetHeaterCoolerStateHEAT(): Promise<void> {
536
423
  this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.HEAT;
537
424
  this.CurrentMode = 5;
538
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set (HEAT) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
539
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
425
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (HEAT) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
426
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
540
427
  }
541
428
 
542
429
  async CurrentHeaterCoolerStateGet(): Promise<CharacteristicValue> {
543
430
  if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
544
431
  this.CurrentTemperatureUndefined();
545
- if (this.CurrentTemperature < this.CurrentTemperatureCached) {
432
+ if (this.CurrentTemperature < this.accessory.context.CurrentTemperature) {
546
433
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
547
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get (COOLLING) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
548
- } else if (this.CurrentTemperature > this.CurrentTemperatureCached) {
434
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
435
+ +` Get (COOLLING) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
436
+ } else if (this.CurrentTemperature > this.accessory.context.CurrentTemperature) {
549
437
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
550
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get (HEATING) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
438
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
439
+ +` Get (HEATING) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
551
440
  }
552
441
  } else {
553
442
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
554
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get (INACTIVE) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
443
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
444
+ +` Get (INACTIVE) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
555
445
  }
556
- this.CurrentHeaterCoolerStateCached = this.CurrentHeaterCoolerState;
557
- this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerStateCached;
446
+ this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerState;
558
447
  return this.CurrentHeaterCoolerState;
559
448
  }
560
449
 
561
450
  async HeatingThresholdTemperatureGet(): Promise<CharacteristicValue> {
562
451
  this.CurrentTemperatureUndefined;
563
- this.CurrentTemperature = this.CurrentTemperatureCached;
564
- this.HeatingThresholdTemperature = this.CurrentTemperatureCached;
565
- this.HeatingThresholdTemperatureCached = this.HeatingThresholdTemperature;
566
- this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperatureCached;
567
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
452
+ this.CurrentTemperature = this.accessory.context.CurrentTemperature;
453
+ this.HeatingThresholdTemperature = this.accessory.context.CurrentTemperature;
454
+ this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
455
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
568
456
  return this.HeatingThresholdTemperature;
569
457
  }
570
458
 
571
459
  async HeatingThresholdTemperatureSet(value: CharacteristicValue): Promise<void> {
572
- this.CurrentTemperatureCached = this.CurrentTemperature;
460
+ this.accessory.context.CurrentTemperature = this.CurrentTemperature;
573
461
  this.CurrentTemperature = value;
574
- this.HeatingThresholdTemperatureCached = this.HeatingThresholdTemperature;
575
- this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperatureCached;
462
+ this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
576
463
  this.debugLog(
577
- `Air Conditioner: ${this.accessory.displayName} Set HeatingThresholdTemperature: ${this.HeatingThresholdTemperature},` +
578
- ` CurrentTemperatureCached: ${this.CurrentTemperatureCached}`,
464
+ `${this.device.remoteType}: ${this.accessory.displayName} Set HeatingThresholdTemperature: ${this.HeatingThresholdTemperature},` +
465
+ ` CurrentTemperatureCached: ${this.accessory.context.CurrentTemperature}`,
579
466
  );
580
467
  this.pushAirConditionerStatusChanges();
581
468
  }
582
469
 
583
470
  async CoolingThresholdTemperatureGet(): Promise<CharacteristicValue> {
584
471
  this.CurrentTemperatureUndefined;
585
- this.CurrentTemperature = this.CurrentTemperatureCached;
586
- this.CoolingThresholdTemperature = this.CurrentTemperatureCached;
587
- this.CoolingThresholdTemperatureCached = this.CoolingThresholdTemperature;
588
- this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperatureCached;
589
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`);
472
+ this.CurrentTemperature = this.accessory.context.CurrentTemperature;
473
+ this.CoolingThresholdTemperature = this.accessory.context.CurrentTemperature;
474
+ this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
475
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`);
590
476
  return this.CoolingThresholdTemperature;
591
477
  }
592
478
 
593
479
  async CoolingThresholdTemperatureSet(value: CharacteristicValue): Promise<void> {
594
- this.CurrentTemperatureCached = this.CurrentTemperature;
480
+ this.accessory.context.CurrentTemperature = this.CurrentTemperature;
595
481
  this.CurrentTemperature = value;
596
- this.CoolingThresholdTemperatureCached = this.CoolingThresholdTemperature;
597
- this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperatureCached;
482
+ this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
598
483
  this.debugLog(
599
- `Air Conditioner: ${this.accessory.displayName} Set CoolingThresholdTemperature: ${this.CoolingThresholdTemperature},` +
600
- ` CurrentTemperatureCached: ${this.CurrentTemperatureCached}`,
484
+ `${this.device.remoteType}: ${this.accessory.displayName} Set CoolingThresholdTemperature: ${this.CoolingThresholdTemperature},` +
485
+ ` CurrentTemperatureCached: ${this.accessory.context.CurrentTemperature}`,
601
486
  );
602
487
  this.pushAirConditionerStatusChanges();
603
488
  }
@@ -606,11 +491,181 @@ export class AirConditioner {
606
491
  if (this.CurrentTemperature === undefined) {
607
492
  this.CurrentTemperature = 24;
608
493
  }
609
- if (this.CurrentTemperatureCached === undefined) {
494
+ if (this.accessory.context.CurrentTemperature === undefined) {
610
495
  this.CurrentTemperature = 30;
611
496
  }
612
497
  }
613
498
 
499
+ async updateHomeKitCharacteristics(): Promise<void> {
500
+ if (this.Active === undefined) {
501
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
502
+ } else {
503
+ this.accessory.context.Active = this.Active;
504
+ this.coolerService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
505
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
506
+ }
507
+ if (this.RotationSpeed === undefined) {
508
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
509
+ } else {
510
+ this.accessory.context.RotationSpeed = this.RotationSpeed;
511
+ this.coolerService?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
512
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
513
+ }
514
+ if (this.CurrentTemperature === undefined) {
515
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
516
+ } else {
517
+ this.accessory.context.CurrentTemperature = this.CurrentTemperature;
518
+ this.coolerService?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
519
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
520
+ }
521
+ if (this.TargetHeaterCoolerState === undefined) {
522
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
523
+ } else {
524
+ this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerState;
525
+ this.coolerService?.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.TargetHeaterCoolerState);
526
+ this.debugLog(
527
+ `${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`,
528
+ );
529
+ }
530
+ if (this.CurrentHeaterCoolerState === undefined) {
531
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
532
+ } else {
533
+ this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerState;
534
+ this.coolerService?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
535
+ this.debugLog(
536
+ `${this.device.remoteType}: ${this.accessory.displayName}`
537
+ + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
538
+ );
539
+ }
540
+ if (this.HeatingThresholdTemperature === undefined) {
541
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
542
+ } else {
543
+ this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
544
+ this.coolerService?.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, this.HeatingThresholdTemperature);
545
+ this.debugLog(
546
+ `${this.device.remoteType}: ${this.accessory.displayName}`
547
+ + ` updateCharacteristic HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`,
548
+ );
549
+ }
550
+ if (this.CoolingThresholdTemperature === undefined) {
551
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`);
552
+ } else {
553
+ this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
554
+ this.coolerService?.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, this.CoolingThresholdTemperature);
555
+ this.debugLog(
556
+ `${this.device.remoteType}: ${this.accessory.displayName}`
557
+ + ` updateCharacteristic CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`,
558
+ );
559
+ }
560
+ }
561
+
562
+ async commandType() {
563
+ let commandType: string;
564
+ if (this.device.customize) {
565
+ commandType = 'customize';
566
+ } else {
567
+ commandType = 'command';
568
+ }
569
+ return commandType;
570
+ }
571
+
572
+ async commandOn() {
573
+ let command: string;
574
+ if (this.device.customize && this.device.customOn) {
575
+ command = this.device.customOn;
576
+ } else {
577
+ command = 'turnOn';
578
+ }
579
+ return command;
580
+ }
581
+
582
+ async commandOff() {
583
+ let command: string;
584
+ if (this.device.customize && this.device.customOn) {
585
+ command = this.device.customOn;
586
+ } else {
587
+ command = 'turnOff';
588
+ }
589
+ return command;
590
+ }
591
+
592
+ async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
593
+ switch (res.statusCode) {
594
+ case 151:
595
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this device type.`);
596
+ break;
597
+ case 152:
598
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found.`);
599
+ break;
600
+ case 160:
601
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported.`);
602
+ break;
603
+ case 161:
604
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline.`);
605
+ break;
606
+ case 171:
607
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
608
+ break;
609
+ case 190:
610
+ this.errorLog(
611
+ `${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
612
+ ` with server, Or command: ${superStringify(res)} format is invalid`,
613
+ );
614
+ break;
615
+ case 100:
616
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent.`);
617
+ break;
618
+ default:
619
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode.`);
620
+ }
621
+ }
622
+
623
+ async apiError(e: any): Promise<void> {
624
+ this.coolerService.updateCharacteristic(this.platform.Characteristic.Active, e);
625
+ this.coolerService.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
626
+ this.coolerService.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
627
+ this.coolerService.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, e);
628
+ this.coolerService.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, e);
629
+ this.coolerService.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, e);
630
+ this.coolerService.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, e);
631
+ }
632
+
633
+ FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
634
+ let FirmwareRevision: string;
635
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
636
+ + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
637
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
638
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
639
+ if (accessory.context.FirmwareRevision) {
640
+ FirmwareRevision = accessory.context.FirmwareRevision;
641
+ } else if (device.firmware) {
642
+ FirmwareRevision = device.firmware;
643
+ } else {
644
+ FirmwareRevision = this.platform.version;
645
+ }
646
+ return FirmwareRevision;
647
+ }
648
+
649
+ async context(device: irdevice & irDevicesConfig) {
650
+ if (this.Active === undefined) {
651
+ this.Active = this.platform.Characteristic.Active.INACTIVE;
652
+ } else {
653
+ this.Active = this.accessory.context.Active;
654
+ }
655
+ if (this.CurrentTemperature === undefined) {
656
+ this.CurrentTemperature = 24;
657
+ } else {
658
+ this.CurrentTemperature = this.accessory.context.CurrentTemperature;
659
+ }
660
+ if (device.irair?.hide_automode) {
661
+ this.hide_automode = device.irair?.hide_automode;
662
+ this.accessory.context.hide_automode = this.hide_automode;
663
+ } else {
664
+ this.hide_automode = device.irair?.hide_automode;
665
+ this.accessory.context.hide_automode = this.hide_automode;
666
+ }
667
+ }
668
+
614
669
  async config(device: irdevice & irDevicesConfig): Promise<void> {
615
670
  let config = {};
616
671
  if (device.irair) {
@@ -619,24 +674,30 @@ export class AirConditioner {
619
674
  if (device.logging !== undefined) {
620
675
  config['logging'] = device.logging;
621
676
  }
677
+ if (device.connectionType !== undefined) {
678
+ config['connectionType'] = device.connectionType;
679
+ }
680
+ if (device.external !== undefined) {
681
+ config['external'] = device.external;
682
+ }
622
683
  if (Object.entries(config).length !== 0) {
623
- this.infoLog(`Air Conditioner: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
684
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
624
685
  }
625
686
  }
626
687
 
627
688
  async logs(device: irdevice & irDevicesConfig): Promise<void> {
628
689
  if (this.platform.debugMode) {
629
690
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
630
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
691
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
631
692
  } else if (device.logging) {
632
693
  this.deviceLogging = this.accessory.context.logging = device.logging;
633
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
694
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
634
695
  } else if (this.platform.config.options?.logging) {
635
696
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
636
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
697
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
637
698
  } else {
638
699
  this.deviceLogging = this.accessory.context.logging = 'standard';
639
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
700
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
640
701
  }
641
702
  }
642
703
 
@@ -664,12 +725,28 @@ export class AirConditioner {
664
725
  }
665
726
  }
666
727
 
728
+ debugWarnLog(...log: any[]): void {
729
+ if (this.enablingDeviceLogging()) {
730
+ if (this.deviceLogging?.includes('debug')) {
731
+ this.platform.log.warn('[DEBUG]', String(...log));
732
+ }
733
+ }
734
+ }
735
+
667
736
  errorLog(...log: any[]): void {
668
737
  if (this.enablingDeviceLogging()) {
669
738
  this.platform.log.error(String(...log));
670
739
  }
671
740
  }
672
741
 
742
+ debugErrorLog(...log: any[]): void {
743
+ if (this.enablingDeviceLogging()) {
744
+ if (this.deviceLogging?.includes('debug')) {
745
+ this.platform.log.error('[DEBUG]', String(...log));
746
+ }
747
+ }
748
+ }
749
+
673
750
  debugLog(...log: any[]): void {
674
751
  if (this.enablingDeviceLogging()) {
675
752
  if (this.deviceLogging === 'debug') {