@switchbot/homebridge-switchbot 2.0.0-beta.2 → 2.0.0-beta.20

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 +32 -28
  5. package/dist/device/bot.d.ts.map +1 -1
  6. package/dist/device/bot.js +646 -648
  7. package/dist/device/bot.js.map +1 -1
  8. package/dist/device/colorbulb.d.ts +34 -19
  9. package/dist/device/colorbulb.d.ts.map +1 -1
  10. package/dist/device/colorbulb.js +429 -304
  11. package/dist/device/colorbulb.js.map +1 -1
  12. package/dist/device/contact.d.ts +16 -7
  13. package/dist/device/contact.d.ts.map +1 -1
  14. package/dist/device/contact.js +288 -230
  15. package/dist/device/contact.js.map +1 -1
  16. package/dist/device/curtain.d.ts +21 -16
  17. package/dist/device/curtain.d.ts.map +1 -1
  18. package/dist/device/curtain.js +519 -489
  19. package/dist/device/curtain.js.map +1 -1
  20. package/dist/device/humidifier.d.ts +22 -18
  21. package/dist/device/humidifier.d.ts.map +1 -1
  22. package/dist/device/humidifier.js +415 -360
  23. package/dist/device/humidifier.js.map +1 -1
  24. package/dist/device/lock.d.ts +22 -8
  25. package/dist/device/lock.d.ts.map +1 -1
  26. package/dist/device/lock.js +253 -147
  27. package/dist/device/lock.js.map +1 -1
  28. package/dist/device/meter.d.ts +21 -16
  29. package/dist/device/meter.d.ts.map +1 -1
  30. package/dist/device/meter.js +325 -255
  31. package/dist/device/meter.js.map +1 -1
  32. package/dist/device/meterplus.d.ts +23 -12
  33. package/dist/device/meterplus.d.ts.map +1 -1
  34. package/dist/device/meterplus.js +346 -208
  35. package/dist/device/meterplus.js.map +1 -1
  36. package/dist/device/motion.d.ts +17 -8
  37. package/dist/device/motion.d.ts.map +1 -1
  38. package/dist/device/motion.js +261 -209
  39. package/dist/device/motion.js.map +1 -1
  40. package/dist/device/plug.d.ts +24 -16
  41. package/dist/device/plug.d.ts.map +1 -1
  42. package/dist/device/plug.js +267 -242
  43. package/dist/device/plug.js.map +1 -1
  44. package/dist/device/striplight.d.ts +51 -16
  45. package/dist/device/striplight.d.ts.map +1 -1
  46. package/dist/device/striplight.js +527 -185
  47. package/dist/device/striplight.js.map +1 -1
  48. package/dist/irdevice/airconditioner.d.ts +7 -12
  49. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  50. package/dist/irdevice/airconditioner.js +261 -230
  51. package/dist/irdevice/airconditioner.js.map +1 -1
  52. package/dist/irdevice/airpurifier.d.ts +3 -3
  53. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  54. package/dist/irdevice/airpurifier.js +137 -104
  55. package/dist/irdevice/airpurifier.js.map +1 -1
  56. package/dist/irdevice/camera.d.ts +9 -8
  57. package/dist/irdevice/camera.d.ts.map +1 -1
  58. package/dist/irdevice/camera.js +116 -86
  59. package/dist/irdevice/camera.js.map +1 -1
  60. package/dist/irdevice/fan.d.ts +8 -7
  61. package/dist/irdevice/fan.d.ts.map +1 -1
  62. package/dist/irdevice/fan.js +143 -109
  63. package/dist/irdevice/fan.js.map +1 -1
  64. package/dist/irdevice/light.d.ts +9 -8
  65. package/dist/irdevice/light.d.ts.map +1 -1
  66. package/dist/irdevice/light.js +120 -103
  67. package/dist/irdevice/light.js.map +1 -1
  68. package/dist/irdevice/other.d.ts +9 -8
  69. package/dist/irdevice/other.d.ts.map +1 -1
  70. package/dist/irdevice/other.js +128 -98
  71. package/dist/irdevice/other.js.map +1 -1
  72. package/dist/irdevice/tv.d.ts +10 -9
  73. package/dist/irdevice/tv.d.ts.map +1 -1
  74. package/dist/irdevice/tv.js +126 -93
  75. package/dist/irdevice/tv.js.map +1 -1
  76. package/dist/irdevice/vacuumcleaner.d.ts +7 -10
  77. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  78. package/dist/irdevice/vacuumcleaner.js +115 -89
  79. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  80. package/dist/irdevice/waterheater.d.ts +6 -9
  81. package/dist/irdevice/waterheater.d.ts.map +1 -1
  82. package/dist/irdevice/waterheater.js +115 -89
  83. package/dist/irdevice/waterheater.js.map +1 -1
  84. package/dist/platform.d.ts +3 -5
  85. package/dist/platform.d.ts.map +1 -1
  86. package/dist/platform.js +203 -200
  87. package/dist/platform.js.map +1 -1
  88. package/dist/settings.d.ts +15 -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 +641 -657
  93. package/src/device/colorbulb.ts +440 -339
  94. package/src/device/contact.ts +289 -233
  95. package/src/device/curtain.ts +523 -503
  96. package/src/device/humidifier.ts +421 -396
  97. package/src/device/lock.ts +257 -147
  98. package/src/device/meter.ts +335 -268
  99. package/src/device/meterplus.ts +354 -213
  100. package/src/device/motion.ts +264 -213
  101. package/src/device/plug.ts +270 -251
  102. package/src/device/striplight.ts +552 -207
  103. package/src/irdevice/airconditioner.ts +263 -241
  104. package/src/irdevice/airpurifier.ts +132 -103
  105. package/src/irdevice/camera.ts +112 -85
  106. package/src/irdevice/fan.ts +138 -106
  107. package/src/irdevice/light.ts +116 -103
  108. package/src/irdevice/other.ts +124 -97
  109. package/src/irdevice/tv.ts +123 -93
  110. package/src/irdevice/vacuumcleaner.ts +112 -89
  111. package/src/irdevice/waterheater.ts +111 -89
  112. package/src/platform.ts +195 -216
  113. package/src/settings.ts +15 -11
