@switchbot/homebridge-switchbot 2.0.0-beta.9 → 2.0.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 (120) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/README.md +3 -2
  3. package/config.schema.json +91 -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 +9 -12
  53. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  54. package/dist/irdevice/airconditioner.js +278 -230
  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 +524 -418
  91. package/dist/platform.js.map +1 -1
  92. package/dist/settings.d.ts +19 -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 +282 -241
  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 +522 -446
  119. package/src/settings.ts +20 -11
  120. package/.github/npm-version-script.js +0 -81
@@ -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';
@@ -17,13 +18,11 @@ export class AirPurifier {
17
18
  // Characteristic Values
18
19
  Active!: CharacteristicValue;
19
20
  APActive!: CharacteristicValue;
20
- ActiveCached!: CharacteristicValue;
21
21
  CurrentAPTemp!: CharacteristicValue;
22
22
  CurrentAPMode!: CharacteristicValue;
23
23
  RotationSpeed!: CharacteristicValue;
24
24
  CurrentAPFanSpeed!: CharacteristicValue;
25
25
  CurrentTemperature!: CharacteristicValue;
26
- CurrentTemperatureCached!: CharacteristicValue;
27
26
  CurrentAirPurifierState!: CharacteristicValue;
28
27
  CurrentHeaterCoolerState!: CharacteristicValue;
29
28
 
@@ -44,23 +43,17 @@ export class AirPurifier {
44
43
  // default placeholders
45
44
  this.logs(device);
46
45
  this.config(device);
47
- if (this.Active === undefined) {
48
- this.Active = this.platform.Characteristic.Active.INACTIVE;
49
- } else {
50
- this.Active = this.accessory.context.Active;
51
- }
52
- if (this.CurrentTemperature === undefined) {
53
- this.CurrentTemperature = 24;
54
- } else {
55
- this.CurrentTemperature = this.accessory.context.CurrentTemperature;
56
- }
46
+ this.context();
57
47
 
58
48
  // set accessory information
59
49
  accessory
60
50
  .getService(this.platform.Service.AccessoryInformation)!
61
51
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
62
52
  .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
63
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
53
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
54
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
55
+ .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
56
+ .updateValue(this.FirmwareRevision(accessory, device));
64
57
 
65
58
  // get the Television service if it exists, otherwise create a new Television service
66
59
  // you can create multiple services for each accessory
@@ -86,38 +79,14 @@ export class AirPurifier {
86
79
  }
87
80
 
88
81
  async ActiveSet(value: CharacteristicValue): Promise<void> {
89
- this.debugLog(`Air Purifier: ${this.accessory.displayName} Set Active: ${value}`);
82
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
83
+ this.Active = value;
84
+ this.accessory.context.Active = this.Active;
90
85
  if (value === this.platform.Characteristic.Active.INACTIVE) {
91
86
  this.pushAirPurifierOffChanges();
92
87
  } else {
93
88
  this.pushAirPurifierOnChanges();
94
89
  }
95
- this.Active = value;
96
- this.ActiveCached = this.Active;
97
- this.accessory.context.Active = this.ActiveCached;
98
- }
99
-
100
- async updateHomeKitCharacteristics(): Promise<void> {
101
- if (this.Active === undefined) {
102
- this.debugLog(`Air Purifier: ${this.accessory.displayName} Active: ${this.Active}`);
103
- } else {
104
- this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
105
- this.debugLog(`Air Purifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
106
- }
107
- if (this.CurrentAirPurifierState === undefined) {
108
- this.debugLog(`Air Purifier: ${this.accessory.displayName} CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
109
- } else {
110
- this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, this.CurrentAirPurifierState);
111
- this.debugLog(`Air Purifier: ${this.accessory.displayName}` + ` updateCharacteristic CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
112
- }
113
- if (this.CurrentHeaterCoolerState === undefined) {
114
- this.debugLog(`Air Purifier: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
115
- } else {
116
- this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
117
- this.debugLog(
118
- `Air Purifier: ${this.accessory.displayName}` + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
119
- );
120
- }
121
90
  }
122
91
 
123
92
  async TargetAirPurifierStateSet(value: CharacteristicValue): Promise<void> {
@@ -158,7 +127,7 @@ export class AirPurifier {
158
127
  */
159
128
  async pushAirPurifierOnChanges(): Promise<void> {
160
129
  if (this.Active !== 1) {
161
- const body = JSON.stringify({
130
+ const body = superStringify({
162
131
  'command': 'turnOn',
163
132
  'parameter': 'default',
164
133
  'commandType': 'command',
@@ -169,7 +138,7 @@ export class AirPurifier {
169
138
 
170
139
  async pushAirPurifierOffChanges(): Promise<void> {
171
140
  if (this.Active !== 0) {
172
- const body = JSON.stringify({
141
+ const body = superStringify({
173
142
  'command': 'turnOff',
174
143
  'parameter': 'default',
175
144
  'commandType': 'command',
@@ -195,7 +164,7 @@ export class AirPurifier {
195
164
  this.CurrentAPFanSpeed = this.CurrentFanSpeed || 1;
196
165
  this.APActive = this.Active === 1 ? 'on' : 'off';
197
166
  const parameter = `${this.CurrentAPTemp},${this.CurrentAPMode},${this.CurrentAPFanSpeed},${this.APActive}`;
198
- const body = JSON.stringify({
167
+ const body = superStringify({
199
168
  'command': 'setAll',
200
169
  'parameter': `${parameter}`,
201
170
  'commandType': 'command',
@@ -213,86 +182,115 @@ export class AirPurifier {
213
182
  }
214
183
 
215
184
  async pushChanges(body): Promise<void> {
216
- try {
185
+ if (this.device.connectionType === 'OpenAPI') {
186
+ try {
217
187
  // Make Push On request to the API
218
- const t = Date.now();
219
- const nonce = 'requestID';
220
- const data = this.platform.config.credentials?.token + t + nonce;
221
- const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
222
- .update(Buffer.from(data, 'utf-8'))
223
- .digest();
224
- const sign = signTerm.toString('base64');
225
- this.debugLog(`Air Purifier: ${this.accessory.displayName} sign: ${sign}`);
226
- this.infoLog(`Air Purifier: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
227
- const options = {
228
- hostname: HostDomain,
229
- port: 443,
230
- path: `${DevicePath}/${this.device.deviceId}/commands`,
231
- method: 'POST',
232
- headers: {
233
- 'Authorization': this.platform.config.credentials?.token,
234
- 'sign': sign,
235
- 'nonce': nonce,
236
- 't': t,
237
- 'Content-Type': 'application/json',
238
- 'Content-Length': body.length,
239
- },
240
- };
241
- const req = https.request(options, res => {
242
- this.debugLog(`Air Purifier: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
243
- this.statusCode({ res });
244
- res.on('data', d => {
245
- this.debugLog(`Air Purifier: ${this.accessory.displayName} d: ${d}`);
188
+ const t = Date.now();
189
+ const nonce = 'requestID';
190
+ const data = this.platform.config.credentials?.token + t + nonce;
191
+ const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
192
+ .update(Buffer.from(data, 'utf-8'))
193
+ .digest();
194
+ const sign = signTerm.toString('base64');
195
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} sign: ${sign}`);
196
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
197
+ const options = {
198
+ hostname: HostDomain,
199
+ port: 443,
200
+ path: `${DevicePath}/${this.device.deviceId}/commands`,
201
+ method: 'POST',
202
+ headers: {
203
+ 'Authorization': this.platform.config.credentials?.token,
204
+ 'sign': sign,
205
+ 'nonce': nonce,
206
+ 't': t,
207
+ 'Content-Type': 'application/json',
208
+ 'Content-Length': body.length,
209
+ },
210
+ };
211
+ const req = https.request(options, res => {
212
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
213
+ this.statusCode({ res });
214
+ res.on('data', d => {
215
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} d: ${d}`);
216
+ });
246
217
  });
247
- });
248
- req.on('error', (e: any) => {
249
- this.errorLog(`Air Purifier: ${this.accessory.displayName} error message: ${e.message}`);
250
- });
251
- req.write(body);
252
- req.end();
253
- this.debugLog(`Air Purifier: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
254
- this.updateHomeKitCharacteristics();
255
- this.CurrentTemperatureCached = this.CurrentTemperature;
256
- this.accessory.context.CurrentTemperature = this.CurrentTemperatureCached;
257
- } catch (e: any) {
258
- this.errorLog(`Air Purifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
259
- if (this.deviceLogging.includes('debug')) {
260
- this.errorLog(
261
- `Air Purifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
218
+ req.on('error', (e: any) => {
219
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} error message: ${e.message}`);
220
+ });
221
+ req.write(body);
222
+ req.end();
223
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
224
+ this.updateHomeKitCharacteristics();
225
+ this.accessory.context.CurrentTemperature = this.CurrentTemperature;
226
+ } catch (e: any) {
227
+ this.apiError(e);
228
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
229
+ + ` Error Message: ${superStringify(e.message)}`,
262
230
  );
263
231
  }
264
- this.apiError(e);
232
+ } else {
233
+ this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
234
+ + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
235
+ }
236
+ }
237
+
238
+ async updateHomeKitCharacteristics(): Promise<void> {
239
+ if (this.Active === undefined) {
240
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
241
+ } else {
242
+ this.accessory.context.Active = this.Active;
243
+ this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
244
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
245
+ }
246
+ if (this.CurrentAirPurifierState === undefined) {
247
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
248
+ } else {
249
+ this.accessory.context.CurrentAirPurifierState = this.CurrentAirPurifierState;
250
+ this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, this.CurrentAirPurifierState);
251
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
252
+ + ` updateCharacteristic CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
253
+ }
254
+ if (this.CurrentHeaterCoolerState === undefined) {
255
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
256
+ } else {
257
+ this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerState;
258
+ this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
259
+ this.debugLog(
260
+ `${this.device.remoteType}: ${this.accessory.displayName}`
261
+ + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
262
+ );
265
263
  }
266
264
  }
267
265
 
268
266
  async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
269
267
  switch (res.statusCode) {
270
268
  case 151:
271
- this.errorLog(`Air Purifier: ${this.accessory.displayName} Command not supported by this device type.`);
269
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this device type.`);
272
270
  break;
273
271
  case 152:
274
- this.errorLog(`Air Purifier: ${this.accessory.displayName} Device not found.`);
272
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found.`);
275
273
  break;
276
274
  case 160:
277
- this.errorLog(`Air Purifier: ${this.accessory.displayName} Command is not supported.`);
275
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported.`);
278
276
  break;
279
277
  case 161:
280
- this.errorLog(`Air Purifier: ${this.accessory.displayName} Device is offline.`);
278
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline.`);
281
279
  break;
282
280
  case 171:
283
- this.errorLog(`Air Purifier: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
281
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
284
282
  break;
285
283
  case 190:
286
284
  this.errorLog(
287
- `Air Purifier: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
288
- ` with server, Or command: ${JSON.stringify(res)} format is invalid`,
285
+ `${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
286
+ ` with server, Or command: ${superStringify(res)} format is invalid`,
289
287
  );
290
288
  break;
291
289
  case 100:
292
- this.debugLog(`Air Purifier: ${this.accessory.displayName} Command successfully sent.`);
290
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent.`);
293
291
  break;
294
292
  default:
295
- this.debugLog(`Air Purifier: ${this.accessory.displayName} Unknown statusCode.`);
293
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode.`);
296
294
  }
297
295
  }
298
296
 
@@ -301,7 +299,35 @@ export class AirPurifier {
301
299
  this.airPurifierService.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, e);
302
300
  this.airPurifierService.updateCharacteristic(this.platform.Characteristic.TargetAirPurifierState, e);
303
301
  this.airPurifierService.updateCharacteristic(this.platform.Characteristic.Active, e);
304
- //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
302
+ }
303
+
304
+ FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
305
+ let FirmwareRevision: string;
306
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
307
+ + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
308
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
309
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
310
+ if (accessory.context.FirmwareRevision) {
311
+ FirmwareRevision = accessory.context.FirmwareRevision;
312
+ } else if (device.firmware) {
313
+ FirmwareRevision = device.firmware;
314
+ } else {
315
+ FirmwareRevision = this.platform.version;
316
+ }
317
+ return FirmwareRevision;
318
+ }
319
+
320
+ private context() {
321
+ if (this.Active === undefined) {
322
+ this.Active = this.platform.Characteristic.Active.INACTIVE;
323
+ } else {
324
+ this.Active = this.accessory.context.Active;
325
+ }
326
+ if (this.CurrentTemperature === undefined) {
327
+ this.CurrentTemperature = 24;
328
+ } else {
329
+ this.CurrentTemperature = this.accessory.context.CurrentTemperature;
330
+ }
305
331
  }
306
332
 
307
333
  async config(device: irdevice & irDevicesConfig): Promise<void> {
@@ -312,24 +338,30 @@ export class AirPurifier {
312
338
  if (device.logging !== undefined) {
313
339
  config['logging'] = device.logging;
314
340
  }
341
+ if (device.connectionType !== undefined) {
342
+ config['connectionType'] = device.connectionType;
343
+ }
344
+ if (device.external !== undefined) {
345
+ config['external'] = device.external;
346
+ }
315
347
  if (Object.entries(config).length !== 0) {
316
- this.infoLog(`Air Purifier: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
348
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
317
349
  }
318
350
  }
319
351
 
320
352
  async logs(device: irdevice & irDevicesConfig): Promise<void> {
321
353
  if (this.platform.debugMode) {
322
354
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
323
- this.debugLog(`Air Purifier: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
355
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
324
356
  } else if (device.logging) {
325
357
  this.deviceLogging = this.accessory.context.logging = device.logging;
326
- this.debugLog(`Air Purifier: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
358
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
327
359
  } else if (this.platform.config.options?.logging) {
328
360
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
329
- this.debugLog(`Air Purifier: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
361
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
330
362
  } else {
331
363
  this.deviceLogging = this.accessory.context.logging = 'standard';
332
- this.debugLog(`Air Purifier: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
364
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
333
365
  }
334
366
  }
335
367
 
@@ -348,12 +380,28 @@ export class AirPurifier {
348
380
  }
349
381
  }
350
382
 
383
+ debugWarnLog(...log: any[]): void {
384
+ if (this.enablingDeviceLogging()) {
385
+ if (this.deviceLogging?.includes('debug')) {
386
+ this.platform.log.warn('[DEBUG]', String(...log));
387
+ }
388
+ }
389
+ }
390
+
351
391
  errorLog(...log: any[]): void {
352
392
  if (this.enablingDeviceLogging()) {
353
393
  this.platform.log.error(String(...log));
354
394
  }
355
395
  }
356
396
 
397
+ debugErrorLog(...log: any[]): void {
398
+ if (this.enablingDeviceLogging()) {
399
+ if (this.deviceLogging?.includes('debug')) {
400
+ this.platform.log.error('[DEBUG]', String(...log));
401
+ }
402
+ }
403
+ }
404
+
357
405
  debugLog(...log: any[]): void {
358
406
  if (this.enablingDeviceLogging()) {
359
407
  if (this.deviceLogging === 'debug') {