@switchbot/homebridge-switchbot 3.5.1-beta.2 → 3.5.1-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/device/blindtilt.d.ts +15 -6
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +203 -255
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -4
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +196 -218
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +9 -4
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +202 -247
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +10 -5
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +329 -378
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +9 -4
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +99 -142
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +19 -7
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +203 -264
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +28 -32
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +186 -225
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +9 -4
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +198 -227
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +9 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +106 -231
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +12 -4
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +192 -232
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +9 -4
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +91 -157
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -5
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +287 -367
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +10 -5
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +171 -216
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +9 -4
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +93 -158
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +9 -4
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +94 -155
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +9 -4
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +84 -142
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -4
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +99 -124
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +9 -6
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +170 -253
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +12 -4
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +102 -128
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +2 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +2 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +2 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +2 -1
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +1 -1
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +2 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +2 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +2 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +2 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +2 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +5 -7
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +51 -34
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +49 -191
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +19 -0
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +279 -0
- package/dist/types/bledevicestatus.d.ts.map +1 -0
- package/dist/types/bledevicestatus.js +2 -0
- package/dist/types/bledevicestatus.js.map +1 -0
- package/dist/types/devicelist.d.ts +89 -0
- package/dist/types/devicelist.d.ts.map +1 -0
- package/dist/types/devicelist.js +6 -0
- package/dist/types/devicelist.js.map +1 -0
- package/dist/types/deviceresponse.d.ts +13 -0
- package/dist/types/deviceresponse.d.ts.map +1 -0
- package/dist/types/deviceresponse.js +2 -0
- package/dist/types/deviceresponse.js.map +1 -0
- package/dist/types/devicestatus.d.ts +149 -0
- package/dist/types/devicestatus.d.ts.map +1 -0
- package/dist/types/devicestatus.js +3 -0
- package/dist/types/devicestatus.js.map +1 -0
- package/dist/types/devicewebhookstatus.d.ts +156 -0
- package/dist/types/devicewebhookstatus.d.ts.map +1 -0
- package/dist/types/devicewebhookstatus.js +2 -0
- package/dist/types/devicewebhookstatus.js.map +1 -0
- package/dist/types/irdevicelist.d.ts +10 -0
- package/dist/types/irdevicelist.d.ts.map +1 -0
- package/dist/types/irdevicelist.js +2 -0
- package/dist/types/irdevicelist.js.map +1 -0
- package/dist/types/pushbody.d.ts +6 -0
- package/dist/types/pushbody.d.ts.map +1 -0
- package/dist/types/pushbody.js +2 -0
- package/dist/types/pushbody.js.map +1 -0
- package/dist/utils.d.ts +25 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +28 -0
- package/dist/utils.js.map +1 -1
- package/package.json +10 -10
- package/src/device/blindtilt.ts +223 -263
- package/src/device/bot.ts +208 -221
- package/src/device/ceilinglight.ts +210 -257
- package/src/device/colorbulb.ts +334 -397
- package/src/device/contact.ts +111 -146
- package/src/device/curtain.ts +220 -283
- package/src/device/device.ts +194 -245
- package/src/device/fan.ts +214 -230
- package/src/device/hub.ts +126 -246
- package/src/device/humidifier.ts +216 -243
- package/src/device/iosensor.ts +114 -166
- package/src/device/lightstrip.ts +302 -377
- package/src/device/lock.ts +187 -221
- package/src/device/meter.ts +116 -177
- package/src/device/meterplus.ts +117 -174
- package/src/device/motion.ts +99 -144
- package/src/device/plug.ts +110 -128
- package/src/device/robotvacuumcleaner.ts +189 -252
- package/src/device/waterdetector.ts +120 -138
- package/src/irdevice/airconditioner.ts +2 -1
- package/src/irdevice/airpurifier.ts +2 -1
- package/src/irdevice/camera.ts +2 -1
- package/src/irdevice/fan.ts +2 -1
- package/src/irdevice/irdevice.ts +3 -2
- package/src/irdevice/light.ts +2 -1
- package/src/irdevice/other.ts +2 -1
- package/src/irdevice/tv.ts +2 -1
- package/src/irdevice/vacuumcleaner.ts +2 -1
- package/src/irdevice/waterheater.ts +2 -1
- package/src/platform.ts +52 -34
- package/src/settings.ts +30 -239
- package/src/types/bledevicestatus.ts +305 -0
- package/src/types/devicelist.ts +124 -0
- package/src/types/deviceresponse.ts +15 -0
- package/src/types/devicestatus.ts +178 -0
- package/src/types/devicewebhookstatus.ts +196 -0
- package/src/types/irdevicelist.ts +15 -0
- package/src/types/pushbody.ts +9 -0
- package/src/utils.ts +33 -0
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* robotvacuumcleaner.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import { deviceBase } from './device.js';
|
|
6
|
-
import {
|
|
7
|
-
import { debounceTime, take, tap } from 'rxjs
|
|
6
|
+
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
7
|
+
import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
|
|
8
8
|
export class RobotVacuumCleaner extends deviceBase {
|
|
9
9
|
platform;
|
|
10
10
|
// Services
|
|
@@ -81,14 +81,14 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
81
81
|
this.refreshStatus();
|
|
82
82
|
// Update Homekit
|
|
83
83
|
this.updateHomeKitCharacteristics();
|
|
84
|
+
//regisiter webhook event handler
|
|
85
|
+
this.registerWebhook();
|
|
84
86
|
// Start an update interval
|
|
85
87
|
interval(this.deviceRefreshRate * 1000)
|
|
86
88
|
.pipe(skipWhile(() => this.robotVacuumCleanerUpdateInProgress))
|
|
87
89
|
.subscribe(async () => {
|
|
88
90
|
await this.refreshStatus();
|
|
89
91
|
});
|
|
90
|
-
//regisiter webhook event handler
|
|
91
|
-
this.registerWebhook(accessory, device);
|
|
92
92
|
// Watch for Plug change events
|
|
93
93
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
94
94
|
this.doRobotVacuumCleanerUpdate
|
|
@@ -100,66 +100,46 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
100
100
|
await this.pushChanges();
|
|
101
101
|
}
|
|
102
102
|
catch (e) {
|
|
103
|
-
this.apiError(e);
|
|
104
|
-
this.errorLog(
|
|
105
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
103
|
+
await this.apiError(e);
|
|
104
|
+
await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
106
105
|
}
|
|
107
106
|
this.robotVacuumCleanerUpdateInProgress = false;
|
|
108
107
|
});
|
|
109
108
|
}
|
|
110
109
|
async BLEparseStatus(serviceData) {
|
|
111
|
-
this.debugLog(
|
|
112
|
-
//
|
|
110
|
+
await this.debugLog('BLEparseStatus');
|
|
111
|
+
// On
|
|
112
|
+
this.LightBulb.On = serviceData.state === 'on' ? true : false;
|
|
113
|
+
await this.debugLog(`On: ${this.LightBulb.On}`);
|
|
114
|
+
// BatteryLevel
|
|
113
115
|
this.Battery.BatteryLevel = Number(serviceData.battery);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}, StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
121
|
-
// State
|
|
122
|
-
switch (serviceData.state) {
|
|
123
|
-
case 'on':
|
|
124
|
-
this.LightBulb.On = true;
|
|
125
|
-
break;
|
|
126
|
-
default:
|
|
127
|
-
this.LightBulb.On = false;
|
|
128
|
-
}
|
|
129
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
|
|
116
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
117
|
+
// StatusLowBattery
|
|
118
|
+
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
119
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
120
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
130
121
|
}
|
|
131
122
|
async openAPIparseStatus(deviceStatus) {
|
|
132
|
-
this.debugLog(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
break;
|
|
137
|
-
default:
|
|
138
|
-
this.LightBulb.On = false;
|
|
139
|
-
}
|
|
140
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
|
|
123
|
+
await this.debugLog('openAPIparseStatus');
|
|
124
|
+
// On
|
|
125
|
+
this.LightBulb.On = deviceStatus.onlineStatus === 'online' ? true : false;
|
|
126
|
+
await this.debugLog(`On: ${this.LightBulb.On}`);
|
|
141
127
|
// BatteryLevel
|
|
142
|
-
this.Battery.BatteryLevel = Number(deviceStatus.
|
|
128
|
+
this.Battery.BatteryLevel = Number(deviceStatus.battery);
|
|
129
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
143
130
|
// StatusLowBattery
|
|
144
|
-
|
|
145
|
-
this.
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
149
|
-
}
|
|
150
|
-
if (Number.isNaN(this.Battery.BatteryLevel)) {
|
|
151
|
-
this.Battery.BatteryLevel = 100;
|
|
152
|
-
}
|
|
131
|
+
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
132
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
133
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
153
134
|
// ChargingState
|
|
154
|
-
this.Battery.ChargingState = deviceStatus.
|
|
135
|
+
this.Battery.ChargingState = deviceStatus.workingStatus === 'Charging'
|
|
155
136
|
? this.hap.Characteristic.ChargingState.CHARGING : this.hap.Characteristic.ChargingState.NOT_CHARGING;
|
|
156
|
-
this.debugLog(
|
|
157
|
-
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}, ChargingState: ${this.Battery.ChargingState}`);
|
|
137
|
+
await this.debugLog(`ChargingState: ${this.Battery.ChargingState}`);
|
|
158
138
|
// Firmware Version
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const deviceVersion = version
|
|
139
|
+
if (deviceStatus.version) {
|
|
140
|
+
const version = deviceStatus.version.toString();
|
|
141
|
+
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
142
|
+
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
163
143
|
this.accessory
|
|
164
144
|
.getService(this.hap.Service.AccessoryInformation)
|
|
165
145
|
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
@@ -167,15 +147,34 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
167
147
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
168
148
|
.updateValue(deviceVersion);
|
|
169
149
|
this.accessory.context.deviceVersion = deviceVersion;
|
|
170
|
-
this.debugSuccessLog(
|
|
150
|
+
await this.debugSuccessLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
|
|
171
151
|
}
|
|
172
152
|
}
|
|
153
|
+
async parseStatusWebhook(context) {
|
|
154
|
+
await this.debugLog('parseStatusWebhook');
|
|
155
|
+
await this.debugLog(`(onlineStatus, battery, workingStatus) = Webhook: (${context.onlineStatus}, ${context.battery}, ${context.workingStatus}),`
|
|
156
|
+
+ ` current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel}, ${this.Battery.ChargingState})`);
|
|
157
|
+
// On
|
|
158
|
+
this.LightBulb.On = context.onlineStatus === 'online' ? true : false;
|
|
159
|
+
await this.debugLog(`On: ${this.LightBulb.On}`);
|
|
160
|
+
// BatteryLevel
|
|
161
|
+
this.Battery.BatteryLevel = Number(context.battery);
|
|
162
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
163
|
+
// StatusLowBattery
|
|
164
|
+
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
165
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
166
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
167
|
+
// ChargingState
|
|
168
|
+
this.Battery.ChargingState = context.workingStatus === 'Charging'
|
|
169
|
+
? this.hap.Characteristic.ChargingState.CHARGING : this.hap.Characteristic.ChargingState.NOT_CHARGING;
|
|
170
|
+
await this.debugLog(`ChargingState: ${this.Battery.ChargingState}`);
|
|
171
|
+
}
|
|
173
172
|
/**
|
|
174
173
|
* Asks the SwitchBot API for the latest device information
|
|
175
174
|
*/
|
|
176
175
|
async refreshStatus() {
|
|
177
176
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
178
|
-
this.errorLog(
|
|
177
|
+
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
179
178
|
}
|
|
180
179
|
else if (this.BLE) {
|
|
181
180
|
await this.BLERefreshStatus();
|
|
@@ -185,12 +184,11 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
185
184
|
}
|
|
186
185
|
else {
|
|
187
186
|
await this.offlineOff();
|
|
188
|
-
this.debugWarnLog(
|
|
189
|
-
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
187
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
190
188
|
}
|
|
191
189
|
}
|
|
192
190
|
async BLERefreshStatus() {
|
|
193
|
-
this.debugLog(
|
|
191
|
+
await this.debugLog('BLERefreshStatus');
|
|
194
192
|
const switchbot = await this.switchbotBLE();
|
|
195
193
|
if (switchbot === undefined) {
|
|
196
194
|
await this.BLERefreshConnection(switchbot);
|
|
@@ -201,62 +199,55 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
201
199
|
// Start to monitor advertisement packets
|
|
202
200
|
const serviceData = await this.monitorAdvertisementPackets(switchbot);
|
|
203
201
|
// Update HomeKit
|
|
204
|
-
if (serviceData.model
|
|
202
|
+
if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
|
|
205
203
|
await this.BLEparseStatus(serviceData);
|
|
206
204
|
await this.updateHomeKitCharacteristics();
|
|
207
205
|
}
|
|
208
206
|
else {
|
|
209
|
-
this.errorLog(
|
|
207
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
210
208
|
await this.BLERefreshConnection(switchbot);
|
|
211
209
|
}
|
|
212
210
|
})();
|
|
213
211
|
}
|
|
214
212
|
}
|
|
215
213
|
async openAPIRefreshStatus() {
|
|
216
|
-
this.debugLog(
|
|
214
|
+
await this.debugLog('openAPIRefreshStatus');
|
|
217
215
|
try {
|
|
218
216
|
const { body, statusCode } = await this.deviceRefreshStatus();
|
|
219
217
|
const deviceStatus = await body.json();
|
|
220
|
-
await this.
|
|
218
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
221
219
|
;
|
|
222
|
-
if (
|
|
223
|
-
await this.
|
|
224
|
-
await this.openAPIparseStatus(deviceStatus);
|
|
220
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
221
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
222
|
+
await this.openAPIparseStatus(deviceStatus.body);
|
|
225
223
|
await this.updateHomeKitCharacteristics();
|
|
226
224
|
}
|
|
227
225
|
else {
|
|
228
|
-
await this.
|
|
226
|
+
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
227
|
+
await this.debugWarnLog(statusCode, deviceStatus);
|
|
229
228
|
}
|
|
230
229
|
}
|
|
231
230
|
catch (e) {
|
|
232
231
|
await this.apiError(e);
|
|
233
|
-
await this.
|
|
232
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
234
233
|
}
|
|
235
234
|
}
|
|
236
|
-
async registerWebhook(
|
|
237
|
-
if (device.webhook) {
|
|
238
|
-
this.debugLog(
|
|
239
|
-
this.platform.webhookEventHandler[device.deviceId] = async (context) => {
|
|
235
|
+
async registerWebhook() {
|
|
236
|
+
if (this.device.webhook) {
|
|
237
|
+
await this.debugLog('is listening webhook.');
|
|
238
|
+
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
240
239
|
try {
|
|
241
|
-
this.debugLog(
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const { BatteryLevel, ChargingState } = this.Battery;
|
|
245
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} (onlineStatus, battery, workingStatus) = `
|
|
246
|
-
+ `Webhook: (${onlineStatus}, ${battery}, ${workingStatus}), current: (${On}, ${BatteryLevel}, ${ChargingState})`);
|
|
247
|
-
this.LightBulb.On = onlineStatus === 'online' ? true : false;
|
|
248
|
-
this.Battery.ChargingState = workingStatus === 'Charging'
|
|
249
|
-
? this.hap.Characteristic.ChargingState.CHARGING : this.hap.Characteristic.ChargingState.NOT_CHARGING;
|
|
250
|
-
this.Battery.BatteryLevel = battery;
|
|
251
|
-
this.updateHomeKitCharacteristics();
|
|
240
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
241
|
+
await this.parseStatusWebhook(context);
|
|
242
|
+
await this.updateHomeKitCharacteristics();
|
|
252
243
|
}
|
|
253
244
|
catch (e) {
|
|
254
|
-
this.errorLog(
|
|
245
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
255
246
|
}
|
|
256
247
|
};
|
|
257
248
|
}
|
|
258
249
|
else {
|
|
259
|
-
this.debugLog(
|
|
250
|
+
await this.debugLog('is not listening webhook.');
|
|
260
251
|
}
|
|
261
252
|
}
|
|
262
253
|
/**
|
|
@@ -269,7 +260,7 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
269
260
|
*/
|
|
270
261
|
async pushChanges() {
|
|
271
262
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
272
|
-
this.errorLog(
|
|
263
|
+
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
273
264
|
}
|
|
274
265
|
else if (this.BLE) {
|
|
275
266
|
await this.BLEpushChanges();
|
|
@@ -279,7 +270,7 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
279
270
|
}
|
|
280
271
|
else {
|
|
281
272
|
await this.offlineOff();
|
|
282
|
-
await this.
|
|
273
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
|
|
283
274
|
}
|
|
284
275
|
// Refresh the status from the API
|
|
285
276
|
interval(15000)
|
|
@@ -290,160 +281,122 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
290
281
|
});
|
|
291
282
|
}
|
|
292
283
|
async BLEpushChanges() {
|
|
293
|
-
this.debugLog(
|
|
284
|
+
await this.debugLog('BLEpushChanges');
|
|
294
285
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
295
|
-
this.
|
|
296
|
-
+ ` On: ${this.LightBulb.On} OnCached: ${this.accessory.context.On}`);
|
|
297
|
-
const switchbot = await this.platform.connectBLE();
|
|
298
|
-
// Convert to BLE Address
|
|
286
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device);
|
|
299
287
|
await this.convertBLEAddress();
|
|
300
|
-
switchbot
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
288
|
+
if (switchbot !== false) {
|
|
289
|
+
switchbot
|
|
290
|
+
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
291
|
+
.then(async (device_list) => {
|
|
292
|
+
await this.infoLog(`On: ${this.LightBulb.On}`);
|
|
293
|
+
return await this.retryBLE({
|
|
294
|
+
max: await this.maxRetryBLE(),
|
|
295
|
+
fn: async () => {
|
|
296
|
+
if (this.LightBulb.On) {
|
|
297
|
+
return await device_list[0].turnOn({ id: this.device.bleMac });
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
return await device_list[0].turnOff({ id: this.device.bleMac });
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
});
|
|
304
|
+
})
|
|
305
|
+
.then(async () => {
|
|
306
|
+
await this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`);
|
|
307
|
+
await this.updateHomeKitCharacteristics();
|
|
308
|
+
})
|
|
309
|
+
.catch(async (e) => {
|
|
310
|
+
await this.apiError(e);
|
|
311
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
312
|
+
await this.BLEPushConnection();
|
|
317
313
|
});
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
this.
|
|
321
|
-
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
322
|
-
+ `On: ${this.LightBulb.On} sent over BLE, sent successfully`);
|
|
323
|
-
this.LightBulb.On = false;
|
|
324
|
-
})
|
|
325
|
-
.catch(async (e) => {
|
|
326
|
-
this.apiError(e);
|
|
327
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
328
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
329
317
|
await this.BLEPushConnection();
|
|
330
|
-
}
|
|
318
|
+
}
|
|
331
319
|
}
|
|
332
320
|
else {
|
|
333
|
-
this.debugLog(
|
|
334
|
-
+ ` On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
321
|
+
await this.debugLog(`No changes (BLEpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
335
322
|
}
|
|
336
323
|
}
|
|
337
324
|
async openAPIpushChanges() {
|
|
338
|
-
this.debugLog(
|
|
325
|
+
await this.debugLog('openAPIpushChanges');
|
|
339
326
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
340
|
-
const
|
|
341
|
-
|
|
327
|
+
const command = this.LightBulb.On ? 'start' : 'dock';
|
|
328
|
+
const bodyChange = JSON.stringify({
|
|
329
|
+
command: `${command}`,
|
|
330
|
+
parameter: 'default',
|
|
331
|
+
commandType: 'command',
|
|
332
|
+
});
|
|
333
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
342
334
|
try {
|
|
343
335
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
344
336
|
const deviceStatus = await body.json();
|
|
345
|
-
await this.
|
|
346
|
-
if (
|
|
347
|
-
this.
|
|
348
|
-
|
|
349
|
-
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
350
|
-
+ `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
337
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
338
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
339
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
340
|
+
await this.updateHomeKitCharacteristics();
|
|
351
341
|
}
|
|
352
342
|
else {
|
|
353
|
-
this.statusCode(statusCode);
|
|
354
|
-
this.statusCode(deviceStatus.statusCode);
|
|
343
|
+
await this.statusCode(statusCode);
|
|
344
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
355
345
|
}
|
|
356
346
|
}
|
|
357
347
|
catch (e) {
|
|
358
348
|
await this.apiError(e);
|
|
359
|
-
await this.
|
|
349
|
+
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
360
350
|
}
|
|
361
351
|
}
|
|
362
352
|
else {
|
|
363
|
-
this.debugLog(
|
|
364
|
-
+ `OnCached: ${this.accessory.context.On}`);
|
|
353
|
+
await this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
365
354
|
}
|
|
366
355
|
}
|
|
367
356
|
async openAPIpushBrightnessChanges() {
|
|
368
|
-
this.debugLog(
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
const
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
357
|
+
await this.debugLog('openAPIpushBrightnessChanges');
|
|
358
|
+
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
359
|
+
const command = this.LightBulb.Brightness === 0 ? 'dock' : 'PowLevel';
|
|
360
|
+
const parameter = this.LightBulb.Brightness === 25 ? '0' : this.LightBulb.Brightness === 50 ? '1' : this.LightBulb.Brightness === 75
|
|
361
|
+
? '2' : this.LightBulb.Brightness === 100 ? '3' : 'default';
|
|
362
|
+
const bodyChange = JSON.stringify({
|
|
363
|
+
command: `${command}`,
|
|
364
|
+
parameter: `${parameter}`,
|
|
365
|
+
commandType: 'command',
|
|
366
|
+
});
|
|
367
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
368
|
+
try {
|
|
369
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
370
|
+
const deviceStatus = await body.json();
|
|
371
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
372
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
373
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
374
|
+
await this.updateHomeKitCharacteristics();
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
await this.statusCode(statusCode);
|
|
378
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
379
|
+
}
|
|
379
380
|
}
|
|
380
|
-
|
|
381
|
-
await this.
|
|
382
|
-
await this.
|
|
381
|
+
catch (e) {
|
|
382
|
+
await this.apiError(e);
|
|
383
|
+
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
383
384
|
}
|
|
384
385
|
}
|
|
385
|
-
catch (e) {
|
|
386
|
-
await this.apiError(e);
|
|
387
|
-
await this.pushChangeError('openAPIpushBrightnessChanges', e);
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
async commands() {
|
|
391
|
-
let command;
|
|
392
|
-
let parameter;
|
|
393
|
-
if (this.LightBulb.On) {
|
|
394
|
-
command = 'start';
|
|
395
|
-
parameter = 'default';
|
|
396
|
-
}
|
|
397
386
|
else {
|
|
398
|
-
|
|
399
|
-
|
|
387
|
+
await this.debugLog(`No changes (openAPIpushBrightnessChanges), Brightness: ${this.LightBulb.Brightness},`
|
|
388
|
+
+ ` BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
400
389
|
}
|
|
401
|
-
const body = JSON.stringify({
|
|
402
|
-
command: `${command}`,
|
|
403
|
-
parameter: `${parameter}`,
|
|
404
|
-
commandType: 'command',
|
|
405
|
-
});
|
|
406
|
-
return body;
|
|
407
|
-
}
|
|
408
|
-
async brightnessCommands() {
|
|
409
|
-
let command;
|
|
410
|
-
let parameter;
|
|
411
|
-
if (this.LightBulb.Brightness === 25) {
|
|
412
|
-
command = 'PowLevel';
|
|
413
|
-
parameter = '0';
|
|
414
|
-
}
|
|
415
|
-
else if (this.LightBulb.Brightness === 50) {
|
|
416
|
-
command = 'PowLevel';
|
|
417
|
-
parameter = '1';
|
|
418
|
-
}
|
|
419
|
-
else if (this.LightBulb.Brightness === 75) {
|
|
420
|
-
command = 'PowLevel';
|
|
421
|
-
parameter = '2';
|
|
422
|
-
}
|
|
423
|
-
else if (this.LightBulb.Brightness === 100) {
|
|
424
|
-
command = 'PowLevel';
|
|
425
|
-
parameter = '3';
|
|
426
|
-
}
|
|
427
|
-
else {
|
|
428
|
-
command = 'dock';
|
|
429
|
-
parameter = 'default';
|
|
430
|
-
}
|
|
431
|
-
const bodyChange = JSON.stringify({
|
|
432
|
-
command: `${command}`,
|
|
433
|
-
parameter: `${parameter}`,
|
|
434
|
-
commandType: 'command',
|
|
435
|
-
});
|
|
436
|
-
return bodyChange;
|
|
437
390
|
}
|
|
438
391
|
/**
|
|
439
392
|
* Handle requests to set the value of the "On" characteristic
|
|
440
393
|
*/
|
|
441
394
|
async OnSet(value) {
|
|
442
|
-
if (this.LightBulb.On
|
|
443
|
-
this.
|
|
395
|
+
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
396
|
+
this.infoLog(`Set On: ${value}`);
|
|
444
397
|
}
|
|
445
398
|
else {
|
|
446
|
-
this.
|
|
399
|
+
this.debugLog(`No Changes, On: ${value}`);
|
|
447
400
|
}
|
|
448
401
|
this.LightBulb.On = value;
|
|
449
402
|
this.doRobotVacuumCleanerUpdate.next();
|
|
@@ -452,78 +405,42 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
452
405
|
* Handle requests to set the value of the "Brightness" characteristic
|
|
453
406
|
*/
|
|
454
407
|
async BrightnessSet(value) {
|
|
455
|
-
if (this.LightBulb.Brightness
|
|
456
|
-
this.
|
|
457
|
-
}
|
|
458
|
-
else if (this.LightBulb.On) {
|
|
459
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
|
|
408
|
+
if (this.LightBulb.On && (this.LightBulb.Brightness !== this.accessory.context.Brightness)) {
|
|
409
|
+
await this.infoLog(`Set Brightness: ${value}`);
|
|
460
410
|
}
|
|
461
411
|
else {
|
|
462
|
-
|
|
412
|
+
if (this.LightBulb.On) {
|
|
413
|
+
this.debugLog(`No Changes, Brightness: ${value}`);
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
this.debugLog(`Brightness: ${value}, On: ${this.LightBulb.On}`);
|
|
417
|
+
}
|
|
463
418
|
}
|
|
464
419
|
this.LightBulb.Brightness = value;
|
|
465
420
|
this.doRobotVacuumCleanerUpdate.next();
|
|
466
421
|
}
|
|
467
422
|
async updateHomeKitCharacteristics() {
|
|
468
423
|
// On
|
|
469
|
-
|
|
470
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
|
|
471
|
-
}
|
|
472
|
-
else {
|
|
473
|
-
this.accessory.context.On = this.LightBulb.On;
|
|
474
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, this.LightBulb.On);
|
|
475
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.LightBulb.On}`);
|
|
476
|
-
}
|
|
424
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.On, this.LightBulb.On, 'On');
|
|
477
425
|
// Brightness
|
|
478
|
-
|
|
479
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
|
|
480
|
-
}
|
|
481
|
-
else {
|
|
482
|
-
this.accessory.context.Brightness = this.LightBulb.Brightness;
|
|
483
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, this.LightBulb.Brightness);
|
|
484
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.LightBulb.Brightness}`);
|
|
485
|
-
}
|
|
426
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Brightness, this.LightBulb.Brightness, 'Brightness');
|
|
486
427
|
// BatteryLevel
|
|
487
|
-
|
|
488
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
489
|
-
}
|
|
490
|
-
else {
|
|
491
|
-
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
|
|
492
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
493
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
494
|
-
}
|
|
428
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel, 'BatteryLevel');
|
|
495
429
|
// StatusLowBattery
|
|
496
|
-
|
|
497
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
498
|
-
}
|
|
499
|
-
else {
|
|
500
|
-
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
501
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
502
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
503
|
-
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
504
|
-
}
|
|
430
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery, 'StatusLowBattery');
|
|
505
431
|
// ChargingState
|
|
506
|
-
|
|
507
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ChargingState: ${this.Battery.ChargingState}`);
|
|
508
|
-
}
|
|
509
|
-
else {
|
|
510
|
-
this.accessory.context.ChargingState = this.Battery.ChargingState;
|
|
511
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.ChargingState, this.Battery.ChargingState);
|
|
512
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
513
|
-
+ ` ChargingState: ${this.Battery.ChargingState}`);
|
|
514
|
-
}
|
|
432
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.ChargingState, this.Battery.ChargingState, 'ChargingState');
|
|
515
433
|
}
|
|
516
434
|
async BLEPushConnection() {
|
|
517
435
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
518
|
-
this.warnLog(
|
|
436
|
+
await this.warnLog('Using OpenAPI Connection to Push Changes');
|
|
519
437
|
await this.openAPIpushChanges();
|
|
520
438
|
}
|
|
521
439
|
}
|
|
522
440
|
async BLERefreshConnection(switchbot) {
|
|
523
|
-
this.errorLog(
|
|
524
|
-
+ ` ${JSON.stringify(switchbot)}`);
|
|
441
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
|
|
525
442
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
526
|
-
this.warnLog(
|
|
443
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
527
444
|
await this.openAPIRefreshStatus();
|
|
528
445
|
}
|
|
529
446
|
}
|