@switchbot/homebridge-switchbot 2.8.1-beta.0 → 2.8.1-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +13 -19
- package/dist/device/hub.js.map +1 -1
- package/dist/device/lightstrip.d.ts +7 -8
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +26 -21
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +3 -3
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +16 -5
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +13 -13
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +32 -21
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +12 -12
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +32 -21
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +8 -13
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +34 -23
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +4 -10
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +20 -15
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +6 -6
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +23 -12
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +4 -4
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/camera.d.ts +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/fan.d.ts +3 -3
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/light.d.ts +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/other.d.ts +2 -2
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/tv.d.ts +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/waterheater.d.ts +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +27 -15
- package/dist/platform.js.map +1 -1
- package/package.json +4 -4
- package/src/device/hub.ts +13 -21
- package/src/device/lightstrip.ts +35 -30
- package/src/device/lock.ts +18 -8
- package/src/device/meter.ts +47 -35
- package/src/device/meterplus.ts +46 -34
- package/src/device/motion.ts +45 -33
- package/src/device/plug.ts +23 -25
- package/src/device/robotvacuumcleaner.ts +31 -19
- package/src/irdevice/airconditioner.ts +4 -4
- package/src/irdevice/camera.ts +1 -1
- package/src/irdevice/fan.ts +3 -3
- package/src/irdevice/light.ts +1 -1
- package/src/irdevice/other.ts +2 -2
- package/src/irdevice/tv.ts +1 -1
- package/src/irdevice/vacuumcleaner.ts +1 -1
- package/src/irdevice/waterheater.ts +1 -1
- package/src/platform.ts +32 -21
package/src/device/motion.ts
CHANGED
|
@@ -25,22 +25,24 @@ export class Motion {
|
|
|
25
25
|
StatusLowBattery!: CharacteristicValue;
|
|
26
26
|
|
|
27
27
|
// OpenAPI Others
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
OpenAPI_BatteryLevel: deviceStatus['battery'];
|
|
29
|
+
OpenAPI_FirmwareRevision: deviceStatus['version'];
|
|
30
|
+
OpenAPI_MotionDetected: deviceStatus['moveDetected'];
|
|
31
|
+
OpenAPI_CurrentAmbientLightLevel: deviceStatus['brightness'];
|
|
32
|
+
|
|
33
|
+
// Status
|
|
34
|
+
BLE_BatteryLevel!: serviceData['battery'];
|
|
35
|
+
BLE_MotionDetected!: serviceData['movement'];
|
|
36
|
+
BLE_CurrentAmbientLightLevel!: serviceData['lightLevel'];
|
|
32
37
|
|
|
33
38
|
// BLE Others
|
|
34
39
|
scanning!: boolean;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
movement!: serviceData['movement'];
|
|
38
|
-
lightLevel!: serviceData['lightLevel'];
|
|
39
|
-
is_light!: any; //serviceData['is_light'];
|
|
40
|
+
BLE_IsConnected?: boolean;
|
|
41
|
+
/*is_light!: any; //serviceData['is_light'];
|
|
40
42
|
tested!: any;
|
|
41
43
|
led!: any;
|
|
42
44
|
iot!: any;
|
|
43
|
-
sense_distance!: any
|
|
45
|
+
sense_distance!: any;*/
|
|
44
46
|
|
|
45
47
|
// Config
|
|
46
48
|
set_minLux!: number;
|
|
@@ -163,7 +165,7 @@ export class Motion {
|
|
|
163
165
|
async BLEparseStatus(): Promise<void> {
|
|
164
166
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
165
167
|
// Movement
|
|
166
|
-
this.MotionDetected = this.
|
|
168
|
+
this.MotionDetected = this.BLE_MotionDetected!;
|
|
167
169
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
168
170
|
if (this.MotionDetected !== this.accessory.context.MotionDetected && this.MotionDetected) {
|
|
169
171
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Detected Motion`);
|
|
@@ -172,7 +174,7 @@ export class Motion {
|
|
|
172
174
|
if (!this.device.motion?.hide_lightsensor) {
|
|
173
175
|
this.set_minLux = this.minLux();
|
|
174
176
|
this.set_maxLux = this.maxLux();
|
|
175
|
-
switch (this.
|
|
177
|
+
switch (this.BLE_CurrentAmbientLightLevel) {
|
|
176
178
|
case 'dark':
|
|
177
179
|
case 1:
|
|
178
180
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
@@ -181,7 +183,7 @@ export class Motion {
|
|
|
181
183
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
182
184
|
}
|
|
183
185
|
this.debugLog(
|
|
184
|
-
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
186
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel},` +
|
|
185
187
|
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
186
188
|
);
|
|
187
189
|
if (this.CurrentAmbientLightLevel !== this.accessory.context.CurrentAmbientLightLevel) {
|
|
@@ -189,10 +191,10 @@ export class Motion {
|
|
|
189
191
|
}
|
|
190
192
|
}
|
|
191
193
|
// Battery
|
|
192
|
-
if (this.
|
|
193
|
-
this.
|
|
194
|
+
if (this.BLE_BatteryLevel === undefined) {
|
|
195
|
+
this.BLE_BatteryLevel = 100;
|
|
194
196
|
}
|
|
195
|
-
this.BatteryLevel = this.
|
|
197
|
+
this.BatteryLevel = this.BLE_BatteryLevel!;
|
|
196
198
|
if (this.BatteryLevel < 10) {
|
|
197
199
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
198
200
|
} else {
|
|
@@ -206,13 +208,13 @@ export class Motion {
|
|
|
206
208
|
async openAPIparseStatus(): Promise<void> {
|
|
207
209
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
208
210
|
// Motion State
|
|
209
|
-
this.MotionDetected = this.
|
|
211
|
+
this.MotionDetected = this.OpenAPI_MotionDetected!;
|
|
210
212
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
211
213
|
// Light Level
|
|
212
214
|
if (!this.device.motion?.hide_lightsensor) {
|
|
213
215
|
this.set_minLux = this.minLux();
|
|
214
216
|
this.set_maxLux = this.maxLux();
|
|
215
|
-
switch (this.
|
|
217
|
+
switch (this.OpenAPI_CurrentAmbientLightLevel) {
|
|
216
218
|
case 'dim':
|
|
217
219
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
218
220
|
break;
|
|
@@ -223,10 +225,10 @@ export class Motion {
|
|
|
223
225
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
224
226
|
}
|
|
225
227
|
// Battery
|
|
226
|
-
if (this.
|
|
227
|
-
this.
|
|
228
|
+
if (this.OpenAPI_BatteryLevel === undefined) {
|
|
229
|
+
this.OpenAPI_BatteryLevel = 100;
|
|
228
230
|
}
|
|
229
|
-
this.BatteryLevel = this.
|
|
231
|
+
this.BatteryLevel = this.OpenAPI_BatteryLevel!;
|
|
230
232
|
if (this.BatteryLevel < 10) {
|
|
231
233
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
232
234
|
} else {
|
|
@@ -286,9 +288,9 @@ export class Motion {
|
|
|
286
288
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
287
289
|
` BLE Address Found: ${ad.address}`,
|
|
288
290
|
);
|
|
289
|
-
this.
|
|
290
|
-
this.
|
|
291
|
-
this.
|
|
291
|
+
this.BLE_MotionDetected = ad.serviceData.movement;
|
|
292
|
+
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
293
|
+
this.BLE_CurrentAmbientLightLevel = ad.serviceData.lightLevel;
|
|
292
294
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
293
295
|
this.debugLog(
|
|
294
296
|
`${this.device.deviceType}: ${this.accessory.displayName} movement: ${ad.serviceData.movement},`
|
|
@@ -296,15 +298,15 @@ export class Motion {
|
|
|
296
298
|
);
|
|
297
299
|
|
|
298
300
|
if (ad.serviceData) {
|
|
299
|
-
this.
|
|
300
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
301
|
+
this.BLE_IsConnected = true;
|
|
302
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
301
303
|
this.debugErrorLog('1');
|
|
302
304
|
await this.stopScanning(switchbot);
|
|
303
305
|
this.scanning = false;
|
|
304
306
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} scanning: ${this.scanning}`);
|
|
305
307
|
} else {
|
|
306
|
-
this.
|
|
307
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
308
|
+
this.BLE_IsConnected = false;
|
|
309
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
308
310
|
}
|
|
309
311
|
};
|
|
310
312
|
// Wait
|
|
@@ -346,10 +348,10 @@ export class Motion {
|
|
|
346
348
|
this.statusCode(statusCode);
|
|
347
349
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
348
350
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
349
|
-
this.
|
|
350
|
-
this.
|
|
351
|
-
this.
|
|
352
|
-
this.
|
|
351
|
+
this.OpenAPI_MotionDetected = deviceStatus.body.moveDetected;
|
|
352
|
+
this.OpenAPI_CurrentAmbientLightLevel = deviceStatus.body.brightness;
|
|
353
|
+
this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
|
|
354
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
353
355
|
this.openAPIparseStatus();
|
|
354
356
|
this.updateHomeKitCharacteristics();
|
|
355
357
|
} catch (e: any) {
|
|
@@ -398,11 +400,21 @@ export class Motion {
|
|
|
398
400
|
);
|
|
399
401
|
}
|
|
400
402
|
}
|
|
403
|
+
// FirmwareRevision
|
|
404
|
+
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
405
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
406
|
+
} else {
|
|
407
|
+
this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
408
|
+
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
409
|
+
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
410
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
411
|
+
+ `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
|
|
412
|
+
}
|
|
401
413
|
}
|
|
402
414
|
|
|
403
415
|
async stopScanning(switchbot: any) {
|
|
404
416
|
await switchbot.stopScan();
|
|
405
|
-
if (this.
|
|
417
|
+
if (this.BLE_IsConnected) {
|
|
406
418
|
await this.BLEparseStatus();
|
|
407
419
|
await this.updateHomeKitCharacteristics();
|
|
408
420
|
} else {
|
package/src/device/plug.ts
CHANGED
|
@@ -15,18 +15,12 @@ export class Plug {
|
|
|
15
15
|
On!: CharacteristicValue;
|
|
16
16
|
|
|
17
17
|
// OpenAPI Others
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
OpenAPI_On: deviceStatus['power'];
|
|
19
|
+
OpenAPI_FirmwareRevision: deviceStatus['version'];
|
|
20
20
|
|
|
21
21
|
// BLE Others
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
delay: serviceData['delay'];
|
|
25
|
-
timer: serviceData['timer'];
|
|
26
|
-
wifiRssi: serviceData['wifiRssi'];
|
|
27
|
-
overload: serviceData['overload'];
|
|
28
|
-
syncUtcTime: serviceData['syncUtcTime'];
|
|
29
|
-
currentPower: serviceData['currentPower'];
|
|
22
|
+
BLE_IsConnected?: boolean;
|
|
23
|
+
BLE_On: serviceData['state'];
|
|
30
24
|
|
|
31
25
|
// Config
|
|
32
26
|
scanDuration!: number;
|
|
@@ -145,7 +139,7 @@ export class Plug {
|
|
|
145
139
|
async BLEparseStatus(): Promise<void> {
|
|
146
140
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
147
141
|
// State
|
|
148
|
-
switch (this.
|
|
142
|
+
switch (this.BLE_On) {
|
|
149
143
|
case 'on':
|
|
150
144
|
this.On = true;
|
|
151
145
|
break;
|
|
@@ -157,7 +151,7 @@ export class Plug {
|
|
|
157
151
|
|
|
158
152
|
async openAPIparseStatus() {
|
|
159
153
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
160
|
-
switch (this.
|
|
154
|
+
switch (this.OpenAPI_On) {
|
|
161
155
|
case 'on':
|
|
162
156
|
this.On = true;
|
|
163
157
|
break;
|
|
@@ -210,13 +204,7 @@ export class Plug {
|
|
|
210
204
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
211
205
|
` BLE Address Found: ${ad.address}`,
|
|
212
206
|
);
|
|
213
|
-
this.
|
|
214
|
-
this.delay = ad.serviceData.delay;
|
|
215
|
-
this.timer = ad.serviceData.timer;
|
|
216
|
-
this.syncUtcTime = ad.serviceData.syncUtcTime;
|
|
217
|
-
this.wifiRssi = ad.serviceData.wifiRssi;
|
|
218
|
-
this.overload = ad.serviceData.overload;
|
|
219
|
-
this.currentPower = ad.serviceData.currentPower;
|
|
207
|
+
this.BLE_On = ad.serviceData.state;
|
|
220
208
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
221
209
|
this.debugLog(
|
|
222
210
|
`${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
|
|
@@ -225,12 +213,12 @@ export class Plug {
|
|
|
225
213
|
);
|
|
226
214
|
|
|
227
215
|
if (ad.serviceData) {
|
|
228
|
-
this.
|
|
229
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
216
|
+
this.BLE_IsConnected = true;
|
|
217
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
230
218
|
await this.stopScanning(switchbot);
|
|
231
219
|
} else {
|
|
232
|
-
this.
|
|
233
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
220
|
+
this.BLE_IsConnected = false;
|
|
221
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
234
222
|
}
|
|
235
223
|
};
|
|
236
224
|
// Wait
|
|
@@ -264,7 +252,7 @@ export class Plug {
|
|
|
264
252
|
this.statusCode(statusCode);
|
|
265
253
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
266
254
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
267
|
-
this.
|
|
255
|
+
this.OpenAPI_On = deviceStatus.body.power;
|
|
268
256
|
this.openAPIparseStatus();
|
|
269
257
|
this.updateHomeKitCharacteristics();
|
|
270
258
|
} catch (e: any) {
|
|
@@ -419,11 +407,21 @@ export class Plug {
|
|
|
419
407
|
this.outletService.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
420
408
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
421
409
|
}
|
|
410
|
+
// FirmwareRevision
|
|
411
|
+
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
412
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
413
|
+
} else {
|
|
414
|
+
this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
415
|
+
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
416
|
+
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
417
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
418
|
+
+ `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
|
|
419
|
+
}
|
|
422
420
|
}
|
|
423
421
|
|
|
424
422
|
async stopScanning(switchbot: any) {
|
|
425
423
|
await switchbot.stopScan();
|
|
426
|
-
if (this.
|
|
424
|
+
if (this.BLE_IsConnected) {
|
|
427
425
|
await this.BLEparseStatus();
|
|
428
426
|
await this.updateHomeKitCharacteristics();
|
|
429
427
|
} else {
|
|
@@ -10,8 +10,8 @@ import { device, devicesConfig, deviceStatus, ad, serviceData, Devices } from '.
|
|
|
10
10
|
|
|
11
11
|
export class RobotVacuumCleaner {
|
|
12
12
|
// Services
|
|
13
|
-
robotVacuumCleanerService: Service;
|
|
14
13
|
batteryService: Service;
|
|
14
|
+
robotVacuumCleanerService: Service;
|
|
15
15
|
|
|
16
16
|
// Characteristic Values
|
|
17
17
|
On!: CharacteristicValue;
|
|
@@ -19,14 +19,16 @@ export class RobotVacuumCleaner {
|
|
|
19
19
|
BatteryLevel!: CharacteristicValue;
|
|
20
20
|
StatusLowBattery!: CharacteristicValue;
|
|
21
21
|
|
|
22
|
-
// OpenAPI
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
// OpenAPI Status
|
|
23
|
+
OpenAPI_On: deviceStatus['power'];
|
|
24
|
+
OpenAPI_BatteryLevel: deviceStatus['battery'];
|
|
25
|
+
OpenAPI_FirmwareRevision: deviceStatus['version'];
|
|
26
|
+
|
|
27
|
+
// BLE Status
|
|
28
|
+
BLE_On: serviceData['state'];
|
|
26
29
|
|
|
27
30
|
// BLE Others
|
|
28
|
-
|
|
29
|
-
state: serviceData['state'];
|
|
31
|
+
BLE_IsConnected?: boolean;
|
|
30
32
|
|
|
31
33
|
// Config
|
|
32
34
|
scanDuration!: number;
|
|
@@ -174,7 +176,7 @@ export class RobotVacuumCleaner {
|
|
|
174
176
|
async BLEparseStatus(): Promise<void> {
|
|
175
177
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
176
178
|
// State
|
|
177
|
-
switch (this.
|
|
179
|
+
switch (this.BLE_On) {
|
|
178
180
|
case 'on':
|
|
179
181
|
this.On = true;
|
|
180
182
|
break;
|
|
@@ -186,7 +188,7 @@ export class RobotVacuumCleaner {
|
|
|
186
188
|
|
|
187
189
|
async openAPIparseStatus() {
|
|
188
190
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
189
|
-
switch (this.
|
|
191
|
+
switch (this.OpenAPI_On) {
|
|
190
192
|
case 'on':
|
|
191
193
|
this.On = true;
|
|
192
194
|
break;
|
|
@@ -196,7 +198,7 @@ export class RobotVacuumCleaner {
|
|
|
196
198
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
197
199
|
|
|
198
200
|
// Battery
|
|
199
|
-
this.BatteryLevel = Number(this.
|
|
201
|
+
this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
|
|
200
202
|
if (this.BatteryLevel < 15) {
|
|
201
203
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
202
204
|
} else {
|
|
@@ -248,7 +250,7 @@ export class RobotVacuumCleaner {
|
|
|
248
250
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
249
251
|
` BLE Address Found: ${ad.address}`,
|
|
250
252
|
);
|
|
251
|
-
this.
|
|
253
|
+
this.BLE_On = ad.serviceData.state;
|
|
252
254
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
253
255
|
this.debugLog(
|
|
254
256
|
`${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
|
|
@@ -257,12 +259,12 @@ export class RobotVacuumCleaner {
|
|
|
257
259
|
);
|
|
258
260
|
|
|
259
261
|
if (ad.serviceData) {
|
|
260
|
-
this.
|
|
261
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
262
|
+
this.BLE_IsConnected = true;
|
|
263
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
262
264
|
await this.stopScanning(switchbot);
|
|
263
265
|
} else {
|
|
264
|
-
this.
|
|
265
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
266
|
+
this.BLE_IsConnected = false;
|
|
267
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
266
268
|
}
|
|
267
269
|
};
|
|
268
270
|
// Wait
|
|
@@ -296,9 +298,9 @@ export class RobotVacuumCleaner {
|
|
|
296
298
|
this.statusCode(statusCode);
|
|
297
299
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
298
300
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
299
|
-
this.
|
|
300
|
-
this.
|
|
301
|
-
this.
|
|
301
|
+
this.OpenAPI_On = deviceStatus.body.power;
|
|
302
|
+
this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
|
|
303
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
302
304
|
this.openAPIparseStatus();
|
|
303
305
|
this.updateHomeKitCharacteristics();
|
|
304
306
|
} catch (e: any) {
|
|
@@ -556,11 +558,21 @@ export class RobotVacuumCleaner {
|
|
|
556
558
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
557
559
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
558
560
|
}
|
|
561
|
+
// FirmwareRevision
|
|
562
|
+
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
563
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
564
|
+
} else {
|
|
565
|
+
this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
566
|
+
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
567
|
+
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
568
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
569
|
+
+ `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
|
|
570
|
+
}
|
|
559
571
|
}
|
|
560
572
|
|
|
561
573
|
async stopScanning(switchbot: any) {
|
|
562
574
|
await switchbot.stopScan();
|
|
563
|
-
if (this.
|
|
575
|
+
if (this.BLE_IsConnected) {
|
|
564
576
|
await this.BLEparseStatus();
|
|
565
577
|
await this.updateHomeKitCharacteristics();
|
|
566
578
|
} else {
|
|
@@ -16,10 +16,10 @@ export class AirConditioner {
|
|
|
16
16
|
Active!: CharacteristicValue;
|
|
17
17
|
RotationSpeed!: CharacteristicValue;
|
|
18
18
|
CurrentTemperature!: CharacteristicValue;
|
|
19
|
+
ThresholdTemperature!: CharacteristicValue;
|
|
19
20
|
CurrentRelativeHumidity?: CharacteristicValue;
|
|
20
21
|
TargetHeaterCoolerState!: CharacteristicValue;
|
|
21
22
|
CurrentHeaterCoolerState!: CharacteristicValue;
|
|
22
|
-
ThresholdTemperature!: CharacteristicValue;
|
|
23
23
|
|
|
24
24
|
// Others
|
|
25
25
|
state!: string;
|
|
@@ -33,12 +33,12 @@ export class AirConditioner {
|
|
|
33
33
|
static MODE_HEAT: number;
|
|
34
34
|
|
|
35
35
|
// Config
|
|
36
|
-
disablePushOn?: boolean;
|
|
37
|
-
disablePushOff?: boolean;
|
|
38
|
-
disablePushDetail?: boolean;
|
|
39
36
|
deviceLogging!: string;
|
|
40
37
|
hide_automode?: boolean;
|
|
38
|
+
disablePushOn?: boolean;
|
|
39
|
+
disablePushOff?: boolean;
|
|
41
40
|
meter?: PlatformAccessory;
|
|
41
|
+
disablePushDetail?: boolean;
|
|
42
42
|
|
|
43
43
|
private readonly valid12 = [1, 2];
|
|
44
44
|
private readonly valid012 = [0, 1, 2];
|
package/src/irdevice/camera.ts
CHANGED
package/src/irdevice/fan.ts
CHANGED
|
@@ -14,18 +14,18 @@ export class Fan {
|
|
|
14
14
|
|
|
15
15
|
// Characteristic Values
|
|
16
16
|
Active!: CharacteristicValue;
|
|
17
|
-
ActiveIdentifier!: CharacteristicValue;
|
|
18
|
-
RotationSpeed!: CharacteristicValue;
|
|
19
17
|
SwingMode!: CharacteristicValue;
|
|
18
|
+
RotationSpeed!: CharacteristicValue;
|
|
19
|
+
ActiveIdentifier!: CharacteristicValue;
|
|
20
20
|
RotationDirection!: CharacteristicValue;
|
|
21
21
|
|
|
22
22
|
// Config
|
|
23
23
|
minStep?: number;
|
|
24
24
|
minValue?: number;
|
|
25
25
|
maxValue?: number;
|
|
26
|
+
deviceLogging!: string;
|
|
26
27
|
disablePushOn?: boolean;
|
|
27
28
|
disablePushOff?: boolean;
|
|
28
|
-
deviceLogging!: string;
|
|
29
29
|
|
|
30
30
|
constructor(
|
|
31
31
|
private readonly platform: SwitchBotPlatform,
|
package/src/irdevice/light.ts
CHANGED
package/src/irdevice/other.ts
CHANGED
|
@@ -16,10 +16,10 @@ export class Others {
|
|
|
16
16
|
Active!: CharacteristicValue;
|
|
17
17
|
|
|
18
18
|
// Config
|
|
19
|
-
disablePushOn?: boolean;
|
|
20
|
-
disablePushOff?: boolean;
|
|
21
19
|
deviceLogging!: string;
|
|
20
|
+
disablePushOn?: boolean;
|
|
22
21
|
otherDeviceType?: string;
|
|
22
|
+
disablePushOff?: boolean;
|
|
23
23
|
|
|
24
24
|
constructor(
|
|
25
25
|
private readonly platform: SwitchBotPlatform,
|
package/src/irdevice/tv.ts
CHANGED
|
@@ -18,10 +18,10 @@ export class TV {
|
|
|
18
18
|
ActiveIdentifier!: CharacteristicValue;
|
|
19
19
|
|
|
20
20
|
// Config
|
|
21
|
+
deviceLogging!: string;
|
|
21
22
|
disablePushOn?: boolean;
|
|
22
23
|
disablePushOff?: boolean;
|
|
23
24
|
disablePushDetail?: boolean;
|
|
24
|
-
deviceLogging!: string;
|
|
25
25
|
|
|
26
26
|
constructor(
|
|
27
27
|
private readonly platform: SwitchBotPlatform,
|
|
@@ -16,9 +16,9 @@ export class WaterHeater {
|
|
|
16
16
|
Active!: CharacteristicValue;
|
|
17
17
|
|
|
18
18
|
// Config
|
|
19
|
+
deviceLogging!: string;
|
|
19
20
|
disablePushOn?: boolean;
|
|
20
21
|
disablePushOff?: boolean;
|
|
21
|
-
deviceLogging!: string;
|
|
22
22
|
|
|
23
23
|
constructor(
|
|
24
24
|
private readonly platform: SwitchBotPlatform,
|
package/src/platform.ts
CHANGED
|
@@ -300,12 +300,18 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
300
300
|
const { body, statusCode, headers } = await request(Devices, {
|
|
301
301
|
headers: this.generateHeaders(),
|
|
302
302
|
});
|
|
303
|
-
|
|
304
|
-
|
|
303
|
+
this.debugWarnLog(`body: ${JSON.stringify(body)}`);
|
|
304
|
+
this.debugWarnLog(`body: ${JSON.stringify(statusCode)}`);
|
|
305
|
+
this.debugWarnLog(`body: ${JSON.stringify(headers)}`);
|
|
306
|
+
const devicesAPI: any = await body.json();
|
|
307
|
+
if (statusCode === 200 && devicesAPI.statusCode === 200) {
|
|
305
308
|
this.debugLog(`Devices: ${JSON.stringify(devicesAPI.body)}`);
|
|
306
|
-
this.debugLog(`Headers: ${JSON.stringify(headers)}`);
|
|
307
309
|
// SwitchBot Devices
|
|
310
|
+
this.debugWarnLog(`devicesAPI: ${JSON.stringify(devicesAPI)}`);
|
|
311
|
+
this.debugWarnLog(`devicesAPI Length: ${devicesAPI.length}`);
|
|
308
312
|
const deviceLists = devicesAPI.body.deviceList;
|
|
313
|
+
this.debugWarnLog(`DeviceLists: ${JSON.stringify(deviceLists)}`);
|
|
314
|
+
this.debugWarnLog(`DeviceLists Length: ${deviceLists.length}`);
|
|
309
315
|
if (!this.config.options?.devices) {
|
|
310
316
|
this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
311
317
|
if (deviceLists.length === 0) {
|
|
@@ -323,25 +329,29 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
323
329
|
}
|
|
324
330
|
} else if (this.config.credentials?.token && this.config.options.devices) {
|
|
325
331
|
this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
332
|
+
if (deviceLists.length === 0) {
|
|
333
|
+
this.debugLog(`SwitchBot API Currently Doesn't Have Any Devices With Cloud Services Enabled: ${JSON.stringify(devicesAPI.body)}`);
|
|
334
|
+
} else {
|
|
335
|
+
const deviceConfigs = this.config.options?.devices;
|
|
336
|
+
|
|
337
|
+
const mergeBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
|
|
338
|
+
a1.map((itm: { deviceId: string }) => ({
|
|
339
|
+
...a2.find(
|
|
340
|
+
(item: { deviceId: string }) =>
|
|
341
|
+
item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
|
|
342
|
+
),
|
|
343
|
+
...itm,
|
|
344
|
+
}));
|
|
345
|
+
|
|
346
|
+
const devices = mergeBydeviceId(deviceLists, deviceConfigs);
|
|
347
|
+
this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
|
|
348
|
+
for (const device of devices) {
|
|
349
|
+
if (device.deviceType) {
|
|
350
|
+
if (device.configDeviceName) {
|
|
351
|
+
device.deviceName = device.configDeviceName;
|
|
352
|
+
}
|
|
353
|
+
this.createDevice(device);
|
|
343
354
|
}
|
|
344
|
-
this.createDevice(device);
|
|
345
355
|
}
|
|
346
356
|
}
|
|
347
357
|
} else {
|
|
@@ -389,6 +399,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
389
399
|
}
|
|
390
400
|
} else {
|
|
391
401
|
this.statusCode(statusCode);
|
|
402
|
+
this.statusCode(devicesAPI.statusCode);
|
|
392
403
|
}
|
|
393
404
|
} catch (e: any) {
|
|
394
405
|
this.debugErrorLog(
|