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