@switchbot/homebridge-switchbot 3.7.1-beta.2 → 3.7.1-beta.21
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 +10 -0
- package/README.md +14 -0
- package/assets/security-privacy-bluetooth.png +0 -0
- package/config.schema.json +74 -2
- package/dist/device/blindtilt.d.ts +21 -9
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +167 -96
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot-old.d.ts +132 -0
- package/dist/device/bot-old.d.ts.map +1 -0
- package/dist/device/bot-old.js +1482 -0
- package/dist/device/bot-old.js.map +1 -0
- package/dist/device/bot.d.ts +10 -9
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +186 -187
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +14 -13
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +87 -97
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +13 -12
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +92 -105
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +6 -5
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +71 -68
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +17 -5
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +184 -118
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +18 -18
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +33 -36
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +9 -8
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +94 -101
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +6 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +69 -65
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +6 -5
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +89 -104
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +6 -5
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +72 -66
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +7 -6
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +85 -99
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +10 -9
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +89 -79
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +6 -5
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +72 -65
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +6 -5
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +72 -64
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +6 -5
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +65 -58
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +13 -12
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +68 -52
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +12 -11
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +93 -82
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +6 -5
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +73 -63
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/server.js +2 -2
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -8
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +61 -105
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +10 -10
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +22 -42
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +9 -9
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +15 -25
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +8 -8
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +21 -40
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +11 -11
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +14 -22
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +9 -9
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +24 -47
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +9 -9
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +40 -83
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +9 -9
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +29 -54
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +5 -5
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +11 -21
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +5 -5
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +11 -22
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +24 -23
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +509 -723
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +5 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +9 -9
- package/dist/types/bledevicestatus.d.ts.map +1 -1
- package/dist/types/devicelist.d.ts +6 -6
- package/dist/types/devicelist.d.ts.map +1 -1
- package/dist/types/deviceresponse.d.ts +4 -4
- package/dist/types/deviceresponse.d.ts.map +1 -1
- package/dist/types/devicestatus.d.ts +2 -2
- package/dist/types/devicestatus.d.ts.map +1 -1
- package/dist/types/devicewebhookstatus.d.ts +5 -5
- package/dist/types/devicewebhookstatus.d.ts.map +1 -1
- package/dist/types/irdevicelist.d.ts +4 -4
- package/dist/types/irdevicelist.d.ts.map +1 -1
- package/dist/types/pushbody.d.ts +2 -2
- package/dist/types/pushbody.d.ts.map +1 -1
- package/dist/utils.d.ts +4 -4
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +9 -13
- package/dist/utils.js.map +1 -1
- package/eslint.config.js +48 -93
- package/package.json +64 -57
- package/src/device/blindtilt.ts +537 -456
- package/src/device/bot-old.ts +1540 -0
- package/src/device/bot.ts +732 -725
- package/src/device/ceilinglight.ts +359 -368
- package/src/device/colorbulb.ts +441 -453
- package/src/device/contact.ts +229 -226
- package/src/device/curtain.ts +526 -444
- package/src/device/device.ts +206 -208
- package/src/device/fan.ts +336 -345
- package/src/device/hub.ts +213 -214
- package/src/device/humidifier.ts +326 -347
- package/src/device/iosensor.ts +211 -209
- package/src/device/lightstrip.ts +391 -404
- package/src/device/lock.ts +292 -282
- package/src/device/meter.ts +212 -210
- package/src/device/meterplus.ts +212 -209
- package/src/device/motion.ts +198 -190
- package/src/device/plug.ts +203 -182
- package/src/device/robotvacuumcleaner.ts +280 -269
- package/src/device/waterdetector.ts +198 -189
- package/src/homebridge-ui/server.ts +16 -15
- package/src/index.ts +5 -6
- package/src/irdevice/airconditioner.ts +277 -326
- package/src/irdevice/airpurifier.ts +124 -143
- package/src/irdevice/camera.ts +58 -64
- package/src/irdevice/fan.ts +106 -123
- package/src/irdevice/irdevice.ts +116 -119
- package/src/irdevice/light.ts +119 -143
- package/src/irdevice/other.ts +417 -461
- package/src/irdevice/tv.ts +155 -177
- package/src/irdevice/vacuumcleaner.ts +54 -60
- package/src/irdevice/waterheater.ts +56 -63
- package/src/platform.ts +1491 -1681
- package/src/settings.ts +172 -169
- package/src/types/bledevicestatus.ts +252 -256
- package/src/types/devicelist.ts +79 -79
- package/src/types/deviceresponse.ts +12 -13
- package/src/types/devicestatus.ts +124 -124
- package/src/types/devicewebhookstatus.ts +126 -131
- package/src/types/irdevicelist.ts +10 -10
- package/src/types/pushbody.ts +5 -5
- package/src/utils.ts +64 -65
- package/tsconfig.json +10 -9
|
@@ -2,245 +2,254 @@
|
|
|
2
2
|
*
|
|
3
3
|
* robotvacuumcleaner.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
import type {
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type {
|
|
12
|
-
import type { robotVacuumCleanerServiceData } from '../types/bledevicestatus.js';
|
|
13
|
-
import type { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
14
|
-
import type { robotVacuumCleanerS1Status, robotVacuumCleanerS1PlusStatus, floorCleaningRobotS10Status } from '../types/devicestatus.js';
|
|
5
|
+
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
|
|
7
|
+
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
|
+
import type { devicesConfig } from '../settings.js'
|
|
9
|
+
import type { robotVacuumCleanerServiceData } from '../types/bledevicestatus.js'
|
|
10
|
+
import type { device } from '../types/devicelist.js'
|
|
11
|
+
import type { floorCleaningRobotS10Status, robotVacuumCleanerS1PlusStatus, robotVacuumCleanerS1Status } from '../types/devicestatus.js'
|
|
15
12
|
import type {
|
|
16
13
|
floorCleaningRobotS10WebhookContext,
|
|
17
14
|
robotVacuumCleanerS1PlusWebhookContext,
|
|
18
15
|
robotVacuumCleanerS1WebhookContext,
|
|
19
|
-
} from '../types/devicewebhookstatus.js'
|
|
16
|
+
} from '../types/devicewebhookstatus.js'
|
|
17
|
+
|
|
18
|
+
/*
|
|
19
|
+
* For Testing Locally:
|
|
20
|
+
* import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
21
|
+
*/
|
|
22
|
+
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
|
|
23
|
+
import { debounceTime, interval, skipWhile, Subject, take, tap } from 'rxjs'
|
|
24
|
+
|
|
25
|
+
import { deviceBase } from './device.js'
|
|
20
26
|
|
|
21
27
|
export class RobotVacuumCleaner extends deviceBase {
|
|
22
28
|
// Services
|
|
23
29
|
private LightBulb: {
|
|
24
|
-
Name: CharacteristicValue
|
|
25
|
-
Service: Service
|
|
26
|
-
On: CharacteristicValue
|
|
27
|
-
Brightness: CharacteristicValue
|
|
28
|
-
}
|
|
30
|
+
Name: CharacteristicValue
|
|
31
|
+
Service: Service
|
|
32
|
+
On: CharacteristicValue
|
|
33
|
+
Brightness: CharacteristicValue
|
|
34
|
+
}
|
|
29
35
|
|
|
30
36
|
private Battery: {
|
|
31
|
-
Name: CharacteristicValue
|
|
32
|
-
Service: Service
|
|
33
|
-
BatteryLevel: CharacteristicValue
|
|
34
|
-
StatusLowBattery: CharacteristicValue
|
|
35
|
-
ChargingState: CharacteristicValue
|
|
36
|
-
}
|
|
37
|
+
Name: CharacteristicValue
|
|
38
|
+
Service: Service
|
|
39
|
+
BatteryLevel: CharacteristicValue
|
|
40
|
+
StatusLowBattery: CharacteristicValue
|
|
41
|
+
ChargingState: CharacteristicValue
|
|
42
|
+
}
|
|
37
43
|
|
|
38
44
|
// OpenAPI
|
|
39
|
-
deviceStatus!: robotVacuumCleanerS1Status | robotVacuumCleanerS1PlusStatus | floorCleaningRobotS10Status
|
|
45
|
+
deviceStatus!: robotVacuumCleanerS1Status | robotVacuumCleanerS1PlusStatus | floorCleaningRobotS10Status
|
|
40
46
|
|
|
41
|
-
//Webhook
|
|
42
|
-
webhookContext!: robotVacuumCleanerS1WebhookContext | robotVacuumCleanerS1PlusWebhookContext | floorCleaningRobotS10WebhookContext
|
|
47
|
+
// Webhook
|
|
48
|
+
webhookContext!: robotVacuumCleanerS1WebhookContext | robotVacuumCleanerS1PlusWebhookContext | floorCleaningRobotS10WebhookContext
|
|
43
49
|
|
|
44
50
|
// BLE
|
|
45
|
-
serviceData!: robotVacuumCleanerServiceData
|
|
51
|
+
serviceData!: robotVacuumCleanerServiceData
|
|
46
52
|
|
|
47
53
|
// Updates
|
|
48
|
-
robotVacuumCleanerUpdateInProgress!: boolean
|
|
49
|
-
doRobotVacuumCleanerUpdate!: Subject<void
|
|
54
|
+
robotVacuumCleanerUpdateInProgress!: boolean
|
|
55
|
+
doRobotVacuumCleanerUpdate!: Subject<void>
|
|
50
56
|
|
|
51
57
|
constructor(
|
|
52
58
|
readonly platform: SwitchBotPlatform,
|
|
53
59
|
accessory: PlatformAccessory,
|
|
54
60
|
device: device & devicesConfig,
|
|
55
61
|
) {
|
|
56
|
-
super(platform, accessory, device)
|
|
62
|
+
super(platform, accessory, device)
|
|
57
63
|
// Set category
|
|
58
|
-
accessory.category = this.hap.Categories.OTHER
|
|
64
|
+
accessory.category = this.hap.Categories.OTHER
|
|
59
65
|
|
|
60
66
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
61
|
-
this.doRobotVacuumCleanerUpdate = new Subject()
|
|
62
|
-
this.robotVacuumCleanerUpdateInProgress = false
|
|
67
|
+
this.doRobotVacuumCleanerUpdate = new Subject()
|
|
68
|
+
this.robotVacuumCleanerUpdateInProgress = false
|
|
63
69
|
|
|
64
70
|
// Initialize Lightbulb Service
|
|
65
|
-
accessory.context.LightBulb = accessory.context.LightBulb ?? {}
|
|
71
|
+
accessory.context.LightBulb = accessory.context.LightBulb ?? {}
|
|
66
72
|
this.LightBulb = {
|
|
67
73
|
Name: accessory.displayName,
|
|
68
74
|
Service: accessory.getService(this.hap.Service.Lightbulb) ?? accessory.addService(this.hap.Service.Lightbulb) as Service,
|
|
69
75
|
On: accessory.context.On ?? false,
|
|
70
76
|
Brightness: accessory.context.Brightness ?? 0,
|
|
71
|
-
}
|
|
72
|
-
accessory.context.LightBulb = this.LightBulb as object
|
|
77
|
+
}
|
|
78
|
+
accessory.context.LightBulb = this.LightBulb as object
|
|
73
79
|
|
|
74
80
|
// Initialize LightBulb Characteristics
|
|
75
|
-
this.LightBulb.Service
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
.onGet(() => {
|
|
79
|
-
return this.LightBulb.On;
|
|
80
|
-
})
|
|
81
|
-
.onSet(this.OnSet.bind(this));
|
|
81
|
+
this.LightBulb.Service.setCharacteristic(this.hap.Characteristic.Name, this.LightBulb.Name).getCharacteristic(this.hap.Characteristic.On).onGet(() => {
|
|
82
|
+
return this.LightBulb.On
|
|
83
|
+
}).onSet(this.OnSet.bind(this))
|
|
82
84
|
|
|
83
85
|
// Initialize LightBulb Brightness Characteristic
|
|
84
|
-
this.LightBulb.Service
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
.onGet(() => {
|
|
94
|
-
return this.LightBulb.Brightness;
|
|
95
|
-
})
|
|
96
|
-
.onSet(this.BrightnessSet.bind(this));
|
|
86
|
+
this.LightBulb.Service.getCharacteristic(this.hap.Characteristic.Brightness).setProps({
|
|
87
|
+
minStep: 25,
|
|
88
|
+
minValue: 0,
|
|
89
|
+
maxValue: 100,
|
|
90
|
+
validValues: [0, 25, 50, 75, 100],
|
|
91
|
+
validValueRanges: [0, 100],
|
|
92
|
+
}).onGet(() => {
|
|
93
|
+
return this.LightBulb.Brightness
|
|
94
|
+
}).onSet(this.BrightnessSet.bind(this))
|
|
97
95
|
|
|
98
96
|
// Initialize Battery Service
|
|
99
|
-
accessory.context.Battery = accessory.context.Battery ?? {}
|
|
97
|
+
accessory.context.Battery = accessory.context.Battery ?? {}
|
|
100
98
|
this.Battery = {
|
|
101
99
|
Name: `${accessory.displayName} Battery`,
|
|
102
100
|
Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
|
|
103
101
|
BatteryLevel: accessory.context.BatteryLevel ?? 100,
|
|
104
102
|
StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
|
|
105
103
|
ChargingState: accessory.context.ChargingState ?? this.hap.Characteristic.ChargingState.NOT_CHARGING,
|
|
106
|
-
}
|
|
107
|
-
accessory.context.Battery = this.Battery as object
|
|
104
|
+
}
|
|
105
|
+
accessory.context.Battery = this.Battery as object
|
|
108
106
|
|
|
109
107
|
// Initialize Battery Characteristics
|
|
110
|
-
this.Battery.Service
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
.
|
|
120
|
-
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
this.Battery.Service
|
|
124
|
-
.getCharacteristic(this.hap.Characteristic.ChargingState)
|
|
125
|
-
.onGet(() => {
|
|
126
|
-
return this.Battery.ChargingState;
|
|
127
|
-
});
|
|
108
|
+
this.Battery.Service.setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name).getCharacteristic(this.hap.Characteristic.BatteryLevel).onGet(() => {
|
|
109
|
+
return this.Battery.BatteryLevel
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
this.Battery.Service.getCharacteristic(this.hap.Characteristic.StatusLowBattery).onGet(() => {
|
|
113
|
+
return this.Battery.StatusLowBattery
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
this.Battery.Service.getCharacteristic(this.hap.Characteristic.ChargingState).onGet(() => {
|
|
117
|
+
return this.Battery.ChargingState
|
|
118
|
+
})
|
|
128
119
|
|
|
129
120
|
// Retrieve initial values and updateHomekit
|
|
130
|
-
|
|
131
|
-
|
|
121
|
+
try {
|
|
122
|
+
this.debugLog('Retrieve initial values and update Homekit')
|
|
123
|
+
this.refreshStatus()
|
|
124
|
+
} catch (e: any) {
|
|
125
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
126
|
+
}
|
|
132
127
|
|
|
133
|
-
//regisiter webhook event handler
|
|
134
|
-
|
|
135
|
-
|
|
128
|
+
// regisiter webhook event handler if enabled
|
|
129
|
+
try {
|
|
130
|
+
this.debugLog('Registering Webhook Event Handler')
|
|
131
|
+
this.registerWebhook()
|
|
132
|
+
} catch (e: any) {
|
|
133
|
+
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// regisiter platform BLE event handler if enabled
|
|
137
|
+
try {
|
|
138
|
+
this.debugLog('Registering Platform BLE Event Handler')
|
|
139
|
+
this.registerPlatformBLE()
|
|
140
|
+
} catch (e: any) {
|
|
141
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
142
|
+
}
|
|
136
143
|
|
|
137
144
|
// Start an update interval
|
|
138
145
|
interval(this.deviceRefreshRate * 1000)
|
|
139
146
|
.pipe(skipWhile(() => this.robotVacuumCleanerUpdateInProgress))
|
|
140
147
|
.subscribe(async () => {
|
|
141
|
-
await this.refreshStatus()
|
|
142
|
-
})
|
|
148
|
+
await this.refreshStatus()
|
|
149
|
+
})
|
|
143
150
|
|
|
144
151
|
// Watch for Plug change events
|
|
145
152
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
146
153
|
this.doRobotVacuumCleanerUpdate
|
|
147
154
|
.pipe(
|
|
148
155
|
tap(() => {
|
|
149
|
-
this.robotVacuumCleanerUpdateInProgress = true
|
|
156
|
+
this.robotVacuumCleanerUpdateInProgress = true
|
|
150
157
|
}),
|
|
151
158
|
debounceTime(this.devicePushRate * 1000),
|
|
152
159
|
)
|
|
153
160
|
.subscribe(async () => {
|
|
154
161
|
try {
|
|
155
|
-
await this.pushChanges()
|
|
162
|
+
await this.pushChanges()
|
|
156
163
|
} catch (e: any) {
|
|
157
|
-
await this.apiError(e)
|
|
158
|
-
await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
164
|
+
await this.apiError(e)
|
|
165
|
+
await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
159
166
|
}
|
|
160
|
-
this.robotVacuumCleanerUpdateInProgress = false
|
|
161
|
-
})
|
|
167
|
+
this.robotVacuumCleanerUpdateInProgress = false
|
|
168
|
+
})
|
|
162
169
|
}
|
|
163
170
|
|
|
164
171
|
async BLEparseStatus(): Promise<void> {
|
|
165
|
-
await this.debugLog('BLEparseStatus')
|
|
166
|
-
await this.debugLog(`(state, battery) = BLE: (${this.serviceData.state}, ${this.serviceData.battery})
|
|
167
|
-
+ ` current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel})`);
|
|
172
|
+
await this.debugLog('BLEparseStatus')
|
|
173
|
+
await this.debugLog(`(state, battery) = BLE: (${this.serviceData.state}, ${this.serviceData.battery}), current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel})`)
|
|
168
174
|
|
|
169
175
|
// On
|
|
170
|
-
this.LightBulb.On = this.
|
|
171
|
-
await this.debugLog(`On: ${this.LightBulb.On}`)
|
|
176
|
+
this.LightBulb.On = !!['InDustCollecting', 'Clearing'].includes(this.deviceStatus.workingStatus)
|
|
177
|
+
await this.debugLog(`On: ${this.LightBulb.On}`)
|
|
172
178
|
|
|
173
179
|
// BatteryLevel
|
|
174
|
-
this.Battery.BatteryLevel = this.serviceData.battery
|
|
175
|
-
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
180
|
+
this.Battery.BatteryLevel = this.serviceData.battery
|
|
181
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
176
182
|
|
|
177
183
|
// StatusLowBattery
|
|
178
184
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
179
|
-
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
180
|
-
|
|
185
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
186
|
+
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
187
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
181
188
|
}
|
|
182
189
|
|
|
183
190
|
async openAPIparseStatus() {
|
|
184
|
-
await this.debugLog('openAPIparseStatus')
|
|
185
|
-
await this.debugLog(`(onlineStatus, battery, workingStatus) = API: (${this.deviceStatus.onlineStatus}, ${this.deviceStatus.battery}
|
|
186
|
-
+ ` ${this.deviceStatus.workingStatus}), current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel}, ${this.Battery.ChargingState})`);
|
|
191
|
+
await this.debugLog('openAPIparseStatus')
|
|
192
|
+
await this.debugLog(`(onlineStatus, battery, workingStatus) = API: (${this.deviceStatus.onlineStatus}, ${this.deviceStatus.battery}, ${this.deviceStatus.workingStatus}), current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel}, ${this.Battery.ChargingState})`)
|
|
187
193
|
|
|
188
194
|
// On
|
|
189
|
-
this.LightBulb.On = this.deviceStatus.onlineStatus === 'online'
|
|
190
|
-
await this.debugLog(`On: ${this.LightBulb.On}`)
|
|
195
|
+
this.LightBulb.On = this.deviceStatus.onlineStatus === 'online'
|
|
196
|
+
await this.debugLog(`On: ${this.LightBulb.On}`)
|
|
191
197
|
|
|
192
198
|
// BatteryLevel
|
|
193
|
-
this.Battery.BatteryLevel = this.deviceStatus.battery
|
|
194
|
-
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
199
|
+
this.Battery.BatteryLevel = this.deviceStatus.battery
|
|
200
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
195
201
|
|
|
196
202
|
// StatusLowBattery
|
|
197
203
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
198
|
-
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
199
|
-
|
|
204
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
205
|
+
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
206
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
200
207
|
|
|
201
208
|
// ChargingState
|
|
202
209
|
this.Battery.ChargingState = this.deviceStatus.workingStatus === 'Charging'
|
|
203
|
-
? this.hap.Characteristic.ChargingState.CHARGING
|
|
204
|
-
|
|
210
|
+
? this.hap.Characteristic.ChargingState.CHARGING
|
|
211
|
+
: this.hap.Characteristic.ChargingState.NOT_CHARGING
|
|
212
|
+
await this.debugLog(`ChargingState: ${this.Battery.ChargingState}`)
|
|
205
213
|
|
|
206
214
|
// Firmware Version
|
|
207
215
|
if (this.deviceStatus.version) {
|
|
208
|
-
const version = this.deviceStatus.version.toString()
|
|
209
|
-
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
210
|
-
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
216
|
+
const version = this.deviceStatus.version.toString()
|
|
217
|
+
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
218
|
+
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
211
219
|
this.accessory
|
|
212
220
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
213
221
|
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
214
222
|
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
|
|
215
223
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
216
|
-
.updateValue(deviceVersion)
|
|
217
|
-
this.accessory.context.version = deviceVersion
|
|
218
|
-
await this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
224
|
+
.updateValue(deviceVersion)
|
|
225
|
+
this.accessory.context.version = deviceVersion
|
|
226
|
+
await this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
219
227
|
}
|
|
220
228
|
}
|
|
221
229
|
|
|
222
230
|
async parseStatusWebhook(): Promise<void> {
|
|
223
|
-
await this.debugLog('parseStatusWebhook')
|
|
224
|
-
await this.debugLog(`(onlineStatus, battery, workingStatus) = Webhook: (${this.webhookContext.onlineStatus}, ${this.webhookContext.battery}
|
|
225
|
-
+ ` ${this.webhookContext.workingStatus}), current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel}, ${this.Battery.ChargingState})`);
|
|
231
|
+
await this.debugLog('parseStatusWebhook')
|
|
232
|
+
await this.debugLog(`(onlineStatus, battery, workingStatus) = Webhook: (${this.webhookContext.onlineStatus}, ${this.webhookContext.battery}, ${this.webhookContext.workingStatus}), current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel}, ${this.Battery.ChargingState})`)
|
|
226
233
|
|
|
227
234
|
// On
|
|
228
|
-
this.LightBulb.On = this.webhookContext.onlineStatus === 'online'
|
|
229
|
-
await this.debugLog(`On: ${this.LightBulb.On}`)
|
|
235
|
+
this.LightBulb.On = this.webhookContext.onlineStatus === 'online'
|
|
236
|
+
await this.debugLog(`On: ${this.LightBulb.On}`)
|
|
230
237
|
|
|
231
238
|
// BatteryLevel
|
|
232
|
-
this.Battery.BatteryLevel = this.webhookContext.battery
|
|
233
|
-
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
239
|
+
this.Battery.BatteryLevel = this.webhookContext.battery
|
|
240
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
234
241
|
|
|
235
242
|
// StatusLowBattery
|
|
236
243
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
237
|
-
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
238
|
-
|
|
244
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
245
|
+
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
246
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
239
247
|
|
|
240
248
|
// ChargingState
|
|
241
249
|
this.Battery.ChargingState = this.webhookContext.workingStatus === 'Charging'
|
|
242
|
-
? this.hap.Characteristic.ChargingState.CHARGING
|
|
243
|
-
|
|
250
|
+
? this.hap.Characteristic.ChargingState.CHARGING
|
|
251
|
+
: this.hap.Characteristic.ChargingState.NOT_CHARGING
|
|
252
|
+
await this.debugLog(`ChargingState: ${this.Battery.ChargingState}`)
|
|
244
253
|
}
|
|
245
254
|
|
|
246
255
|
/**
|
|
@@ -248,224 +257,231 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
248
257
|
*/
|
|
249
258
|
async refreshStatus(): Promise<void> {
|
|
250
259
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
251
|
-
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
252
|
-
} else if (this.BLE
|
|
253
|
-
await this.BLERefreshStatus()
|
|
260
|
+
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
261
|
+
} else if (this.BLE) {
|
|
262
|
+
await this.BLERefreshStatus()
|
|
254
263
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
255
|
-
await this.openAPIRefreshStatus()
|
|
264
|
+
await this.openAPIRefreshStatus()
|
|
256
265
|
} else {
|
|
257
|
-
await this.offlineOff()
|
|
258
|
-
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
266
|
+
await this.offlineOff()
|
|
267
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
259
268
|
}
|
|
260
269
|
}
|
|
261
270
|
|
|
262
271
|
async BLERefreshStatus(): Promise<void> {
|
|
263
|
-
await this.debugLog('BLERefreshStatus')
|
|
272
|
+
await this.debugLog('BLERefreshStatus')
|
|
273
|
+
const switchbot = await this.switchbotBLE()
|
|
274
|
+
if (switchbot === undefined) {
|
|
275
|
+
await this.BLERefreshConnection(switchbot)
|
|
276
|
+
} else {
|
|
277
|
+
// Start to monitor advertisement packets
|
|
278
|
+
(async () => {
|
|
279
|
+
// Start to monitor advertisement packets
|
|
280
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as unknown as robotVacuumCleanerServiceData
|
|
281
|
+
// Update HomeKit
|
|
282
|
+
if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
|
|
283
|
+
this.serviceData = serviceData
|
|
284
|
+
await this.BLEparseStatus()
|
|
285
|
+
await this.updateHomeKitCharacteristics()
|
|
286
|
+
} else {
|
|
287
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
288
|
+
await this.BLERefreshConnection(switchbot)
|
|
289
|
+
}
|
|
290
|
+
})()
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
async registerPlatformBLE(): Promise<void> {
|
|
295
|
+
await this.debugLog('registerPlatformBLE')
|
|
264
296
|
if (this.config.options?.BLE) {
|
|
265
|
-
await this.debugLog('is listening to Platform BLE.')
|
|
266
|
-
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase()
|
|
267
|
-
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
297
|
+
await this.debugLog('is listening to Platform BLE.')
|
|
298
|
+
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase()
|
|
299
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
268
300
|
this.platform.bleEventHandler[this.device.bleMac] = async (context: robotVacuumCleanerServiceData) => {
|
|
269
301
|
try {
|
|
270
|
-
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
271
|
-
this.serviceData = context
|
|
272
|
-
await this.BLEparseStatus()
|
|
273
|
-
await this.updateHomeKitCharacteristics()
|
|
302
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
303
|
+
this.serviceData = context
|
|
304
|
+
await this.BLEparseStatus()
|
|
305
|
+
await this.updateHomeKitCharacteristics()
|
|
274
306
|
} catch (e: any) {
|
|
275
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
307
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
276
308
|
}
|
|
277
|
-
};
|
|
278
|
-
} else {
|
|
279
|
-
await this.debugLog('is using Device BLE Scanning.');
|
|
280
|
-
const switchbot = await this.switchbotBLE();
|
|
281
|
-
if (switchbot === undefined) {
|
|
282
|
-
await this.BLERefreshConnection(switchbot);
|
|
283
|
-
} else {
|
|
284
|
-
// Start to monitor advertisement packets
|
|
285
|
-
(async () => {
|
|
286
|
-
// Start to monitor advertisement packets
|
|
287
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as unknown as robotVacuumCleanerServiceData;
|
|
288
|
-
// Update HomeKit
|
|
289
|
-
if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
|
|
290
|
-
this.serviceData = serviceData;
|
|
291
|
-
await this.BLEparseStatus();
|
|
292
|
-
await this.updateHomeKitCharacteristics();
|
|
293
|
-
} else {
|
|
294
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
295
|
-
await this.BLERefreshConnection(switchbot);
|
|
296
|
-
}
|
|
297
|
-
})();
|
|
298
309
|
}
|
|
310
|
+
} else {
|
|
311
|
+
await this.debugLog('is not listening to Platform BLE')
|
|
299
312
|
}
|
|
300
313
|
}
|
|
301
314
|
|
|
302
315
|
async openAPIRefreshStatus(): Promise<void> {
|
|
303
|
-
await this.debugLog('openAPIRefreshStatus')
|
|
316
|
+
await this.debugLog('openAPIRefreshStatus')
|
|
304
317
|
try {
|
|
305
|
-
const { body, statusCode } = await this.deviceRefreshStatus()
|
|
306
|
-
const deviceStatus: any = await body.json()
|
|
307
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
318
|
+
const { body, statusCode } = await this.deviceRefreshStatus()
|
|
319
|
+
const deviceStatus: any = await body.json()
|
|
320
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
308
321
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
309
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
310
|
-
this.deviceStatus = deviceStatus.body
|
|
311
|
-
await this.openAPIparseStatus()
|
|
312
|
-
await this.updateHomeKitCharacteristics()
|
|
322
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
323
|
+
this.deviceStatus = deviceStatus.body
|
|
324
|
+
await this.openAPIparseStatus()
|
|
325
|
+
await this.updateHomeKitCharacteristics()
|
|
313
326
|
} else {
|
|
314
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
315
|
-
await this.debugWarnLog(statusCode, deviceStatus)
|
|
327
|
+
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
328
|
+
await this.debugWarnLog(statusCode, deviceStatus)
|
|
316
329
|
}
|
|
317
330
|
} catch (e: any) {
|
|
318
|
-
await this.apiError(e)
|
|
319
|
-
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
331
|
+
await this.apiError(e)
|
|
332
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
320
333
|
}
|
|
321
334
|
}
|
|
322
335
|
|
|
323
336
|
async registerWebhook() {
|
|
324
337
|
if (this.device.webhook) {
|
|
325
|
-
await this.debugLog('is listening webhook.')
|
|
326
|
-
this.platform.webhookEventHandler[this.device.deviceId] = async (context: robotVacuumCleanerS1WebhookContext
|
|
327
|
-
| robotVacuumCleanerS1PlusWebhookContext | floorCleaningRobotS10WebhookContext) => {
|
|
338
|
+
await this.debugLog('is listening webhook.')
|
|
339
|
+
this.platform.webhookEventHandler[this.device.deviceId] = async (context: robotVacuumCleanerS1WebhookContext | robotVacuumCleanerS1PlusWebhookContext | floorCleaningRobotS10WebhookContext) => {
|
|
328
340
|
try {
|
|
329
|
-
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
330
|
-
this.webhookContext = context
|
|
331
|
-
await this.parseStatusWebhook()
|
|
332
|
-
await this.updateHomeKitCharacteristics()
|
|
341
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
342
|
+
this.webhookContext = context
|
|
343
|
+
await this.parseStatusWebhook()
|
|
344
|
+
await this.updateHomeKitCharacteristics()
|
|
333
345
|
} catch (e: any) {
|
|
334
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
346
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
335
347
|
}
|
|
336
|
-
}
|
|
348
|
+
}
|
|
337
349
|
} else {
|
|
338
|
-
await this.debugLog('is not listening webhook.')
|
|
350
|
+
await this.debugLog('is not listening webhook.')
|
|
339
351
|
}
|
|
340
352
|
}
|
|
341
353
|
|
|
342
354
|
/**
|
|
343
355
|
* Pushes the requested changes to the SwitchBot API
|
|
344
|
-
* deviceType
|
|
345
|
-
* Robot Vacuum Cleaner S1 "command" "start" "default"
|
|
346
|
-
* Robot Vacuum Cleaner S1 "command" "stop" "default"
|
|
347
|
-
* Robot Vacuum Cleaner S1 "command" "dock" "default" =
|
|
348
|
-
* Robot Vacuum Cleaner S1 "command" "PowLevel" "{0-3}" =
|
|
356
|
+
* deviceType commandType Command parameter Description
|
|
357
|
+
* Robot Vacuum Cleaner S1 "command" "start" "default" = start vacuuming
|
|
358
|
+
* Robot Vacuum Cleaner S1 "command" "stop" "default" = stop vacuuming
|
|
359
|
+
* Robot Vacuum Cleaner S1 "command" "dock" "default" = return to charging dock
|
|
360
|
+
* Robot Vacuum Cleaner S1 "command" "PowLevel" "{0-3}" = set suction power level: 0 (Quiet), 1 (Standard), 2 (Strong), 3 (MAX)
|
|
349
361
|
*/
|
|
350
362
|
async pushChanges(): Promise<void> {
|
|
351
363
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
352
|
-
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
|
|
364
|
+
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
|
|
353
365
|
} else if (this.BLE) {
|
|
354
|
-
await this.BLEpushChanges()
|
|
366
|
+
await this.BLEpushChanges()
|
|
355
367
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
356
|
-
await this.openAPIpushChanges()
|
|
368
|
+
await this.openAPIpushChanges()
|
|
357
369
|
} else {
|
|
358
|
-
await this.offlineOff()
|
|
359
|
-
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
|
|
370
|
+
await this.offlineOff()
|
|
371
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
|
|
360
372
|
}
|
|
361
373
|
// Refresh the status from the API
|
|
362
374
|
interval(15000)
|
|
363
375
|
.pipe(skipWhile(() => this.robotVacuumCleanerUpdateInProgress))
|
|
364
376
|
.pipe(take(1))
|
|
365
377
|
.subscribe(async () => {
|
|
366
|
-
await this.refreshStatus()
|
|
367
|
-
})
|
|
378
|
+
await this.refreshStatus()
|
|
379
|
+
})
|
|
368
380
|
}
|
|
369
381
|
|
|
370
382
|
async BLEpushChanges(): Promise<void> {
|
|
371
|
-
await this.debugLog('BLEpushChanges')
|
|
383
|
+
await this.debugLog('BLEpushChanges')
|
|
372
384
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
373
|
-
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
374
|
-
await this.convertBLEAddress()
|
|
385
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
386
|
+
await this.convertBLEAddress()
|
|
375
387
|
if (switchbot !== false) {
|
|
376
388
|
switchbot
|
|
377
389
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
378
390
|
.then(async (device_list: any) => {
|
|
379
|
-
await this.infoLog(`On: ${this.LightBulb.On}`)
|
|
391
|
+
await this.infoLog(`On: ${this.LightBulb.On}`)
|
|
380
392
|
return await this.retryBLE({
|
|
381
393
|
max: await this.maxRetryBLE(),
|
|
382
394
|
fn: async () => {
|
|
383
395
|
if (this.LightBulb.On) {
|
|
384
|
-
return await device_list[0].turnOn({ id: this.device.bleMac })
|
|
396
|
+
return await device_list[0].turnOn({ id: this.device.bleMac })
|
|
385
397
|
} else {
|
|
386
|
-
return await device_list[0].turnOff({ id: this.device.bleMac })
|
|
398
|
+
return await device_list[0].turnOff({ id: this.device.bleMac })
|
|
387
399
|
}
|
|
388
400
|
},
|
|
389
|
-
})
|
|
401
|
+
})
|
|
390
402
|
})
|
|
391
403
|
.then(async () => {
|
|
392
|
-
await this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`)
|
|
393
|
-
await this.updateHomeKitCharacteristics()
|
|
404
|
+
await this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`)
|
|
405
|
+
await this.updateHomeKitCharacteristics()
|
|
394
406
|
})
|
|
395
407
|
.catch(async (e: any) => {
|
|
396
|
-
await this.apiError(e)
|
|
397
|
-
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
398
|
-
await this.BLEPushConnection()
|
|
399
|
-
})
|
|
408
|
+
await this.apiError(e)
|
|
409
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
410
|
+
await this.BLEPushConnection()
|
|
411
|
+
})
|
|
400
412
|
} else {
|
|
401
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
402
|
-
await this.BLEPushConnection()
|
|
413
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
414
|
+
await this.BLEPushConnection()
|
|
403
415
|
}
|
|
404
416
|
} else {
|
|
405
|
-
await this.debugLog(`No changes (BLEpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
417
|
+
await this.debugLog(`No changes (BLEpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
406
418
|
}
|
|
407
419
|
}
|
|
408
420
|
|
|
409
421
|
async openAPIpushChanges() {
|
|
410
|
-
await this.debugLog('openAPIpushChanges')
|
|
422
|
+
await this.debugLog('openAPIpushChanges')
|
|
411
423
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
412
|
-
const command = this.LightBulb.On ? 'start' : 'dock'
|
|
424
|
+
const command = this.LightBulb.On ? 'start' : 'dock'
|
|
413
425
|
const bodyChange = JSON.stringify({
|
|
414
426
|
command: `${command}`,
|
|
415
427
|
parameter: 'default',
|
|
416
428
|
commandType: 'command',
|
|
417
|
-
})
|
|
418
|
-
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
429
|
+
})
|
|
430
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
419
431
|
try {
|
|
420
|
-
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
421
|
-
const deviceStatus: any = await body.json()
|
|
422
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
432
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
433
|
+
const deviceStatus: any = await body.json()
|
|
434
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
423
435
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
424
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
425
|
-
await this.updateHomeKitCharacteristics()
|
|
436
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
437
|
+
await this.updateHomeKitCharacteristics()
|
|
426
438
|
} else {
|
|
427
|
-
await this.statusCode(statusCode)
|
|
428
|
-
await this.statusCode(deviceStatus.statusCode)
|
|
439
|
+
await this.statusCode(statusCode)
|
|
440
|
+
await this.statusCode(deviceStatus.statusCode)
|
|
429
441
|
}
|
|
430
442
|
} catch (e: any) {
|
|
431
|
-
await this.apiError(e)
|
|
432
|
-
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
443
|
+
await this.apiError(e)
|
|
444
|
+
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
433
445
|
}
|
|
434
446
|
} else {
|
|
435
|
-
await this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
447
|
+
await this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
436
448
|
}
|
|
437
449
|
}
|
|
438
450
|
|
|
439
451
|
async openAPIpushBrightnessChanges() {
|
|
440
|
-
await this.debugLog('openAPIpushBrightnessChanges')
|
|
452
|
+
await this.debugLog('openAPIpushBrightnessChanges')
|
|
441
453
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
442
|
-
const command = this.LightBulb.Brightness === 0 ? 'dock' : 'PowLevel'
|
|
443
|
-
const parameter = this.LightBulb.Brightness === 25
|
|
444
|
-
? '
|
|
454
|
+
const command = this.LightBulb.Brightness === 0 ? 'dock' : 'PowLevel'
|
|
455
|
+
const parameter = this.LightBulb.Brightness === 25
|
|
456
|
+
? '0'
|
|
457
|
+
: this.LightBulb.Brightness === 50
|
|
458
|
+
? '1'
|
|
459
|
+
: this.LightBulb.Brightness === 75
|
|
460
|
+
? '2'
|
|
461
|
+
: this.LightBulb.Brightness === 100 ? '3' : 'default'
|
|
445
462
|
const bodyChange = JSON.stringify({
|
|
446
463
|
command: `${command}`,
|
|
447
464
|
parameter: `${parameter}`,
|
|
448
465
|
commandType: 'command',
|
|
449
|
-
})
|
|
450
|
-
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
466
|
+
})
|
|
467
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
451
468
|
try {
|
|
452
|
-
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
453
|
-
const deviceStatus: any = await body.json()
|
|
454
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
469
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
470
|
+
const deviceStatus: any = await body.json()
|
|
471
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
455
472
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
456
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
457
|
-
await this.updateHomeKitCharacteristics()
|
|
473
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
474
|
+
await this.updateHomeKitCharacteristics()
|
|
458
475
|
} else {
|
|
459
|
-
await this.statusCode(statusCode)
|
|
460
|
-
await this.statusCode(deviceStatus.statusCode)
|
|
476
|
+
await this.statusCode(statusCode)
|
|
477
|
+
await this.statusCode(deviceStatus.statusCode)
|
|
461
478
|
}
|
|
462
479
|
} catch (e: any) {
|
|
463
|
-
await this.apiError(e)
|
|
464
|
-
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
480
|
+
await this.apiError(e)
|
|
481
|
+
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
465
482
|
}
|
|
466
483
|
} else {
|
|
467
|
-
await this.debugLog(`No changes (openAPIpushBrightnessChanges), Brightness: ${this.LightBulb.Brightness}
|
|
468
|
-
+ ` BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
484
|
+
await this.debugLog(`No changes (openAPIpushBrightnessChanges), Brightness: ${this.LightBulb.Brightness}, BrightnessCached: ${this.accessory.context.Brightness}`)
|
|
469
485
|
}
|
|
470
486
|
}
|
|
471
487
|
|
|
@@ -474,13 +490,13 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
474
490
|
*/
|
|
475
491
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
476
492
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
477
|
-
this.infoLog(`Set On: ${value}`)
|
|
493
|
+
this.infoLog(`Set On: ${value}`)
|
|
478
494
|
} else {
|
|
479
|
-
this.debugLog(`No Changes, On: ${value}`)
|
|
495
|
+
this.debugLog(`No Changes, On: ${value}`)
|
|
480
496
|
}
|
|
481
497
|
|
|
482
|
-
this.LightBulb.On = value
|
|
483
|
-
this.doRobotVacuumCleanerUpdate.next()
|
|
498
|
+
this.LightBulb.On = value
|
|
499
|
+
this.doRobotVacuumCleanerUpdate.next()
|
|
484
500
|
}
|
|
485
501
|
|
|
486
502
|
/**
|
|
@@ -488,59 +504,54 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
488
504
|
*/
|
|
489
505
|
async BrightnessSet(value: CharacteristicValue): Promise<void> {
|
|
490
506
|
if (this.LightBulb.On && (this.LightBulb.Brightness !== this.accessory.context.Brightness)) {
|
|
491
|
-
await this.infoLog(`Set Brightness: ${value}`)
|
|
507
|
+
await this.infoLog(`Set Brightness: ${value}`)
|
|
492
508
|
} else {
|
|
493
509
|
if (this.LightBulb.On) {
|
|
494
|
-
this.debugLog(`No Changes, Brightness: ${value}`)
|
|
510
|
+
this.debugLog(`No Changes, Brightness: ${value}`)
|
|
495
511
|
} else {
|
|
496
|
-
this.debugLog(`Brightness: ${value}, On: ${this.LightBulb.On}`)
|
|
512
|
+
this.debugLog(`Brightness: ${value}, On: ${this.LightBulb.On}`)
|
|
497
513
|
}
|
|
498
514
|
}
|
|
499
515
|
|
|
500
|
-
this.LightBulb.Brightness = value
|
|
501
|
-
this.doRobotVacuumCleanerUpdate.next()
|
|
516
|
+
this.LightBulb.Brightness = value
|
|
517
|
+
this.doRobotVacuumCleanerUpdate.next()
|
|
502
518
|
}
|
|
503
519
|
|
|
504
520
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
505
521
|
// On
|
|
506
|
-
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.On,
|
|
507
|
-
this.LightBulb.On, 'On');
|
|
522
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.On, this.LightBulb.On, 'On')
|
|
508
523
|
// Brightness
|
|
509
|
-
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Brightness,
|
|
510
|
-
this.LightBulb.Brightness, 'Brightness');
|
|
524
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Brightness, this.LightBulb.Brightness, 'Brightness')
|
|
511
525
|
// BatteryLevel
|
|
512
|
-
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.BatteryLevel,
|
|
513
|
-
this.Battery.BatteryLevel, 'BatteryLevel');
|
|
526
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel, 'BatteryLevel')
|
|
514
527
|
// StatusLowBattery
|
|
515
|
-
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.StatusLowBattery,
|
|
516
|
-
this.Battery.StatusLowBattery, 'StatusLowBattery');
|
|
528
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery, 'StatusLowBattery')
|
|
517
529
|
// ChargingState
|
|
518
|
-
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.ChargingState,
|
|
519
|
-
this.Battery.ChargingState, 'ChargingState');
|
|
530
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.ChargingState, this.Battery.ChargingState, 'ChargingState')
|
|
520
531
|
}
|
|
521
532
|
|
|
522
533
|
async BLEPushConnection() {
|
|
523
534
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
524
|
-
await this.warnLog('Using OpenAPI Connection to Push Changes')
|
|
525
|
-
await this.openAPIpushChanges()
|
|
535
|
+
await this.warnLog('Using OpenAPI Connection to Push Changes')
|
|
536
|
+
await this.openAPIpushChanges()
|
|
526
537
|
}
|
|
527
538
|
}
|
|
528
539
|
|
|
529
540
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
530
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
541
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
531
542
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
532
|
-
await this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
533
|
-
await this.openAPIRefreshStatus()
|
|
543
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
544
|
+
await this.openAPIRefreshStatus()
|
|
534
545
|
}
|
|
535
546
|
}
|
|
536
547
|
|
|
537
548
|
async offlineOff(): Promise<void> {
|
|
538
549
|
if (this.device.offline) {
|
|
539
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, false)
|
|
550
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, false)
|
|
540
551
|
}
|
|
541
552
|
}
|
|
542
553
|
|
|
543
554
|
async apiError(e: any): Promise<void> {
|
|
544
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, e)
|
|
555
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, e)
|
|
545
556
|
}
|
|
546
557
|
}
|