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