@switchbot/homebridge-switchbot 3.6.1-beta.1 → 3.6.1-beta.10
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 +11 -0
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +35 -17
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +1 -2
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +186 -396
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +3 -2
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +56 -31
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +3 -2
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +57 -29
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +35 -18
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +7 -5
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +9 -0
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +30 -3
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +35 -18
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +37 -18
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +39 -20
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +37 -18
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +4 -3
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +57 -31
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +36 -17
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +37 -18
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +37 -18
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +35 -16
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +36 -17
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +35 -16
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +35 -16
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/other.d.ts +1 -0
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +186 -228
- package/dist/irdevice/other.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +11 -2
- package/dist/platform.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +1 -0
- package/dist/types/bledevicestatus.d.ts.map +1 -1
- package/dist/utils.d.ts +8 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +16 -0
- package/dist/utils.js.map +1 -1
- package/package.json +6 -6
- package/src/device/blindtilt.ts +32 -17
- package/src/device/bot.ts +179 -406
- package/src/device/ceilinglight.ts +53 -33
- package/src/device/colorbulb.ts +55 -31
- package/src/device/contact.ts +32 -19
- package/src/device/curtain.ts +7 -6
- package/src/device/device.ts +36 -3
- package/src/device/fan.ts +32 -19
- package/src/device/hub.ts +34 -18
- package/src/device/humidifier.ts +36 -20
- package/src/device/iosensor.ts +34 -18
- package/src/device/lightstrip.ts +56 -33
- package/src/device/lock.ts +33 -17
- package/src/device/meter.ts +34 -18
- package/src/device/meterplus.ts +34 -18
- package/src/device/motion.ts +32 -16
- package/src/device/plug.ts +33 -17
- package/src/device/robotvacuumcleaner.ts +32 -16
- package/src/device/waterdetector.ts +32 -16
- package/src/irdevice/other.ts +214 -283
- package/src/platform.ts +11 -2
- package/src/types/bledevicestatus.ts +1 -0
- package/src/utils.ts +15 -0
package/src/device/humidifier.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* humidifier.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import { deviceBase } from './device.js';
|
|
6
|
-
import { convertUnits } from '../utils.js';
|
|
6
|
+
import { convertUnits, validHumidity } from '../utils.js';
|
|
7
7
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
8
8
|
import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
|
|
9
9
|
|
|
@@ -197,7 +197,7 @@ export class Humidifier extends deviceBase {
|
|
|
197
197
|
await this.debugLog(`Active: ${this.HumidifierDehumidifier.Active}`);
|
|
198
198
|
|
|
199
199
|
// Current Relative Humidity
|
|
200
|
-
this.HumidifierDehumidifier.CurrentRelativeHumidity = this.serviceData.
|
|
200
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = validHumidity(this.serviceData.humidity);
|
|
201
201
|
await this.debugLog(`CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
202
202
|
|
|
203
203
|
// Target Humidifier Dehumidifier State
|
|
@@ -238,7 +238,7 @@ export class Humidifier extends deviceBase {
|
|
|
238
238
|
await this.debugLog(`Active: ${this.HumidifierDehumidifier.Active}`);
|
|
239
239
|
|
|
240
240
|
// Current Relative Humidity
|
|
241
|
-
this.HumidifierDehumidifier.CurrentRelativeHumidity = this.deviceStatus.
|
|
241
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = validHumidity(this.deviceStatus.humidity);
|
|
242
242
|
await this.debugLog(`CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
243
243
|
|
|
244
244
|
// Current Temperature
|
|
@@ -301,7 +301,7 @@ export class Humidifier extends deviceBase {
|
|
|
301
301
|
+ ` ${this.HumidifierDehumidifier.CurrentRelativeHumidity})`);
|
|
302
302
|
|
|
303
303
|
// CurrentRelativeHumidity
|
|
304
|
-
this.HumidifierDehumidifier.CurrentRelativeHumidity = this.webhookContext.humidity;
|
|
304
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = validHumidity(this.webhookContext.humidity);
|
|
305
305
|
await this.debugLog(`CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
306
306
|
|
|
307
307
|
// CurrentTemperature
|
|
@@ -330,25 +330,41 @@ export class Humidifier extends deviceBase {
|
|
|
330
330
|
|
|
331
331
|
async BLERefreshStatus(): Promise<void> {
|
|
332
332
|
await this.debugLog('BLERefreshStatus');
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
await this.
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as humidifierServiceData;
|
|
342
|
-
// Update HomeKit
|
|
343
|
-
if (serviceData.model === SwitchBotBLEModel.Humidifier && serviceData.modelName === SwitchBotBLEModelName.Humidifier) {
|
|
344
|
-
this.serviceData = serviceData;
|
|
333
|
+
if (this.config.options?.BLE) {
|
|
334
|
+
await this.debugLog('is listening to Platform BLE.');
|
|
335
|
+
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
336
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
337
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: humidifierServiceData) => {
|
|
338
|
+
try {
|
|
339
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`);
|
|
340
|
+
this.serviceData = context;
|
|
345
341
|
await this.BLEparseStatus();
|
|
346
342
|
await this.updateHomeKitCharacteristics();
|
|
347
|
-
}
|
|
348
|
-
await this.errorLog(`failed to
|
|
349
|
-
await this.BLERefreshConnection(switchbot);
|
|
343
|
+
} catch (e: any) {
|
|
344
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
350
345
|
}
|
|
351
|
-
}
|
|
346
|
+
};
|
|
347
|
+
} else {
|
|
348
|
+
await this.debugLog('is using Device BLE Scanning.');
|
|
349
|
+
const switchbot = await this.switchbotBLE();
|
|
350
|
+
if (switchbot === undefined) {
|
|
351
|
+
await this.BLERefreshConnection(switchbot);
|
|
352
|
+
} else {
|
|
353
|
+
// Start to monitor advertisement packets
|
|
354
|
+
(async () => {
|
|
355
|
+
// Start to monitor advertisement packets
|
|
356
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as humidifierServiceData;
|
|
357
|
+
// Update HomeKit
|
|
358
|
+
if (serviceData.model === SwitchBotBLEModel.Humidifier && serviceData.modelName === SwitchBotBLEModelName.Humidifier) {
|
|
359
|
+
this.serviceData = serviceData;
|
|
360
|
+
await this.BLEparseStatus();
|
|
361
|
+
await this.updateHomeKitCharacteristics();
|
|
362
|
+
} else {
|
|
363
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
364
|
+
await this.BLERefreshConnection(switchbot);
|
|
365
|
+
}
|
|
366
|
+
})();
|
|
367
|
+
}
|
|
352
368
|
}
|
|
353
369
|
}
|
|
354
370
|
|
package/src/device/iosensor.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { Units } from 'homebridge';
|
|
6
6
|
import { deviceBase } from './device.js';
|
|
7
|
-
import { convertUnits } from '../utils.js';
|
|
8
7
|
import { Subject, interval, skipWhile } from 'rxjs';
|
|
8
|
+
import { convertUnits, validHumidity } from '../utils.js';
|
|
9
9
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
10
10
|
|
|
11
11
|
import type { devicesConfig } from '../settings.js';
|
|
@@ -187,7 +187,7 @@ export class IOSensor extends deviceBase {
|
|
|
187
187
|
|
|
188
188
|
// CurrentRelativeHumidity
|
|
189
189
|
if (!this.device.iosensor?.hide_humidity && this.HumiditySensor?.Service) {
|
|
190
|
-
this.HumiditySensor.CurrentRelativeHumidity = this.serviceData.humidity;
|
|
190
|
+
this.HumiditySensor.CurrentRelativeHumidity = validHumidity(this.serviceData.humidity, 0, 100);
|
|
191
191
|
await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`);
|
|
192
192
|
}
|
|
193
193
|
|
|
@@ -283,25 +283,41 @@ export class IOSensor extends deviceBase {
|
|
|
283
283
|
|
|
284
284
|
async BLERefreshStatus(): Promise<void> {
|
|
285
285
|
await this.debugLog('BLERefreshStatus');
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
await this.
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as outdoorMeterServiceData;
|
|
295
|
-
// Update HomeKit
|
|
296
|
-
if (serviceData.model === SwitchBotBLEModel.OutdoorMeter && serviceData.modelName === SwitchBotBLEModelName.OutdoorMeter) {
|
|
297
|
-
this.serviceData = serviceData;
|
|
286
|
+
if (this.config.options?.BLE) {
|
|
287
|
+
await this.debugLog('is listening to Platform BLE.');
|
|
288
|
+
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
289
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
290
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: outdoorMeterServiceData) => {
|
|
291
|
+
try {
|
|
292
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`);
|
|
293
|
+
this.serviceData = context;
|
|
298
294
|
await this.BLEparseStatus();
|
|
299
295
|
await this.updateHomeKitCharacteristics();
|
|
300
|
-
}
|
|
301
|
-
await this.errorLog(`failed to
|
|
302
|
-
await this.BLERefreshConnection(switchbot);
|
|
296
|
+
} catch (e: any) {
|
|
297
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
303
298
|
}
|
|
304
|
-
}
|
|
299
|
+
};
|
|
300
|
+
} else {
|
|
301
|
+
await this.debugLog('is using Device BLE Scanning.');
|
|
302
|
+
const switchbot = await this.switchbotBLE();
|
|
303
|
+
if (switchbot === undefined) {
|
|
304
|
+
await this.BLERefreshConnection(switchbot);
|
|
305
|
+
} else {
|
|
306
|
+
// Start to monitor advertisement packets
|
|
307
|
+
(async () => {
|
|
308
|
+
// Start to monitor advertisement packets
|
|
309
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as outdoorMeterServiceData;
|
|
310
|
+
// Update HomeKit
|
|
311
|
+
if (serviceData.model === SwitchBotBLEModel.OutdoorMeter && serviceData.modelName === SwitchBotBLEModelName.OutdoorMeter) {
|
|
312
|
+
this.serviceData = serviceData;
|
|
313
|
+
await this.BLEparseStatus();
|
|
314
|
+
await this.updateHomeKitCharacteristics();
|
|
315
|
+
} else {
|
|
316
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
317
|
+
await this.BLERefreshConnection(switchbot);
|
|
318
|
+
}
|
|
319
|
+
})();
|
|
320
|
+
}
|
|
305
321
|
}
|
|
306
322
|
}
|
|
307
323
|
|
package/src/device/lightstrip.ts
CHANGED
|
@@ -10,8 +10,8 @@ import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
|
|
|
10
10
|
import type { devicesConfig } from '../settings.js';
|
|
11
11
|
import type { device } from '../types/devicelist.js';
|
|
12
12
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
13
|
-
import type { stripLightServiceData } from '../types/bledevicestatus.js';
|
|
14
13
|
import type { stripLightStatus } from '../types/devicestatus.js';
|
|
14
|
+
import type { stripLightServiceData } from '../types/bledevicestatus.js';
|
|
15
15
|
import type { stripLightWebhookContext } from '../types/devicewebhookstatus.js';
|
|
16
16
|
import type { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
|
|
17
17
|
|
|
@@ -42,8 +42,9 @@ export class StripLight extends deviceBase {
|
|
|
42
42
|
serviceData!: stripLightServiceData;
|
|
43
43
|
|
|
44
44
|
// Adaptive Lighting
|
|
45
|
+
adaptiveLighting!: boolean;
|
|
46
|
+
adaptiveLightingShift!: number;
|
|
45
47
|
AdaptiveLightingController?: ControllerConstructor | Controller<ControllerServiceMap>;
|
|
46
|
-
adaptiveLightingShift?: number;
|
|
47
48
|
|
|
48
49
|
// Updates
|
|
49
50
|
stripLightUpdateInProgress!: boolean;
|
|
@@ -59,7 +60,8 @@ export class StripLight extends deviceBase {
|
|
|
59
60
|
accessory.category = this.hap.Categories.LIGHTBULB;
|
|
60
61
|
|
|
61
62
|
// Adaptive Lighting
|
|
62
|
-
this.
|
|
63
|
+
this.getAdaptiveLightingSettings(accessory, device);
|
|
64
|
+
|
|
63
65
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
64
66
|
this.doStripLightUpdate = new Subject();
|
|
65
67
|
this.stripLightUpdateInProgress = false;
|
|
@@ -77,23 +79,24 @@ export class StripLight extends deviceBase {
|
|
|
77
79
|
};
|
|
78
80
|
accessory.context.LightBulb = this.LightBulb as object;
|
|
79
81
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
this.accessory.
|
|
83
|
-
|
|
84
|
-
this.
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
if (this.adaptiveLightingShift !== -1) {
|
|
82
|
+
if (this.adaptiveLighting && this.adaptiveLightingShift === -1 && this.LightBulb) {
|
|
83
|
+
accessory.removeService(this.LightBulb.Service);
|
|
84
|
+
this.LightBulb.Service = accessory.addService(this.hap.Service.Lightbulb);
|
|
85
|
+
accessory.context.adaptiveLighting = false;
|
|
86
|
+
this.debugLog(`adaptiveLighting: ${this.adaptiveLighting}`);
|
|
87
|
+
} else if (this.adaptiveLighting && this.adaptiveLightingShift >= 0 && this.LightBulb) {
|
|
88
88
|
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.LightBulb.Service, {
|
|
89
|
+
controllerMode: this.hap.AdaptiveLightingControllerMode.AUTOMATIC,
|
|
89
90
|
customTemperatureAdjustment: this.adaptiveLightingShift,
|
|
90
91
|
});
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
this.debugLog(`adaptiveLighting: ${this.
|
|
94
|
-
|
|
92
|
+
accessory.configureController(this.AdaptiveLightingController);
|
|
93
|
+
accessory.context.adaptiveLighting = true;
|
|
94
|
+
this.debugLog(`adaptiveLighting: ${this.adaptiveLighting}, adaptiveLightingShift: ${this.adaptiveLightingShift}`,
|
|
95
|
+
);
|
|
96
|
+
} else {
|
|
97
|
+
accessory.context.adaptiveLighting = false;
|
|
98
|
+
this.debugLog(`adaptiveLighting: ${accessory.context.adaptiveLighting}`);
|
|
95
99
|
}
|
|
96
|
-
this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
97
100
|
|
|
98
101
|
// Initialize LightBulb Characteristics
|
|
99
102
|
this.LightBulb.Service
|
|
@@ -313,25 +316,41 @@ export class StripLight extends deviceBase {
|
|
|
313
316
|
|
|
314
317
|
async BLERefreshStatus(): Promise<void> {
|
|
315
318
|
await this.debugLog('BLERefreshStatus');
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
await this.
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as stripLightServiceData;
|
|
325
|
-
// Update HomeKit
|
|
326
|
-
if (serviceData.model === SwitchBotBLEModel.StripLight && serviceData.modelName === SwitchBotBLEModelName.StripLight) {
|
|
327
|
-
this.serviceData = serviceData;
|
|
319
|
+
if (this.config.options?.BLE) {
|
|
320
|
+
await this.debugLog('is listening to Platform BLE.');
|
|
321
|
+
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
322
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
323
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: stripLightServiceData) => {
|
|
324
|
+
try {
|
|
325
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`);
|
|
326
|
+
this.serviceData = context;
|
|
328
327
|
await this.BLEparseStatus();
|
|
329
328
|
await this.updateHomeKitCharacteristics();
|
|
330
|
-
}
|
|
331
|
-
await this.errorLog(`failed to
|
|
332
|
-
await this.BLERefreshConnection(switchbot);
|
|
329
|
+
} catch (e: any) {
|
|
330
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
333
331
|
}
|
|
334
|
-
}
|
|
332
|
+
};
|
|
333
|
+
} else {
|
|
334
|
+
await this.debugLog('is using Device BLE Scanning.');
|
|
335
|
+
const switchbot = await this.switchbotBLE();
|
|
336
|
+
if (switchbot === undefined) {
|
|
337
|
+
await this.BLERefreshConnection(switchbot);
|
|
338
|
+
} else {
|
|
339
|
+
// Start to monitor advertisement packets
|
|
340
|
+
(async () => {
|
|
341
|
+
// Start to monitor advertisement packets
|
|
342
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as stripLightServiceData;
|
|
343
|
+
// Update HomeKit
|
|
344
|
+
if (serviceData.model === SwitchBotBLEModel.StripLight && serviceData.modelName === SwitchBotBLEModelName.StripLight) {
|
|
345
|
+
this.serviceData = serviceData;
|
|
346
|
+
await this.BLEparseStatus();
|
|
347
|
+
await this.updateHomeKitCharacteristics();
|
|
348
|
+
} else {
|
|
349
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
350
|
+
await this.BLERefreshConnection(switchbot);
|
|
351
|
+
}
|
|
352
|
+
})();
|
|
353
|
+
}
|
|
335
354
|
}
|
|
336
355
|
}
|
|
337
356
|
|
|
@@ -757,7 +776,11 @@ export class StripLight extends deviceBase {
|
|
|
757
776
|
this.LightBulb.Saturation, 'Saturation');
|
|
758
777
|
}
|
|
759
778
|
|
|
760
|
-
async
|
|
779
|
+
async getAdaptiveLightingSettings(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
|
|
780
|
+
// Adaptive Lighting
|
|
781
|
+
this.adaptiveLighting = accessory.context.adaptiveLighting ?? true;
|
|
782
|
+
await this.debugLog(`adaptiveLighting: ${this.adaptiveLighting}`);
|
|
783
|
+
// Adaptive Lighting Shift
|
|
761
784
|
if (device.striplight?.adaptiveLightingShift) {
|
|
762
785
|
this.adaptiveLightingShift = device.striplight.adaptiveLightingShift;
|
|
763
786
|
this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
package/src/device/lock.ts
CHANGED
|
@@ -309,26 +309,42 @@ export class Lock extends deviceBase {
|
|
|
309
309
|
|
|
310
310
|
async BLERefreshStatus(): Promise<void> {
|
|
311
311
|
await this.debugLog('BLERefreshStatus');
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
await this.
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as lockServiceData | lockProServiceData;
|
|
321
|
-
// Update HomeKit
|
|
322
|
-
if ((serviceData.model === SwitchBotBLEModel.Lock || SwitchBotBLEModel.LockPro)
|
|
323
|
-
&& (serviceData.modelName === SwitchBotBLEModelName.Lock || SwitchBotBLEModelName.LockPro)) {
|
|
324
|
-
this.serviceData = serviceData;
|
|
312
|
+
if (this.config.options?.BLE) {
|
|
313
|
+
await this.debugLog('is listening to Platform BLE.');
|
|
314
|
+
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
315
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
316
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: lockServiceData | lockProServiceData) => {
|
|
317
|
+
try {
|
|
318
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`);
|
|
319
|
+
this.serviceData = context;
|
|
325
320
|
await this.BLEparseStatus();
|
|
326
321
|
await this.updateHomeKitCharacteristics();
|
|
327
|
-
}
|
|
328
|
-
await this.errorLog(`failed to
|
|
329
|
-
await this.BLERefreshConnection(switchbot);
|
|
322
|
+
} catch (e: any) {
|
|
323
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
330
324
|
}
|
|
331
|
-
}
|
|
325
|
+
};
|
|
326
|
+
} else {
|
|
327
|
+
await this.debugLog('is using Device BLE Scanning.');
|
|
328
|
+
const switchbot = await this.switchbotBLE();
|
|
329
|
+
if (switchbot === undefined) {
|
|
330
|
+
await this.BLERefreshConnection(switchbot);
|
|
331
|
+
} else {
|
|
332
|
+
// Start to monitor advertisement packets
|
|
333
|
+
(async () => {
|
|
334
|
+
// Start to monitor advertisement packets
|
|
335
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as lockServiceData | lockProServiceData;
|
|
336
|
+
// Update HomeKit
|
|
337
|
+
if ((serviceData.model === SwitchBotBLEModel.Lock || SwitchBotBLEModel.LockPro)
|
|
338
|
+
&& (serviceData.modelName === SwitchBotBLEModelName.Lock || SwitchBotBLEModelName.LockPro)) {
|
|
339
|
+
this.serviceData = serviceData;
|
|
340
|
+
await this.BLEparseStatus();
|
|
341
|
+
await this.updateHomeKitCharacteristics();
|
|
342
|
+
} else {
|
|
343
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
344
|
+
await this.BLERefreshConnection(switchbot);
|
|
345
|
+
}
|
|
346
|
+
})();
|
|
347
|
+
}
|
|
332
348
|
}
|
|
333
349
|
}
|
|
334
350
|
|
package/src/device/meter.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { Units } from 'homebridge';
|
|
6
6
|
import { deviceBase } from './device.js';
|
|
7
|
-
import { convertUnits } from '../utils.js';
|
|
8
7
|
import { Subject, interval, skipWhile } from 'rxjs';
|
|
8
|
+
import { convertUnits, validHumidity } from '../utils.js';
|
|
9
9
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
10
10
|
|
|
11
11
|
import type { devicesConfig } from '../settings.js';
|
|
@@ -170,7 +170,7 @@ export class Meter extends deviceBase {
|
|
|
170
170
|
|
|
171
171
|
// CurrentRelativeHumidity
|
|
172
172
|
if (!this.device.iosensor?.hide_humidity && this.HumiditySensor?.Service) {
|
|
173
|
-
this.HumiditySensor.CurrentRelativeHumidity = this.serviceData.humidity;
|
|
173
|
+
this.HumiditySensor.CurrentRelativeHumidity = validHumidity(this.serviceData.humidity, 0, 100);
|
|
174
174
|
await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`);
|
|
175
175
|
}
|
|
176
176
|
|
|
@@ -277,25 +277,41 @@ export class Meter extends deviceBase {
|
|
|
277
277
|
|
|
278
278
|
async BLERefreshStatus(): Promise<void> {
|
|
279
279
|
await this.debugLog('BLERefreshStatus');
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
await this.
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as meterServiceData;
|
|
289
|
-
// Update HomeKit
|
|
290
|
-
if (serviceData.model === SwitchBotBLEModel.Meter && serviceData.modelName === SwitchBotBLEModelName.Meter) {
|
|
291
|
-
this.serviceData = serviceData;
|
|
280
|
+
if (this.config.options?.BLE) {
|
|
281
|
+
await this.debugLog('is listening to Platform BLE.');
|
|
282
|
+
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
283
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
284
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: meterServiceData) => {
|
|
285
|
+
try {
|
|
286
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`);
|
|
287
|
+
this.serviceData = context;
|
|
292
288
|
await this.BLEparseStatus();
|
|
293
289
|
await this.updateHomeKitCharacteristics();
|
|
294
|
-
}
|
|
295
|
-
await this.errorLog(`failed to
|
|
296
|
-
await this.BLERefreshConnection(switchbot);
|
|
290
|
+
} catch (e: any) {
|
|
291
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
297
292
|
}
|
|
298
|
-
}
|
|
293
|
+
};
|
|
294
|
+
} else {
|
|
295
|
+
await this.debugLog('is using Device BLE Scanning.');
|
|
296
|
+
const switchbot = await this.switchbotBLE();
|
|
297
|
+
if (switchbot === undefined) {
|
|
298
|
+
await this.BLERefreshConnection(switchbot);
|
|
299
|
+
} else {
|
|
300
|
+
// Start to monitor advertisement packets
|
|
301
|
+
(async () => {
|
|
302
|
+
// Start to monitor advertisement packets
|
|
303
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as meterServiceData;
|
|
304
|
+
// Update HomeKit
|
|
305
|
+
if (serviceData.model === SwitchBotBLEModel.Meter && serviceData.modelName === SwitchBotBLEModelName.Meter) {
|
|
306
|
+
this.serviceData = serviceData;
|
|
307
|
+
await this.BLEparseStatus();
|
|
308
|
+
await this.updateHomeKitCharacteristics();
|
|
309
|
+
} else {
|
|
310
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
311
|
+
await this.BLERefreshConnection(switchbot);
|
|
312
|
+
}
|
|
313
|
+
})();
|
|
314
|
+
}
|
|
299
315
|
}
|
|
300
316
|
}
|
|
301
317
|
|
package/src/device/meterplus.ts
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
import { Units } from 'homebridge';
|
|
6
6
|
import { deviceBase } from './device.js';
|
|
7
7
|
import { Subject, interval, skipWhile } from 'rxjs';
|
|
8
|
+
import { convertUnits, validHumidity } from '../utils.js';
|
|
8
9
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
9
10
|
|
|
10
|
-
import { convertUnits } from '../utils.js';
|
|
11
11
|
import type { devicesConfig } from '../settings.js';
|
|
12
12
|
import type { device } from '../types/devicelist.js';
|
|
13
13
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
@@ -175,7 +175,7 @@ export class MeterPlus extends deviceBase {
|
|
|
175
175
|
|
|
176
176
|
// CurrentRelativeHumidity
|
|
177
177
|
if (!this.device.iosensor?.hide_humidity && this.HumiditySensor?.Service) {
|
|
178
|
-
this.HumiditySensor.CurrentRelativeHumidity = this.serviceData.humidity;
|
|
178
|
+
this.HumiditySensor.CurrentRelativeHumidity = validHumidity(this.serviceData.humidity, 0, 100);
|
|
179
179
|
await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`);
|
|
180
180
|
}
|
|
181
181
|
// Current Temperature
|
|
@@ -278,25 +278,41 @@ export class MeterPlus extends deviceBase {
|
|
|
278
278
|
|
|
279
279
|
async BLERefreshStatus(): Promise<void> {
|
|
280
280
|
await this.debugLog('BLERefreshStatus');
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
await this.
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as meterPlusServiceData;
|
|
290
|
-
// Update HomeKit
|
|
291
|
-
if (serviceData.model === SwitchBotBLEModel.MeterPlus && serviceData.modelName === SwitchBotBLEModelName.MeterPlus) {
|
|
292
|
-
this.serviceData = serviceData;
|
|
281
|
+
if (this.config.options?.BLE) {
|
|
282
|
+
await this.debugLog('is listening to Platform BLE.');
|
|
283
|
+
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
284
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
285
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: meterPlusServiceData) => {
|
|
286
|
+
try {
|
|
287
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`);
|
|
288
|
+
this.serviceData = context;
|
|
293
289
|
await this.BLEparseStatus();
|
|
294
290
|
await this.updateHomeKitCharacteristics();
|
|
295
|
-
}
|
|
296
|
-
await this.errorLog(`failed to
|
|
297
|
-
await this.BLERefreshConnection(switchbot);
|
|
291
|
+
} catch (e: any) {
|
|
292
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
298
293
|
}
|
|
299
|
-
}
|
|
294
|
+
};
|
|
295
|
+
} else {
|
|
296
|
+
await this.debugLog('is using Device BLE Scanning.');
|
|
297
|
+
const switchbot = await this.switchbotBLE();
|
|
298
|
+
if (switchbot === undefined) {
|
|
299
|
+
await this.BLERefreshConnection(switchbot);
|
|
300
|
+
} else {
|
|
301
|
+
// Start to monitor advertisement packets
|
|
302
|
+
(async () => {
|
|
303
|
+
// Start to monitor advertisement packets
|
|
304
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as meterPlusServiceData;
|
|
305
|
+
// Update HomeKit
|
|
306
|
+
if (serviceData.model === SwitchBotBLEModel.MeterPlus && serviceData.modelName === SwitchBotBLEModelName.MeterPlus) {
|
|
307
|
+
this.serviceData = serviceData;
|
|
308
|
+
await this.BLEparseStatus();
|
|
309
|
+
await this.updateHomeKitCharacteristics();
|
|
310
|
+
} else {
|
|
311
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
312
|
+
await this.BLERefreshConnection(switchbot);
|
|
313
|
+
}
|
|
314
|
+
})();
|
|
315
|
+
}
|
|
300
316
|
}
|
|
301
317
|
}
|
|
302
318
|
|
package/src/device/motion.ts
CHANGED
|
@@ -249,25 +249,41 @@ export class Motion extends deviceBase {
|
|
|
249
249
|
|
|
250
250
|
async BLERefreshStatus(): Promise<void> {
|
|
251
251
|
await this.debugLog('BLERefreshStatus');
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
await this.
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as motionSensorServiceData;
|
|
261
|
-
// Update HomeKit
|
|
262
|
-
if (serviceData.model === SwitchBotBLEModel.MotionSensor && serviceData.modelName === SwitchBotBLEModelName.MotionSensor) {
|
|
263
|
-
this.serviceData = serviceData;
|
|
252
|
+
if (this.config.options?.BLE) {
|
|
253
|
+
await this.debugLog('is listening to Platform BLE.');
|
|
254
|
+
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
255
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
256
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: motionSensorServiceData) => {
|
|
257
|
+
try {
|
|
258
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`);
|
|
259
|
+
this.serviceData = context;
|
|
264
260
|
await this.BLEparseStatus();
|
|
265
261
|
await this.updateHomeKitCharacteristics();
|
|
266
|
-
}
|
|
267
|
-
await this.errorLog(`failed to
|
|
268
|
-
await this.BLERefreshConnection(switchbot);
|
|
262
|
+
} catch (e: any) {
|
|
263
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
269
264
|
}
|
|
270
|
-
}
|
|
265
|
+
};
|
|
266
|
+
} else {
|
|
267
|
+
await this.debugLog('is using Device BLE Scanning.');
|
|
268
|
+
const switchbot = await this.switchbotBLE();
|
|
269
|
+
if (switchbot === undefined) {
|
|
270
|
+
await this.BLERefreshConnection(switchbot);
|
|
271
|
+
} else {
|
|
272
|
+
// Start to monitor advertisement packets
|
|
273
|
+
(async () => {
|
|
274
|
+
// Start to monitor advertisement packets
|
|
275
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as motionSensorServiceData;
|
|
276
|
+
// Update HomeKit
|
|
277
|
+
if (serviceData.model === SwitchBotBLEModel.MotionSensor && serviceData.modelName === SwitchBotBLEModelName.MotionSensor) {
|
|
278
|
+
this.serviceData = serviceData;
|
|
279
|
+
await this.BLEparseStatus();
|
|
280
|
+
await this.updateHomeKitCharacteristics();
|
|
281
|
+
} else {
|
|
282
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
283
|
+
await this.BLERefreshConnection(switchbot);
|
|
284
|
+
}
|
|
285
|
+
})();
|
|
286
|
+
}
|
|
271
287
|
}
|
|
272
288
|
}
|
|
273
289
|
|
package/src/device/plug.ts
CHANGED
|
@@ -160,26 +160,42 @@ export class Plug extends deviceBase {
|
|
|
160
160
|
|
|
161
161
|
async BLERefreshStatus(): Promise<void> {
|
|
162
162
|
await this.debugLog('BLERefreshStatus');
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
await this.
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as plugMiniUSServiceData | plugMiniJPServiceData;
|
|
172
|
-
// Update HomeKit
|
|
173
|
-
if ((serviceData.model === SwitchBotBLEModel.PlugMiniUS || SwitchBotBLEModel.PlugMiniJP)
|
|
174
|
-
&& serviceData.modelName === (SwitchBotBLEModelName.PlugMini || SwitchBotBLEModelName.PlugMini)) {
|
|
175
|
-
this.serviceData = serviceData;
|
|
163
|
+
if (this.config.options?.BLE) {
|
|
164
|
+
await this.debugLog('is listening to Platform BLE.');
|
|
165
|
+
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
166
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
167
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: plugMiniUSServiceData | plugMiniJPServiceData) => {
|
|
168
|
+
try {
|
|
169
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`);
|
|
170
|
+
this.serviceData = context;
|
|
176
171
|
await this.BLEparseStatus();
|
|
177
172
|
await this.updateHomeKitCharacteristics();
|
|
178
|
-
}
|
|
179
|
-
await this.errorLog(`failed to
|
|
180
|
-
await this.BLERefreshConnection(switchbot);
|
|
173
|
+
} catch (e: any) {
|
|
174
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
181
175
|
}
|
|
182
|
-
}
|
|
176
|
+
};
|
|
177
|
+
} else {
|
|
178
|
+
await this.debugLog('is using Device BLE Scanning.');
|
|
179
|
+
const switchbot = await this.switchbotBLE();
|
|
180
|
+
if (switchbot === undefined) {
|
|
181
|
+
await this.BLERefreshConnection(switchbot);
|
|
182
|
+
} else {
|
|
183
|
+
// Start to monitor advertisement packets
|
|
184
|
+
(async () => {
|
|
185
|
+
// Start to monitor advertisement packets
|
|
186
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as plugMiniUSServiceData | plugMiniJPServiceData;
|
|
187
|
+
// Update HomeKit
|
|
188
|
+
if ((serviceData.model === SwitchBotBLEModel.PlugMiniUS || SwitchBotBLEModel.PlugMiniJP)
|
|
189
|
+
&& serviceData.modelName === (SwitchBotBLEModelName.PlugMini || SwitchBotBLEModelName.PlugMini)) {
|
|
190
|
+
this.serviceData = serviceData;
|
|
191
|
+
await this.BLEparseStatus();
|
|
192
|
+
await this.updateHomeKitCharacteristics();
|
|
193
|
+
} else {
|
|
194
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
195
|
+
await this.BLERefreshConnection(switchbot);
|
|
196
|
+
}
|
|
197
|
+
})();
|
|
198
|
+
}
|
|
183
199
|
}
|
|
184
200
|
}
|
|
185
201
|
|