@@ -3,9 +3,11 @@ import crypto from 'crypto';
3
3
  import { Context } from 'vm';
4
4
  import { interval, Subject } from 'rxjs';
5
5
  import { skipWhile } from 'rxjs/operators';
6
+ import superStringify from 'super-stringify';
6
7
  import { SwitchBotPlatform } from '../platform';
7
8
  import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
8
9
  import { device, devicesConfig, serviceData, switchbot, deviceStatus, ad, HostDomain, DevicePath } from '../settings';
10
+ import { IncomingMessage } from 'http';
9
11
 
10
12
  /**
11
13
  * Platform Accessory
@@ -54,13 +56,17 @@ export class Contact {
54
56
  contactUbpdateInProgress!: boolean;
55
57
  doContactUpdate!: Subject<void>;
56
58
 
59
+ // Connection
60
+ private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'Both');
61
+ private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'Both');
62
+
57
63
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
58
64
  // default placeholders
59
65
  this.logs(device);
60
66
  this.scan(device);
61
67
  this.refreshRate(device);
62
68
  this.config(device);
63
- this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
69
+ this.context();
64
70
 
65
71
  // this is subject we use to track when we need to POST changes to the SwitchBot API
66
72
  this.doContactUpdate = new Subject();
@@ -98,49 +104,49 @@ export class Contact {
98
104
 
99
105
  // Motion Sensor Service
100
106
  if (device.contact?.hide_motionsensor) {
101
- this.debugLog(`Contact Sensor: ${accessory.displayName} Removing Motion Sensor Service`);
107
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Motion Sensor Service`);
102
108
  this.motionService = this.accessory.getService(this.platform.Service.MotionSensor);
103
109
  accessory.removeService(this.motionService!);
104
110
  } else if (!this.motionService) {
105
- this.debugLog(`Contact Sensor: ${accessory.displayName} Add Motion Sensor Service`);
111
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Motion Sensor Service`);
106
112
  (this.motionService =
107
113
  this.accessory.getService(this.platform.Service.MotionSensor) || this.accessory.addService(this.platform.Service.MotionSensor)),
108
114
  `${accessory.displayName} Motion Sensor`;
109
115
 
110
116
  this.motionService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Motion Sensor`);
111
117
  } else {
112
- this.debugLog(`Contact Sensor: ${accessory.displayName} Motion Sensor Service Not Added`);
118
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Motion Sensor Service Not Added`);
113
119
  }
114
120
 
115
121
  // Light Sensor Service
116
122
  if (device.contact?.hide_lightsensor) {
117
- this.debugLog(`Contact Sensor: ${accessory.displayName} Removing Light Sensor Service`);
123
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
118
124
  this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor);
119
125
  accessory.removeService(this.lightSensorService!);
120
126
  } else if (!this.lightSensorService) {
121
- this.debugLog(`Contact Sensor: ${accessory.displayName} Add Light Sensor Service`);
127
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
122
128
  (this.lightSensorService =
123
129
  this.accessory.getService(this.platform.Service.LightSensor) || this.accessory.addService(this.platform.Service.LightSensor)),
124
130
  `${accessory.displayName} Light Sensor`;
125
131
 
126
132
  this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
127
133
  } else {
128
- this.debugLog(`Contact Sensor: ${accessory.displayName} Light Sensor Service Not Added`);
134
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Light Sensor Service Not Added`);
129
135
  }
130
136
 
131
137
  // Battery Service
132
- if (!device.ble) {
133
- this.debugLog(`Contact Sensor: ${accessory.displayName} Removing Battery Service`);
138
+ if (!this.BLE) {
139
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Battery Service`);
134
140
  this.batteryService = this.accessory.getService(this.platform.Service.Battery);
135
141
  accessory.removeService(this.batteryService!);
136
- } else if (device.ble && !this.batteryService) {
137
- this.debugLog(`Contact Sensor: ${accessory.displayName} Add Battery Service`);
142
+ } else if (this.BLE && !this.batteryService) {
143
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
138
144
  (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
139
145
  `${accessory.displayName} Battery`;
140
146
 
141
147
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
142
148
  } else {
143
- this.debugLog(`Contact Sensor: ${accessory.displayName} Battery Service Not Added`);
149
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
144
150
  }
145
151
 
146
152
  // Retrieve initial values and updateHomekit
@@ -158,15 +164,19 @@ export class Contact {
158
164
  * Parse the device status from the SwitchBot api
159
165
  */
