@switchbot/homebridge-switchbot 3.7.1-beta.1 → 3.7.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 +8 -0
- package/config.schema.json +7 -1
- package/dist/device/blindtilt.d.ts +3 -1
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +61 -28
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +1 -0
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +102 -80
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +1 -0
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +53 -28
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +1 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +53 -28
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +1 -0
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +53 -28
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +2 -0
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +74 -43
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +247 -394
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +1 -0
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +53 -28
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +1 -0
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +53 -28
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +1 -0
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +53 -28
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +1 -0
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +53 -28
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +1 -0
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +53 -28
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +1 -0
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +54 -29
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +1 -0
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +53 -28
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +1 -0
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +53 -28
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +1 -0
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +53 -28
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +1 -0
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +54 -29
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +1 -0
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +53 -28
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +1 -0
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +53 -28
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +30 -133
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/platform.d.ts +19 -18
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +369 -524
- 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 +13 -13
- package/src/device/blindtilt.ts +59 -27
- package/src/device/bot.ts +98 -77
- package/src/device/ceilinglight.ts +51 -27
- package/src/device/colorbulb.ts +50 -26
- package/src/device/contact.ts +50 -26
- package/src/device/curtain.ts +71 -40
- package/src/device/device.ts +283 -395
- package/src/device/fan.ts +50 -26
- package/src/device/hub.ts +50 -26
- package/src/device/humidifier.ts +50 -26
- package/src/device/iosensor.ts +50 -26
- package/src/device/lightstrip.ts +50 -26
- package/src/device/lock.ts +51 -27
- package/src/device/meter.ts +50 -26
- package/src/device/meterplus.ts +50 -26
- package/src/device/motion.ts +50 -26
- package/src/device/plug.ts +51 -27
- package/src/device/robotvacuumcleaner.ts +50 -26
- package/src/device/waterdetector.ts +50 -26
- package/src/irdevice/irdevice.ts +54 -134
- package/src/platform.ts +379 -529
- package/src/settings.ts +1 -0
package/src/device/meter.ts
CHANGED
|
@@ -6,6 +6,10 @@ import { Units } from 'homebridge';
|
|
|
6
6
|
import { deviceBase } from './device.js';
|
|
7
7
|
import { Subject, interval, skipWhile } from 'rxjs';
|
|
8
8
|
import { convertUnits, validHumidity } from '../utils.js';
|
|
9
|
+
/*
|
|
10
|
+
* For Testing Locally:
|
|
11
|
+
* import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
12
|
+
*/
|
|
9
13
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
10
14
|
|
|
11
15
|
import type { devicesConfig } from '../settings.js';
|
|
@@ -148,12 +152,28 @@ export class Meter extends deviceBase {
|
|
|
148
152
|
}
|
|
149
153
|
|
|
150
154
|
// Retrieve initial values and updateHomekit
|
|
151
|
-
|
|
152
|
-
|
|
155
|
+
try {
|
|
156
|
+
this.debugLog('Retrieve initial values and update Homekit');
|
|
157
|
+
this.refreshStatus();
|
|
158
|
+
} catch (e: any) {
|
|
159
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`);
|
|
160
|
+
}
|
|
153
161
|
|
|
154
|
-
//regisiter webhook event handler
|
|
155
|
-
|
|
156
|
-
|
|
162
|
+
//regisiter webhook event handler if enabled
|
|
163
|
+
try {
|
|
164
|
+
this.debugLog('Registering Webhook Event Handler');
|
|
165
|
+
this.registerWebhook();
|
|
166
|
+
} catch (e: any) {
|
|
167
|
+
this.errorLog(`failed to registerWebhook, Error: ${e}`);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
//regisiter platform BLE event handler if enabled
|
|
171
|
+
try {
|
|
172
|
+
this.debugLog('Registering Platform BLE Event Handler');
|
|
173
|
+
this.registerPlatformBLE();
|
|
174
|
+
} catch (e: any) {
|
|
175
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`);
|
|
176
|
+
}
|
|
157
177
|
|
|
158
178
|
// Start an update interval
|
|
159
179
|
interval(this.deviceRefreshRate * 1000)
|
|
@@ -265,7 +285,7 @@ export class Meter extends deviceBase {
|
|
|
265
285
|
async refreshStatus(): Promise<void> {
|
|
266
286
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
267
287
|
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
268
|
-
} else if (this.BLE
|
|
288
|
+
} else if (this.BLE) {
|
|
269
289
|
await this.BLERefreshStatus();
|
|
270
290
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
271
291
|
await this.openAPIRefreshStatus();
|
|
@@ -277,6 +297,29 @@ export class Meter extends deviceBase {
|
|
|
277
297
|
|
|
278
298
|
async BLERefreshStatus(): Promise<void> {
|
|
279
299
|
await this.debugLog('BLERefreshStatus');
|
|
300
|
+
const switchbot = await this.switchbotBLE();
|
|
301
|
+
if (switchbot === undefined) {
|
|
302
|
+
await this.BLERefreshConnection(switchbot);
|
|
303
|
+
} else {
|
|
304
|
+
// Start to monitor advertisement packets
|
|
305
|
+
(async () => {
|
|
306
|
+
// Start to monitor advertisement packets
|
|
307
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as meterServiceData;
|
|
308
|
+
// Update HomeKit
|
|
309
|
+
if (serviceData.model === SwitchBotBLEModel.Meter && serviceData.modelName === SwitchBotBLEModelName.Meter) {
|
|
310
|
+
this.serviceData = serviceData;
|
|
311
|
+
await this.BLEparseStatus();
|
|
312
|
+
await this.updateHomeKitCharacteristics();
|
|
313
|
+
} else {
|
|
314
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
315
|
+
await this.BLERefreshConnection(switchbot);
|
|
316
|
+
}
|
|
317
|
+
})();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
async registerPlatformBLE(): Promise<void> {
|
|
322
|
+
await this.debugLog('registerPlatformBLE');
|
|
280
323
|
if (this.config.options?.BLE) {
|
|
281
324
|
await this.debugLog('is listening to Platform BLE.');
|
|
282
325
|
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
@@ -292,26 +335,7 @@ export class Meter extends deviceBase {
|
|
|
292
335
|
}
|
|
293
336
|
};
|
|
294
337
|
} else {
|
|
295
|
-
await this.debugLog('is
|
|
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
|
-
}
|
|
338
|
+
await this.debugLog('is not listening to Platform BLE');
|
|
315
339
|
}
|
|
316
340
|
}
|
|
317
341
|
|
package/src/device/meterplus.ts
CHANGED
|
@@ -6,6 +6,10 @@ import { Units } from 'homebridge';
|
|
|
6
6
|
import { deviceBase } from './device.js';
|
|
7
7
|
import { Subject, interval, skipWhile } from 'rxjs';
|
|
8
8
|
import { convertUnits, validHumidity } from '../utils.js';
|
|
9
|
+
/*
|
|
10
|
+
* For Testing Locally:
|
|
11
|
+
* import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
12
|
+
*/
|
|
9
13
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
10
14
|
|
|
11
15
|
import type { devicesConfig } from '../settings.js';
|
|
@@ -153,12 +157,28 @@ export class MeterPlus extends deviceBase {
|
|
|
153
157
|
}
|
|
154
158
|
|
|
155
159
|
// Retrieve initial values and updateHomekit
|
|
156
|
-
|
|
157
|
-
|
|
160
|
+
try {
|
|
161
|
+
this.debugLog('Retrieve initial values and update Homekit');
|
|
162
|
+
this.refreshStatus();
|
|
163
|
+
} catch (e: any) {
|
|
164
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`);
|
|
165
|
+
}
|
|
158
166
|
|
|
159
|
-
//regisiter webhook event handler
|
|
160
|
-
|
|
161
|
-
|
|
167
|
+
//regisiter webhook event handler if enabled
|
|
168
|
+
try {
|
|
169
|
+
this.debugLog('Registering Webhook Event Handler');
|
|
170
|
+
this.registerWebhook();
|
|
171
|
+
} catch (e: any) {
|
|
172
|
+
this.errorLog(`failed to registerWebhook, Error: ${e}`);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
//regisiter platform BLE event handler if enabled
|
|
176
|
+
try {
|
|
177
|
+
this.debugLog('Registering Platform BLE Event Handler');
|
|
178
|
+
this.registerPlatformBLE();
|
|
179
|
+
} catch (e: any) {
|
|
180
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`);
|
|
181
|
+
}
|
|
162
182
|
|
|
163
183
|
// Start an update interval
|
|
164
184
|
interval(this.deviceRefreshRate * 1000)
|
|
@@ -266,7 +286,7 @@ export class MeterPlus extends deviceBase {
|
|
|
266
286
|
async refreshStatus(): Promise<void> {
|
|
267
287
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
268
288
|
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
269
|
-
} else if (this.BLE
|
|
289
|
+
} else if (this.BLE) {
|
|
270
290
|
await this.BLERefreshStatus();
|
|
271
291
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
272
292
|
await this.openAPIRefreshStatus();
|
|
@@ -278,6 +298,29 @@ export class MeterPlus extends deviceBase {
|
|
|
278
298
|
|
|
279
299
|
async BLERefreshStatus(): Promise<void> {
|
|
280
300
|
await this.debugLog('BLERefreshStatus');
|
|
301
|
+
const switchbot = await this.switchbotBLE();
|
|
302
|
+
if (switchbot === undefined) {
|
|
303
|
+
await this.BLERefreshConnection(switchbot);
|
|
304
|
+
} else {
|
|
305
|
+
// Start to monitor advertisement packets
|
|
306
|
+
(async () => {
|
|
307
|
+
// Start to monitor advertisement packets
|
|
308
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as meterPlusServiceData;
|
|
309
|
+
// Update HomeKit
|
|
310
|
+
if (serviceData.model === SwitchBotBLEModel.MeterPlus && serviceData.modelName === SwitchBotBLEModelName.MeterPlus) {
|
|
311
|
+
this.serviceData = serviceData;
|
|
312
|
+
await this.BLEparseStatus();
|
|
313
|
+
await this.updateHomeKitCharacteristics();
|
|
314
|
+
} else {
|
|
315
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
316
|
+
await this.BLERefreshConnection(switchbot);
|
|
317
|
+
}
|
|
318
|
+
})();
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
async registerPlatformBLE(): Promise<void> {
|
|
323
|
+
await this.debugLog('registerPlatformBLE');
|
|
281
324
|
if (this.config.options?.BLE) {
|
|
282
325
|
await this.debugLog('is listening to Platform BLE.');
|
|
283
326
|
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
@@ -293,26 +336,7 @@ export class MeterPlus extends deviceBase {
|
|
|
293
336
|
}
|
|
294
337
|
};
|
|
295
338
|
} else {
|
|
296
|
-
await this.debugLog('is
|
|
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
|
-
}
|
|
339
|
+
await this.debugLog('is not listening to Platform BLE');
|
|
316
340
|
}
|
|
317
341
|
}
|
|
318
342
|
|
package/src/device/motion.ts
CHANGED
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { deviceBase } from './device.js';
|
|
7
7
|
import { Subject, interval, skipWhile } from 'rxjs';
|
|
8
|
+
/*
|
|
9
|
+
* For Testing Locally:
|
|
10
|
+
* import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
11
|
+
*/
|
|
8
12
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
9
13
|
|
|
10
14
|
import type { devicesConfig } from '../settings.js';
|
|
@@ -138,12 +142,28 @@ export class Motion extends deviceBase {
|
|
|
138
142
|
};
|
|
139
143
|
|
|
140
144
|
// Retrieve initial values and updateHomekit
|
|
141
|
-
|
|
142
|
-
|
|
145
|
+
try {
|
|
146
|
+
this.debugLog('Retrieve initial values and update Homekit');
|
|
147
|
+
this.refreshStatus();
|
|
148
|
+
} catch (e: any) {
|
|
149
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`);
|
|
150
|
+
}
|
|
143
151
|
|
|
144
|
-
//regisiter webhook event handler
|
|
145
|
-
|
|
146
|
-
|
|
152
|
+
//regisiter webhook event handler if enabled
|
|
153
|
+
try {
|
|
154
|
+
this.debugLog('Registering Webhook Event Handler');
|
|
155
|
+
this.registerWebhook();
|
|
156
|
+
} catch (e: any) {
|
|
157
|
+
this.errorLog(`failed to registerWebhook, Error: ${e}`);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
//regisiter platform BLE event handler if enabled
|
|
161
|
+
try {
|
|
162
|
+
this.debugLog('Registering Platform BLE Event Handler');
|
|
163
|
+
this.registerPlatformBLE();
|
|
164
|
+
} catch (e: any) {
|
|
165
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`);
|
|
166
|
+
}
|
|
147
167
|
|
|
148
168
|
// Start an update interval
|
|
149
169
|
interval(this.deviceRefreshRate * 1000)
|
|
@@ -236,7 +256,7 @@ export class Motion extends deviceBase {
|
|
|
236
256
|
async refreshStatus(): Promise<void> {
|
|
237
257
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
238
258
|
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
239
|
-
} else if (this.BLE
|
|
259
|
+
} else if (this.BLE) {
|
|
240
260
|
await this.BLERefreshStatus();
|
|
241
261
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
242
262
|
await this.openAPIRefreshStatus();
|
|
@@ -248,6 +268,29 @@ export class Motion extends deviceBase {
|
|
|
248
268
|
|
|
249
269
|
async BLERefreshStatus(): Promise<void> {
|
|
250
270
|
await this.debugLog('BLERefreshStatus');
|
|
271
|
+
const switchbot = await this.switchbotBLE();
|
|
272
|
+
if (switchbot === undefined) {
|
|
273
|
+
await this.BLERefreshConnection(switchbot);
|
|
274
|
+
} else {
|
|
275
|
+
// Start to monitor advertisement packets
|
|
276
|
+
(async () => {
|
|
277
|
+
// Start to monitor advertisement packets
|
|
278
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as motionSensorServiceData;
|
|
279
|
+
// Update HomeKit
|
|
280
|
+
if (serviceData.model === SwitchBotBLEModel.MotionSensor && serviceData.modelName === SwitchBotBLEModelName.MotionSensor) {
|
|
281
|
+
this.serviceData = serviceData;
|
|
282
|
+
await this.BLEparseStatus();
|
|
283
|
+
await this.updateHomeKitCharacteristics();
|
|
284
|
+
} else {
|
|
285
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
286
|
+
await this.BLERefreshConnection(switchbot);
|
|
287
|
+
}
|
|
288
|
+
})();
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
async registerPlatformBLE(): Promise<void> {
|
|
293
|
+
await this.debugLog('registerPlatformBLE');
|
|
251
294
|
if (this.config.options?.BLE) {
|
|
252
295
|
await this.debugLog('is listening to Platform BLE.');
|
|
253
296
|
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
@@ -263,26 +306,7 @@ export class Motion extends deviceBase {
|
|
|
263
306
|
}
|
|
264
307
|
};
|
|
265
308
|
} else {
|
|
266
|
-
await this.debugLog('is
|
|
267
|
-
const switchbot = await this.switchbotBLE();
|
|
268
|
-
if (switchbot === undefined) {
|
|
269
|
-
await this.BLERefreshConnection(switchbot);
|
|
270
|
-
} else {
|
|
271
|
-
// Start to monitor advertisement packets
|
|
272
|
-
(async () => {
|
|
273
|
-
// Start to monitor advertisement packets
|
|
274
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as motionSensorServiceData;
|
|
275
|
-
// Update HomeKit
|
|
276
|
-
if (serviceData.model === SwitchBotBLEModel.MotionSensor && serviceData.modelName === SwitchBotBLEModelName.MotionSensor) {
|
|
277
|
-
this.serviceData = serviceData;
|
|
278
|
-
await this.BLEparseStatus();
|
|
279
|
-
await this.updateHomeKitCharacteristics();
|
|
280
|
-
} else {
|
|
281
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
282
|
-
await this.BLERefreshConnection(switchbot);
|
|
283
|
-
}
|
|
284
|
-
})();
|
|
285
|
-
}
|
|
309
|
+
await this.debugLog('is not listening to Platform BLE');
|
|
286
310
|
}
|
|
287
311
|
}
|
|
288
312
|
|
package/src/device/plug.ts
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* plug.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import { deviceBase } from './device.js';
|
|
6
|
+
/*
|
|
7
|
+
* For Testing Locally:
|
|
8
|
+
* import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
9
|
+
*/
|
|
6
10
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
7
11
|
import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
|
|
8
12
|
|
|
@@ -66,12 +70,28 @@ export class Plug extends deviceBase {
|
|
|
66
70
|
.onSet(this.OnSet.bind(this));
|
|
67
71
|
|
|
68
72
|
// Retrieve initial values and updateHomekit
|
|
69
|
-
|
|
70
|
-
|
|
73
|
+
try {
|
|
74
|
+
this.debugLog('Retrieve initial values and update Homekit');
|
|
75
|
+
this.refreshStatus();
|
|
76
|
+
} catch (e: any) {
|
|
77
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`);
|
|
78
|
+
}
|
|
71
79
|
|
|
72
|
-
//regisiter webhook event handler
|
|
73
|
-
|
|
74
|
-
|
|
80
|
+
//regisiter webhook event handler if enabled
|
|
81
|
+
try {
|
|
82
|
+
this.debugLog('Registering Webhook Event Handler');
|
|
83
|
+
this.registerWebhook();
|
|
84
|
+
} catch (e: any) {
|
|
85
|
+
this.errorLog(`failed to registerWebhook, Error: ${e}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//regisiter platform BLE event handler if enabled
|
|
89
|
+
try {
|
|
90
|
+
this.debugLog('Registering Platform BLE Event Handler');
|
|
91
|
+
this.registerPlatformBLE();
|
|
92
|
+
} catch (e: any) {
|
|
93
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`);
|
|
94
|
+
}
|
|
75
95
|
|
|
76
96
|
// Start an update interval
|
|
77
97
|
interval(this.deviceRefreshRate * 1000)
|
|
@@ -148,7 +168,7 @@ export class Plug extends deviceBase {
|
|
|
148
168
|
async refreshStatus(): Promise<void> {
|
|
149
169
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
150
170
|
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
151
|
-
} else if (this.BLE
|
|
171
|
+
} else if (this.BLE) {
|
|
152
172
|
await this.BLERefreshStatus();
|
|
153
173
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
154
174
|
await this.openAPIRefreshStatus();
|
|
@@ -160,6 +180,30 @@ export class Plug extends deviceBase {
|
|
|
160
180
|
|
|
161
181
|
async BLERefreshStatus(): Promise<void> {
|
|
162
182
|
await this.debugLog('BLERefreshStatus');
|
|
183
|
+
const switchbot = await this.switchbotBLE();
|
|
184
|
+
if (switchbot === undefined) {
|
|
185
|
+
await this.BLERefreshConnection(switchbot);
|
|
186
|
+
} else {
|
|
187
|
+
// Start to monitor advertisement packets
|
|
188
|
+
(async () => {
|
|
189
|
+
// Start to monitor advertisement packets
|
|
190
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as plugMiniUSServiceData | plugMiniJPServiceData;
|
|
191
|
+
// Update HomeKit
|
|
192
|
+
if ((serviceData.model === SwitchBotBLEModel.PlugMiniUS || SwitchBotBLEModel.PlugMiniJP)
|
|
193
|
+
&& serviceData.modelName === (SwitchBotBLEModelName.PlugMini || SwitchBotBLEModelName.PlugMini)) {
|
|
194
|
+
this.serviceData = serviceData;
|
|
195
|
+
await this.BLEparseStatus();
|
|
196
|
+
await this.updateHomeKitCharacteristics();
|
|
197
|
+
} else {
|
|
198
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
199
|
+
await this.BLERefreshConnection(switchbot);
|
|
200
|
+
}
|
|
201
|
+
})();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
async registerPlatformBLE(): Promise<void> {
|
|
206
|
+
await this.debugLog('registerPlatformBLE');
|
|
163
207
|
if (this.config.options?.BLE) {
|
|
164
208
|
await this.debugLog('is listening to Platform BLE.');
|
|
165
209
|
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
@@ -175,27 +219,7 @@ export class Plug extends deviceBase {
|
|
|
175
219
|
}
|
|
176
220
|
};
|
|
177
221
|
} else {
|
|
178
|
-
await this.debugLog('is
|
|
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
|
-
}
|
|
222
|
+
await this.debugLog('is not listening to Platform BLE');
|
|
199
223
|
}
|
|
200
224
|
}
|
|
201
225
|
|
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* robotvacuumcleaner.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import { deviceBase } from './device.js';
|
|
6
|
+
/*
|
|
7
|
+
* For Testing Locally:
|
|
8
|
+
* import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
9
|
+
*/
|
|
6
10
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
7
11
|
import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
|
|
8
12
|
|
|
@@ -127,12 +131,28 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
127
131
|
});
|
|
128
132
|
|
|
129
133
|
// Retrieve initial values and updateHomekit
|
|
130
|
-
|
|
131
|
-
|
|
134
|
+
try {
|
|
135
|
+
this.debugLog('Retrieve initial values and update Homekit');
|
|
136
|
+
this.refreshStatus();
|
|
137
|
+
} catch (e: any) {
|
|
138
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
//regisiter webhook event handler if enabled
|
|
142
|
+
try {
|
|
143
|
+
this.debugLog('Registering Webhook Event Handler');
|
|
144
|
+
this.registerWebhook();
|
|
145
|
+
} catch (e: any) {
|
|
146
|
+
this.errorLog(`failed to registerWebhook, Error: ${e}`);
|
|
147
|
+
}
|
|
132
148
|
|
|
133
|
-
//regisiter
|
|
134
|
-
|
|
135
|
-
|
|
149
|
+
//regisiter platform BLE event handler if enabled
|
|
150
|
+
try {
|
|
151
|
+
this.debugLog('Registering Platform BLE Event Handler');
|
|
152
|
+
this.registerPlatformBLE();
|
|
153
|
+
} catch (e: any) {
|
|
154
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`);
|
|
155
|
+
}
|
|
136
156
|
|
|
137
157
|
// Start an update interval
|
|
138
158
|
interval(this.deviceRefreshRate * 1000)
|
|
@@ -249,7 +269,7 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
249
269
|
async refreshStatus(): Promise<void> {
|
|
250
270
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
251
271
|
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
252
|
-
} else if (this.BLE
|
|
272
|
+
} else if (this.BLE) {
|
|
253
273
|
await this.BLERefreshStatus();
|
|
254
274
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
255
275
|
await this.openAPIRefreshStatus();
|
|
@@ -261,6 +281,29 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
261
281
|
|
|
262
282
|
async BLERefreshStatus(): Promise<void> {
|
|
263
283
|
await this.debugLog('BLERefreshStatus');
|
|
284
|
+
const switchbot = await this.switchbotBLE();
|
|
285
|
+
if (switchbot === undefined) {
|
|
286
|
+
await this.BLERefreshConnection(switchbot);
|
|
287
|
+
} else {
|
|
288
|
+
// Start to monitor advertisement packets
|
|
289
|
+
(async () => {
|
|
290
|
+
// Start to monitor advertisement packets
|
|
291
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as unknown as robotVacuumCleanerServiceData;
|
|
292
|
+
// Update HomeKit
|
|
293
|
+
if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
|
|
294
|
+
this.serviceData = serviceData;
|
|
295
|
+
await this.BLEparseStatus();
|
|
296
|
+
await this.updateHomeKitCharacteristics();
|
|
297
|
+
} else {
|
|
298
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
299
|
+
await this.BLERefreshConnection(switchbot);
|
|
300
|
+
}
|
|
301
|
+
})();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
async registerPlatformBLE(): Promise<void> {
|
|
306
|
+
await this.debugLog('registerPlatformBLE');
|
|
264
307
|
if (this.config.options?.BLE) {
|
|
265
308
|
await this.debugLog('is listening to Platform BLE.');
|
|
266
309
|
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
@@ -276,26 +319,7 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
276
319
|
}
|
|
277
320
|
};
|
|
278
321
|
} else {
|
|
279
|
-
await this.debugLog('is
|
|
280
|
-
const switchbot = await this.switchbotBLE();
|
|
281
|
-
if (switchbot === undefined) {
|
|
282
|
-
await this.BLERefreshConnection(switchbot);
|
|
283
|
-
} else {
|
|
284
|
-
// Start to monitor advertisement packets
|
|
285
|
-
(async () => {
|
|
286
|
-
// Start to monitor advertisement packets
|
|
287
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as unknown as robotVacuumCleanerServiceData;
|
|
288
|
-
// Update HomeKit
|
|
289
|
-
if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
|
|
290
|
-
this.serviceData = serviceData;
|
|
291
|
-
await this.BLEparseStatus();
|
|
292
|
-
await this.updateHomeKitCharacteristics();
|
|
293
|
-
} else {
|
|
294
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
295
|
-
await this.BLERefreshConnection(switchbot);
|
|
296
|
-
}
|
|
297
|
-
})();
|
|
298
|
-
}
|
|
322
|
+
await this.debugLog('is not listening to Platform BLE');
|
|
299
323
|
}
|
|
300
324
|
}
|
|
301
325
|
|
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { deviceBase } from './device.js';
|
|
6
6
|
import { Subject, interval, skipWhile } from 'rxjs';
|
|
7
|
+
/*
|
|
8
|
+
* For Testing Locally:
|
|
9
|
+
* import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
10
|
+
*/
|
|
7
11
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
8
12
|
|
|
9
13
|
import type { devicesConfig } from '../settings.js';
|
|
@@ -118,12 +122,28 @@ export class WaterDetector extends deviceBase {
|
|
|
118
122
|
}
|
|
119
123
|
|
|
120
124
|
// Retrieve initial values and updateHomekit
|
|
121
|
-
|
|
122
|
-
|
|
125
|
+
try {
|
|
126
|
+
this.debugLog('Retrieve initial values and update Homekit');
|
|
127
|
+
this.refreshStatus();
|
|
128
|
+
} catch (e: any) {
|
|
129
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
//regisiter webhook event handler if enabled
|
|
133
|
+
try {
|
|
134
|
+
this.debugLog('Registering Webhook Event Handler');
|
|
135
|
+
this.registerWebhook();
|
|
136
|
+
} catch (e: any) {
|
|
137
|
+
this.errorLog(`failed to registerWebhook, Error: ${e}`);
|
|
138
|
+
}
|
|
123
139
|
|
|
124
|
-
//regisiter
|
|
125
|
-
|
|
126
|
-
|
|
140
|
+
//regisiter platform BLE event handler if enabled
|
|
141
|
+
try {
|
|
142
|
+
this.debugLog('Registering Platform BLE Event Handler');
|
|
143
|
+
this.registerPlatformBLE();
|
|
144
|
+
} catch (e: any) {
|
|
145
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`);
|
|
146
|
+
}
|
|
127
147
|
|
|
128
148
|
// Start an update interval
|
|
129
149
|
interval(this.deviceRefreshRate * 1000)
|
|
@@ -234,7 +254,7 @@ export class WaterDetector extends deviceBase {
|
|
|
234
254
|
async refreshStatus(): Promise<void> {
|
|
235
255
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
236
256
|
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
237
|
-
} else if (this.BLE
|
|
257
|
+
} else if (this.BLE) {
|
|
238
258
|
await this.BLERefreshStatus();
|
|
239
259
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
240
260
|
await this.openAPIRefreshStatus();
|
|
@@ -246,6 +266,29 @@ export class WaterDetector extends deviceBase {
|
|
|
246
266
|
|
|
247
267
|
async BLERefreshStatus(): Promise<void> {
|
|
248
268
|
await this.debugLog('BLERefreshStatus');
|
|
269
|
+
const switchbot = await this.switchbotBLE();
|
|
270
|
+
if (switchbot === undefined) {
|
|
271
|
+
await this.BLERefreshConnection(switchbot);
|
|
272
|
+
} else {
|
|
273
|
+
// Start to monitor advertisement packets
|
|
274
|
+
(async () => {
|
|
275
|
+
// Start to monitor advertisement packets
|
|
276
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as waterLeakDetectorServiceData;
|
|
277
|
+
// Update HomeKit
|
|
278
|
+
if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
|
|
279
|
+
this.serviceData = serviceData;
|
|
280
|
+
await this.BLEparseStatus();
|
|
281
|
+
await this.updateHomeKitCharacteristics();
|
|
282
|
+
} else {
|
|
283
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
284
|
+
await this.BLERefreshConnection(switchbot);
|
|
285
|
+
}
|
|
286
|
+
})();
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async registerPlatformBLE(): Promise<void> {
|
|
291
|
+
await this.debugLog('registerPlatformBLE');
|
|
249
292
|
if (this.config.options?.BLE) {
|
|
250
293
|
await this.debugLog('is listening to Platform BLE.');
|
|
251
294
|
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
@@ -261,26 +304,7 @@ export class WaterDetector extends deviceBase {
|
|
|
261
304
|
}
|
|
262
305
|
};
|
|
263
306
|
} else {
|
|
264
|
-
await this.debugLog('is
|
|
265
|
-
const switchbot = await this.switchbotBLE();
|
|
266
|
-
if (switchbot === undefined) {
|
|
267
|
-
await this.BLERefreshConnection(switchbot);
|
|
268
|
-
} else {
|
|
269
|
-
// Start to monitor advertisement packets
|
|
270
|
-
(async () => {
|
|
271
|
-
// Start to monitor advertisement packets
|
|
272
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as waterLeakDetectorServiceData;
|
|
273
|
-
// Update HomeKit
|
|
274
|
-
if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
|
|
275
|
-
this.serviceData = serviceData;
|
|
276
|
-
await this.BLEparseStatus();
|
|
277
|
-
await this.updateHomeKitCharacteristics();
|
|
278
|
-
} else {
|
|
279
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
280
|
-
await this.BLERefreshConnection(switchbot);
|
|
281
|
-
}
|
|
282
|
-
})();
|
|
283
|
-
}
|
|
307
|
+
await this.debugLog('is not listening to Platform BLE');
|
|
284
308
|
}
|
|
285
309
|
}
|
|
286
310
|
|