@switchbot/homebridge-switchbot 3.5.0-beta.4 → 3.5.0-beta.40
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 -1
- package/config.schema.json +120 -17
- package/dist/device/blindtilt.d.ts +21 -94
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +349 -756
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +25 -71
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +584 -759
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -67
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +211 -587
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +13 -74
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +252 -632
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +14 -65
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +206 -531
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +17 -86
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +337 -786
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +59 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +671 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/fan.d.ts +51 -0
- package/dist/device/fan.d.ts.map +1 -0
- package/dist/device/fan.js +503 -0
- package/dist/device/fan.js.map +1 -0
- package/dist/device/hub.d.ts +15 -59
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +244 -596
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +10 -65
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +209 -571
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +11 -64
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +176 -584
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -68
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +254 -568
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +15 -62
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +212 -542
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +13 -63
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +172 -577
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +13 -64
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +161 -577
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +13 -69
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +138 -518
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -57
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +84 -452
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -62
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +142 -451
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +9 -70
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +123 -664
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +2 -2
- package/dist/index.js +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -48
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +309 -419
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +7 -38
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +72 -304
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +6 -35
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +34 -278
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +6 -39
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +67 -311
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +40 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +512 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +6 -34
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +23 -272
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +18 -47
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +352 -546
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +7 -39
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +82 -321
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +6 -35
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +41 -284
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +6 -35
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +42 -287
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +14 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +343 -198
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +41 -11
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +0 -552
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +77 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +638 -1
- package/dist/utils.js.map +1 -1
- package/package.json +16 -15
- package/src/custom.d.ts +2 -1
- package/src/device/blindtilt.ts +375 -782
- package/src/device/bot.ts +618 -844
- package/src/device/ceilinglight.ts +224 -607
- package/src/device/colorbulb.ts +266 -656
- package/src/device/contact.ts +231 -553
- package/src/device/curtain.ts +357 -810
- package/src/device/device.ts +699 -0
- package/src/device/fan.ts +552 -0
- package/src/device/hub.ts +271 -624
- package/src/device/humidifier.ts +239 -618
- package/src/device/iosensor.ts +202 -610
- package/src/device/lightstrip.ts +275 -596
- package/src/device/lock.ts +249 -582
- package/src/device/meter.ts +198 -601
- package/src/device/meterplus.ts +186 -602
- package/src/device/motion.ts +158 -541
- package/src/device/plug.ts +94 -480
- package/src/device/robotvacuumcleaner.ts +163 -477
- package/src/device/waterdetector.ts +141 -689
- package/src/homebridge-ui/public/index.html +2 -2
- package/src/index.ts +1 -1
- package/src/irdevice/airconditioner.ts +330 -446
- package/src/irdevice/airpurifier.ts +89 -321
- package/src/irdevice/camera.ts +42 -293
- package/src/irdevice/fan.ts +78 -327
- package/src/irdevice/irdevice.ts +528 -0
- package/src/irdevice/light.ts +32 -287
- package/src/irdevice/other.ts +396 -615
- package/src/irdevice/tv.ts +100 -339
- package/src/irdevice/vacuumcleaner.ts +49 -305
- package/src/irdevice/waterheater.ts +50 -310
- package/src/platform.ts +353 -206
- package/src/settings.ts +57 -566
- package/src/utils.ts +642 -1
|
@@ -1,87 +1,52 @@
|
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* robotvacuumcleaner.ts: @switchbot/homebridge-switchbot.
|
|
4
|
+
*/
|
|
1
5
|
import { request } from 'undici';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { debounceTime,
|
|
6
|
+
import { Subject, interval, skipWhile } from 'rxjs';
|
|
7
|
+
import { deviceBase } from './device.js';
|
|
8
|
+
import { debounceTime, take, tap } from 'rxjs/operators';
|
|
5
9
|
import { Devices } from '../settings.js';
|
|
6
|
-
export class RobotVacuumCleaner {
|
|
10
|
+
export class RobotVacuumCleaner extends deviceBase {
|
|
7
11
|
platform;
|
|
8
|
-
accessory;
|
|
9
|
-
device;
|
|
10
|
-
api;
|
|
11
|
-
log;
|
|
12
|
-
config;
|
|
13
|
-
hap;
|
|
14
12
|
// Services
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// Characteristic Values
|
|
18
|
-
On;
|
|
19
|
-
Brightness;
|
|
20
|
-
BatteryLevel;
|
|
21
|
-
StatusLowBattery;
|
|
22
|
-
FirmwareRevision;
|
|
23
|
-
// OpenAPI Status
|
|
24
|
-
OpenAPI_On;
|
|
25
|
-
OpenAPI_BatteryLevel;
|
|
26
|
-
OpenAPI_FirmwareRevision;
|
|
27
|
-
// BLE Status
|
|
28
|
-
BLE_On;
|
|
29
|
-
// BLE Others
|
|
30
|
-
BLE_IsConnected;
|
|
31
|
-
// Config
|
|
32
|
-
scanDuration;
|
|
33
|
-
deviceLogging;
|
|
34
|
-
deviceRefreshRate;
|
|
13
|
+
LightBulb;
|
|
14
|
+
Battery;
|
|
35
15
|
// Updates
|
|
36
16
|
robotVacuumCleanerUpdateInProgress;
|
|
37
17
|
doRobotVacuumCleanerUpdate;
|
|
38
|
-
// Connection
|
|
39
|
-
OpenAPI;
|
|
40
|
-
BLE;
|
|
41
18
|
constructor(platform, accessory, device) {
|
|
19
|
+
super(platform, accessory, device);
|
|
42
20
|
this.platform = platform;
|
|
43
|
-
this.accessory = accessory;
|
|
44
|
-
this.device = device;
|
|
45
|
-
this.api = this.platform.api;
|
|
46
|
-
this.log = this.platform.log;
|
|
47
|
-
this.config = this.platform.config;
|
|
48
|
-
this.hap = this.api.hap;
|
|
49
|
-
// Connection
|
|
50
|
-
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
51
|
-
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
52
|
-
// default placeholders
|
|
53
|
-
this.deviceLogs(device);
|
|
54
|
-
this.scan(device);
|
|
55
|
-
this.refreshRate(device);
|
|
56
|
-
this.deviceContext();
|
|
57
|
-
this.deviceConfig(device);
|
|
58
21
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
59
22
|
this.doRobotVacuumCleanerUpdate = new Subject();
|
|
60
23
|
this.robotVacuumCleanerUpdateInProgress = false;
|
|
24
|
+
// Initialize Lightbulb property
|
|
25
|
+
this.LightBulb = {
|
|
26
|
+
Service: accessory.getService(this.hap.Service.Lightbulb),
|
|
27
|
+
On: accessory.context.On || false,
|
|
28
|
+
Brightness: accessory.context.Brightness || 0,
|
|
29
|
+
};
|
|
30
|
+
// Initialize Battery property
|
|
31
|
+
this.Battery = {
|
|
32
|
+
Service: accessory.getService(this.hap.Service.Battery),
|
|
33
|
+
BatteryLevel: accessory.context.BatteryLevel || 100,
|
|
34
|
+
StatusLowBattery: accessory.context.StatusLowBattery || this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
|
|
35
|
+
};
|
|
61
36
|
// Retrieve initial values and updateHomekit
|
|
62
37
|
this.refreshStatus();
|
|
63
|
-
// set accessory information
|
|
64
|
-
accessory
|
|
65
|
-
.getService(this.hap.Service.AccessoryInformation)
|
|
66
|
-
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
67
|
-
.setCharacteristic(this.hap.Characteristic.Model, this.model(device))
|
|
68
|
-
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
69
|
-
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
70
38
|
// get the Lightbulb service if it exists, otherwise create a new Lightbulb service
|
|
71
39
|
// you can create multiple services for each accessory
|
|
72
|
-
const
|
|
73
|
-
(this.
|
|
74
|
-
|| accessory.addService(this.hap.Service.Lightbulb)),
|
|
75
|
-
this.
|
|
76
|
-
if (!this.robotVacuumCleanerService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
77
|
-
this.robotVacuumCleanerService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
78
|
-
}
|
|
40
|
+
const LightBulbService = `${accessory.displayName} ${device.deviceType}`;
|
|
41
|
+
(this.LightBulb.Service = accessory.getService(this.hap.Service.Lightbulb)
|
|
42
|
+
|| accessory.addService(this.hap.Service.Lightbulb)), LightBulbService;
|
|
43
|
+
this.LightBulb.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
79
44
|
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
80
45
|
// see https://developers.homebridge.io/#/service/Lightbulb
|
|
81
46
|
// create handlers for required characteristics
|
|
82
|
-
this.
|
|
47
|
+
this.LightBulb.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
83
48
|
// handle Brightness events using the Brightness characteristic
|
|
84
|
-
this.
|
|
49
|
+
this.LightBulb.Service
|
|
85
50
|
.getCharacteristic(this.hap.Characteristic.Brightness)
|
|
86
51
|
.setProps({
|
|
87
52
|
minStep: 25,
|
|
@@ -91,17 +56,14 @@ export class RobotVacuumCleaner {
|
|
|
91
56
|
validValueRanges: [0, 100],
|
|
92
57
|
})
|
|
93
58
|
.onGet(() => {
|
|
94
|
-
return this.Brightness;
|
|
59
|
+
return this.LightBulb.Brightness;
|
|
95
60
|
})
|
|
96
61
|
.onSet(this.BrightnessSet.bind(this));
|
|
97
62
|
// Battery Service
|
|
98
|
-
const
|
|
99
|
-
(this.
|
|
100
|
-
|| accessory.addService(this.hap.Service.Battery)),
|
|
101
|
-
this.
|
|
102
|
-
if (!this.batteryService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
103
|
-
this.batteryService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
104
|
-
}
|
|
63
|
+
const BatteryService = `${accessory.displayName} Battery`;
|
|
64
|
+
(this.Battery.Service = this.accessory.getService(this.hap.Service.Battery)
|
|
65
|
+
|| accessory.addService(this.hap.Service.Battery)), BatteryService;
|
|
66
|
+
this.Battery.Service.setCharacteristic(this.hap.Characteristic.Name, BatteryService);
|
|
105
67
|
// Update Homekit
|
|
106
68
|
this.updateHomeKitCharacteristics();
|
|
107
69
|
// Start an update interval
|
|
@@ -111,19 +73,20 @@ export class RobotVacuumCleaner {
|
|
|
111
73
|
await this.refreshStatus();
|
|
112
74
|
});
|
|
113
75
|
//regisiter webhook event handler
|
|
114
|
-
if (
|
|
115
|
-
this.
|
|
76
|
+
if (device.webhook) {
|
|
77
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
|
|
116
78
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
117
79
|
try {
|
|
118
80
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
119
81
|
const { onlineStatus, battery } = context;
|
|
120
|
-
const { On
|
|
82
|
+
const { On } = this.LightBulb;
|
|
83
|
+
const { BatteryLevel } = this.Battery;
|
|
121
84
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
122
85
|
'(onlineStatus, battery) = ' +
|
|
123
86
|
`Webhook:(${onlineStatus}, ${battery}), ` +
|
|
124
87
|
`current:(${On}, ${BatteryLevel})`);
|
|
125
|
-
this.On = onlineStatus === 'online' ? true : false;
|
|
126
|
-
this.BatteryLevel = battery;
|
|
88
|
+
this.LightBulb.On = onlineStatus === 'online' ? true : false;
|
|
89
|
+
this.Battery.BatteryLevel = battery;
|
|
127
90
|
this.updateHomeKitCharacteristics();
|
|
128
91
|
}
|
|
129
92
|
catch (e) {
|
|
@@ -140,10 +103,10 @@ export class RobotVacuumCleaner {
|
|
|
140
103
|
}), debounceTime(this.platform.config.options.pushRate * 1000))
|
|
141
104
|
.subscribe(async () => {
|
|
142
105
|
try {
|
|
143
|
-
if (this.On !== this.accessory.context.On) {
|
|
106
|
+
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
144
107
|
await this.pushChanges();
|
|
145
108
|
}
|
|
146
|
-
if (this.On && this.Brightness !== this.accessory.context.Brightness) {
|
|
109
|
+
if (this.LightBulb.On && this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
147
110
|
await this.openAPIpushBrightnessChanges();
|
|
148
111
|
}
|
|
149
112
|
}
|
|
@@ -155,57 +118,59 @@ export class RobotVacuumCleaner {
|
|
|
155
118
|
this.robotVacuumCleanerUpdateInProgress = false;
|
|
156
119
|
});
|
|
157
120
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (
|
|
163
|
-
this.
|
|
164
|
-
/*} else if (this.BLE) {
|
|
165
|
-
await this.BLEparseStatus();*/
|
|
166
|
-
}
|
|
167
|
-
else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
168
|
-
await this.openAPIparseStatus();
|
|
121
|
+
async BLEparseStatus(serviceData) {
|
|
122
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
123
|
+
// Battery
|
|
124
|
+
this.Battery.BatteryLevel = Number(serviceData.battery);
|
|
125
|
+
if (this.Battery.BatteryLevel < 10) {
|
|
126
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
169
127
|
}
|
|
170
128
|
else {
|
|
171
|
-
|
|
172
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`);
|
|
129
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
173
130
|
}
|
|
174
|
-
|
|
175
|
-
async BLEparseStatus() {
|
|
176
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
131
|
+
this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}, StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
177
132
|
// State
|
|
178
|
-
switch (
|
|
133
|
+
switch (serviceData.state) {
|
|
179
134
|
case 'on':
|
|
180
|
-
this.On = true;
|
|
135
|
+
this.LightBulb.On = true;
|
|
181
136
|
break;
|
|
182
137
|
default:
|
|
183
|
-
this.On = false;
|
|
138
|
+
this.LightBulb.On = false;
|
|
184
139
|
}
|
|
185
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
140
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
|
|
186
141
|
}
|
|
187
|
-
async openAPIparseStatus() {
|
|
142
|
+
async openAPIparseStatus(deviceStatus) {
|
|
188
143
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
189
|
-
switch (
|
|
144
|
+
switch (deviceStatus.body.power) {
|
|
190
145
|
case 'on':
|
|
191
|
-
this.On = true;
|
|
146
|
+
this.LightBulb.On = true;
|
|
192
147
|
break;
|
|
193
148
|
default:
|
|
194
|
-
this.On = false;
|
|
149
|
+
this.LightBulb.On = false;
|
|
195
150
|
}
|
|
196
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
197
|
-
//
|
|
198
|
-
this.BatteryLevel = Number(
|
|
199
|
-
if (this.BatteryLevel <
|
|
200
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
151
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
|
|
152
|
+
// BatteryLevel
|
|
153
|
+
this.Battery.BatteryLevel = Number(deviceStatus.body.battery);
|
|
154
|
+
if (this.Battery.BatteryLevel < 10) {
|
|
155
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
201
156
|
}
|
|
202
157
|
else {
|
|
203
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
158
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
204
159
|
}
|
|
205
|
-
|
|
160
|
+
if (Number.isNaN(this.Battery.BatteryLevel)) {
|
|
161
|
+
this.Battery.BatteryLevel = 100;
|
|
162
|
+
}
|
|
163
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
|
|
164
|
+
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
206
165
|
// FirmwareRevision
|
|
207
|
-
|
|
208
|
-
|
|
166
|
+
if (deviceStatus.body.version) {
|
|
167
|
+
this.accessory.context.version = deviceStatus.body.version;
|
|
168
|
+
this.accessory
|
|
169
|
+
.getService(this.hap.Service.AccessoryInformation)
|
|
170
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, this.accessory.context.version)
|
|
171
|
+
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
172
|
+
.updateValue(this.accessory.context.version);
|
|
173
|
+
}
|
|
209
174
|
}
|
|
210
175
|
/**
|
|
211
176
|
* Asks the SwitchBot API for the latest device information
|
|
@@ -247,7 +212,6 @@ export class RobotVacuumCleaner {
|
|
|
247
212
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.serviceData.model}`);
|
|
248
213
|
if (this.device.bleMac === ad.address && ad.serviceData.model === '?') {
|
|
249
214
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
250
|
-
this.BLE_On = ad.serviceData.state;
|
|
251
215
|
}
|
|
252
216
|
else {
|
|
253
217
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
@@ -258,7 +222,7 @@ export class RobotVacuumCleaner {
|
|
|
258
222
|
// Stop to monitor
|
|
259
223
|
await switchbot.stopScan();
|
|
260
224
|
// Update HomeKit
|
|
261
|
-
await this.BLEparseStatus();
|
|
225
|
+
await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
|
|
262
226
|
await this.updateHomeKitCharacteristics();
|
|
263
227
|
})();
|
|
264
228
|
/*if (switchbot !== false) {
|
|
@@ -274,7 +238,7 @@ export class RobotVacuumCleaner {
|
|
|
274
238
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
275
239
|
` BLE Address Found: ${ad.address}`,
|
|
276
240
|
);
|
|
277
|
-
|
|
241
|
+
serviceData.state = ad.serviceData.state;
|
|
278
242
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
279
243
|
this.debugLog(
|
|
280
244
|
`${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
|
|
@@ -313,7 +277,7 @@ export class RobotVacuumCleaner {
|
|
|
313
277
|
async openAPIRefreshStatus() {
|
|
314
278
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
315
279
|
try {
|
|
316
|
-
const { body, statusCode } = await
|
|
280
|
+
const { body, statusCode } = await this.platform.retryRequest(this.deviceMaxRetries, this.deviceDelayBetweenRetries, `${Devices}/${this.device.deviceId}/status`, {
|
|
317
281
|
headers: this.platform.generateHeaders(),
|
|
318
282
|
});
|
|
319
283
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
@@ -321,12 +285,9 @@ export class RobotVacuumCleaner {
|
|
|
321
285
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
322
286
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
323
287
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
324
|
-
this.
|
|
288
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
325
289
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
326
|
-
this.
|
|
327
|
-
this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
|
|
328
|
-
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
329
|
-
this.openAPIparseStatus();
|
|
290
|
+
this.openAPIparseStatus(deviceStatus);
|
|
330
291
|
this.updateHomeKitCharacteristics();
|
|
331
292
|
}
|
|
332
293
|
else {
|
|
@@ -371,8 +332,9 @@ export class RobotVacuumCleaner {
|
|
|
371
332
|
}
|
|
372
333
|
async BLEpushChanges() {
|
|
373
334
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
|
|
374
|
-
if (this.On !== this.accessory.context.On) {
|
|
375
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges
|
|
335
|
+
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
336
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`
|
|
337
|
+
+ ` On: ${this.LightBulb.On} OnCached: ${this.accessory.context.On}`);
|
|
376
338
|
const switchbot = await this.platform.connectBLE();
|
|
377
339
|
// Convert to BLE Address
|
|
378
340
|
this.device.bleMac = this.device
|
|
@@ -386,11 +348,11 @@ export class RobotVacuumCleaner {
|
|
|
386
348
|
id: this.device.bleMac,
|
|
387
349
|
})
|
|
388
350
|
.then(async (device_list) => {
|
|
389
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
390
|
-
return await this.
|
|
391
|
-
max: this.
|
|
351
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
|
|
352
|
+
return await this.retryBLE({
|
|
353
|
+
max: await this.maxRetryBLE(),
|
|
392
354
|
fn: async () => {
|
|
393
|
-
if (this.On) {
|
|
355
|
+
if (this.LightBulb.On) {
|
|
394
356
|
return await device_list[0].turnOn({ id: this.device.bleMac });
|
|
395
357
|
}
|
|
396
358
|
else {
|
|
@@ -401,7 +363,9 @@ export class RobotVacuumCleaner {
|
|
|
401
363
|
})
|
|
402
364
|
.then(() => {
|
|
403
365
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
404
|
-
this.
|
|
366
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
367
|
+
+ `On: ${this.LightBulb.On} sent over BLE, sent successfully`);
|
|
368
|
+
this.LightBulb.On = false;
|
|
405
369
|
})
|
|
406
370
|
.catch(async (e) => {
|
|
407
371
|
this.apiError(e);
|
|
@@ -411,24 +375,14 @@ export class RobotVacuumCleaner {
|
|
|
411
375
|
});
|
|
412
376
|
}
|
|
413
377
|
else {
|
|
414
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges
|
|
378
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges,`
|
|
379
|
+
+ ` On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
415
380
|
}
|
|
416
381
|
}
|
|
417
382
|
async openAPIpushChanges() {
|
|
418
383
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
419
|
-
if (this.On !== this.accessory.context.On) {
|
|
420
|
-
|
|
421
|
-
if (this.On) {
|
|
422
|
-
command = 'turnOn';
|
|
423
|
-
}
|
|
424
|
-
else {
|
|
425
|
-
command = 'turnOff';
|
|
426
|
-
}
|
|
427
|
-
const bodyChange = JSON.stringify({
|
|
428
|
-
command: `${command}`,
|
|
429
|
-
parameter: 'default',
|
|
430
|
-
commandType: 'command',
|
|
431
|
-
});
|
|
384
|
+
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
385
|
+
const bodyChange = await this.commands();
|
|
432
386
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
433
387
|
try {
|
|
434
388
|
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
@@ -444,6 +398,8 @@ export class RobotVacuumCleaner {
|
|
|
444
398
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
445
399
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
446
400
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
401
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
402
|
+
+ `request to SwitchBot API, body: ${JSON.stringify(bodyChange)} sent successfully`);
|
|
447
403
|
}
|
|
448
404
|
else {
|
|
449
405
|
this.statusCode(statusCode);
|
|
@@ -458,16 +414,17 @@ export class RobotVacuumCleaner {
|
|
|
458
414
|
}
|
|
459
415
|
else {
|
|
460
416
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` +
|
|
461
|
-
`On: ${this.On}, ` +
|
|
417
|
+
`On: ${this.LightBulb.On}, ` +
|
|
462
418
|
`OnCached: ${this.accessory.context.On}`);
|
|
463
419
|
}
|
|
464
420
|
}
|
|
465
421
|
async openAPIpushBrightnessChanges() {
|
|
466
422
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushBrightnessChanges`);
|
|
467
|
-
const
|
|
468
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${
|
|
423
|
+
const bodyChange = await this.brightnessCommands();
|
|
424
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
469
425
|
try {
|
|
470
426
|
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
427
|
+
body: bodyChange,
|
|
471
428
|
method: 'POST',
|
|
472
429
|
headers: this.platform.generateHeaders(),
|
|
473
430
|
});
|
|
@@ -476,8 +433,10 @@ export class RobotVacuumCleaner {
|
|
|
476
433
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
477
434
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
478
435
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
479
|
-
this.
|
|
436
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
480
437
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
438
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
439
|
+
+ `request to SwitchBot API, body: ${deviceStatus} sent successfully`);
|
|
481
440
|
}
|
|
482
441
|
else {
|
|
483
442
|
this.statusCode(statusCode);
|
|
@@ -490,10 +449,10 @@ export class RobotVacuumCleaner {
|
|
|
490
449
|
` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
491
450
|
}
|
|
492
451
|
}
|
|
493
|
-
commands() {
|
|
452
|
+
async commands() {
|
|
494
453
|
let command;
|
|
495
454
|
let parameter;
|
|
496
|
-
if (this.On) {
|
|
455
|
+
if (this.LightBulb.On) {
|
|
497
456
|
command = 'start';
|
|
498
457
|
parameter = 'default';
|
|
499
458
|
}
|
|
@@ -508,22 +467,22 @@ export class RobotVacuumCleaner {
|
|
|
508
467
|
});
|
|
509
468
|
return body;
|
|
510
469
|
}
|
|
511
|
-
brightnessCommands() {
|
|
470
|
+
async brightnessCommands() {
|
|
512
471
|
let command;
|
|
513
472
|
let parameter;
|
|
514
|
-
if (this.Brightness === 25) {
|
|
473
|
+
if (this.LightBulb.Brightness === 25) {
|
|
515
474
|
command = 'PowLevel';
|
|
516
475
|
parameter = '0';
|
|
517
476
|
}
|
|
518
|
-
else if (this.Brightness === 50) {
|
|
477
|
+
else if (this.LightBulb.Brightness === 50) {
|
|
519
478
|
command = 'PowLevel';
|
|
520
479
|
parameter = '1';
|
|
521
480
|
}
|
|
522
|
-
else if (this.Brightness === 75) {
|
|
481
|
+
else if (this.LightBulb.Brightness === 75) {
|
|
523
482
|
command = 'PowLevel';
|
|
524
483
|
parameter = '2';
|
|
525
484
|
}
|
|
526
|
-
else if (this.Brightness === 100) {
|
|
485
|
+
else if (this.LightBulb.Brightness === 100) {
|
|
527
486
|
command = 'PowLevel';
|
|
528
487
|
parameter = '3';
|
|
529
488
|
}
|
|
@@ -531,105 +490,79 @@ export class RobotVacuumCleaner {
|
|
|
531
490
|
command = 'dock';
|
|
532
491
|
parameter = 'default';
|
|
533
492
|
}
|
|
534
|
-
const
|
|
493
|
+
const bodyChange = JSON.stringify({
|
|
535
494
|
command: `${command}`,
|
|
536
495
|
parameter: `${parameter}`,
|
|
537
496
|
commandType: 'command',
|
|
538
497
|
});
|
|
539
|
-
return
|
|
498
|
+
return bodyChange;
|
|
540
499
|
}
|
|
541
500
|
/**
|
|
542
501
|
* Handle requests to set the value of the "On" characteristic
|
|
543
502
|
*/
|
|
544
503
|
async OnSet(value) {
|
|
545
|
-
if (this.On === this.accessory.context.On) {
|
|
504
|
+
if (this.LightBulb.On === this.accessory.context.On) {
|
|
546
505
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set On: ${value}`);
|
|
547
506
|
}
|
|
548
507
|
else {
|
|
549
508
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set On: ${value}`);
|
|
550
509
|
}
|
|
551
|
-
this.On = value;
|
|
510
|
+
this.LightBulb.On = value;
|
|
552
511
|
this.doRobotVacuumCleanerUpdate.next();
|
|
553
512
|
}
|
|
554
513
|
/**
|
|
555
514
|
* Handle requests to set the value of the "Brightness" characteristic
|
|
556
515
|
*/
|
|
557
516
|
async BrightnessSet(value) {
|
|
558
|
-
if (this.Brightness === this.accessory.context.Brightness) {
|
|
517
|
+
if (this.LightBulb.Brightness === this.accessory.context.Brightness) {
|
|
559
518
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Brightness: ${value}`);
|
|
560
519
|
}
|
|
561
|
-
else if (this.On) {
|
|
520
|
+
else if (this.LightBulb.On) {
|
|
562
521
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
|
|
563
522
|
}
|
|
564
523
|
else {
|
|
565
524
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
|
|
566
525
|
}
|
|
567
|
-
this.Brightness = value;
|
|
526
|
+
this.LightBulb.Brightness = value;
|
|
568
527
|
this.doRobotVacuumCleanerUpdate.next();
|
|
569
528
|
}
|
|
570
529
|
async updateHomeKitCharacteristics() {
|
|
571
530
|
// On
|
|
572
|
-
if (this.On === undefined) {
|
|
573
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
531
|
+
if (this.LightBulb.On === undefined) {
|
|
532
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
|
|
574
533
|
}
|
|
575
534
|
else {
|
|
576
|
-
this.accessory.context.On = this.On;
|
|
577
|
-
this.
|
|
578
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
535
|
+
this.accessory.context.On = this.LightBulb.On;
|
|
536
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, this.LightBulb.On);
|
|
537
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.LightBulb.On}`);
|
|
579
538
|
}
|
|
580
539
|
// Brightness
|
|
581
|
-
if (this.Brightness === undefined) {
|
|
582
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
540
|
+
if (this.LightBulb.Brightness === undefined) {
|
|
541
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
|
|
583
542
|
}
|
|
584
543
|
else {
|
|
585
|
-
this.accessory.context.Brightness = this.Brightness;
|
|
586
|
-
this.
|
|
587
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
|
|
544
|
+
this.accessory.context.Brightness = this.LightBulb.Brightness;
|
|
545
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, this.LightBulb.Brightness);
|
|
546
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.LightBulb.Brightness}`);
|
|
588
547
|
}
|
|
589
548
|
// BatteryLevel
|
|
590
|
-
if (this.BatteryLevel === undefined) {
|
|
591
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
549
|
+
if (this.Battery.BatteryLevel === undefined) {
|
|
550
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
592
551
|
}
|
|
593
552
|
else {
|
|
594
|
-
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
595
|
-
this.
|
|
596
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
553
|
+
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
|
|
554
|
+
this.Battery.Service?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
555
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
597
556
|
}
|
|
598
557
|
// StatusLowBattery
|
|
599
|
-
if (this.StatusLowBattery === undefined) {
|
|
600
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
558
|
+
if (this.Battery.StatusLowBattery === undefined) {
|
|
559
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
601
560
|
}
|
|
602
561
|
else {
|
|
603
|
-
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
604
|
-
this.
|
|
605
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
606
|
-
|
|
607
|
-
}
|
|
608
|
-
async stopScanning(switchbot) {
|
|
609
|
-
switchbot.stopScan();
|
|
610
|
-
if (this.BLE_IsConnected) {
|
|
611
|
-
await this.BLEparseStatus();
|
|
612
|
-
await this.updateHomeKitCharacteristics();
|
|
613
|
-
}
|
|
614
|
-
else {
|
|
615
|
-
await this.BLERefreshConnection(switchbot);
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
async getCustomBLEAddress(switchbot) {
|
|
619
|
-
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
620
|
-
(async () => {
|
|
621
|
-
// Start to monitor advertisement packets
|
|
622
|
-
await switchbot.startScan({
|
|
623
|
-
model: '?',
|
|
624
|
-
});
|
|
625
|
-
// Set an event handler
|
|
626
|
-
switchbot.onadvertisement = (ad) => {
|
|
627
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
628
|
-
};
|
|
629
|
-
await sleep(10000);
|
|
630
|
-
// Stop to monitor
|
|
631
|
-
switchbot.stopScan();
|
|
632
|
-
})();
|
|
562
|
+
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
563
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
564
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
565
|
+
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
633
566
|
}
|
|
634
567
|
}
|
|
635
568
|
async BLEPushConnection() {
|
|
@@ -646,255 +579,13 @@ export class RobotVacuumCleaner {
|
|
|
646
579
|
await this.openAPIRefreshStatus();
|
|
647
580
|
}
|
|
648
581
|
}
|
|
649
|
-
async retry({ max, fn }) {
|
|
650
|
-
return fn().catch(async (e) => {
|
|
651
|
-
if (max === 0) {
|
|
652
|
-
throw e;
|
|
653
|
-
}
|
|
654
|
-
this.infoLog(e);
|
|
655
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
|
|
656
|
-
await sleep(1000);
|
|
657
|
-
return this.retry({ max: max - 1, fn });
|
|
658
|
-
});
|
|
659
|
-
}
|
|
660
|
-
maxRetry() {
|
|
661
|
-
if (this.device.maxRetry) {
|
|
662
|
-
return this.device.maxRetry;
|
|
663
|
-
}
|
|
664
|
-
else {
|
|
665
|
-
return 5;
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
model(device) {
|
|
669
|
-
let model;
|
|
670
|
-
if (device.deviceType === 'Robot Vacuum Cleaner S1 Plus') {
|
|
671
|
-
model = 'W3011010';
|
|
672
|
-
}
|
|
673
|
-
else if (device.deviceType === 'Robot Vacuum Cleaner S1') {
|
|
674
|
-
model = 'W3011000';
|
|
675
|
-
}
|
|
676
|
-
else {
|
|
677
|
-
model = 'N/A';
|
|
678
|
-
}
|
|
679
|
-
return model;
|
|
680
|
-
}
|
|
681
|
-
async scan(device) {
|
|
682
|
-
if (device.scanDuration) {
|
|
683
|
-
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
684
|
-
if (this.BLE) {
|
|
685
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
else {
|
|
689
|
-
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
690
|
-
if (this.BLE) {
|
|
691
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
async statusCode(statusCode) {
|
|
696
|
-
switch (statusCode) {
|
|
697
|
-
case 151:
|
|
698
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
699
|
-
break;
|
|
700
|
-
case 152:
|
|
701
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
702
|
-
break;
|
|
703
|
-
case 160:
|
|
704
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
705
|
-
break;
|
|
706
|
-
case 161:
|
|
707
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
708
|
-
this.offlineOff();
|
|
709
|
-
break;
|
|
710
|
-
case 171:
|
|
711
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
712
|
-
`Hub: ${this.device.hubDeviceId}`);
|
|
713
|
-
this.offlineOff();
|
|
714
|
-
break;
|
|
715
|
-
case 190:
|
|
716
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
717
|
-
` Or command format is invalid, statusCode: ${statusCode}`);
|
|
718
|
-
break;
|
|
719
|
-
case 100:
|
|
720
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
721
|
-
break;
|
|
722
|
-
case 200:
|
|
723
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
724
|
-
break;
|
|
725
|
-
case 400:
|
|
726
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
727
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
728
|
-
break;
|
|
729
|
-
case 401:
|
|
730
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
731
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
732
|
-
break;
|
|
733
|
-
case 403:
|
|
734
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
735
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
736
|
-
break;
|
|
737
|
-
case 404:
|
|
738
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
739
|
-
+ `statusCode: ${statusCode}`);
|
|
740
|
-
break;
|
|
741
|
-
case 406:
|
|
742
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
743
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
744
|
-
break;
|
|
745
|
-
case 415:
|
|
746
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
747
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
748
|
-
break;
|
|
749
|
-
case 422:
|
|
750
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, `
|
|
751
|
-
+ `but the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
752
|
-
break;
|
|
753
|
-
case 429:
|
|
754
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
755
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
756
|
-
break;
|
|
757
|
-
case 500:
|
|
758
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
759
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
760
|
-
break;
|
|
761
|
-
default:
|
|
762
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
763
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
582
|
async offlineOff() {
|
|
767
583
|
if (this.device.offline) {
|
|
768
|
-
|
|
769
|
-
await this.updateHomeKitCharacteristics();
|
|
584
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, false);
|
|
770
585
|
}
|
|
771
586
|
}
|
|
772
587
|
async apiError(e) {
|
|
773
|
-
this.
|
|
774
|
-
}
|
|
775
|
-
async deviceContext() {
|
|
776
|
-
if (this.On === undefined) {
|
|
777
|
-
this.On = false;
|
|
778
|
-
}
|
|
779
|
-
else {
|
|
780
|
-
this.On = this.accessory.context.On;
|
|
781
|
-
}
|
|
782
|
-
if (this.Brightness === undefined) {
|
|
783
|
-
this.Brightness = 0;
|
|
784
|
-
}
|
|
785
|
-
else {
|
|
786
|
-
this.Brightness = this.accessory.context.Brightness;
|
|
787
|
-
}
|
|
788
|
-
if (this.FirmwareRevision === undefined) {
|
|
789
|
-
this.FirmwareRevision = this.platform.version;
|
|
790
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
async refreshRate(device) {
|
|
794
|
-
if (device.refreshRate) {
|
|
795
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
796
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
797
|
-
}
|
|
798
|
-
else if (this.platform.config.options.refreshRate) {
|
|
799
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
800
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
async deviceConfig(device) {
|
|
804
|
-
let config = {};
|
|
805
|
-
if (device.plug) {
|
|
806
|
-
config = device.plug;
|
|
807
|
-
}
|
|
808
|
-
if (device.connectionType !== undefined) {
|
|
809
|
-
config['connectionType'] = device.connectionType;
|
|
810
|
-
}
|
|
811
|
-
if (device.external !== undefined) {
|
|
812
|
-
config['external'] = device.external;
|
|
813
|
-
}
|
|
814
|
-
if (device.logging !== undefined) {
|
|
815
|
-
config['logging'] = device.logging;
|
|
816
|
-
}
|
|
817
|
-
if (device.refreshRate !== undefined) {
|
|
818
|
-
config['refreshRate'] = device.refreshRate;
|
|
819
|
-
}
|
|
820
|
-
if (device.scanDuration !== undefined) {
|
|
821
|
-
config['scanDuration'] = device.scanDuration;
|
|
822
|
-
}
|
|
823
|
-
if (device.offline !== undefined) {
|
|
824
|
-
config['offline'] = device.offline;
|
|
825
|
-
}
|
|
826
|
-
if (device.maxRetry !== undefined) {
|
|
827
|
-
config['maxRetry'] = device.maxRetry;
|
|
828
|
-
}
|
|
829
|
-
if (device.webhook !== undefined) {
|
|
830
|
-
config['webhook'] = device.webhook;
|
|
831
|
-
}
|
|
832
|
-
if (Object.entries(config).length !== 0) {
|
|
833
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
async deviceLogs(device) {
|
|
837
|
-
if (this.platform.debugMode) {
|
|
838
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
839
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
840
|
-
}
|
|
841
|
-
else if (device.logging) {
|
|
842
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
843
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
844
|
-
}
|
|
845
|
-
else if (this.platform.config.options?.logging) {
|
|
846
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
847
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
848
|
-
}
|
|
849
|
-
else {
|
|
850
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
851
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
/**
|
|
855
|
-
* Logging for Device
|
|
856
|
-
*/
|
|
857
|
-
infoLog(...log) {
|
|
858
|
-
if (this.enablingDeviceLogging()) {
|
|
859
|
-
this.platform.log.info(String(...log));
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
warnLog(...log) {
|
|
863
|
-
if (this.enablingDeviceLogging()) {
|
|
864
|
-
this.platform.log.warn(String(...log));
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
debugWarnLog(...log) {
|
|
868
|
-
if (this.enablingDeviceLogging()) {
|
|
869
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
870
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
errorLog(...log) {
|
|
875
|
-
if (this.enablingDeviceLogging()) {
|
|
876
|
-
this.platform.log.error(String(...log));
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
debugErrorLog(...log) {
|
|
880
|
-
if (this.enablingDeviceLogging()) {
|
|
881
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
882
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
debugLog(...log) {
|
|
887
|
-
if (this.enablingDeviceLogging()) {
|
|
888
|
-
if (this.deviceLogging === 'debug') {
|
|
889
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
890
|
-
}
|
|
891
|
-
else {
|
|
892
|
-
this.platform.log.debug(String(...log));
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
enablingDeviceLogging() {
|
|
897
|
-
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
588
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
898
589
|
}
|
|
899
590
|
}
|
|
900
591
|
//# sourceMappingURL=robotvacuumcleaner.js.map
|