160
166
  async parseStatus(): Promise<void> {
161
- if (this.SwitchToOpenAPI || !this.device.ble) {
167
+ if (this.BLE && !this.SwitchToOpenAPI) {
168
+ await this.BLEparseStatus();
169
+ } else if (this.OpenAPI && this.platform.config.credentials?.token) {
170
+ this.SwitchToOpenAPI = false;
162
171
  await this.openAPIparseStatus();
163
172
  } else {
164
- await this.BLEparseStatus();
173
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
174
+ + ` ${this.device.connectionType}, parseStatus will not happen.`);
165
175
  }
166
176
  }
167
177
 
168
178
  async BLEparseStatus(): Promise<void> {
169
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} BLE parseStatus`);
179
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
170
180
  // Door State
171
181
  switch (this.doorState) {
172
182
  case 'open':
@@ -178,12 +188,12 @@ export class Contact {
178
188
  this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
179
189
  break;
180
190
  default:
181
- this.errorLog(`Contact Sensor: ${this.accessory.displayName} timeout no closed, doorstate: ${this.doorState}`);
191
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} timeout no closed, doorstate: ${this.doorState}`);
182
192
  }
183
193
  // Movement
184
194
  if (!this.device.contact?.hide_motionsensor) {
185
195
  this.MotionDetected = Boolean(this.movement);
186
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
196
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
187
197
  }
