@switchbot/homebridge-switchbot 1.5.1-beta.3 → 1.6.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.
- package/CHANGELOG.md +15 -2
- package/config.schema.json +9 -0
- package/dist/devices/bots.d.ts +4 -0
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +79 -18
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +3 -1
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +34 -11
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +2 -0
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +21 -6
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +2 -0
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +21 -6
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +2 -0
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +21 -6
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +2 -0
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +20 -5
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +2 -0
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +40 -9
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +2 -0
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +19 -4
- package/dist/devices/plugs.js.map +1 -1
- package/dist/irdevices/airconditioners.js +3 -3
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.js +3 -3
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.js +3 -3
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.js +3 -3
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.js +3 -3
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.js +3 -3
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.js +3 -3
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +3 -3
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.js +2 -2
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +0 -5
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +4 -2
- package/src/devices/bots.ts +81 -18
- package/src/devices/colorbulb.ts +39 -12
- package/src/devices/contact.ts +22 -6
- package/src/devices/curtains.ts +22 -6
- package/src/devices/humidifiers.ts +22 -6
- package/src/devices/meters.ts +21 -5
- package/src/devices/motion.ts +40 -9
- package/src/devices/plugs.ts +20 -4
- package/src/irdevices/airconditioners.ts +3 -3
- package/src/irdevices/airpurifiers.ts +3 -3
- package/src/irdevices/cameras.ts +3 -3
- package/src/irdevices/fans.ts +3 -3
- package/src/irdevices/lights.ts +3 -3
- package/src/irdevices/others.ts +3 -3
- package/src/irdevices/tvs.ts +3 -3
- package/src/irdevices/vacuumcleaners.ts +3 -3
- package/src/irdevices/waterheaters.ts +2 -2
- package/src/platform.ts +0 -5
- package/src/settings.ts +1 -0
package/src/devices/bots.ts
CHANGED
|
@@ -36,6 +36,8 @@ export class Bot {
|
|
|
36
36
|
battery!: serviceData['battery'];
|
|
37
37
|
|
|
38
38
|
// Config
|
|
39
|
+
botMode!: string;
|
|
40
|
+
scanDuration!: number;
|
|
39
41
|
deviceLogging!: string;
|
|
40
42
|
deviceRefreshRate!: number;
|
|
41
43
|
|
|
@@ -52,8 +54,11 @@ export class Bot {
|
|
|
52
54
|
public device: device & devicesConfig,
|
|
53
55
|
) {
|
|
54
56
|
// default placeholders
|
|
55
|
-
this.refreshRate();
|
|
56
57
|
this.logs();
|
|
58
|
+
this.scan();
|
|
59
|
+
this.refreshRate();
|
|
60
|
+
this.PressOrSwitch();
|
|
61
|
+
|
|
57
62
|
if (this.On === undefined) {
|
|
58
63
|
this.On = false;
|
|
59
64
|
this.accessory.context.On = this.On;
|
|
@@ -67,7 +72,7 @@ export class Bot {
|
|
|
67
72
|
this.doublePress = 1;
|
|
68
73
|
}
|
|
69
74
|
this.BatteryLevel = 100;
|
|
70
|
-
this.StatusLowBattery =
|
|
75
|
+
this.StatusLowBattery = 0;
|
|
71
76
|
|
|
72
77
|
// Bot Config
|
|
73
78
|
this.debugLog(`Bot: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline}, mode: ${device.bot?.mode},`
|
|
@@ -195,10 +200,26 @@ export class Bot {
|
|
|
195
200
|
}
|
|
196
201
|
}
|
|
197
202
|
|
|
203
|
+
scan() {
|
|
204
|
+
if (this.device.scanDuration) {
|
|
205
|
+
this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
|
|
206
|
+
if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
|
|
207
|
+
this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
208
|
+
}
|
|
209
|
+
} else {
|
|
210
|
+
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
211
|
+
if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
|
|
212
|
+
this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
198
219
|
logs() {
|
|
199
220
|
if (this.platform.debugMode) {
|
|
200
221
|
this.deviceLogging = this.accessory.context.logging = 'debug';
|
|
201
|
-
this.warnLog(`
|
|
222
|
+
this.warnLog(`Bot: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
202
223
|
} else if (this.device.logging) {
|
|
203
224
|
this.deviceLogging = this.accessory.context.logging = this.device.logging;
|
|
204
225
|
if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
|
|
@@ -214,6 +235,22 @@ export class Bot {
|
|
|
214
235
|
}
|
|
215
236
|
}
|
|
216
237
|
|
|
238
|
+
PressOrSwitch() {
|
|
239
|
+
if (!this.device.bot?.mode) {
|
|
240
|
+
this.botMode = 'switch';
|
|
241
|
+
this.warnLog(`Bot: ${this.accessory.displayName} does not have bot mode set in the Plugin's SwitchBot Device Settings,`);
|
|
242
|
+
this.warnLog(`Bot: ${this.accessory.displayName} is defaulting to "${this.botMode}" mode, you may experience issues.`);
|
|
243
|
+
} else if (this.device.bot?.mode === 'switch') {
|
|
244
|
+
this.botMode = 'switch';
|
|
245
|
+
this.infoLog(`Bot: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
|
|
246
|
+
} else if (this.device.bot?.mode === 'press') {
|
|
247
|
+
this.botMode = 'press';
|
|
248
|
+
this.infoLog(`Bot: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
|
|
249
|
+
} else {
|
|
250
|
+
throw new Error(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
217
254
|
/**
|
|
218
255
|
* Parse the device status from the SwitchBot api
|
|
219
256
|
*/
|
|
@@ -229,10 +266,17 @@ export class Bot {
|
|
|
229
266
|
this.debugLog(`Bot: ${this.accessory.displayName} BLE parseStatus`);
|
|
230
267
|
// BLEmode (true if Switch Mode) | (false if Press Mode)
|
|
231
268
|
if (this.mode) {
|
|
232
|
-
this.
|
|
233
|
-
this.
|
|
269
|
+
this.OnCached = this.On;
|
|
270
|
+
this.accessory.context.On = this.OnCached;
|
|
271
|
+
if (this.On === undefined) {
|
|
272
|
+
this.On = Boolean(this.state);
|
|
273
|
+
}
|
|
274
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, mode: ${this.mode}, On: ${this.On}`);
|
|
234
275
|
} else {
|
|
235
|
-
this.
|
|
276
|
+
this.On = false;
|
|
277
|
+
this.OnCached = this.On;
|
|
278
|
+
this.accessory.context.On = this.OnCached;
|
|
279
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Press Mode, mode: ${this.mode}, On: ${this.On}`);
|
|
236
280
|
}
|
|
237
281
|
|
|
238
282
|
this.BatteryLevel = Number(this.battery);
|
|
@@ -250,13 +294,19 @@ export class Bot {
|
|
|
250
294
|
private async openAPIparseStatus() {
|
|
251
295
|
if (this.platform.config.credentials?.openToken) {
|
|
252
296
|
this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
253
|
-
if (this.
|
|
297
|
+
if (this.botMode === 'press') {
|
|
254
298
|
this.On = false;
|
|
299
|
+
this.OnCached = this.On;
|
|
300
|
+
this.accessory.context.On = this.OnCached;
|
|
255
301
|
} else {
|
|
256
302
|
if (this.deviceStatus.body.power === 'on') {
|
|
257
303
|
this.On = true;
|
|
304
|
+
this.OnCached = this.On;
|
|
305
|
+
this.accessory.context.On = this.OnCached;
|
|
258
306
|
} else {
|
|
259
307
|
this.On = false;
|
|
308
|
+
this.OnCached = this.On;
|
|
309
|
+
this.accessory.context.On = this.OnCached;
|
|
260
310
|
}
|
|
261
311
|
}
|
|
262
312
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
@@ -308,8 +358,8 @@ export class Bot {
|
|
|
308
358
|
this.debugLog(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
309
359
|
}
|
|
310
360
|
};
|
|
311
|
-
// Wait
|
|
312
|
-
return switchbot.wait(
|
|
361
|
+
// Wait 2 seconds
|
|
362
|
+
return switchbot.wait(this.scanDuration * 1000);
|
|
313
363
|
}).then(async () => {
|
|
314
364
|
// Stop to monitor
|
|
315
365
|
switchbot.stopScan();
|
|
@@ -389,14 +439,25 @@ export class Bot {
|
|
|
389
439
|
if (this.On !== this.OnCached) {
|
|
390
440
|
this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges`);
|
|
391
441
|
const switchbot = this.connectBLE();
|
|
392
|
-
if (this.
|
|
393
|
-
this.debugLog(`Bot: ${this.accessory.displayName}
|
|
442
|
+
if (this.botMode === 'press') {
|
|
443
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
|
|
394
444
|
switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac })
|
|
395
445
|
.then((device_list: { press: (arg0: { id: string | undefined; }) => any; }[]) => {
|
|
396
|
-
this.infoLog(`Bot: ${this.accessory.displayName}
|
|
446
|
+
this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
397
447
|
return device_list[0].press({ id: this.device.bleMac });
|
|
398
448
|
}).then(() => {
|
|
399
449
|
this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
|
|
450
|
+
this.On = false;
|
|
451
|
+
this.OnCached = this.On;
|
|
452
|
+
this.accessory.context.On = this.OnCached;
|
|
453
|
+
setTimeout(() => {
|
|
454
|
+
if (this.device.bot?.deviceType === 'switch') {
|
|
455
|
+
this.switchService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
|
|
456
|
+
} else {
|
|
457
|
+
this.outletService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
|
|
458
|
+
}
|
|
459
|
+
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}, Switch Timeout`);
|
|
460
|
+
}, 500);
|
|
400
461
|
}).catch(async (e: any) => {
|
|
401
462
|
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
402
463
|
if (this.deviceLogging === 'debug') {
|
|
@@ -413,13 +474,15 @@ export class Bot {
|
|
|
413
474
|
}
|
|
414
475
|
this.apiError(e);
|
|
415
476
|
});
|
|
416
|
-
} else if (this.
|
|
417
|
-
this.debugLog(`Bot: ${this.accessory.displayName} Press Mode: ${this.
|
|
477
|
+
} else if (this.botMode === 'switch') {
|
|
478
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Press Mode: ${this.botMode}`);
|
|
418
479
|
switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac }).then((device_list: any) => {
|
|
419
480
|
this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
420
481
|
return this.turnOnOff(device_list);
|
|
421
482
|
}).then(() => {
|
|
422
483
|
this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
|
|
484
|
+
this.OnCached = this.On;
|
|
485
|
+
this.accessory.context.On = this.OnCached;
|
|
423
486
|
}).catch(async (e: any) => {
|
|
424
487
|
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
425
488
|
if (this.deviceLogging === 'debug') {
|
|
@@ -437,7 +500,7 @@ export class Bot {
|
|
|
437
500
|
this.apiError(e);
|
|
438
501
|
});
|
|
439
502
|
} else {
|
|
440
|
-
|
|
503
|
+
throw new Error(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
|
|
441
504
|
}
|
|
442
505
|
}
|
|
443
506
|
this.OnCached = this.On;
|
|
@@ -462,15 +525,15 @@ export class Bot {
|
|
|
462
525
|
parameter: 'default',
|
|
463
526
|
} as payload;
|
|
464
527
|
|
|
465
|
-
if (this.
|
|
528
|
+
if (this.botMode === 'switch' && this.On) {
|
|
466
529
|
payload.command = 'turnOn';
|
|
467
530
|
this.On = true;
|
|
468
531
|
this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`);
|
|
469
|
-
} else if (this.
|
|
532
|
+
} else if (this.botMode === 'switch' && !this.On) {
|
|
470
533
|
payload.command = 'turnOff';
|
|
471
534
|
this.On = false;
|
|
472
535
|
this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`);
|
|
473
|
-
} else if (this.
|
|
536
|
+
} else if (this.botMode === 'press') {
|
|
474
537
|
payload.command = 'press';
|
|
475
538
|
this.debugLog(`Bot: ${this.accessory.displayName} Press Mode`);
|
|
476
539
|
this.On = false;
|
package/src/devices/colorbulb.ts
CHANGED
|
@@ -36,9 +36,10 @@ export class ColorBulb {
|
|
|
36
36
|
set_minStep?: number;
|
|
37
37
|
deviceLogging!: string;
|
|
38
38
|
deviceRefreshRate!: number;
|
|
39
|
+
adaptiveLightingShift?: number;
|
|
39
40
|
|
|
40
41
|
// Adaptive Lighting
|
|
41
|
-
AdaptiveLightingController
|
|
42
|
+
AdaptiveLightingController?: ControllerConstructor | Controller<ControllerServiceMap>;
|
|
42
43
|
minKelvin: number;
|
|
43
44
|
maxKelvin: number;
|
|
44
45
|
|
|
@@ -53,8 +54,9 @@ export class ColorBulb {
|
|
|
53
54
|
public device: device & devicesConfig,
|
|
54
55
|
) {
|
|
55
56
|
// default placeholders
|
|
56
|
-
this.refreshRate();
|
|
57
57
|
this.logs();
|
|
58
|
+
this.refreshRate();
|
|
59
|
+
this.adaptiveLighting();
|
|
58
60
|
if (this.On === undefined) {
|
|
59
61
|
this.On = false;
|
|
60
62
|
} else {
|
|
@@ -68,7 +70,8 @@ export class ColorBulb {
|
|
|
68
70
|
this.maxKelvin = 9000;
|
|
69
71
|
|
|
70
72
|
// ColorBulb Config
|
|
71
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} Config: (ble: ${device.ble}, set_minStep: ${device.colorbulb?.set_minStep}
|
|
73
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Config: (ble: ${device.ble}, set_minStep: ${device.colorbulb?.set_minStep},`
|
|
74
|
+
+ ` adaptiveLighting: ${device.colorbulb?.adaptiveLightingShift})`);
|
|
72
75
|
|
|
73
76
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
74
77
|
this.doColorBulbUpdate = new Subject();
|
|
@@ -85,12 +88,20 @@ export class ColorBulb {
|
|
|
85
88
|
.setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-COLORBULB-W1401400')
|
|
86
89
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
|
|
87
90
|
|
|
88
|
-
// get the
|
|
91
|
+
// get the Lightbulb service if it exists, otherwise create a new Lightbulb service
|
|
89
92
|
// you can create multiple services for each accessory
|
|
90
93
|
(this.service =
|
|
91
94
|
accessory.getService(this.platform.Service.Lightbulb) ||
|
|
92
95
|
accessory.addService(this.platform.Service.Lightbulb)), `${accessory.displayName} Light Bulb`;
|
|
93
96
|
|
|
97
|
+
|
|
98
|
+
if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
|
|
99
|
+
this.accessory.removeService(this.service);
|
|
100
|
+
this.service = this.accessory.addService(this.platform.Service.Lightbulb);
|
|
101
|
+
this.accessory.context.adaptiveLighting = false;
|
|
102
|
+
this.warnLog(`Color Bulb: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
|
|
103
|
+
}
|
|
104
|
+
|
|
94
105
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
95
106
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
96
107
|
// accessory.getService('NAME') ?? accessory.addService(this.platform.Service.Outlet, 'NAME', 'USER_DEFINED_SUBTYPE');
|
|
@@ -153,11 +164,17 @@ export class ColorBulb {
|
|
|
153
164
|
})
|
|
154
165
|
.onSet(this.SaturationSet.bind(this));
|
|
155
166
|
|
|
156
|
-
|
|
157
|
-
this.
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
167
|
+
|
|
168
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
169
|
+
if (this.adaptiveLightingShift !== -1) {
|
|
170
|
+
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.service, {
|
|
171
|
+
customTemperatureAdjustment: this.adaptiveLightingShift,
|
|
172
|
+
});
|
|
173
|
+
this.accessory.configureController(this.AdaptiveLightingController);
|
|
174
|
+
this.accessory.context.adaptiveLighting = true;
|
|
175
|
+
this.warnLog(`Color Bulb: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},`
|
|
176
|
+
+ ` adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
177
|
+
}
|
|
161
178
|
|
|
162
179
|
// Update Homekit
|
|
163
180
|
this.updateHomeKitCharacteristics();
|
|
@@ -214,22 +231,32 @@ export class ColorBulb {
|
|
|
214
231
|
logs() {
|
|
215
232
|
if (this.platform.debugMode) {
|
|
216
233
|
this.deviceLogging = this.accessory.context.logging = 'debug';
|
|
217
|
-
this.warnLog(`
|
|
234
|
+
this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
218
235
|
} else if (this.device.logging) {
|
|
219
236
|
this.deviceLogging = this.accessory.context.logging = this.device.logging;
|
|
220
237
|
if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
|
|
221
|
-
this.warnLog(`
|
|
238
|
+
this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
222
239
|
}
|
|
223
240
|
} else if (this.platform.config.options?.logging) {
|
|
224
241
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
225
242
|
if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
|
|
226
|
-
this.warnLog(`
|
|
243
|
+
this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
227
244
|
}
|
|
228
245
|
} else {
|
|
229
246
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
230
247
|
}
|
|
231
248
|
}
|
|
232
249
|
|
|
250
|
+
adaptiveLighting() {
|
|
251
|
+
if (this.device.colorbulb?.adaptiveLightingShift) {
|
|
252
|
+
this.adaptiveLightingShift = this.device.colorbulb.adaptiveLightingShift;
|
|
253
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
254
|
+
} else {
|
|
255
|
+
this.adaptiveLightingShift = 0;
|
|
256
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
233
260
|
private minStep(): number {
|
|
234
261
|
if (this.device.colorbulb?.set_minStep) {
|
|
235
262
|
this.set_minStep = this.device.colorbulb?.set_minStep;
|
package/src/devices/contact.ts
CHANGED
|
@@ -37,6 +37,7 @@ export class Contact {
|
|
|
37
37
|
lightLevel!: serviceData['lightLevel'];
|
|
38
38
|
|
|
39
39
|
// Config
|
|
40
|
+
scanDuration!: number;
|
|
40
41
|
deviceLogging!: string;
|
|
41
42
|
deviceRefreshRate!: number;
|
|
42
43
|
|
|
@@ -50,8 +51,9 @@ export class Contact {
|
|
|
50
51
|
public device: device & devicesConfig,
|
|
51
52
|
) {
|
|
52
53
|
// default placeholders
|
|
53
|
-
this.refreshRate();
|
|
54
54
|
this.logs();
|
|
55
|
+
this.scan();
|
|
56
|
+
this.refreshRate();
|
|
55
57
|
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
56
58
|
|
|
57
59
|
// Contact Config
|
|
@@ -157,19 +159,33 @@ export class Contact {
|
|
|
157
159
|
}
|
|
158
160
|
}
|
|
159
161
|
|
|
162
|
+
scan() {
|
|
163
|
+
if (this.device.scanDuration) {
|
|
164
|
+
this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
|
|
165
|
+
if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
|
|
166
|
+
this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
170
|
+
if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
|
|
171
|
+
this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
160
176
|
logs() {
|
|
161
177
|
if (this.platform.debugMode) {
|
|
162
178
|
this.deviceLogging = this.accessory.context.logging = 'debug';
|
|
163
|
-
this.warnLog(`
|
|
179
|
+
this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
164
180
|
} else if (this.device.logging) {
|
|
165
181
|
this.deviceLogging = this.accessory.context.logging = this.device.logging;
|
|
166
182
|
if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
|
|
167
|
-
this.warnLog(`
|
|
183
|
+
this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
168
184
|
}
|
|
169
185
|
} else if (this.platform.config.options?.logging) {
|
|
170
186
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
171
187
|
if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
|
|
172
|
-
this.warnLog(`
|
|
188
|
+
this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
173
189
|
}
|
|
174
190
|
} else {
|
|
175
191
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
@@ -293,8 +309,8 @@ export class Contact {
|
|
|
293
309
|
this.debugLog(`Contact Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
294
310
|
}
|
|
295
311
|
};
|
|
296
|
-
// Wait
|
|
297
|
-
return switchbot.wait(
|
|
312
|
+
// Wait 2 seconds
|
|
313
|
+
return switchbot.wait(this.scanDuration * 1000);
|
|
298
314
|
}).then(async () => {
|
|
299
315
|
// Stop to monitor
|
|
300
316
|
switchbot.stopScan();
|
package/src/devices/curtains.ts
CHANGED
|
@@ -42,6 +42,7 @@ export class Curtain {
|
|
|
42
42
|
curtainRefreshRate!: number;
|
|
43
43
|
set_minLux!: number;
|
|
44
44
|
set_maxLux!: number;
|
|
45
|
+
scanDuration!: number;
|
|
45
46
|
deviceLogging!: string;
|
|
46
47
|
deviceRefreshRate!: number;
|
|
47
48
|
spaceBetweenLevels!: number;
|
|
@@ -56,9 +57,10 @@ export class Curtain {
|
|
|
56
57
|
public device: device & devicesConfig,
|
|
57
58
|
) {
|
|
58
59
|
// default placeholders
|
|
59
|
-
this.refreshRate();
|
|
60
60
|
this.logs();
|
|
61
|
+
this.scan();
|
|
61
62
|
this.setMinMax();
|
|
63
|
+
this.refreshRate();
|
|
62
64
|
this.CurrentPosition = 0;
|
|
63
65
|
this.TargetPosition = 0;
|
|
64
66
|
this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
|
|
@@ -219,19 +221,33 @@ export class Curtain {
|
|
|
219
221
|
}
|
|
220
222
|
}
|
|
221
223
|
|
|
224
|
+
scan() {
|
|
225
|
+
if (this.device.scanDuration) {
|
|
226
|
+
this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
|
|
227
|
+
if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
|
|
228
|
+
this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
229
|
+
}
|
|
230
|
+
} else {
|
|
231
|
+
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
232
|
+
if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
|
|
233
|
+
this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
222
238
|
logs() {
|
|
223
239
|
if (this.platform.debugMode) {
|
|
224
240
|
this.deviceLogging = this.accessory.context.logging = 'debug';
|
|
225
|
-
this.warnLog(`
|
|
241
|
+
this.warnLog(`Curtain: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
226
242
|
} else if (this.device.logging) {
|
|
227
243
|
this.deviceLogging = this.accessory.context.logging = this.device.logging;
|
|
228
244
|
if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
|
|
229
|
-
this.warnLog(`
|
|
245
|
+
this.warnLog(`Curtain: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
230
246
|
}
|
|
231
247
|
} else if (this.platform.config.options?.logging) {
|
|
232
248
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
233
249
|
if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
|
|
234
|
-
this.warnLog(`
|
|
250
|
+
this.warnLog(`Curtain: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
235
251
|
}
|
|
236
252
|
} else {
|
|
237
253
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
@@ -461,8 +477,8 @@ export class Curtain {
|
|
|
461
477
|
this.debugLog(`Curtain: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
462
478
|
}
|
|
463
479
|
};
|
|
464
|
-
// Wait
|
|
465
|
-
return switchbot.wait(
|
|
480
|
+
// Wait 2 seconds
|
|
481
|
+
return switchbot.wait(this.scanDuration * 1000);
|
|
466
482
|
}).then(async () => {
|
|
467
483
|
// Stop to monitor
|
|
468
484
|
switchbot.stopScan();
|
|
@@ -37,6 +37,7 @@ export class Humidifier {
|
|
|
37
37
|
|
|
38
38
|
// Config
|
|
39
39
|
set_minStep?: number;
|
|
40
|
+
scanDuration!: number;
|
|
40
41
|
deviceLogging!: string;
|
|
41
42
|
deviceRefreshRate!: number;
|
|
42
43
|
|
|
@@ -50,8 +51,9 @@ export class Humidifier {
|
|
|
50
51
|
public device: device & devicesConfig,
|
|
51
52
|
) {
|
|
52
53
|
// default placeholders
|
|
53
|
-
this.refreshRate();
|
|
54
54
|
this.logs();
|
|
55
|
+
this.scan();
|
|
56
|
+
this.refreshRate();
|
|
55
57
|
this.CurrentRelativeHumidity = 0;
|
|
56
58
|
this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
57
59
|
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
@@ -204,19 +206,33 @@ export class Humidifier {
|
|
|
204
206
|
}
|
|
205
207
|
}
|
|
206
208
|
|
|
209
|
+
scan() {
|
|
210
|
+
if (this.device.scanDuration) {
|
|
211
|
+
this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
|
|
212
|
+
if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
|
|
213
|
+
this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
214
|
+
}
|
|
215
|
+
} else {
|
|
216
|
+
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
217
|
+
if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
|
|
218
|
+
this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
207
223
|
logs() {
|
|
208
224
|
if (this.platform.debugMode) {
|
|
209
225
|
this.deviceLogging = this.accessory.context.logging = 'debug';
|
|
210
|
-
this.warnLog(`
|
|
226
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
211
227
|
} else if (this.device.logging) {
|
|
212
228
|
this.deviceLogging = this.accessory.context.logging = this.device.logging;
|
|
213
229
|
if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
|
|
214
|
-
this.warnLog(`
|
|
230
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
215
231
|
}
|
|
216
232
|
} else if (this.platform.config.options?.logging) {
|
|
217
233
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
218
234
|
if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
|
|
219
|
-
this.warnLog(`
|
|
235
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
220
236
|
}
|
|
221
237
|
} else {
|
|
222
238
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
@@ -358,8 +374,8 @@ export class Humidifier {
|
|
|
358
374
|
this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
359
375
|
}
|
|
360
376
|
};
|
|
361
|
-
// Wait
|
|
362
|
-
return switchbot.wait(
|
|
377
|
+
// Wait 2 seconds
|
|
378
|
+
return switchbot.wait(this.scanDuration * 1000);
|
|
363
379
|
}).then(async () => {
|
|
364
380
|
// Stop to monitor
|
|
365
381
|
switchbot.stopScan();
|
package/src/devices/meters.ts
CHANGED
|
@@ -40,6 +40,7 @@ export class Meter {
|
|
|
40
40
|
humidity!: serviceData['humidity'];
|
|
41
41
|
|
|
42
42
|
// Config
|
|
43
|
+
scanDuration!: number;
|
|
43
44
|
deviceLogging!: string;
|
|
44
45
|
deviceRefreshRate!: number;
|
|
45
46
|
|
|
@@ -53,8 +54,9 @@ export class Meter {
|
|
|
53
54
|
public device: device & devicesConfig,
|
|
54
55
|
) {
|
|
55
56
|
// default placeholders
|
|
56
|
-
this.refreshRate();
|
|
57
57
|
this.logs();
|
|
58
|
+
this.scan();
|
|
59
|
+
this.refreshRate();
|
|
58
60
|
if (this.BatteryLevel === undefined) {
|
|
59
61
|
this.BatteryLevel = 100;
|
|
60
62
|
} else {
|
|
@@ -194,19 +196,33 @@ export class Meter {
|
|
|
194
196
|
}
|
|
195
197
|
}
|
|
196
198
|
|
|
199
|
+
scan() {
|
|
200
|
+
if (this.device.scanDuration) {
|
|
201
|
+
this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
|
|
202
|
+
if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
|
|
203
|
+
this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
204
|
+
}
|
|
205
|
+
} else {
|
|
206
|
+
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
207
|
+
if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
|
|
208
|
+
this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
197
213
|
logs() {
|
|
198
214
|
if (this.platform.debugMode) {
|
|
199
215
|
this.deviceLogging = this.accessory.context.logging = 'debug';
|
|
200
|
-
this.warnLog(`
|
|
216
|
+
this.warnLog(`Meter: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
201
217
|
} else if (this.device.logging) {
|
|
202
218
|
this.deviceLogging = this.accessory.context.logging = this.device.logging;
|
|
203
219
|
if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
|
|
204
|
-
this.warnLog(`
|
|
220
|
+
this.warnLog(`Meter: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
205
221
|
}
|
|
206
222
|
} else if (this.platform.config.options?.logging) {
|
|
207
223
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
208
224
|
if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
|
|
209
|
-
this.warnLog(`
|
|
225
|
+
this.warnLog(`Meter: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
210
226
|
}
|
|
211
227
|
} else {
|
|
212
228
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
@@ -324,7 +340,7 @@ export class Meter {
|
|
|
324
340
|
}
|
|
325
341
|
};
|
|
326
342
|
// Wait 10 seconds
|
|
327
|
-
return switchbot.wait(
|
|
343
|
+
return switchbot.wait(this.scanDuration * 1000);
|
|
328
344
|
}).then(async () => {
|
|
329
345
|
// Stop to monitor
|
|
330
346
|
switchbot.stopScan();
|