@switchbot/homebridge-switchbot 3.5.0 → 3.5.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/.github/npm-version-script.cjs +81 -0
- package/config.schema.json +4 -4
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +32 -63
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +31 -63
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +51 -111
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +38 -113
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +22 -49
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +53 -61
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +17 -1
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +112 -5
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +42 -95
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +7 -1
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +52 -14
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +52 -99
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +25 -43
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +1 -1
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +53 -115
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +33 -61
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +25 -43
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +24 -42
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +22 -40
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +29 -61
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +36 -77
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +21 -40
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +8 -25
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +6 -17
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +6 -17
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +6 -17
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +6 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +24 -0
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +6 -17
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +6 -17
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +6 -17
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +6 -17
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +6 -17
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/settings.d.ts +2 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/utils.d.ts +19 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +20 -1
- package/dist/utils.js.map +1 -1
- package/package.json +8 -8
- package/src/device/blindtilt.ts +30 -63
- package/src/device/bot.ts +29 -63
- package/src/device/ceilinglight.ts +48 -111
- package/src/device/colorbulb.ts +37 -114
- package/src/device/contact.ts +20 -49
- package/src/device/curtain.ts +52 -62
- package/src/device/device.ts +124 -7
- package/src/device/fan.ts +40 -97
- package/src/device/hub.ts +53 -16
- package/src/device/humidifier.ts +49 -99
- package/src/device/iosensor.ts +23 -43
- package/src/device/lightstrip.ts +51 -116
- package/src/device/lock.ts +32 -62
- package/src/device/meter.ts +23 -43
- package/src/device/meterplus.ts +22 -42
- package/src/device/motion.ts +20 -40
- package/src/device/plug.ts +27 -61
- package/src/device/robotvacuumcleaner.ts +33 -78
- package/src/device/waterdetector.ts +20 -40
- package/src/irdevice/airconditioner.ts +8 -23
- package/src/irdevice/airpurifier.ts +6 -17
- package/src/irdevice/camera.ts +6 -17
- package/src/irdevice/fan.ts +6 -17
- package/src/irdevice/irdevice.ts +24 -0
- package/src/irdevice/light.ts +6 -17
- package/src/irdevice/other.ts +6 -17
- package/src/irdevice/tv.ts +6 -17
- package/src/irdevice/vacuumcleaner.ts +6 -17
- package/src/irdevice/waterheater.ts +6 -17
- package/src/settings.ts +2 -1
- package/src/utils.ts +20 -1
package/src/device/iosensor.ts
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { Units } from 'homebridge';
|
|
6
6
|
import { deviceBase } from './device.js';
|
|
7
|
-
import { Devices } from '../settings.js';
|
|
8
7
|
import { convertUnits } from '../utils.js';
|
|
9
8
|
import { Subject, interval, skipWhile } from 'rxjs';
|
|
10
9
|
|
|
@@ -174,9 +173,9 @@ export class IOSensor extends deviceBase {
|
|
|
174
173
|
}
|
|
175
174
|
|
|
176
175
|
// Current Temperature
|
|
177
|
-
if (!this.device.
|
|
178
|
-
serviceData.temperature!.c < 0 ? 0 : serviceData.temperature!.c > 100 ? 100 : serviceData.temperature!.c;
|
|
179
|
-
this.TemperatureSensor!.CurrentTemperature =
|
|
176
|
+
if (!this.device.meter?.hide_temperature) {
|
|
177
|
+
const celcius = serviceData.temperature!.c < 0 ? 0 : serviceData.temperature!.c > 100 ? 100 : serviceData.temperature!.c;
|
|
178
|
+
this.TemperatureSensor!.CurrentTemperature = celcius;
|
|
180
179
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.TemperatureSensor!.CurrentTemperature}°c`);
|
|
181
180
|
}
|
|
182
181
|
}
|
|
@@ -244,58 +243,39 @@ export class IOSensor extends deviceBase {
|
|
|
244
243
|
|
|
245
244
|
async BLERefreshStatus(): Promise<void> {
|
|
246
245
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
|
|
247
|
-
const switchbot = await this.
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
.
|
|
251
|
-
|
|
252
|
-
.toLowerCase();
|
|
253
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
254
|
-
this.getCustomBLEAddress(switchbot);
|
|
246
|
+
const switchbot = await this.switchbotBLE();
|
|
247
|
+
|
|
248
|
+
if (switchbot === undefined) {
|
|
249
|
+
await this.BLERefreshConnection(switchbot);
|
|
250
|
+
} else {
|
|
255
251
|
// Start to monitor advertisement packets
|
|
256
|
-
|
|
252
|
+
(async () => {
|
|
257
253
|
// Start to monitor advertisement packets
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
|
|
264
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
254
|
+
const serviceData: serviceData = await this.monitorAdvertisementPackets(switchbot);
|
|
255
|
+
// Update HomeKit
|
|
256
|
+
if (serviceData.model !== '' && serviceData.modelName !== '') {
|
|
257
|
+
await this.BLEparseStatus(serviceData);
|
|
258
|
+
await this.updateHomeKitCharacteristics();
|
|
265
259
|
} else {
|
|
266
|
-
this.
|
|
260
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed to get serviceData, serviceData: ${serviceData}`);
|
|
261
|
+
await this.BLERefreshConnection(switchbot);
|
|
267
262
|
}
|
|
268
|
-
};
|
|
269
|
-
// Wait 10 seconds
|
|
270
|
-
await switchbot.wait(this.scanDuration * 1000);
|
|
271
|
-
// Stop to monitor
|
|
272
|
-
await switchbot.stopScan();
|
|
273
|
-
// Update HomeKit
|
|
274
|
-
await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
|
|
275
|
-
await this.updateHomeKitCharacteristics();
|
|
276
|
-
})();
|
|
277
|
-
if (switchbot === undefined) {
|
|
278
|
-
await this.BLERefreshConnection(switchbot);
|
|
263
|
+
})();
|
|
279
264
|
}
|
|
280
265
|
}
|
|
281
266
|
|
|
282
267
|
async openAPIRefreshStatus(): Promise<void> {
|
|
283
268
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
284
269
|
try {
|
|
285
|
-
const { body, statusCode } = await this.
|
|
286
|
-
`${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
|
|
287
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
270
|
+
const { body, statusCode } = await this.deviceRefreshStatus();
|
|
288
271
|
const deviceStatus: any = await body.json();
|
|
289
|
-
this.
|
|
290
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
272
|
+
await this.refreshStatusCodes(statusCode, deviceStatus);;
|
|
291
273
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
292
|
-
this.
|
|
293
|
-
|
|
294
|
-
this.
|
|
295
|
-
this.updateHomeKitCharacteristics();
|
|
274
|
+
await this.successfulRefreshStatus(statusCode, deviceStatus);
|
|
275
|
+
await this.openAPIparseStatus(deviceStatus);
|
|
276
|
+
await this.updateHomeKitCharacteristics();
|
|
296
277
|
} else {
|
|
297
|
-
this.
|
|
298
|
-
this.statusCode(deviceStatus.statusCode);
|
|
278
|
+
await this.statusCodes(statusCode, deviceStatus);
|
|
299
279
|
}
|
|
300
280
|
} catch (e: any) {
|
|
301
281
|
this.apiError(e);
|
package/src/device/lightstrip.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* lightstrip.ts: @switchbot/homebridge-switchbot.
|
|
4
|
+
*/
|
|
2
5
|
import { deviceBase } from './device.js';
|
|
3
|
-
import { Devices } from '../settings.js';
|
|
4
6
|
import { hs2rgb, rgb2hs, m2hs } from '../utils.js';
|
|
5
7
|
import { interval, skipWhile, Subject } from 'rxjs';
|
|
6
8
|
import { debounceTime, take, tap } from 'rxjs/operators';
|
|
7
9
|
|
|
8
10
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
9
|
-
import type { device, devicesConfig,
|
|
11
|
+
import type { device, devicesConfig, serviceData, deviceStatus } from '../settings.js';
|
|
10
12
|
import type { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
|
|
11
13
|
|
|
12
14
|
/**
|
|
@@ -290,58 +292,39 @@ export class StripLight extends deviceBase {
|
|
|
290
292
|
|
|
291
293
|
async BLERefreshStatus(): Promise<void> {
|
|
292
294
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
|
|
293
|
-
const switchbot = await this.
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
.
|
|
297
|
-
|
|
298
|
-
.toLowerCase();
|
|
299
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
300
|
-
this.getCustomBLEAddress(switchbot);
|
|
295
|
+
const switchbot = await this.switchbotBLE();
|
|
296
|
+
|
|
297
|
+
if (switchbot === undefined) {
|
|
298
|
+
await this.BLERefreshConnection(switchbot);
|
|
299
|
+
} else {
|
|
301
300
|
// Start to monitor advertisement packets
|
|
302
|
-
|
|
301
|
+
(async () => {
|
|
303
302
|
// Start to monitor advertisement packets
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
|
|
310
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
303
|
+
const serviceData: serviceData = await this.monitorAdvertisementPackets(switchbot);
|
|
304
|
+
// Update HomeKit
|
|
305
|
+
if (serviceData.model !== '' && serviceData.modelName !== '') {
|
|
306
|
+
await this.BLEparseStatus(serviceData);
|
|
307
|
+
await this.updateHomeKitCharacteristics();
|
|
311
308
|
} else {
|
|
312
|
-
this.
|
|
309
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed to get serviceData, serviceData: ${serviceData}`);
|
|
310
|
+
await this.BLERefreshConnection(switchbot);
|
|
313
311
|
}
|
|
314
|
-
};
|
|
315
|
-
// Wait 10 seconds
|
|
316
|
-
await switchbot.wait(this.scanDuration * 1000);
|
|
317
|
-
// Stop to monitor
|
|
318
|
-
await switchbot.stopScan();
|
|
319
|
-
// Update HomeKit
|
|
320
|
-
await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
|
|
321
|
-
await this.updateHomeKitCharacteristics();
|
|
322
|
-
})();
|
|
323
|
-
if (switchbot === undefined) {
|
|
324
|
-
await this.BLERefreshConnection(switchbot);
|
|
312
|
+
})();
|
|
325
313
|
}
|
|
326
314
|
}
|
|
327
315
|
|
|
328
316
|
async openAPIRefreshStatus(): Promise<void> {
|
|
329
317
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
330
318
|
try {
|
|
331
|
-
const { body, statusCode } = await this.
|
|
332
|
-
`${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
|
|
333
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
319
|
+
const { body, statusCode } = await this.deviceRefreshStatus();
|
|
334
320
|
const deviceStatus: any = await body.json();
|
|
335
|
-
this.
|
|
336
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
321
|
+
await this.refreshStatusCodes(statusCode, deviceStatus);;
|
|
337
322
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
338
|
-
this.
|
|
339
|
-
|
|
340
|
-
this.
|
|
341
|
-
this.updateHomeKitCharacteristics();
|
|
323
|
+
await this.successfulRefreshStatus(statusCode, deviceStatus);
|
|
324
|
+
await this.openAPIparseStatus(deviceStatus);
|
|
325
|
+
await this.updateHomeKitCharacteristics();
|
|
342
326
|
} else {
|
|
343
|
-
this.
|
|
344
|
-
this.statusCode(deviceStatus.statusCode);
|
|
327
|
+
await this.statusCodes(statusCode, deviceStatus);
|
|
345
328
|
}
|
|
346
329
|
} catch (e: any) {
|
|
347
330
|
this.apiError(e);
|
|
@@ -434,8 +417,8 @@ export class StripLight extends deviceBase {
|
|
|
434
417
|
async pushChanges(): Promise<void> {
|
|
435
418
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
436
419
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
437
|
-
|
|
438
|
-
|
|
420
|
+
} else if (this.BLE) {
|
|
421
|
+
await this.BLEpushChanges();
|
|
439
422
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
440
423
|
await this.openAPIpushChanges();
|
|
441
424
|
} else {
|
|
@@ -459,16 +442,9 @@ export class StripLight extends deviceBase {
|
|
|
459
442
|
+ ` On: ${this.LightBulb.On} OnCached: ${this.accessory.context.On}`);
|
|
460
443
|
const switchbot = await this.platform.connectBLE();
|
|
461
444
|
// Convert to BLE Address
|
|
462
|
-
|
|
463
|
-
.deviceId!.match(/.{1,2}/g)!
|
|
464
|
-
.join(':')
|
|
465
|
-
.toLowerCase();
|
|
466
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
445
|
+
await this.convertBLEAddress();
|
|
467
446
|
switchbot
|
|
468
|
-
.discover({
|
|
469
|
-
model: 'r',
|
|
470
|
-
id: this.device.bleMac,
|
|
471
|
-
})
|
|
447
|
+
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
472
448
|
.then(async (device_list: any) => {
|
|
473
449
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
|
|
474
450
|
return await this.retryBLE({
|
|
@@ -520,16 +496,9 @@ export class StripLight extends deviceBase {
|
|
|
520
496
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
521
497
|
const switchbot = await this.platform.connectBLE();
|
|
522
498
|
// Convert to BLE Address
|
|
523
|
-
|
|
524
|
-
.deviceId!.match(/.{1,2}/g)!
|
|
525
|
-
.join(':')
|
|
526
|
-
.toLowerCase();
|
|
527
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
499
|
+
await this.convertBLEAddress();
|
|
528
500
|
switchbot
|
|
529
|
-
.discover({
|
|
530
|
-
model: 'u',
|
|
531
|
-
id: this.device.bleMac,
|
|
532
|
-
})
|
|
501
|
+
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
533
502
|
.then(async (device_list: any) => {
|
|
534
503
|
this.infoLog(`${this.accessory.displayName} Target Brightness: ${this.LightBulb.Brightness}`);
|
|
535
504
|
return await device_list[0].setBrightness(this.LightBulb.Brightness);
|
|
@@ -562,16 +531,9 @@ export class StripLight extends deviceBase {
|
|
|
562
531
|
|
|
563
532
|
const switchbot = await this.platform.connectBLE();
|
|
564
533
|
// Convert to BLE Address
|
|
565
|
-
|
|
566
|
-
.deviceId!.match(/.{1,2}/g)!
|
|
567
|
-
.join(':')
|
|
568
|
-
.toLowerCase();
|
|
569
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
534
|
+
await this.convertBLEAddress();
|
|
570
535
|
switchbot
|
|
571
|
-
.discover({
|
|
572
|
-
model: 'u',
|
|
573
|
-
id: this.device.bleMac,
|
|
574
|
-
})
|
|
536
|
+
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
575
537
|
.then(async (device_list: any) => {
|
|
576
538
|
this.infoLog(`${this.accessory.displayName} Target RGB: ${(this.LightBulb.Brightness, red, green, blue)}`);
|
|
577
539
|
return await device_list[0].setRGB(this.LightBulb.Brightness, red, green, blue);
|
|
@@ -608,24 +570,15 @@ export class StripLight extends deviceBase {
|
|
|
608
570
|
});
|
|
609
571
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
610
572
|
try {
|
|
611
|
-
const { body, statusCode } = await
|
|
612
|
-
body: bodyChange,
|
|
613
|
-
method: 'POST',
|
|
614
|
-
headers: this.platform.generateHeaders(),
|
|
615
|
-
});
|
|
616
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
573
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
617
574
|
const deviceStatus: any = await body.json();
|
|
618
|
-
this.
|
|
619
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
620
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
575
|
+
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
621
576
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
622
|
-
this.
|
|
623
|
-
|
|
624
|
-
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
625
|
-
+ `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
577
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
|
|
578
|
+
await this.updateHomeKitCharacteristics();
|
|
626
579
|
} else {
|
|
627
|
-
this.statusCode(statusCode);
|
|
628
|
-
this.statusCode(deviceStatus.statusCode);
|
|
580
|
+
await this.statusCode(statusCode);
|
|
581
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
629
582
|
}
|
|
630
583
|
} catch (e: any) {
|
|
631
584
|
this.apiError(e);
|
|
@@ -662,24 +615,15 @@ export class StripLight extends deviceBase {
|
|
|
662
615
|
});
|
|
663
616
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
664
617
|
try {
|
|
665
|
-
const { body, statusCode } = await
|
|
666
|
-
body: bodyChange,
|
|
667
|
-
method: 'POST',
|
|
668
|
-
headers: this.platform.generateHeaders(),
|
|
669
|
-
});
|
|
670
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
618
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
671
619
|
const deviceStatus: any = await body.json();
|
|
672
|
-
this.
|
|
673
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
674
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
620
|
+
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
675
621
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
676
|
-
this.
|
|
677
|
-
|
|
678
|
-
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
679
|
-
+ `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
622
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
|
|
623
|
+
await this.updateHomeKitCharacteristics();
|
|
680
624
|
} else {
|
|
681
|
-
this.statusCode(statusCode);
|
|
682
|
-
this.statusCode(deviceStatus.statusCode);
|
|
625
|
+
await this.statusCode(statusCode);
|
|
626
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
683
627
|
}
|
|
684
628
|
} catch (e: any) {
|
|
685
629
|
this.apiError(e);
|
|
@@ -702,24 +646,15 @@ export class StripLight extends deviceBase {
|
|
|
702
646
|
});
|
|
703
647
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
704
648
|
try {
|
|
705
|
-
const { body, statusCode } = await
|
|
706
|
-
body: bodyChange,
|
|
707
|
-
method: 'POST',
|
|
708
|
-
headers: this.platform.generateHeaders(),
|
|
709
|
-
});
|
|
710
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
649
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
711
650
|
const deviceStatus: any = await body.json();
|
|
712
|
-
this.
|
|
713
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
714
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
651
|
+
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
715
652
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
716
|
-
this.
|
|
717
|
-
|
|
718
|
-
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
719
|
-
+ `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
653
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
|
|
654
|
+
await this.updateHomeKitCharacteristics();
|
|
720
655
|
} else {
|
|
721
|
-
this.statusCode(statusCode);
|
|
722
|
-
this.statusCode(deviceStatus.statusCode);
|
|
656
|
+
await this.statusCode(statusCode);
|
|
657
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
723
658
|
}
|
|
724
659
|
} catch (e: any) {
|
|
725
660
|
this.apiError(e);
|
package/src/device/lock.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* lock.ts: @switchbot/homebridge-switchbot.
|
|
4
|
+
*/
|
|
2
5
|
import { deviceBase } from './device.js';
|
|
3
6
|
import { interval, Subject } from 'rxjs';
|
|
4
|
-
import { Devices } from '../settings.js';
|
|
5
7
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
6
8
|
|
|
7
9
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
8
10
|
import type { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
9
|
-
import type { device, devicesConfig,
|
|
11
|
+
import type { device, devicesConfig, serviceData, deviceStatus } from '../settings.js';
|
|
10
12
|
|
|
11
13
|
export class Lock extends deviceBase {
|
|
12
14
|
// Services
|
|
@@ -289,58 +291,39 @@ export class Lock extends deviceBase {
|
|
|
289
291
|
|
|
290
292
|
async BLERefreshStatus(): Promise<void> {
|
|
291
293
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
|
|
292
|
-
const switchbot = await this.
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
.
|
|
296
|
-
|
|
297
|
-
.toLowerCase();
|
|
298
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
299
|
-
this.getCustomBLEAddress(switchbot);
|
|
294
|
+
const switchbot = await this.switchbotBLE();
|
|
295
|
+
|
|
296
|
+
if (switchbot === undefined) {
|
|
297
|
+
await this.BLERefreshConnection(switchbot);
|
|
298
|
+
} else {
|
|
300
299
|
// Start to monitor advertisement packets
|
|
301
|
-
|
|
300
|
+
(async () => {
|
|
302
301
|
// Start to monitor advertisement packets
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
|
|
309
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
302
|
+
const serviceData: serviceData = await this.monitorAdvertisementPackets(switchbot);
|
|
303
|
+
// Update HomeKit
|
|
304
|
+
if (serviceData.model !== '' && serviceData.modelName !== '') {
|
|
305
|
+
await this.BLEparseStatus(serviceData);
|
|
306
|
+
await this.updateHomeKitCharacteristics();
|
|
310
307
|
} else {
|
|
311
|
-
this.
|
|
308
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed to get serviceData, serviceData: ${serviceData}`);
|
|
309
|
+
await this.BLERefreshConnection(switchbot);
|
|
312
310
|
}
|
|
313
|
-
};
|
|
314
|
-
// Wait 10 seconds
|
|
315
|
-
await switchbot.wait(this.scanDuration * 1000);
|
|
316
|
-
// Stop to monitor
|
|
317
|
-
await switchbot.stopScan();
|
|
318
|
-
// Update HomeKit
|
|
319
|
-
await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
|
|
320
|
-
await this.updateHomeKitCharacteristics();
|
|
321
|
-
})();
|
|
322
|
-
if (switchbot === undefined) {
|
|
323
|
-
await this.BLERefreshConnection(switchbot);
|
|
311
|
+
})();
|
|
324
312
|
}
|
|
325
313
|
}
|
|
326
314
|
|
|
327
315
|
async openAPIRefreshStatus(): Promise<void> {
|
|
328
316
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
329
317
|
try {
|
|
330
|
-
const { body, statusCode } = await this.
|
|
331
|
-
`${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
|
|
332
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
318
|
+
const { body, statusCode } = await this.deviceRefreshStatus();
|
|
333
319
|
const deviceStatus: any = await body.json();
|
|
334
|
-
this.
|
|
335
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
320
|
+
await this.refreshStatusCodes(statusCode, deviceStatus);;
|
|
336
321
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
337
|
-
this.
|
|
338
|
-
|
|
339
|
-
this.
|
|
340
|
-
this.updateHomeKitCharacteristics();
|
|
322
|
+
await this.successfulRefreshStatus(statusCode, deviceStatus);
|
|
323
|
+
await this.openAPIparseStatus(deviceStatus);
|
|
324
|
+
await this.updateHomeKitCharacteristics();
|
|
341
325
|
} else {
|
|
342
|
-
this.
|
|
343
|
-
this.statusCode(deviceStatus.statusCode);
|
|
326
|
+
await this.statusCodes(statusCode, deviceStatus);
|
|
344
327
|
}
|
|
345
328
|
} catch (e: any) {
|
|
346
329
|
this.apiError(e);
|
|
@@ -403,11 +386,7 @@ export class Lock extends deviceBase {
|
|
|
403
386
|
+ ` LockTargetStateCached: ${this.accessory.context.LockTargetState}`);
|
|
404
387
|
const switchbot = await this.platform.connectBLE();
|
|
405
388
|
// Convert to BLE Address
|
|
406
|
-
|
|
407
|
-
.deviceId!.match(/.{1,2}/g)!
|
|
408
|
-
.join(':')
|
|
409
|
-
.toLowerCase();
|
|
410
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
389
|
+
await this.convertBLEAddress();
|
|
411
390
|
switchbot
|
|
412
391
|
.discover({
|
|
413
392
|
model: '',
|
|
@@ -450,24 +429,15 @@ export class Lock extends deviceBase {
|
|
|
450
429
|
});
|
|
451
430
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
452
431
|
try {
|
|
453
|
-
const { body, statusCode } = await
|
|
454
|
-
body: bodyChange,
|
|
455
|
-
method: 'POST',
|
|
456
|
-
headers: this.platform.generateHeaders(),
|
|
457
|
-
});
|
|
458
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
432
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
459
433
|
const deviceStatus: any = await body.json();
|
|
460
|
-
this.
|
|
461
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
462
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
434
|
+
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
463
435
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
464
|
-
this.
|
|
465
|
-
|
|
466
|
-
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
467
|
-
+ `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
436
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
|
|
437
|
+
await this.updateHomeKitCharacteristics();
|
|
468
438
|
} else {
|
|
469
|
-
this.statusCode(statusCode);
|
|
470
|
-
this.statusCode(deviceStatus.statusCode);
|
|
439
|
+
await this.statusCode(statusCode);
|
|
440
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
471
441
|
}
|
|
472
442
|
} catch (e: any) {
|
|
473
443
|
this.apiError(e);
|
package/src/device/meter.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* meter.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import { Units } from 'homebridge';
|
|
6
|
-
import { Devices } from '../settings.js';
|
|
7
6
|
import { deviceBase } from './device.js';
|
|
8
7
|
import { convertUnits } from '../utils.js';
|
|
9
8
|
import { Subject, interval, skipWhile } from 'rxjs';
|
|
@@ -166,10 +165,10 @@ export class Meter extends deviceBase {
|
|
|
166
165
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.HumiditySensor!.CurrentRelativeHumidity}%`);
|
|
167
166
|
}
|
|
168
167
|
|
|
169
|
-
//
|
|
168
|
+
// Current Temperature
|
|
170
169
|
if (!this.device.meter?.hide_temperature) {
|
|
171
|
-
serviceData.temperature!.c < 0 ? 0 : serviceData.temperature!.c > 100 ? 100 : serviceData.temperature!.c;
|
|
172
|
-
this.TemperatureSensor!.CurrentTemperature =
|
|
170
|
+
const celcius = serviceData.temperature!.c < 0 ? 0 : serviceData.temperature!.c > 100 ? 100 : serviceData.temperature!.c;
|
|
171
|
+
this.TemperatureSensor!.CurrentTemperature = celcius;
|
|
173
172
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.TemperatureSensor!.CurrentTemperature}°c`);
|
|
174
173
|
}
|
|
175
174
|
}
|
|
@@ -237,58 +236,39 @@ export class Meter extends deviceBase {
|
|
|
237
236
|
|
|
238
237
|
async BLERefreshStatus(): Promise<void> {
|
|
239
238
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
|
|
240
|
-
const switchbot = await this.
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
.
|
|
244
|
-
|
|
245
|
-
.toLowerCase();
|
|
246
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
247
|
-
this.getCustomBLEAddress(switchbot);
|
|
239
|
+
const switchbot = await this.switchbotBLE();
|
|
240
|
+
|
|
241
|
+
if (switchbot === undefined) {
|
|
242
|
+
await this.BLERefreshConnection(switchbot);
|
|
243
|
+
} else {
|
|
248
244
|
// Start to monitor advertisement packets
|
|
249
|
-
|
|
245
|
+
(async () => {
|
|
250
246
|
// Start to monitor advertisement packets
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
|
|
257
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
247
|
+
const serviceData: serviceData = await this.monitorAdvertisementPackets(switchbot);
|
|
248
|
+
// Update HomeKit
|
|
249
|
+
if (serviceData.model !== '' && serviceData.modelName !== '') {
|
|
250
|
+
await this.BLEparseStatus(serviceData);
|
|
251
|
+
await this.updateHomeKitCharacteristics();
|
|
258
252
|
} else {
|
|
259
|
-
this.
|
|
253
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed to get serviceData, serviceData: ${serviceData}`);
|
|
254
|
+
await this.BLERefreshConnection(switchbot);
|
|
260
255
|
}
|
|
261
|
-
};
|
|
262
|
-
// Wait 10 seconds
|
|
263
|
-
await switchbot.wait(this.scanDuration * 1000);
|
|
264
|
-
// Stop to monitor
|
|
265
|
-
await switchbot.stopScan();
|
|
266
|
-
// Update HomeKit
|
|
267
|
-
await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
|
|
268
|
-
await this.updateHomeKitCharacteristics();
|
|
269
|
-
})();
|
|
270
|
-
if (switchbot === undefined) {
|
|
271
|
-
await this.BLERefreshConnection(switchbot);
|
|
256
|
+
})();
|
|
272
257
|
}
|
|
273
258
|
}
|
|
274
259
|
|
|
275
260
|
async openAPIRefreshStatus(): Promise<void> {
|
|
276
261
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
277
262
|
try {
|
|
278
|
-
const { body, statusCode } = await this.
|
|
279
|
-
`${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
|
|
280
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
263
|
+
const { body, statusCode } = await this.deviceRefreshStatus();
|
|
281
264
|
const deviceStatus: any = await body.json();
|
|
282
|
-
this.
|
|
283
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
265
|
+
await this.refreshStatusCodes(statusCode, deviceStatus);;
|
|
284
266
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
285
|
-
this.
|
|
286
|
-
|
|
287
|
-
this.
|
|
288
|
-
this.updateHomeKitCharacteristics();
|
|
267
|
+
await this.successfulRefreshStatus(statusCode, deviceStatus);
|
|
268
|
+
await this.openAPIparseStatus(deviceStatus);
|
|
269
|
+
await this.updateHomeKitCharacteristics();
|
|
289
270
|
} else {
|
|
290
|
-
this.
|
|
291
|
-
this.statusCode(deviceStatus.statusCode);
|
|
271
|
+
await this.statusCodes(statusCode, deviceStatus);
|
|
292
272
|
}
|
|
293
273
|
} catch (e: any) {
|
|
294
274
|
this.apiError(e);
|