188
198
  // Light Level
189
199
  if (!this.device.contact?.hide_lightsensor) {
@@ -198,7 +208,7 @@ export class Contact {
198
208
  this.CurrentAmbientLightLevel = this.set_maxLux;
199
209
  }
200
210
  this.debugLog(
201
- `Contact Sensor: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
211
+ `${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
202
212
  ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
203
213
  );
204
214
  }
@@ -212,44 +222,40 @@ export class Contact {
212
222
  } else {
213
223
  this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
214
224
  }
215
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
225
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, `
226
+ + `StatusLowBattery: ${this.StatusLowBattery}`);
216
227
  }
217
228
 
218
229
  async openAPIparseStatus(): Promise<void> {
219
- if (this.device.ble) {
220
- this.SwitchToOpenAPI = false;
230
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
231
+ // Contact State
232
+ if (this.openState === 'open') {
233
+ this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
234
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
235
+ } else if (this.openState === 'close') {
236
+ this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
237
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
238
+ } else {
239
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openState: ${this.openState}`);
221
240
  }
222
- if (this.platform.config.credentials?.token) {
223
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} OpenAPI parseStatus`);
224
- // Contact State
225
- if (this.openState === 'open') {
226
- this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
227
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
228
- } else if (this.openState === 'close') {
229
- this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
230
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
231
- } else {
232
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} openState: ${this.openState}`);
233
- }
234
- // Motion State
235
- if (!this.device.contact?.hide_motionsensor) {
236
- this.MotionDetected = this.moveDetected!;
237
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
238
- }
239
- // Light Level
240
- if (!this.device.contact?.hide_lightsensor) {
241
- this.set_minLux = this.minLux();
242
- this.set_maxLux = this.maxLux();
243
- switch (this.brightness) {
244
- case 'dim':
245
- this.CurrentAmbientLightLevel = this.set_minLux;
246
- break;
247
- case 'bright':
248
- default:
249
- this.CurrentAmbientLightLevel = this.set_maxLux;
250
- }
251
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
241
+ // Motion State
242
+ if (!this.device.contact?.hide_motionsensor) {
243
+ this.MotionDetected = this.moveDetected!;
244
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
245
+ }
246
+ // Light Level
247
+ if (!this.device.contact?.hide_lightsensor) {
248
+ this.set_minLux = this.minLux();
249
+ this.set_maxLux = this.maxLux();
250
+ switch (this.brightness) {
251
+ case 'dim':
252
+ this.CurrentAmbientLightLevel = this.set_minLux;
253
+ break;
254
+ case 'bright':
255
+ default:
256
+ this.CurrentAmbientLightLevel = this.set_maxLux;
252
257
  }
258
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
253
259
  }
254
260
  }
255
261
 
