@switchbot/homebridge-switchbot 2.8.0-beta.9 → 2.8.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -2
- package/README.md +1 -1
- package/dist/device/blindtilt.d.ts +21 -22
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +78 -77
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +11 -13
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +93 -75
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +10 -13
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +40 -27
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +16 -23
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +55 -46
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +16 -22
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +82 -73
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +21 -24
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +76 -77
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +10 -8
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +50 -35
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +8 -10
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +34 -21
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +16 -20
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +42 -29
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +2 -5
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +9 -8
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +15 -19
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +71 -28
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +5 -9
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +16 -20
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +6 -10
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +16 -20
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +6 -8
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +49 -47
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +2 -5
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +9 -8
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +6 -8
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +20 -4
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -0
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +67 -86
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +0 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +0 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +64 -63
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +3 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +12 -12
- package/src/device/blindtilt.ts +103 -100
- package/src/device/bot.ts +105 -89
- package/src/device/ceilinglight.ts +56 -46
- package/src/device/colorbulb.ts +78 -76
- package/src/device/contact.ts +100 -94
- package/src/device/curtain.ts +101 -101
- package/src/device/hub.ts +61 -43
- package/src/device/humidifier.ts +42 -33
- package/src/device/iosensor.ts +59 -50
- package/src/device/lightstrip.ts +14 -17
- package/src/device/lock.ts +91 -50
- package/src/device/meter.ts +22 -30
- package/src/device/meterplus.ts +23 -32
- package/src/device/motion.ts +55 -53
- package/src/device/plug.ts +12 -15
- package/src/device/robotvacuumcleaner.ts +33 -16
- package/src/irdevice/airconditioner.ts +80 -94
- package/src/irdevice/airpurifier.ts +1 -1
- package/src/irdevice/camera.ts +1 -1
- package/src/irdevice/fan.ts +1 -4
- package/src/irdevice/light.ts +1 -1
- package/src/irdevice/other.ts +1 -1
- package/src/irdevice/tv.ts +1 -4
- package/src/irdevice/vacuumcleaner.ts +1 -1
- package/src/irdevice/waterheater.ts +1 -1
- package/src/platform.ts +73 -73
- package/src/settings.ts +6 -2
package/src/device/motion.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { interval, Subject } from 'rxjs';
|
|
|
5
5
|
import { skipWhile } from 'rxjs/operators';
|
|
6
6
|
import { SwitchBotPlatform } from '../platform';
|
|
7
7
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
8
|
-
import { device, devicesConfig, serviceData,
|
|
8
|
+
import { device, devicesConfig, serviceData, deviceStatus, ad, Devices } from '../settings';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Platform Accessory
|
|
@@ -16,25 +16,23 @@ export class Motion {
|
|
|
16
16
|
// Services
|
|
17
17
|
motionSensorService: Service;
|
|
18
18
|
lightSensorService?: Service;
|
|
19
|
-
batteryService
|
|
19
|
+
batteryService: Service;
|
|
20
20
|
|
|
21
21
|
// Characteristic Values
|
|
22
22
|
MotionDetected!: CharacteristicValue;
|
|
23
23
|
CurrentAmbientLightLevel!: CharacteristicValue;
|
|
24
|
-
BatteryLevel
|
|
25
|
-
StatusLowBattery
|
|
24
|
+
BatteryLevel!: CharacteristicValue;
|
|
25
|
+
StatusLowBattery!: CharacteristicValue;
|
|
26
26
|
|
|
27
27
|
// OpenAPI Others
|
|
28
|
-
deviceStatus
|
|
28
|
+
Version: deviceStatus['version'];
|
|
29
|
+
Battery: deviceStatus['battery'];
|
|
29
30
|
moveDetected: deviceStatus['moveDetected'];
|
|
30
31
|
brightness: deviceStatus['brightness'];
|
|
31
32
|
|
|
32
33
|
// BLE Others
|
|
33
34
|
scanning!: boolean;
|
|
34
35
|
connected?: boolean;
|
|
35
|
-
switchbot!: switchbot;
|
|
36
|
-
serviceData!: serviceData;
|
|
37
|
-
address!: ad['address'];
|
|
38
36
|
battery!: serviceData['battery'];
|
|
39
37
|
movement!: serviceData['movement'];
|
|
40
38
|
lightLevel!: serviceData['lightLevel'];
|
|
@@ -124,20 +122,14 @@ export class Motion {
|
|
|
124
122
|
}
|
|
125
123
|
|
|
126
124
|
// Battery Service
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
this.
|
|
133
|
-
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
|
|
134
|
-
`${accessory.displayName} Battery`;
|
|
135
|
-
|
|
136
|
-
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
137
|
-
this.batteryService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
138
|
-
} else {
|
|
139
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
|
|
125
|
+
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)),
|
|
126
|
+
`${accessory.displayName} Battery`;
|
|
127
|
+
|
|
128
|
+
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
129
|
+
if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
130
|
+
this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
140
131
|
}
|
|
132
|
+
this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
141
133
|
|
|
142
134
|
// Retrieve initial values and updateHomekit
|
|
143
135
|
this.updateHomeKitCharacteristics();
|
|
@@ -230,6 +222,19 @@ export class Motion {
|
|
|
230
222
|
}
|
|
231
223
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
232
224
|
}
|
|
225
|
+
// Battery
|
|
226
|
+
if (this.battery === undefined) {
|
|
227
|
+
this.battery = 100;
|
|
228
|
+
}
|
|
229
|
+
this.BatteryLevel = this.Battery!;
|
|
230
|
+
if (this.BatteryLevel < 10) {
|
|
231
|
+
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
232
|
+
} else {
|
|
233
|
+
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
234
|
+
}
|
|
235
|
+
this.debugLog(
|
|
236
|
+
`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},` + ` StatusLowBattery: ${this.StatusLowBattery}`,
|
|
237
|
+
);
|
|
233
238
|
}
|
|
234
239
|
|
|
235
240
|
/**
|
|
@@ -276,28 +281,21 @@ export class Motion {
|
|
|
276
281
|
fn: async () => {
|
|
277
282
|
// Set an event hander
|
|
278
283
|
this.scanning = true;
|
|
279
|
-
switchbot.onadvertisement = async (ad:
|
|
280
|
-
this.address = ad.address;
|
|
284
|
+
switchbot.onadvertisement = async (ad: ad) => {
|
|
281
285
|
this.debugLog(
|
|
282
286
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
283
|
-
` BLE Address Found: ${
|
|
287
|
+
` BLE Address Found: ${ad.address}`,
|
|
284
288
|
);
|
|
285
|
-
this.serviceData = ad.serviceData;
|
|
286
289
|
this.movement = ad.serviceData.movement;
|
|
287
|
-
this.tested = ad.serviceData.tested;
|
|
288
290
|
this.battery = ad.serviceData.battery;
|
|
289
|
-
this.led = ad.serviceData.led;
|
|
290
|
-
this.iot = ad.serviceData.led;
|
|
291
|
-
this.sense_distance = ad.serviceData.sense_distance;
|
|
292
291
|
this.lightLevel = ad.serviceData.lightLevel;
|
|
293
|
-
this.is_light = ad.serviceData.is_light;
|
|
294
292
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
295
293
|
this.debugLog(
|
|
296
|
-
`${this.device.deviceType}: ${this.accessory.displayName} movement: ${ad.serviceData.movement}
|
|
297
|
-
|
|
294
|
+
`${this.device.deviceType}: ${this.accessory.displayName} movement: ${ad.serviceData.movement},`
|
|
295
|
+
+ ` lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`,
|
|
298
296
|
);
|
|
299
297
|
|
|
300
|
-
if (
|
|
298
|
+
if (ad.serviceData) {
|
|
301
299
|
this.connected = true;
|
|
302
300
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
303
301
|
this.debugErrorLog('1');
|
|
@@ -343,13 +341,15 @@ export class Motion {
|
|
|
343
341
|
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
344
342
|
headers: this.platform.generateHeaders(),
|
|
345
343
|
});
|
|
346
|
-
const deviceStatus = await body.json();
|
|
344
|
+
const deviceStatus: any = await body.json();
|
|
347
345
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
348
346
|
this.statusCode(statusCode);
|
|
349
347
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
350
348
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
351
349
|
this.moveDetected = deviceStatus.body.moveDetected;
|
|
352
350
|
this.brightness = deviceStatus.body.brightness;
|
|
351
|
+
this.Battery = deviceStatus.body.battery;
|
|
352
|
+
this.Version = deviceStatus.body.version;
|
|
353
353
|
this.openAPIparseStatus();
|
|
354
354
|
this.updateHomeKitCharacteristics();
|
|
355
355
|
} catch (e: any) {
|
|
@@ -372,21 +372,21 @@ export class Motion {
|
|
|
372
372
|
this.motionSensorService.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected);
|
|
373
373
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`);
|
|
374
374
|
}
|
|
375
|
+
if (this.BatteryLevel === undefined) {
|
|
376
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
377
|
+
} else {
|
|
378
|
+
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
379
|
+
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
380
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
381
|
+
}
|
|
382
|
+
if (this.StatusLowBattery === undefined) {
|
|
383
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
384
|
+
} else {
|
|
385
|
+
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
386
|
+
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
387
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
388
|
+
}
|
|
375
389
|
if (this.BLE) {
|
|
376
|
-
if (this.BatteryLevel === undefined) {
|
|
377
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
378
|
-
} else {
|
|
379
|
-
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
380
|
-
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
381
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
382
|
-
}
|
|
383
|
-
if (this.StatusLowBattery === undefined) {
|
|
384
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
385
|
-
} else {
|
|
386
|
-
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
387
|
-
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
388
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
389
|
-
}
|
|
390
390
|
if (this.CurrentAmbientLightLevel === undefined) {
|
|
391
391
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
392
392
|
} else {
|
|
@@ -539,9 +539,9 @@ export class Motion {
|
|
|
539
539
|
|
|
540
540
|
async apiError(e: any): Promise<void> {
|
|
541
541
|
this.motionSensorService.updateCharacteristic(this.platform.Characteristic.MotionDetected, e);
|
|
542
|
+
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
|
|
543
|
+
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
|
|
542
544
|
if (this.BLE) {
|
|
543
|
-
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
|
|
544
|
-
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
|
|
545
545
|
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
|
|
546
546
|
}
|
|
547
547
|
}
|
|
@@ -553,10 +553,12 @@ export class Motion {
|
|
|
553
553
|
);
|
|
554
554
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
555
555
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
556
|
-
if (
|
|
557
|
-
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
558
|
-
} else if (device.firmware) {
|
|
556
|
+
if (device.firmware) {
|
|
559
557
|
FirmwareRevision = device.firmware;
|
|
558
|
+
} else if (device.version) {
|
|
559
|
+
FirmwareRevision = JSON.stringify(device.version);
|
|
560
|
+
} else if (accessory.context.FirmwareRevision) {
|
|
561
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
560
562
|
} else {
|
|
561
563
|
FirmwareRevision = this.platform.version;
|
|
562
564
|
}
|
package/src/device/plug.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { interval, Subject } from 'rxjs';
|
|
|
5
5
|
import { SwitchBotPlatform } from '../platform';
|
|
6
6
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
7
7
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
8
|
-
import { device, devicesConfig, deviceStatus, ad, serviceData,
|
|
8
|
+
import { device, devicesConfig, deviceStatus, ad, serviceData, Devices } from '../settings';
|
|
9
9
|
|
|
10
10
|
export class Plug {
|
|
11
11
|
// Services
|
|
@@ -15,14 +15,11 @@ export class Plug {
|
|
|
15
15
|
On!: CharacteristicValue;
|
|
16
16
|
|
|
17
17
|
// OpenAPI Others
|
|
18
|
+
Version: deviceStatus['version'];
|
|
18
19
|
power: deviceStatus['power'];
|
|
19
|
-
deviceStatus!: any; //deviceStatusResponse;
|
|
20
20
|
|
|
21
21
|
// BLE Others
|
|
22
22
|
connected?: boolean;
|
|
23
|
-
switchbot!: switchbot;
|
|
24
|
-
address!: ad['address'];
|
|
25
|
-
serviceData!: serviceData;
|
|
26
23
|
state: serviceData['state'];
|
|
27
24
|
delay: serviceData['delay'];
|
|
28
25
|
timer: serviceData['timer'];
|
|
@@ -208,13 +205,11 @@ export class Plug {
|
|
|
208
205
|
})
|
|
209
206
|
.then(async () => {
|
|
210
207
|
// Set an event hander
|
|
211
|
-
switchbot.onadvertisement = async (ad:
|
|
212
|
-
this.address = ad.address;
|
|
208
|
+
switchbot.onadvertisement = async (ad: ad) => {
|
|
213
209
|
this.debugLog(
|
|
214
210
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
215
|
-
` BLE Address Found: ${
|
|
211
|
+
` BLE Address Found: ${ad.address}`,
|
|
216
212
|
);
|
|
217
|
-
this.serviceData = ad.serviceData;
|
|
218
213
|
this.state = ad.serviceData.state;
|
|
219
214
|
this.delay = ad.serviceData.delay;
|
|
220
215
|
this.timer = ad.serviceData.timer;
|
|
@@ -229,7 +224,7 @@ export class Plug {
|
|
|
229
224
|
`wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
|
|
230
225
|
);
|
|
231
226
|
|
|
232
|
-
if (
|
|
227
|
+
if (ad.serviceData) {
|
|
233
228
|
this.connected = true;
|
|
234
229
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
235
230
|
await this.stopScanning(switchbot);
|
|
@@ -264,7 +259,7 @@ export class Plug {
|
|
|
264
259
|
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
265
260
|
headers: this.platform.generateHeaders(),
|
|
266
261
|
});
|
|
267
|
-
const deviceStatus = await body.json();
|
|
262
|
+
const deviceStatus: any = await body.json();
|
|
268
263
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
269
264
|
this.statusCode(statusCode);
|
|
270
265
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
@@ -382,7 +377,7 @@ export class Plug {
|
|
|
382
377
|
method: 'POST',
|
|
383
378
|
headers: this.platform.generateHeaders(),
|
|
384
379
|
});
|
|
385
|
-
const deviceStatus = await body.json();
|
|
380
|
+
const deviceStatus: any = await body.json();
|
|
386
381
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
387
382
|
this.statusCode(statusCode);
|
|
388
383
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
@@ -583,10 +578,12 @@ export class Plug {
|
|
|
583
578
|
);
|
|
584
579
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
585
580
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
586
|
-
if (
|
|
587
|
-
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
588
|
-
} else if (device.firmware) {
|
|
581
|
+
if (device.firmware) {
|
|
589
582
|
FirmwareRevision = device.firmware;
|
|
583
|
+
} else if (device.version) {
|
|
584
|
+
FirmwareRevision = JSON.stringify(device.version);
|
|
585
|
+
} else if (accessory.context.FirmwareRevision) {
|
|
586
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
590
587
|
} else {
|
|
591
588
|
FirmwareRevision = this.platform.version;
|
|
592
589
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable brace-style */
|
|
1
2
|
import { Context } from 'vm';
|
|
2
3
|
import { request } from 'undici';
|
|
3
4
|
import { sleep } from '../utils';
|
|
@@ -5,28 +6,26 @@ import { interval, Subject } from 'rxjs';
|
|
|
5
6
|
import { SwitchBotPlatform } from '../platform';
|
|
6
7
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
7
8
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
8
|
-
import { device, devicesConfig, deviceStatus, ad, serviceData,
|
|
9
|
+
import { device, devicesConfig, deviceStatus, ad, serviceData, Devices } from '../settings';
|
|
9
10
|
|
|
10
11
|
export class RobotVacuumCleaner {
|
|
11
12
|
// Services
|
|
12
13
|
robotVacuumCleanerService: Service;
|
|
13
|
-
batteryService
|
|
14
|
+
batteryService: Service;
|
|
14
15
|
|
|
15
16
|
// Characteristic Values
|
|
16
17
|
On!: CharacteristicValue;
|
|
17
18
|
Brightness!: CharacteristicValue;
|
|
18
|
-
BatteryLevel
|
|
19
|
-
StatusLowBattery
|
|
19
|
+
BatteryLevel!: CharacteristicValue;
|
|
20
|
+
StatusLowBattery!: CharacteristicValue;
|
|
20
21
|
|
|
21
22
|
// OpenAPI Others
|
|
23
|
+
Version: deviceStatus['version'];
|
|
24
|
+
Battery: deviceStatus['battery'];
|
|
22
25
|
power: deviceStatus['power'];
|
|
23
|
-
deviceStatus!: any; //deviceStatusResponse;
|
|
24
26
|
|
|
25
27
|
// BLE Others
|
|
26
28
|
connected?: boolean;
|
|
27
|
-
switchbot!: switchbot;
|
|
28
|
-
address!: ad['address'];
|
|
29
|
-
serviceData!: serviceData;
|
|
30
29
|
state: serviceData['state'];
|
|
31
30
|
|
|
32
31
|
// Config
|
|
@@ -107,6 +106,15 @@ export class RobotVacuumCleaner {
|
|
|
107
106
|
})
|
|
108
107
|
.onSet(this.BrightnessSet.bind(this));
|
|
109
108
|
|
|
109
|
+
// Battery Service
|
|
110
|
+
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)),
|
|
111
|
+
`${accessory.displayName} Battery`;
|
|
112
|
+
|
|
113
|
+
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
114
|
+
if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
115
|
+
this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
116
|
+
}
|
|
117
|
+
|
|
110
118
|
// Update Homekit
|
|
111
119
|
this.updateHomeKitCharacteristics();
|
|
112
120
|
|
|
@@ -186,6 +194,15 @@ export class RobotVacuumCleaner {
|
|
|
186
194
|
this.On = false;
|
|
187
195
|
}
|
|
188
196
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
197
|
+
|
|
198
|
+
// Battery
|
|
199
|
+
this.BatteryLevel = Number(this.Battery);
|
|
200
|
+
if (this.BatteryLevel < 15) {
|
|
201
|
+
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
202
|
+
} else {
|
|
203
|
+
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
204
|
+
}
|
|
205
|
+
this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
|
|
189
206
|
}
|
|
190
207
|
|
|
191
208
|
/**
|
|
@@ -226,13 +243,11 @@ export class RobotVacuumCleaner {
|
|
|
226
243
|
})
|
|
227
244
|
.then(async () => {
|
|
228
245
|
// Set an event hander
|
|
229
|
-
switchbot.onadvertisement = async (ad:
|
|
230
|
-
this.address = ad.address;
|
|
246
|
+
switchbot.onadvertisement = async (ad: ad) => {
|
|
231
247
|
this.debugLog(
|
|
232
248
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
233
|
-
` BLE Address Found: ${
|
|
249
|
+
` BLE Address Found: ${ad.address}`,
|
|
234
250
|
);
|
|
235
|
-
this.serviceData = ad.serviceData;
|
|
236
251
|
this.state = ad.serviceData.state;
|
|
237
252
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
238
253
|
this.debugLog(
|
|
@@ -241,7 +256,7 @@ export class RobotVacuumCleaner {
|
|
|
241
256
|
`wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
|
|
242
257
|
);
|
|
243
258
|
|
|
244
|
-
if (
|
|
259
|
+
if (ad.serviceData) {
|
|
245
260
|
this.connected = true;
|
|
246
261
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
247
262
|
await this.stopScanning(switchbot);
|
|
@@ -276,12 +291,14 @@ export class RobotVacuumCleaner {
|
|
|
276
291
|
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
277
292
|
headers: this.platform.generateHeaders(),
|
|
278
293
|
});
|
|
279
|
-
const deviceStatus = await body.json();
|
|
294
|
+
const deviceStatus: any = await body.json();
|
|
280
295
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
281
296
|
this.statusCode(statusCode);
|
|
282
297
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
283
298
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
284
299
|
this.power = deviceStatus.body.power;
|
|
300
|
+
this.Battery = deviceStatus.body.battery;
|
|
301
|
+
this.Version = deviceStatus.body.version;
|
|
285
302
|
this.openAPIparseStatus();
|
|
286
303
|
this.updateHomeKitCharacteristics();
|
|
287
304
|
} catch (e: any) {
|
|
@@ -393,7 +410,7 @@ export class RobotVacuumCleaner {
|
|
|
393
410
|
method: 'POST',
|
|
394
411
|
headers: this.platform.generateHeaders(),
|
|
395
412
|
});
|
|
396
|
-
const deviceStatus = await body.json();
|
|
413
|
+
const deviceStatus: any = await body.json();
|
|
397
414
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
398
415
|
this.statusCode(statusCode);
|
|
399
416
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
@@ -422,7 +439,7 @@ export class RobotVacuumCleaner {
|
|
|
422
439
|
method: 'POST',
|
|
423
440
|
headers: this.platform.generateHeaders(),
|
|
424
441
|
});
|
|
425
|
-
const deviceStatus = await body.json();
|
|
442
|
+
const deviceStatus: any = await body.json();
|
|
426
443
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
427
444
|
this.statusCode(statusCode);
|
|
428
445
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|