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