@@ -257,15 +263,18 @@ export class Contact {
257
263
  * Asks the SwitchBot API for the latest device information
258
264
  */
259
265
  async refreshStatus(): Promise<void> {
260
- if (this.device.ble) {
266
+ if (this.BLE) {
261
267
  await this.BLERefreshStatus();
262
- } else {
268
+ } else if (this.OpenAPI) {
263
269
  await this.openAPIRefreshStatus();
270
+ } else {
271
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
272
+ + ` ${this.device.connectionType}, refreshStatus will not happen.`);
264
273
  }
265
274
  }
266
275
 
267
276
  async BLERefreshStatus(): Promise<void> {
268
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} BLE refreshStatus`);
277
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
269
278
  const switchbot = await this.platform.connectBLE();
270
279
  // Convert to BLE Address
271
280
  this.device.bleMac =
@@ -274,7 +283,7 @@ export class Contact {
274
283
  .deviceId!.match(/.{1,2}/g)!
275
284
  .join(':')
276
285
  .toLowerCase();
277
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
286
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
278
287
  this.getCustomBLEAddress(switchbot);
279
288
  // Start to monitor advertisement packets
280
289
  if (switchbot !== false) {
@@ -290,26 +299,26 @@ export class Contact {
290
299
  if (this.deviceLogging.includes('debug')) {
291
300
  this.infoLog(this.address);
292
301
  this.infoLog(this.device.bleMac);
293
- this.infoLog(`Contact Sensor: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
294
- this.infoLog(`Contact Sensor: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
302
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
303
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
295
304
  }
296
305
  this.serviceData = ad.serviceData;
297
306
  this.movement = ad.serviceData.movement;
298
307
  this.doorState = ad.serviceData.doorState;
299
308
  this.lightLevel = ad.serviceData.lightLevel;
300
309
  this.battery = ad.serviceData.battery;
301
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
310
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
302
311
  this.debugLog(
303
- `Contact Sensor: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, doorState: ` +
312
+ `${this.device.deviceType}: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, doorState: ` +
304
313
  `${ad.serviceData.doorState}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`,
305
314
  );
306
315
 
307
316
  if (this.serviceData) {
308
317
  this.connected = true;
309
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
318
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
310
319
  } else {
311
320
  this.connected = false;
312
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
321
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
313
322
  }
314
323
  };
315
324
  // Wait 2 seconds
@@ -326,110 +335,67 @@ export class Contact {
326
335
  }
327
336
  })
328
337
  .catch(async (e: any) => {
329
- this.errorLog(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
330
- if (this.deviceLogging.includes('debug')) {
331
- this.errorLog(
332
- `Contact Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` +
333
- ` Error Message: ${JSON.stringify(e.message)}`,
334
- );
335
- }
336
- if (this.platform.config.credentials?.token) {
337
- this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
338
- this.SwitchToOpenAPI = true;
339
- await this.openAPIRefreshStatus();
340
- }
341
338
  this.apiError(e);
339
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
340
+ + ` Connection, Error Message: ${superStringify(e.message)}`);
341
+ await this.BLEconnection(switchbot);
342
342
  });
343
343
  } else {
344
344
  await this.BLEconnection(switchbot);
345
345
  }
346
346
  }
347
347
 
348
- async getCustomBLEAddress(switchbot: any) {
349
- if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
350
- (async () => {
351
- // Start to monitor advertisement packets
352
- await switchbot.startScan({
353
- model: 'd',
354
- });
355
- // Set an event handler
356
- switchbot.onadvertisement = (ad: any) => {
357
- this.warnLog(`Contact Sensor: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
358
- };
359
- await switchbot.wait(10000);
360
- // Stop to monitor
361
- switchbot.stopScan();
362
- })();
363
- }
364
- }
365
-
366
- async BLEconnection(switchbot: any): Promise<void> {
367
- this.errorLog(`Contact Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
368
- if (this.platform.config.credentials?.token) {
369
- this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
370
- this.SwitchToOpenAPI = true;
371
- await this.openAPIRefreshStatus();
372
- }
373
- }
374
-
375
348
  async openAPIRefreshStatus(): Promise<void> {
376
- if (this.platform.config.credentials?.token) {
377
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} OpenAPI refreshStatus`);
378
- try {
379
- const t = Date.now();
380
- const nonce = 'requestID';
381
- const data = this.platform.config.credentials?.token + t + nonce;
382
- const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
383
- const sign = signTerm.toString('base64');
384
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} sign: ${sign}`);
385
- const options = {
386
- hostname: HostDomain,
387
- port: 443,
388
- path: `${DevicePath}/${this.device.deviceId}/status`,
389
- method: 'GET',
390
- headers: {
391
- Authorization: this.platform.config.credentials?.token,
392
- sign: sign,
393
- nonce: nonce,
394
- t: t,
395
- 'Content-Type': 'application/json',
396
- },
397
- };
398
- const req = https.request(options, (res) => {
399
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
400
- let rawData = '';
401
- res.on('data', (d) => {
402
- rawData += d;
403
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} d: ${d}`);
404
- });
405
- res.on('end', () => {
406
- try {
407
- this.deviceStatus = JSON.parse(rawData);
408
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
409
- this.openState = this.deviceStatus.body.openState;
410
- this.moveDetected = this.deviceStatus.body.moveDetected;
411
- this.brightness = this.deviceStatus.body.brightness;
412
- this.parseStatus();
413
- this.updateHomeKitCharacteristics();
414
- } catch (e: any) {
415
- this.errorLog(`Contact Sensor: ${this.accessory.displayName} error message: ${e.message}`);
416
- }
417
- });
349
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
350
+ try {
351
+ const t = Date.now();
352
+ const nonce = 'requestID';
353
+ const data = this.platform.config.credentials?.token + t + nonce;
354
+ const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
355
+ const sign = signTerm.toString('base64');
356
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
357
+ const options = {
358
+ hostname: HostDomain,
359
+ port: 443,
360
+ path: `${DevicePath}/${this.device.deviceId}/status`,
361
+ method: 'GET',
362
+ headers: {
363
+ Authorization: this.platform.config.credentials?.token,
364
+ sign: sign,
365
+ nonce: nonce,
366
+ t: t,
367
+ 'Content-Type': 'application/json',
368
+ },
369
+ };
370
+ const req = https.request(options, (res) => {
371
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus statusCode: ${res.statusCode}`);
372
+ let rawData = '';
373
+ res.on('data', (d) => {
374
+ rawData += d;
375
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
418
376
  });
419
- req.on('error', (e: any) => {
420
- this.errorLog(`Contact Sensor: ${this.accessory.displayName} error message: ${e.message}`);
377
+ res.on('end', () => {
378
+ try {
379
+ this.deviceStatus = JSON.parse(rawData);
380
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
381
+ this.openState = this.deviceStatus.body.openState;
382
+ this.moveDetected = this.deviceStatus.body.moveDetected;
383
+ this.brightness = this.deviceStatus.body.brightness;
384
+ this.parseStatus();
385
+ this.updateHomeKitCharacteristics();
386
+ } catch (e: any) {
387
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
388
+ }
421
389
  });
422
- req.end();
423
- } catch (e: any) {
424
- this.errorLog(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
425
- if (this.deviceLogging.includes('debug')) {
426
- this.errorLog(
427
- `Contact Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
428
- ` Error Message: ${JSON.stringify(e.message)}`,
429
- );
430
- }
431
- this.apiError(e);
432
- }
390
+ });
391
+ req.on('error', (e: any) => {
392
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
393
+ });
394
+ req.end();
395
+ } catch (e: any) {
396
+ this.apiError(e);
397
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
398
+ + ` Connection, Error Message: ${superStringify(e.message)}`);
433
399
  }
