@switchbot/homebridge-switchbot 1.6.4-beta.3 → 1.7.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,6 +36,9 @@ export class Contact {
36
36
  lightLevel!: serviceData['lightLevel'];
37
37
 
38
38
  // Config
39
+ set_minLux!: number;
40
+ set_maxLux!: number;
41
+ spaceBetweenLevels!: number;
39
42
  scanDuration!: number;
40
43
  deviceLogging!: string;
41
44
  deviceRefreshRate!: number;
@@ -191,6 +194,24 @@ export class Contact {
191
194
  }
192
195
  }
193
196
 
197
+ private minLux(): number {
198
+ if (this.device.curtain?.set_minLux) {
199
+ this.set_minLux = this.device.contact!.set_minLux!;
200
+ } else {
201
+ this.set_minLux = 1;
202
+ }
203
+ return this.set_minLux;
204
+ }
205
+
206
+ private maxLux(): number {
207
+ if (this.device.curtain?.set_maxLux) {
208
+ this.set_maxLux = this.device.contact!.set_maxLux!;
209
+ } else {
210
+ this.set_maxLux = 6001;
211
+ }
212
+ return this.set_maxLux;
213
+ }
214
+
194
215
  /**
195
216
  * Parse the device status from the SwitchBot api
196
217
  */
@@ -204,7 +225,7 @@ export class Contact {
204
225
 
205
226
  private async BLEparseStatus() {
206
227
  this.debugLog(`Contact Sensor: ${this.accessory.displayName} BLE parseStatus`);
207
- if (this.device.contact?.hide_motionsensor) {
228
+ if (!this.device.contact?.hide_motionsensor) {
208
229
  // Movement
209
230
  this.MotionDetected = Boolean(this.movement);
210
231
  }
@@ -221,7 +242,8 @@ export class Contact {
221
242
  default:
222
243
  this.errorLog(`Contact Sensor: ${this.accessory.displayName} timeout no closed, doorstate: ${this.doorState}`);
223
244
  }
224
- if (this.device.contact?.hide_lightsensor) {// Light Level
245
+ // Light Level
246
+ if (!this.device.contact?.hide_lightsensor) {
225
247
  switch (this.lightLevel) {
226
248
  case 'dark':
227
249
  case 0:
@@ -231,6 +253,63 @@ export class Contact {
231
253
  this.CurrentAmbientLightLevel = 100000;
232
254
  }
233
255
  }
256
+
257
+ /*
258
+ // Light Level
259
+ if (!this.device.contact?.hide_lightsensor) {
260
+ this.set_minLux = this.minLux();
261
+ this.set_maxLux = this.maxLux();
262
+ this.spaceBetweenLevels = 9;
263
+
264
+ //
265
+ switch (this.lightLevel) {
266
+ case 1:
267
+ this.CurrentAmbientLightLevel = this.set_minLux;
268
+ this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
269
+ break;
270
+ case 2:
271
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels);
272
+ this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
273
+ + ` Calculation: ${((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels)}`);
274
+ break;
275
+ case 3:
276
+ this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 2);
277
+ this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
278
+ break;
279
+ case 4:
280
+ this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 3);
281
+ this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
282
+ break;
283
+ case 5:
284
+ this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 4);
285
+ this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
286
+ break;
287
+ case 6:
288
+ this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 5);
289
+ this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
290
+ break;
291
+ case 7:
292
+ this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 6);
293
+ this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
294
+ break;
295
+ case 8:
296
+ this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 7);
297
+ this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
298
+ break;
299
+ case 9:
300
+ this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 8);
301
+ this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
302
+ break;
303
+ case 10:
304
+ default:
305
+ this.CurrentAmbientLightLevel = this.set_maxLux;
306
+ this.debugLog();
307
+ }
308
+ this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
309
+ + ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
310
+ }*/
311
+
312
+
234
313
  // Battery
235
314
  this.BatteryLevel = Number(this.battery);
236
315
  if (this.BatteryLevel < 10) {
@@ -245,6 +324,7 @@ export class Contact {
245
324
 
246
325
  private async openAPIparseStatus() {
247
326
  if (this.platform.config.credentials?.openToken) {
327
+ // Contact State
248
328
  this.debugLog(`Contact Sensor: ${this.accessory.displayName} OpenAPI parseStatus`);
249
329
  if (this.deviceStatus.body.openState === 'open') {
250
330
  this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
@@ -255,10 +335,26 @@ export class Contact {
255
335
  } else {
256
336
  this.debugLog(`Contact Sensor: ${this.accessory.displayName} openState: ${this.deviceStatus.body.openState}`);
257
337
  }
258
- if (this.device.contact?.hide_motionsensor) {
338
+ // Motion State
339
+ if (!this.device.contact?.hide_motionsensor) {
259
340
  this.MotionDetected = Boolean(this.deviceStatus.body.moveDetected);
260
341
  }
261
342
  this.debugLog(`Contact Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
343
+ // Light Level
344
+ if (!this.device.contact?.hide_lightsensor) {
345
+ this.set_minLux = this.minLux();
346
+ this.set_maxLux = this.maxLux();
347
+ // Brightness
348
+ switch (this.deviceStatus.body.brightness) {
349
+ case 'dim':
350
+ this.CurrentAmbientLightLevel = this.set_minLux;
351
+ break;
352
+ case 'bright':
353
+ default:
354
+ this.CurrentAmbientLightLevel = this.set_maxLux;
355
+ }
356
+ this.debugLog(`Contact Sensor: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
357
+ }
262
358
  }
263
359
  }
264
360
 
package/src/settings.ts CHANGED
@@ -84,6 +84,8 @@ export type curtain = {
84
84
 
85
85
  export type contact = {
86
86
  hide_lightsensor?: boolean;
87
+ set_minLux?: number;
88
+ set_maxLux?: number;
87
89
  hide_motionsensor?: boolean;
88
90
  };
89
91