@switchbot/homebridge-switchbot 2.0.0-beta.3 → 2.0.0-beta.31

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