434
400
  }
435
401
 
@@ -438,42 +404,151 @@ export class Contact {
438
404
  */
439
405
  async updateHomeKitCharacteristics(): Promise<void> {
440
406
  if (this.ContactSensorState === undefined) {
441
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
407
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
442
408
  } else {
409
+ this.accessory.context.ContactSensorState = this.ContactSensorState;
443
410
  this.contactSensorservice.updateCharacteristic(this.platform.Characteristic.ContactSensorState, this.ContactSensorState);
444
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} updateCharacteristic ContactSensorState: ${this.ContactSensorState}`);
411
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ContactSensorState: ${this.ContactSensorState}`);
445
412
  }
446
413
  if (!this.device.contact?.hide_motionsensor) {
447
414
  if (this.MotionDetected === undefined) {
448
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
415
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
449
416
  } else {
417
+ this.accessory.context.MotionDetected = this.MotionDetected;
450
418
  this.motionService?.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected);
451
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`);
419
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`);
452
420
  }
453
421
  }
454
422
  if (!this.device.contact?.hide_lightsensor) {
455
423
  if (this.CurrentAmbientLightLevel === undefined) {
456
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
424
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
457
425
  } else {
426
+ this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
458
427
  this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
459
- this.debugLog(
460
- `Contact Sensor: ${this.accessory.displayName}` + ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
428
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
429
+ + ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
461
430
  );
462
431
  }
463
432
  }
