@switchbot/homebridge-switchbot 3.5.1-beta.9 → 3.5.2-beta.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 +7 -0
- package/config.schema.json +19 -3
- package/dist/device/blindtilt.d.ts +6 -4
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +61 -47
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +6 -3
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +60 -26
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +6 -3
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +48 -30
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +6 -3
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +54 -37
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +6 -3
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +46 -32
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +6 -4
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +42 -28
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +7 -4
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +61 -152
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +6 -3
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +54 -33
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +6 -3
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +50 -31
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +6 -3
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +48 -29
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +6 -3
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +45 -28
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +6 -3
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +47 -29
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +6 -3
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +39 -26
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +6 -3
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +44 -28
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +6 -3
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +43 -28
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +6 -3
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +38 -25
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +6 -3
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +31 -18
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +6 -3
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +38 -23
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +6 -3
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +44 -27
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +2 -2
- package/dist/irdevice/airconditioner.d.ts +1 -3
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +67 -177
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +0 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +24 -53
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +12 -17
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +22 -38
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +22 -10
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +94 -100
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +20 -38
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +79 -77
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +38 -53
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +11 -16
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +11 -16
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +4 -6
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +564 -665
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +10 -8
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +2 -1
- package/dist/types/bledevicestatus.d.ts.map +1 -1
- package/dist/types/devicestatus.d.ts +1 -1
- package/dist/types/devicestatus.d.ts.map +1 -1
- package/package.json +14 -14
- package/src/device/blindtilt.ts +65 -49
- package/src/device/bot.ts +80 -27
- package/src/device/ceilinglight.ts +58 -32
- package/src/device/colorbulb.ts +58 -44
- package/src/device/contact.ts +50 -32
- package/src/device/curtain.ts +52 -29
- package/src/device/device.ts +63 -135
- package/src/device/fan.ts +68 -34
- package/src/device/hub.ts +63 -34
- package/src/device/humidifier.ts +61 -34
- package/src/device/iosensor.ts +52 -31
- package/src/device/lightstrip.ts +53 -30
- package/src/device/lock.ts +56 -27
- package/src/device/meter.ts +61 -30
- package/src/device/meterplus.ts +57 -30
- package/src/device/motion.ts +51 -27
- package/src/device/plug.ts +39 -19
- package/src/device/robotvacuumcleaner.ts +54 -25
- package/src/device/waterdetector.ts +63 -29
- package/src/homebridge-ui/public/index.html +2 -2
- package/src/irdevice/airconditioner.ts +76 -165
- package/src/irdevice/airpurifier.ts +29 -49
- package/src/irdevice/camera.ts +13 -16
- package/src/irdevice/fan.ts +25 -35
- package/src/irdevice/irdevice.ts +97 -96
- package/src/irdevice/light.ts +21 -35
- package/src/irdevice/other.ts +79 -77
- package/src/irdevice/tv.ts +40 -51
- package/src/irdevice/vacuumcleaner.ts +12 -15
- package/src/irdevice/waterheater.ts +12 -15
- package/src/platform.ts +566 -696
- package/src/settings.ts +11 -8
- package/src/types/bledevicestatus.ts +4 -2
- package/src/types/devicestatus.ts +1 -1
package/src/device/motion.ts
CHANGED
|
@@ -41,6 +41,15 @@ export class Motion extends deviceBase {
|
|
|
41
41
|
CurrentAmbientLightLevel: CharacteristicValue;
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
+
// OpenAPI
|
|
45
|
+
deviceStatus!: motionSensorStatus;
|
|
46
|
+
|
|
47
|
+
//Webhook
|
|
48
|
+
webhookContext!: motionSensorWebhookContext;
|
|
49
|
+
|
|
50
|
+
// BLE
|
|
51
|
+
serviceData!: motionSensorServiceData;
|
|
52
|
+
|
|
44
53
|
// Updates
|
|
45
54
|
motionUbpdateInProgress!: boolean;
|
|
46
55
|
doMotionUpdate!: Subject<void>;
|
|
@@ -51,6 +60,9 @@ export class Motion extends deviceBase {
|
|
|
51
60
|
device: device & devicesConfig,
|
|
52
61
|
) {
|
|
53
62
|
super(platform, accessory, device);
|
|
63
|
+
// Set category
|
|
64
|
+
accessory.category = this.hap.Categories.SENSOR;
|
|
65
|
+
|
|
54
66
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
55
67
|
this.doMotionUpdate = new Subject();
|
|
56
68
|
this.motionUbpdateInProgress = false;
|
|
@@ -103,7 +115,7 @@ export class Motion extends deviceBase {
|
|
|
103
115
|
// Initialize Light Sensor Service
|
|
104
116
|
if (device.motion?.hide_lightsensor) {
|
|
105
117
|
if (this.LightSensor) {
|
|
106
|
-
this.debugLog(
|
|
118
|
+
this.debugLog('Removing Light Sensor Service');
|
|
107
119
|
this.LightSensor.Service = this.accessory.getService(this.hap.Service.LightSensor) as Service;
|
|
108
120
|
accessory.removeService(this.LightSensor.Service);
|
|
109
121
|
}
|
|
@@ -126,14 +138,12 @@ export class Motion extends deviceBase {
|
|
|
126
138
|
});
|
|
127
139
|
};
|
|
128
140
|
|
|
129
|
-
|
|
130
141
|
// Retrieve initial values and updateHomekit
|
|
142
|
+
this.debugLog('Retrieve initial values and update Homekit');
|
|
131
143
|
this.refreshStatus();
|
|
132
144
|
|
|
133
|
-
// Retrieve initial values and updateHomekit
|
|
134
|
-
this.updateHomeKitCharacteristics();
|
|
135
|
-
|
|
136
145
|
//regisiter webhook event handler
|
|
146
|
+
this.debugLog('Registering Webhook Event Handler');
|
|
137
147
|
this.registerWebhook();
|
|
138
148
|
|
|
139
149
|
// Start an update interval
|
|
@@ -144,52 +154,62 @@ export class Motion extends deviceBase {
|
|
|
144
154
|
});
|
|
145
155
|
}
|
|
146
156
|
|
|
147
|
-
async BLEparseStatus(
|
|
157
|
+
async BLEparseStatus(): Promise<void> {
|
|
148
158
|
await this.debugLog('BLEparseStatus');
|
|
159
|
+
await this.debugLog(`(moveDetected) = BLE: (${this.serviceData.movement}), current: (${this.MotionSensor.MotionDetected})`);
|
|
160
|
+
|
|
149
161
|
// Movement
|
|
150
|
-
this.MotionSensor.MotionDetected = serviceData.movement;
|
|
162
|
+
this.MotionSensor.MotionDetected = this.serviceData.movement;
|
|
151
163
|
await this.debugLog(`MotionDetected: ${this.MotionSensor.MotionDetected}`);
|
|
164
|
+
|
|
152
165
|
// CurrentAmbientLightLevel
|
|
153
166
|
if (!this.device.motion?.hide_lightsensor && this.LightSensor?.Service) {
|
|
154
167
|
const set_minLux = this.device.blindTilt?.set_minLux ?? 1;
|
|
155
168
|
const set_maxLux = this.device.blindTilt?.set_maxLux ?? 6001;
|
|
156
|
-
const lightLevel = serviceData.lightLevel === 'bright' ? set_maxLux : set_minLux;
|
|
169
|
+
const lightLevel = this.serviceData.lightLevel === 'bright' ? set_maxLux : set_minLux;
|
|
157
170
|
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2);
|
|
158
|
-
await this.debugLog(`LightLevel: ${serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
171
|
+
await this.debugLog(`LightLevel: ${this.serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
159
172
|
}
|
|
173
|
+
|
|
160
174
|
// BatteryLevel
|
|
161
|
-
this.Battery.BatteryLevel = serviceData.battery;
|
|
175
|
+
this.Battery.BatteryLevel = this.serviceData.battery;
|
|
162
176
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
177
|
+
|
|
163
178
|
// StatusLowBattery
|
|
164
179
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
165
180
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
166
181
|
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
167
182
|
}
|
|
168
183
|
|
|
169
|
-
async openAPIparseStatus(
|
|
184
|
+
async openAPIparseStatus(): Promise<void> {
|
|
170
185
|
await this.debugLog('openAPIparseStatus');
|
|
186
|
+
await this.debugLog(`(moveDetected) = OpenAPI: (${this.deviceStatus.moveDetected}), current: (${this.MotionSensor.MotionDetected})`);
|
|
187
|
+
|
|
171
188
|
// Motion State
|
|
172
|
-
this.MotionSensor.MotionDetected = deviceStatus.moveDetected;
|
|
189
|
+
this.MotionSensor.MotionDetected = this.deviceStatus.moveDetected;
|
|
173
190
|
await this.debugLog(`MotionDetected: ${this.MotionSensor.MotionDetected}`);
|
|
191
|
+
|
|
174
192
|
// CurrentAmbientLightLevel
|
|
175
193
|
if (!this.device.motion?.hide_lightsensor && this.LightSensor?.Service) {
|
|
176
194
|
const set_minLux = this.device.blindTilt?.set_minLux ?? 1;
|
|
177
195
|
const set_maxLux = this.device.blindTilt?.set_maxLux ?? 6001;
|
|
178
|
-
const lightLevel = deviceStatus.brightness === 'bright' ? set_maxLux : set_minLux;
|
|
196
|
+
const lightLevel = this.deviceStatus.brightness === 'bright' ? set_maxLux : set_minLux;
|
|
179
197
|
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2);
|
|
180
|
-
await this.debugLog(`LightLevel: ${deviceStatus.brightness}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
198
|
+
await this.debugLog(`LightLevel: ${this.deviceStatus.brightness}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
181
199
|
}
|
|
182
200
|
// BatteryLevel
|
|
183
|
-
this.Battery.BatteryLevel =
|
|
201
|
+
this.Battery.BatteryLevel = this.deviceStatus.battery;
|
|
184
202
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
203
|
+
|
|
185
204
|
// StatusLowBattery
|
|
186
205
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
187
206
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
188
207
|
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
208
|
+
|
|
189
209
|
// FirmwareVersion
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
210
|
+
if (this.deviceStatus.version) {
|
|
211
|
+
const version = this.deviceStatus.version.toString();
|
|
212
|
+
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
193
213
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
194
214
|
this.accessory
|
|
195
215
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
@@ -197,16 +217,17 @@ export class Motion extends deviceBase {
|
|
|
197
217
|
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
|
|
198
218
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
199
219
|
.updateValue(deviceVersion);
|
|
200
|
-
this.accessory.context.
|
|
201
|
-
await this.debugLog(`
|
|
220
|
+
this.accessory.context.version = deviceVersion;
|
|
221
|
+
await this.debugLog(`version: ${this.accessory.context.version}`);
|
|
202
222
|
}
|
|
203
223
|
}
|
|
204
224
|
|
|
205
|
-
async parseStatusWebhook(
|
|
225
|
+
async parseStatusWebhook(): Promise<void> {
|
|
206
226
|
await this.debugLog('parseStatusWebhook');
|
|
207
|
-
await this.debugLog(`(detectionState) = Webhook: (${
|
|
227
|
+
await this.debugLog(`(detectionState) = Webhook: (${this.webhookContext.detectionState}), current: (${this.MotionSensor.MotionDetected})`);
|
|
228
|
+
|
|
208
229
|
// MotionDetected
|
|
209
|
-
this.MotionSensor.MotionDetected =
|
|
230
|
+
this.MotionSensor.MotionDetected = this.webhookContext.detectionState === 'DETECTED' ? true : false;
|
|
210
231
|
await this.debugLog(`MotionDetected: ${this.MotionSensor.MotionDetected}`);
|
|
211
232
|
}
|
|
212
233
|
|
|
@@ -239,7 +260,8 @@ export class Motion extends deviceBase {
|
|
|
239
260
|
const serviceData = await this.monitorAdvertisementPackets(switchbot) as motionSensorServiceData;
|
|
240
261
|
// Update HomeKit
|
|
241
262
|
if (serviceData.model === SwitchBotBLEModel.MotionSensor && serviceData.modelName === SwitchBotBLEModelName.MotionSensor) {
|
|
242
|
-
|
|
263
|
+
this.serviceData = serviceData;
|
|
264
|
+
await this.BLEparseStatus();
|
|
243
265
|
await this.updateHomeKitCharacteristics();
|
|
244
266
|
} else {
|
|
245
267
|
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
@@ -257,7 +279,8 @@ export class Motion extends deviceBase {
|
|
|
257
279
|
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
|
|
258
280
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
259
281
|
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
260
|
-
|
|
282
|
+
this.deviceStatus = deviceStatus.body;
|
|
283
|
+
await this.openAPIparseStatus();
|
|
261
284
|
await this.updateHomeKitCharacteristics();
|
|
262
285
|
} else {
|
|
263
286
|
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
@@ -275,7 +298,8 @@ export class Motion extends deviceBase {
|
|
|
275
298
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: motionSensorWebhookContext) => {
|
|
276
299
|
try {
|
|
277
300
|
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
278
|
-
|
|
301
|
+
this.webhookContext = context;
|
|
302
|
+
await this.parseStatusWebhook();
|
|
279
303
|
await this.updateHomeKitCharacteristics();
|
|
280
304
|
} catch (e: any) {
|
|
281
305
|
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
@@ -307,7 +331,7 @@ export class Motion extends deviceBase {
|
|
|
307
331
|
}
|
|
308
332
|
|
|
309
333
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
310
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${
|
|
334
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
311
335
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
312
336
|
await this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
313
337
|
await this.openAPIRefreshStatus();
|
package/src/device/plug.ts
CHANGED
|
@@ -21,6 +21,15 @@ export class Plug extends deviceBase {
|
|
|
21
21
|
On: CharacteristicValue;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
+
// OpenAPI
|
|
25
|
+
deviceStatus!: plugStatus | plugMiniStatus;
|
|
26
|
+
|
|
27
|
+
//Webhook
|
|
28
|
+
webhookContext!: plugWebhookContext | plugMiniUSWebhookContext | plugMiniJPWebhookContext;
|
|
29
|
+
|
|
30
|
+
// BLE
|
|
31
|
+
serviceData!: plugMiniUSServiceData | plugMiniJPServiceData;
|
|
32
|
+
|
|
24
33
|
// Updates
|
|
25
34
|
plugUpdateInProgress!: boolean;
|
|
26
35
|
doPlugUpdate!: Subject<void>;
|
|
@@ -31,6 +40,9 @@ export class Plug extends deviceBase {
|
|
|
31
40
|
device: device & devicesConfig,
|
|
32
41
|
) {
|
|
33
42
|
super(platform, accessory, device);
|
|
43
|
+
// Set category
|
|
44
|
+
accessory.category = this.hap.Categories.OUTLET;
|
|
45
|
+
|
|
34
46
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
35
47
|
this.doPlugUpdate = new Subject();
|
|
36
48
|
this.plugUpdateInProgress = false;
|
|
@@ -54,12 +66,11 @@ export class Plug extends deviceBase {
|
|
|
54
66
|
.onSet(this.OnSet.bind(this));
|
|
55
67
|
|
|
56
68
|
// Retrieve initial values and updateHomekit
|
|
69
|
+
this.debugLog('Retrieve initial values and update Homekit');
|
|
57
70
|
this.refreshStatus();
|
|
58
71
|
|
|
59
|
-
// Update Homekit
|
|
60
|
-
this.updateHomeKitCharacteristics();
|
|
61
|
-
|
|
62
72
|
//regisiter webhook event handler
|
|
73
|
+
this.debugLog('Registering Webhook Event Handler');
|
|
63
74
|
this.registerWebhook();
|
|
64
75
|
|
|
65
76
|
// Start an update interval
|
|
@@ -89,22 +100,27 @@ export class Plug extends deviceBase {
|
|
|
89
100
|
});
|
|
90
101
|
}
|
|
91
102
|
|
|
92
|
-
async BLEparseStatus(
|
|
103
|
+
async BLEparseStatus(): Promise<void> {
|
|
93
104
|
await this.debugLog('BLEparseStatus');
|
|
105
|
+
await this.debugLog(`(powerState) = BLE: (${this.serviceData.state}), current:(${this.Outlet.On})`);
|
|
106
|
+
|
|
94
107
|
// On
|
|
95
|
-
this.Outlet.On = serviceData.state === 'on' ? true : false;
|
|
108
|
+
this.Outlet.On = this.serviceData.state === 'on' ? true : false;
|
|
96
109
|
await this.debugLog(`On: ${this.Outlet.On}`);
|
|
97
110
|
}
|
|
98
111
|
|
|
99
|
-
async openAPIparseStatus(
|
|
112
|
+
async openAPIparseStatus() {
|
|
100
113
|
await this.debugLog('openAPIparseStatus');
|
|
114
|
+
await this.debugLog(`(powerState) = OpenAPI: (${this.deviceStatus.power}), current:(${this.Outlet.On})`);
|
|
115
|
+
|
|
101
116
|
// On
|
|
102
|
-
this.Outlet.On = deviceStatus.power === 'on' ? true : false;
|
|
117
|
+
this.Outlet.On = this.deviceStatus.power === 'on' ? true : false;
|
|
103
118
|
await this.debugLog(`On: ${this.Outlet.On}`);
|
|
119
|
+
|
|
104
120
|
// Firmware Version
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
121
|
+
if (this.deviceStatus.version) {
|
|
122
|
+
const version = this.deviceStatus.version.toString();
|
|
123
|
+
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
108
124
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
109
125
|
this.accessory
|
|
110
126
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
@@ -112,16 +128,17 @@ export class Plug extends deviceBase {
|
|
|
112
128
|
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
|
|
113
129
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
114
130
|
.updateValue(deviceVersion);
|
|
115
|
-
this.accessory.context.
|
|
116
|
-
await this.debugSuccessLog(`
|
|
131
|
+
this.accessory.context.version = deviceVersion;
|
|
132
|
+
await this.debugSuccessLog(`version: ${this.accessory.context.version}`);
|
|
117
133
|
}
|
|
118
134
|
}
|
|
119
135
|
|
|
120
|
-
async parseStatusWebhook(
|
|
136
|
+
async parseStatusWebhook(): Promise<void> {
|
|
121
137
|
await this.debugLog('parseStatusWebhook');
|
|
122
|
-
await this.debugLog(`(powerState) = Webhook: (${
|
|
138
|
+
await this.debugLog(`(powerState) = Webhook: (${this.webhookContext.powerState}), current:(${this.Outlet.On})`);
|
|
139
|
+
|
|
123
140
|
// On
|
|
124
|
-
this.Outlet.On =
|
|
141
|
+
this.Outlet.On = this.webhookContext.powerState === 'ON' ? true : false;
|
|
125
142
|
await this.debugLog(`On: ${this.Outlet.On}`);
|
|
126
143
|
}
|
|
127
144
|
|
|
@@ -155,7 +172,8 @@ export class Plug extends deviceBase {
|
|
|
155
172
|
// Update HomeKit
|
|
156
173
|
if ((serviceData.model === SwitchBotBLEModel.PlugMiniUS || SwitchBotBLEModel.PlugMiniJP)
|
|
157
174
|
&& serviceData.modelName === (SwitchBotBLEModelName.PlugMini || SwitchBotBLEModelName.PlugMini)) {
|
|
158
|
-
|
|
175
|
+
this.serviceData = serviceData;
|
|
176
|
+
await this.BLEparseStatus();
|
|
159
177
|
await this.updateHomeKitCharacteristics();
|
|
160
178
|
} else {
|
|
161
179
|
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
@@ -173,7 +191,8 @@ export class Plug extends deviceBase {
|
|
|
173
191
|
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
|
|
174
192
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
175
193
|
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
176
|
-
|
|
194
|
+
this.deviceStatus = deviceStatus.body;
|
|
195
|
+
await this.openAPIparseStatus();
|
|
177
196
|
await this.updateHomeKitCharacteristics();
|
|
178
197
|
} else {
|
|
179
198
|
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
@@ -192,7 +211,8 @@ export class Plug extends deviceBase {
|
|
|
192
211
|
| plugMiniJPWebhookContext) => {
|
|
193
212
|
try {
|
|
194
213
|
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
195
|
-
|
|
214
|
+
this.webhookContext = context;
|
|
215
|
+
await this.parseStatusWebhook();
|
|
196
216
|
await this.updateHomeKitCharacteristics();
|
|
197
217
|
} catch (e: any) {
|
|
198
218
|
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
@@ -331,7 +351,7 @@ export class Plug extends deviceBase {
|
|
|
331
351
|
}
|
|
332
352
|
|
|
333
353
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
334
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${
|
|
354
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
335
355
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
336
356
|
await this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
337
357
|
await this.openAPIRefreshStatus();
|
|
@@ -35,6 +35,15 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
35
35
|
ChargingState: CharacteristicValue;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
+
// OpenAPI
|
|
39
|
+
deviceStatus!: robotVacuumCleanerS1Status | robotVacuumCleanerS1PlusStatus | floorCleaningRobotS10Status;
|
|
40
|
+
|
|
41
|
+
//Webhook
|
|
42
|
+
webhookContext!: robotVacuumCleanerS1WebhookContext | robotVacuumCleanerS1PlusWebhookContext | floorCleaningRobotS10WebhookContext;
|
|
43
|
+
|
|
44
|
+
// BLE
|
|
45
|
+
serviceData!: robotVacuumCleanerServiceData;
|
|
46
|
+
|
|
38
47
|
// Updates
|
|
39
48
|
robotVacuumCleanerUpdateInProgress!: boolean;
|
|
40
49
|
doRobotVacuumCleanerUpdate!: Subject<void>;
|
|
@@ -45,6 +54,9 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
45
54
|
device: device & devicesConfig,
|
|
46
55
|
) {
|
|
47
56
|
super(platform, accessory, device);
|
|
57
|
+
// Set category
|
|
58
|
+
accessory.category = this.hap.Categories.OTHER;
|
|
59
|
+
|
|
48
60
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
49
61
|
this.doRobotVacuumCleanerUpdate = new Subject();
|
|
50
62
|
this.robotVacuumCleanerUpdateInProgress = false;
|
|
@@ -115,12 +127,11 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
115
127
|
});
|
|
116
128
|
|
|
117
129
|
// Retrieve initial values and updateHomekit
|
|
130
|
+
this.debugLog('Retrieve initial values and update Homekit');
|
|
118
131
|
this.refreshStatus();
|
|
119
132
|
|
|
120
|
-
// Update Homekit
|
|
121
|
-
this.updateHomeKitCharacteristics();
|
|
122
|
-
|
|
123
133
|
//regisiter webhook event handler
|
|
134
|
+
this.debugLog('Registering Webhook Event Handler');
|
|
124
135
|
this.registerWebhook();
|
|
125
136
|
|
|
126
137
|
// Start an update interval
|
|
@@ -150,39 +161,51 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
150
161
|
});
|
|
151
162
|
}
|
|
152
163
|
|
|
153
|
-
async BLEparseStatus(
|
|
164
|
+
async BLEparseStatus(): Promise<void> {
|
|
154
165
|
await this.debugLog('BLEparseStatus');
|
|
166
|
+
await this.debugLog(`(state, battery) = BLE: (${this.serviceData.state}, ${this.serviceData.battery}),`
|
|
167
|
+
+ ` current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel})`);
|
|
168
|
+
|
|
155
169
|
// On
|
|
156
|
-
this.LightBulb.On = serviceData.state === 'on' ? true : false;
|
|
170
|
+
this.LightBulb.On = this.serviceData.state === 'on' ? true : false;
|
|
157
171
|
await this.debugLog(`On: ${this.LightBulb.On}`);
|
|
172
|
+
|
|
158
173
|
// BatteryLevel
|
|
159
|
-
this.Battery.BatteryLevel =
|
|
174
|
+
this.Battery.BatteryLevel = this.serviceData.battery;
|
|
160
175
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
176
|
+
|
|
161
177
|
// StatusLowBattery
|
|
162
178
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
163
179
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
164
180
|
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
165
181
|
}
|
|
166
182
|
|
|
167
|
-
async openAPIparseStatus(
|
|
183
|
+
async openAPIparseStatus() {
|
|
168
184
|
await this.debugLog('openAPIparseStatus');
|
|
185
|
+
await this.debugLog(`(onlineStatus, battery, workingStatus) = API: (${this.deviceStatus.onlineStatus}, ${this.deviceStatus.battery},`
|
|
186
|
+
+ ` ${this.deviceStatus.workingStatus}), current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel}, ${this.Battery.ChargingState})`);
|
|
187
|
+
|
|
169
188
|
// On
|
|
170
|
-
this.LightBulb.On = deviceStatus.onlineStatus === 'online' ? true : false;
|
|
189
|
+
this.LightBulb.On = this.deviceStatus.onlineStatus === 'online' ? true : false;
|
|
171
190
|
await this.debugLog(`On: ${this.LightBulb.On}`);
|
|
191
|
+
|
|
172
192
|
// BatteryLevel
|
|
173
|
-
this.Battery.BatteryLevel =
|
|
193
|
+
this.Battery.BatteryLevel = this.deviceStatus.battery;
|
|
174
194
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
195
|
+
|
|
175
196
|
// StatusLowBattery
|
|
176
197
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
177
198
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
178
199
|
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
200
|
+
|
|
179
201
|
// ChargingState
|
|
180
|
-
this.Battery.ChargingState = deviceStatus.workingStatus === 'Charging'
|
|
202
|
+
this.Battery.ChargingState = this.deviceStatus.workingStatus === 'Charging'
|
|
181
203
|
? this.hap.Characteristic.ChargingState.CHARGING : this.hap.Characteristic.ChargingState.NOT_CHARGING;
|
|
182
204
|
await this.debugLog(`ChargingState: ${this.Battery.ChargingState}`);
|
|
205
|
+
|
|
183
206
|
// Firmware Version
|
|
184
|
-
if (deviceStatus.version) {
|
|
185
|
-
const version = deviceStatus.version.toString();
|
|
207
|
+
if (this.deviceStatus.version) {
|
|
208
|
+
const version = this.deviceStatus.version.toString();
|
|
186
209
|
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
187
210
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
188
211
|
this.accessory
|
|
@@ -191,28 +214,31 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
191
214
|
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
|
|
192
215
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
193
216
|
.updateValue(deviceVersion);
|
|
194
|
-
this.accessory.context.
|
|
195
|
-
await this.debugSuccessLog(`
|
|
217
|
+
this.accessory.context.version = deviceVersion;
|
|
218
|
+
await this.debugSuccessLog(`version: ${this.accessory.context.version}`);
|
|
196
219
|
}
|
|
197
220
|
}
|
|
198
221
|
|
|
199
|
-
async parseStatusWebhook(
|
|
200
|
-
| floorCleaningRobotS10WebhookContext): Promise<void> {
|
|
222
|
+
async parseStatusWebhook(): Promise<void> {
|
|
201
223
|
await this.debugLog('parseStatusWebhook');
|
|
202
|
-
await this.debugLog(`(onlineStatus, battery, workingStatus) = Webhook: (${
|
|
203
|
-
+ ` current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel}, ${this.Battery.ChargingState})`);
|
|
224
|
+
await this.debugLog(`(onlineStatus, battery, workingStatus) = Webhook: (${this.webhookContext.onlineStatus}, ${this.webhookContext.battery},`
|
|
225
|
+
+ ` ${this.webhookContext.workingStatus}), current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel}, ${this.Battery.ChargingState})`);
|
|
226
|
+
|
|
204
227
|
// On
|
|
205
|
-
this.LightBulb.On =
|
|
228
|
+
this.LightBulb.On = this.webhookContext.onlineStatus === 'online' ? true : false;
|
|
206
229
|
await this.debugLog(`On: ${this.LightBulb.On}`);
|
|
230
|
+
|
|
207
231
|
// BatteryLevel
|
|
208
|
-
this.Battery.BatteryLevel =
|
|
232
|
+
this.Battery.BatteryLevel = this.webhookContext.battery;
|
|
209
233
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
234
|
+
|
|
210
235
|
// StatusLowBattery
|
|
211
236
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
212
237
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
213
238
|
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
239
|
+
|
|
214
240
|
// ChargingState
|
|
215
|
-
this.Battery.ChargingState =
|
|
241
|
+
this.Battery.ChargingState = this.webhookContext.workingStatus === 'Charging'
|
|
216
242
|
? this.hap.Characteristic.ChargingState.CHARGING : this.hap.Characteristic.ChargingState.NOT_CHARGING;
|
|
217
243
|
await this.debugLog(`ChargingState: ${this.Battery.ChargingState}`);
|
|
218
244
|
}
|
|
@@ -246,7 +272,8 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
246
272
|
const serviceData = await this.monitorAdvertisementPackets(switchbot) as unknown as robotVacuumCleanerServiceData;
|
|
247
273
|
// Update HomeKit
|
|
248
274
|
if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
|
|
249
|
-
|
|
275
|
+
this.serviceData = serviceData;
|
|
276
|
+
await this.BLEparseStatus();
|
|
250
277
|
await this.updateHomeKitCharacteristics();
|
|
251
278
|
} else {
|
|
252
279
|
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
@@ -264,7 +291,8 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
264
291
|
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
|
|
265
292
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
266
293
|
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
267
|
-
|
|
294
|
+
this.deviceStatus = deviceStatus.body;
|
|
295
|
+
await this.openAPIparseStatus();
|
|
268
296
|
await this.updateHomeKitCharacteristics();
|
|
269
297
|
} else {
|
|
270
298
|
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
@@ -283,7 +311,8 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
283
311
|
| robotVacuumCleanerS1PlusWebhookContext | floorCleaningRobotS10WebhookContext) => {
|
|
284
312
|
try {
|
|
285
313
|
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
286
|
-
|
|
314
|
+
this.webhookContext = context;
|
|
315
|
+
await this.parseStatusWebhook();
|
|
287
316
|
await this.updateHomeKitCharacteristics();
|
|
288
317
|
} catch (e: any) {
|
|
289
318
|
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
@@ -482,7 +511,7 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
482
511
|
}
|
|
483
512
|
|
|
484
513
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
485
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${
|
|
514
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
486
515
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
487
516
|
await this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
488
517
|
await this.openAPIRefreshStatus();
|