464
- if (this.device.ble) {
433
+ if (this.BLE) {
465
434
  if (this.BatteryLevel === undefined) {
466
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
435
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
467
436
  } else {
437
+ this.accessory.context.BatteryLevel = this.BatteryLevel;
468
438
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
469
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
439
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
470
440
  }
471
441
  if (this.StatusLowBattery === undefined) {
472
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
442
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
473
443
  } else {
444
+ this.accessory.context.StatusLowBattery = this.StatusLowBattery;
474
445
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
475
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
446
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
447
+ }
448
+ }
449
+ }
450
+
451
+ async getCustomBLEAddress(switchbot: any) {
452
+ if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
453
+ (async () => {
454
+ // Start to monitor advertisement packets
455
+ await switchbot.startScan({
456
+ model: 'd',
457
+ });
458
+ // Set an event handler
459
+ switchbot.onadvertisement = (ad: any) => {
460
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
461
+ };
462
+ await switchbot.wait(10000);
463
+ // Stop to monitor
464
+ switchbot.stopScan();
465
+ })();
466
+ }
467
+ }
468
+
469
+ async BLEconnection(switchbot: any): Promise<void> {
470
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
471
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
472
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
473
+ this.SwitchToOpenAPI = true;
474
+ await this.openAPIRefreshStatus();
475
+ }
476
+ }
477
+
478
+ minLux(): number {
479
+ if (this.device.contact?.set_minLux) {
480
+ this.set_minLux = this.device.contact!.set_minLux!;
481
+ } else {
482
+ this.set_minLux = 1;
483
+ }
484
+ return this.set_minLux;
485
+ }
486
+
487
+ maxLux(): number {
488
+ if (this.device.contact?.set_maxLux) {
489
+ this.set_maxLux = this.device.contact!.set_maxLux!;
490
+ } else {
491
+ this.set_maxLux = 6001;
492
+ }
493
+ return this.set_maxLux;
494
+ }
495
+
496
+ async scan(device: device & devicesConfig): Promise<void> {
497
+ if (device.scanDuration) {
498
+ this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
499
+ if (this.BLE) {
500
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
476
501
  }
502
+ } else {
503
+ this.scanDuration = this.accessory.context.scanDuration = 1;
504
+ if (this.BLE) {
505
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
506
+ }
507
+ }
508
+ }
509
+
510
+ async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
511
+ switch (res.statusCode) {
512
+ case 151:
513
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
514
+ break;
515
+ case 152:
516
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
517
+ break;
518
+ case 160:
519
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
520
+ break;
521
+ case 161:
522
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
523
+ this.offlineOff();
524
+ break;
525
+ case 171:
526
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
527
+ this.offlineOff();
528
+ break;
529
+ case 190:
530
+ this.errorLog(
531
+ `${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
532
+ ` Or command: ${superStringify(res)} format is invalid`,
533
+ );
534
+ break;
535
+ case 100:
536
+ if (this.platform.debugMode) {
537
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
538
+ }
539
+ break;
540
+ default:
541
+ if (this.platform.debugMode) {
542
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
543
+ }
544
+ }
545
+ }
546
+
547
+ async offlineOff(): Promise<void> {
548
+ if (this.device.offline) {
549
+ this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
550
+ this.contactSensorservice.getCharacteristic(this.platform.Characteristic.ContactSensorState).updateValue(this.ContactSensorState);
551
+ await this.updateHomeKitCharacteristics();
477
552
  }
478
553
  }
479
554
 
@@ -485,11 +560,49 @@ export class Contact {
485
560
  if (!this.device.contact?.hide_lightsensor) {
486
561
  this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
487
562
  }
488
- if (this.device.ble) {
563
+ if (this.BLE) {
489
564
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
490
565
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
491
566
  }
492
- //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
567
+ }
568
+
569
+ FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
570
+ let FirmwareRevision: string;
571
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
572
+ + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
573
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
574
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
575
+ if (accessory.context.FirmwareRevision) {
576
+ FirmwareRevision = accessory.context.FirmwareRevision;
577
+ } else if (device.firmware) {
578
+ FirmwareRevision = device.firmware;
579
+ } else {
580
+ FirmwareRevision = this.platform.version;
581
+ }
582
+ return FirmwareRevision;
583
+ }
584
+
585
+ async context() {
586
+ if (this.MotionDetected === undefined) {
587
+ this.MotionDetected = false;
588
+ } else {
589
+ this.MotionDetected = this.accessory.context.MotionDetected;
590
+ }
591
+ if (this.ContactSensorState === undefined) {
592
+ this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
593
+ } else {
594
+ this.ContactSensorState = this.accessory.context.ContactSensorState;
595
+ }
596
+ }
597
+
598
+ async refreshRate(device: device & devicesConfig): Promise<void> {
599
+ if (device.refreshRate) {
600
+ this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
601
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
602
+ } else if (this.platform.config.options!.refreshRate) {
603
+ this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
604
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
605
+ }
493
606
  }
494
607
 
495
608
  async config(device: device & devicesConfig): Promise<void> {
@@ -497,8 +610,8 @@ export class Contact {
497
610
  if (device.contact) {
498
611
  config = device.contact;
499
612
  }
500
- if (device.ble) {
501
- config['ble'] = device.ble;
613
+ if (device.connectionType !== undefined) {
614
+ config['connectionType'] = device.connectionType;
502
615
  }
503
616
  if (device.logging !== undefined) {
504
617
  config['logging'] = device.logging;
@@ -510,81 +623,24 @@ export class Contact {
510
623
  config['scanDuration'] = device.scanDuration;
511
624
  }
512
625
  if (Object.entries(config).length !== 0) {
513
- this.infoLog(`Contact Sensor: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
514
- }
515
- }
516
-
517
- async refreshRate(device: device & devicesConfig): Promise<void> {
518
- if (device.refreshRate) {
519
- this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
520
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
521
- } else if (this.platform.config.options!.refreshRate) {
522
- this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
523
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
524
- }
525
- }
526
-
527
- async scan(device: device & devicesConfig): Promise<void> {
528
- if (device.scanDuration) {
529
- this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
530
- if (device.ble) {
531
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
532
- }
533
- } else {
534
- this.scanDuration = this.accessory.context.scanDuration = 1;
535
- if (this.device.ble) {
536
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
537
- }
626
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
538
627
  }
539
628
  }
540
629
 
541
630
  async logs(device: device & devicesConfig): Promise<void> {
542
631
  if (this.platform.debugMode) {
543
632
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
544
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
633
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
545
634
  } else if (device.logging) {
546
635
  this.deviceLogging = this.accessory.context.logging = device.logging;
547
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
636
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
548
637
  } else if (this.platform.config.options?.logging) {
549
638
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
550
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
639
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
551
640
  } else {
552
641
  this.deviceLogging = this.accessory.context.logging = 'standard';
553
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
554
- }
555
- }
556
-
557
- FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
558
- let FirmwareRevision: string;
559
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
560
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
561
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
562
- if (accessory.context.FirmwareRevision) {
563
- FirmwareRevision = accessory.context.FirmwareRevision;
564
- } else if (device.firmware) {
565
- FirmwareRevision = device.firmware;
566
- } else {
567
- FirmwareRevision = this.platform.version;
642
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
568
643
  }
569
- return FirmwareRevision;
570
- }
571
-
572
- minLux(): number {
573
- if (this.device.contact?.set_minLux) {
574
- this.set_minLux = this.device.contact!.set_minLux!;
575
- } else {
576
- this.set_minLux = 1;
577
- }
578
- return this.set_minLux;
579
- }
580
-
581
- maxLux(): number {
582
- if (this.device.contact?.set_maxLux) {
583
- this.set_maxLux = this.device.contact!.set_maxLux!;
584
- } else {
585
- this.set_maxLux = 6001;
586
- }
587
- return this.set_maxLux;
588
644
  }
589
645
 
590
646
  /**