@switchbot/homebridge-switchbot 3.5.1-beta.12 → 3.5.1-beta.13
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/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 +57 -45
- 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 +38 -24
- 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 +40 -21
- 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 +42 -31
- 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 +40 -28
- 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 +35 -22
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +13 -2
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +223 -108
- 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 +48 -29
- 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 +43 -26
- 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 +43 -26
- 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 +39 -24
- 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 +43 -27
- 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 +33 -22
- 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 +38 -24
- 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 +37 -24
- 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 +33 -22
- 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 +27 -16
- 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 +34 -21
- 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 +38 -23
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +19 -72
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.js +4 -4
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +3 -10
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +7 -25
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +1 -1
- package/dist/irdevice/irdevice.js +1 -1
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +9 -27
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.js +1 -1
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +3 -18
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +2 -9
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +2 -9
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +0 -11
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +11 -184
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +9 -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 +9 -9
- package/src/device/blindtilt.ts +60 -47
- package/src/device/bot.ts +47 -25
- package/src/device/ceilinglight.ts +52 -21
- package/src/device/colorbulb.ts +45 -31
- package/src/device/contact.ts +43 -28
- package/src/device/curtain.ts +45 -23
- package/src/device/device.ts +226 -96
- package/src/device/fan.ts +61 -30
- package/src/device/hub.ts +55 -29
- package/src/device/humidifier.ts +55 -31
- package/src/device/iosensor.ts +45 -27
- package/src/device/lightstrip.ts +48 -28
- package/src/device/lock.ts +49 -23
- package/src/device/meter.ts +54 -26
- package/src/device/meterplus.ts +50 -26
- package/src/device/motion.ts +45 -24
- package/src/device/plug.ts +34 -17
- package/src/device/robotvacuumcleaner.ts +49 -23
- package/src/device/waterdetector.ts +56 -25
- package/src/irdevice/airconditioner.ts +19 -65
- package/src/irdevice/airpurifier.ts +4 -4
- package/src/irdevice/camera.ts +4 -9
- package/src/irdevice/fan.ts +10 -22
- package/src/irdevice/irdevice.ts +1 -1
- package/src/irdevice/light.ts +10 -24
- package/src/irdevice/other.ts +1 -1
- package/src/irdevice/tv.ts +5 -16
- package/src/irdevice/vacuumcleaner.ts +3 -8
- package/src/irdevice/waterheater.ts +3 -8
- package/src/platform.ts +11 -184
- package/src/settings.ts +10 -8
- package/src/types/bledevicestatus.ts +4 -2
- package/src/types/devicestatus.ts +1 -1
package/src/device/iosensor.ts
CHANGED
|
@@ -42,6 +42,15 @@ export class IOSensor extends deviceBase {
|
|
|
42
42
|
CurrentTemperature: CharacteristicValue;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
+
// OpenAPI
|
|
46
|
+
deviceStatus!: outdoorMeterStatus;
|
|
47
|
+
|
|
48
|
+
//Webhook
|
|
49
|
+
webhookContext!: outdoorMeterWebhookContext;
|
|
50
|
+
|
|
51
|
+
// BLE
|
|
52
|
+
serviceData!: outdoorMeterServiceData;
|
|
53
|
+
|
|
45
54
|
// Updates
|
|
46
55
|
ioSensorUpdateInProgress!: boolean;
|
|
47
56
|
doIOSensorUpdate: Subject<void>;
|
|
@@ -143,12 +152,11 @@ export class IOSensor extends deviceBase {
|
|
|
143
152
|
}
|
|
144
153
|
|
|
145
154
|
// Retrieve initial values and updateHomekit
|
|
155
|
+
this.debugLog('Retrieve initial values and update Homekit');
|
|
146
156
|
this.refreshStatus();
|
|
147
157
|
|
|
148
|
-
// Retrieve initial values and updateHomekit
|
|
149
|
-
this.updateHomeKitCharacteristics();
|
|
150
|
-
|
|
151
158
|
//regisiter webhook event handler
|
|
159
|
+
this.debugLog('Registering Webhook Event Handler');
|
|
152
160
|
this.registerWebhook();
|
|
153
161
|
|
|
154
162
|
// Start an update interval
|
|
@@ -159,11 +167,14 @@ export class IOSensor extends deviceBase {
|
|
|
159
167
|
});
|
|
160
168
|
}
|
|
161
169
|
|
|
162
|
-
async BLEparseStatus(
|
|
170
|
+
async BLEparseStatus(): Promise<void> {
|
|
163
171
|
await this.debugLog('BLEparseStatus');
|
|
172
|
+
await this.debugLog(`(battery, temperature, humidity) = BLE:(${this.serviceData.battery}, ${this.serviceData.temperature.c},`
|
|
173
|
+
+ ` ${this.serviceData.humidity}), current:(${this.Battery.BatteryLevel}, ${this.TemperatureSensor?.CurrentTemperature},`
|
|
174
|
+
+ ` ${this.HumiditySensor?.CurrentRelativeHumidity})`);
|
|
164
175
|
|
|
165
176
|
// BatteryLevel
|
|
166
|
-
this.Battery.BatteryLevel =
|
|
177
|
+
this.Battery.BatteryLevel = this.serviceData.battery;
|
|
167
178
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
168
179
|
|
|
169
180
|
// StatusLowBattery
|
|
@@ -173,23 +184,26 @@ export class IOSensor extends deviceBase {
|
|
|
173
184
|
|
|
174
185
|
// CurrentRelativeHumidity
|
|
175
186
|
if (!this.device.iosensor?.hide_humidity && this.HumiditySensor?.Service) {
|
|
176
|
-
this.HumiditySensor.CurrentRelativeHumidity = serviceData.humidity;
|
|
187
|
+
this.HumiditySensor.CurrentRelativeHumidity = this.serviceData.humidity;
|
|
177
188
|
await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`);
|
|
178
189
|
}
|
|
179
190
|
|
|
180
191
|
// Current Temperature
|
|
181
192
|
if (!this.device.meter?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
182
|
-
const CELSIUS = serviceData.temperature.c < 0 ? 0 : serviceData.temperature.c > 100 ? 100 : serviceData.temperature.c;
|
|
193
|
+
const CELSIUS = this.serviceData.temperature.c < 0 ? 0 : this.serviceData.temperature.c > 100 ? 100 : this.serviceData.temperature.c;
|
|
183
194
|
this.TemperatureSensor.CurrentTemperature = CELSIUS;
|
|
184
195
|
await this.debugLog(`Temperature: ${this.TemperatureSensor.CurrentTemperature}°c`);
|
|
185
196
|
}
|
|
186
197
|
}
|
|
187
198
|
|
|
188
|
-
async openAPIparseStatus(
|
|
199
|
+
async openAPIparseStatus(): Promise<void> {
|
|
189
200
|
await this.debugLog('openAPIparseStatus');
|
|
201
|
+
await this.debugLog(`(battery, temperature, humidity) = OpenAPI:(${this.deviceStatus.battery}, ${this.deviceStatus.temperature},`
|
|
202
|
+
+ ` ${this.deviceStatus.humidity}), current:(${this.Battery.BatteryLevel}, ${this.TemperatureSensor?.CurrentTemperature},`
|
|
203
|
+
+ ` ${this.HumiditySensor?.CurrentRelativeHumidity})`);
|
|
190
204
|
|
|
191
205
|
// BatteryLevel
|
|
192
|
-
this.Battery.BatteryLevel =
|
|
206
|
+
this.Battery.BatteryLevel = this.deviceStatus.battery;
|
|
193
207
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
194
208
|
|
|
195
209
|
// StatusLowBattery
|
|
@@ -199,20 +213,20 @@ export class IOSensor extends deviceBase {
|
|
|
199
213
|
|
|
200
214
|
// CurrentRelativeHumidity
|
|
201
215
|
if (!this.device.iosensor?.hide_humidity && this.HumiditySensor?.Service) {
|
|
202
|
-
this.HumiditySensor.CurrentRelativeHumidity = deviceStatus.humidity;
|
|
216
|
+
this.HumiditySensor.CurrentRelativeHumidity = this.deviceStatus.humidity;
|
|
203
217
|
await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`);
|
|
204
218
|
}
|
|
205
219
|
|
|
206
220
|
// Current Temperature
|
|
207
221
|
if (!this.device.meter?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
208
|
-
this.TemperatureSensor.CurrentTemperature = deviceStatus.temperature;
|
|
222
|
+
this.TemperatureSensor.CurrentTemperature = this.deviceStatus.temperature;
|
|
209
223
|
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`);
|
|
210
224
|
}
|
|
211
225
|
|
|
212
226
|
// Firmware Version
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
227
|
+
if (this.deviceStatus.version) {
|
|
228
|
+
const version = this.deviceStatus.version.toString();
|
|
229
|
+
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
216
230
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
217
231
|
this.accessory
|
|
218
232
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
@@ -225,24 +239,25 @@ export class IOSensor extends deviceBase {
|
|
|
225
239
|
}
|
|
226
240
|
}
|
|
227
241
|
|
|
228
|
-
async parseStatusWebhook(
|
|
242
|
+
async parseStatusWebhook(): Promise<void> {
|
|
229
243
|
await this.debugLog('parseStatusWebhook');
|
|
230
|
-
await this.debugLog(`(scale, temperature, humidity) = Webhook:(${
|
|
231
|
-
this.device.iosensor?.convertUnitTo)}, ${
|
|
232
|
-
+ ` ${this.HumiditySensor?.CurrentRelativeHumidity})`);
|
|
244
|
+
await this.debugLog(`(scale, temperature, humidity) = Webhook:(${this.webhookContext.scale}, ${convertUnits(this.webhookContext.temperature,
|
|
245
|
+
this.webhookContext.scale, this.device.iosensor?.convertUnitTo)}, ${this.webhookContext.humidity}),`
|
|
246
|
+
+ ` current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity})`);
|
|
233
247
|
|
|
234
|
-
if (
|
|
235
|
-
await this.warnLog(`received a non-CELSIUS Webhook scale: ${
|
|
248
|
+
if (this.webhookContext.scale !== 'CELSIUS' && this.device.iosensor?.convertUnitTo === undefined) {
|
|
249
|
+
await this.warnLog(`received a non-CELSIUS Webhook scale: ${this.webhookContext.scale}, Use the *convertUnitsTo* config under Hub settings,`
|
|
236
250
|
+ ' if displaying incorrectly in HomeKit.');
|
|
237
251
|
}
|
|
238
252
|
// CurrentRelativeHumidity
|
|
239
253
|
if (this.device.iosensor?.hide_humidity && this.HumiditySensor?.Service) {
|
|
240
|
-
this.HumiditySensor.CurrentRelativeHumidity =
|
|
254
|
+
this.HumiditySensor.CurrentRelativeHumidity = this.webhookContext.humidity;
|
|
241
255
|
await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`);
|
|
242
256
|
}
|
|
243
257
|
// CurrentTemperature
|
|
244
258
|
if (this.device.iosensor?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
245
|
-
this.TemperatureSensor.CurrentTemperature = convertUnits(
|
|
259
|
+
this.TemperatureSensor.CurrentTemperature = convertUnits(this.webhookContext.temperature, this.webhookContext.scale,
|
|
260
|
+
this.device.iosensor?.convertUnitTo);
|
|
246
261
|
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`);
|
|
247
262
|
}
|
|
248
263
|
}
|
|
@@ -273,10 +288,11 @@ export class IOSensor extends deviceBase {
|
|
|
273
288
|
// Start to monitor advertisement packets
|
|
274
289
|
(async () => {
|
|
275
290
|
// Start to monitor advertisement packets
|
|
276
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as
|
|
291
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as outdoorMeterServiceData;
|
|
277
292
|
// Update HomeKit
|
|
278
293
|
if (serviceData.model === SwitchBotBLEModel.OutdoorMeter && serviceData.modelName === SwitchBotBLEModelName.OutdoorMeter) {
|
|
279
|
-
|
|
294
|
+
this.serviceData = serviceData;
|
|
295
|
+
await this.BLEparseStatus();
|
|
280
296
|
await this.updateHomeKitCharacteristics();
|
|
281
297
|
} else {
|
|
282
298
|
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
@@ -294,7 +310,8 @@ export class IOSensor extends deviceBase {
|
|
|
294
310
|
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
|
|
295
311
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
296
312
|
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
297
|
-
|
|
313
|
+
this.deviceStatus = deviceStatus.body;
|
|
314
|
+
await this.openAPIparseStatus();
|
|
298
315
|
await this.updateHomeKitCharacteristics();
|
|
299
316
|
} else {
|
|
300
317
|
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
@@ -309,10 +326,11 @@ export class IOSensor extends deviceBase {
|
|
|
309
326
|
async registerWebhook() {
|
|
310
327
|
if (this.device.webhook) {
|
|
311
328
|
await this.debugLog('is listening webhook.');
|
|
312
|
-
this.
|
|
329
|
+
this.webhookEventHandler[this.device.deviceId] = async (context: outdoorMeterWebhookContext) => {
|
|
313
330
|
try {
|
|
314
331
|
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
315
|
-
|
|
332
|
+
this.webhookContext = context;
|
|
333
|
+
await this.parseStatusWebhook();
|
|
316
334
|
await this.updateHomeKitCharacteristics();
|
|
317
335
|
} catch (e: any) {
|
|
318
336
|
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
package/src/device/lightstrip.ts
CHANGED
|
@@ -32,6 +32,15 @@ export class StripLight extends deviceBase {
|
|
|
32
32
|
ColorTemperature?: CharacteristicValue;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
// OpenAPI
|
|
36
|
+
deviceStatus!: stripLightStatus;
|
|
37
|
+
|
|
38
|
+
//Webhook
|
|
39
|
+
webhookContext!: stripLightWebhookContext;
|
|
40
|
+
|
|
41
|
+
// BLE
|
|
42
|
+
serviceData!: stripLightServiceData;
|
|
43
|
+
|
|
35
44
|
// Adaptive Lighting
|
|
36
45
|
AdaptiveLightingController?: ControllerConstructor | Controller<ControllerServiceMap>;
|
|
37
46
|
adaptiveLightingShift?: number;
|
|
@@ -146,12 +155,11 @@ export class StripLight extends deviceBase {
|
|
|
146
155
|
.onSet(this.SaturationSet.bind(this));
|
|
147
156
|
|
|
148
157
|
// Retrieve initial values and updateHomekit
|
|
158
|
+
this.debugLog('Retrieve initial values and update Homekit');
|
|
149
159
|
this.refreshStatus();
|
|
150
160
|
|
|
151
|
-
// Update Homekit
|
|
152
|
-
this.updateHomeKitCharacteristics();
|
|
153
|
-
|
|
154
161
|
//regisiter webhook event handler
|
|
162
|
+
this.debugLog('Registering Webhook Event Handler');
|
|
155
163
|
this.registerWebhook();
|
|
156
164
|
|
|
157
165
|
// Start an update interval
|
|
@@ -181,20 +189,24 @@ export class StripLight extends deviceBase {
|
|
|
181
189
|
});
|
|
182
190
|
}
|
|
183
191
|
|
|
184
|
-
async BLEparseStatus(
|
|
192
|
+
async BLEparseStatus(): Promise<void> {
|
|
185
193
|
await this.debugLog('BLEparseStatus');
|
|
194
|
+
await this.debugLog(`(power, brightness, color) = BLE:(${this.serviceData.power}, ${this.serviceData.brightness},`
|
|
195
|
+
+ ` ${this.serviceData.red}:${this.serviceData.green}:${this.serviceData.blue}), current:(${this.LightBulb.On},`
|
|
196
|
+
+ ` ${this.LightBulb.Brightness}, ${this.LightBulb.Hue}, ${this.LightBulb.Saturation})`);
|
|
197
|
+
|
|
186
198
|
// On
|
|
187
|
-
this.LightBulb.On = serviceData.power;
|
|
199
|
+
this.LightBulb.On = this.serviceData.power;
|
|
188
200
|
await this.debugLog(`On: ${this.LightBulb.On}`);
|
|
189
201
|
|
|
190
202
|
// Brightness
|
|
191
|
-
this.LightBulb.Brightness = serviceData.brightness;
|
|
203
|
+
this.LightBulb.Brightness = this.serviceData.brightness;
|
|
192
204
|
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
193
205
|
|
|
194
206
|
// Color, Hue & Brightness
|
|
195
|
-
await this.debugLog(`red: ${serviceData.red}, green: ${serviceData.green}, blue: ${serviceData.blue}`);
|
|
196
|
-
const [hue, saturation] = rgb2hs(serviceData.red, serviceData.green, serviceData.blue);
|
|
197
|
-
await this.debugLog(`hs: ${JSON.stringify(rgb2hs(serviceData.red, serviceData.green, serviceData.blue))}`);
|
|
207
|
+
await this.debugLog(`red: ${this.serviceData.red}, green: ${this.serviceData.green}, blue: ${this.serviceData.blue}`);
|
|
208
|
+
const [hue, saturation] = rgb2hs(this.serviceData.red, this.serviceData.green, this.serviceData.blue);
|
|
209
|
+
await this.debugLog(`hs: ${JSON.stringify(rgb2hs(this.serviceData.red, this.serviceData.green, this.serviceData.blue))}`);
|
|
198
210
|
|
|
199
211
|
// Hue
|
|
200
212
|
this.LightBulb.Hue = hue;
|
|
@@ -205,19 +217,23 @@ export class StripLight extends deviceBase {
|
|
|
205
217
|
this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
|
|
206
218
|
}
|
|
207
219
|
|
|
208
|
-
async openAPIparseStatus(
|
|
220
|
+
async openAPIparseStatus(): Promise<void> {
|
|
209
221
|
await this.debugLog('openAPIparseStatus');
|
|
222
|
+
await this.debugLog(`(power, brightness, color) = API:(${this.deviceStatus.power}, ${this.deviceStatus.brightness},`
|
|
223
|
+
+ ` ${this.deviceStatus.color}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.Hue},`
|
|
224
|
+
+ ` ${this.LightBulb.Saturation})`);
|
|
225
|
+
|
|
210
226
|
// On
|
|
211
|
-
this.LightBulb.On = deviceStatus.power === 'on' ? true : false;
|
|
227
|
+
this.LightBulb.On = this.deviceStatus.power === 'on' ? true : false;
|
|
212
228
|
await this.debugLog(`On: ${this.LightBulb.On}`);
|
|
213
229
|
|
|
214
230
|
// Brightness
|
|
215
|
-
this.LightBulb.Brightness = deviceStatus.brightness;
|
|
231
|
+
this.LightBulb.Brightness = this.deviceStatus.brightness;
|
|
216
232
|
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
217
233
|
|
|
218
234
|
// Color, Hue & Brightness
|
|
219
|
-
await this.debugLog(`color: ${JSON.stringify(deviceStatus.color)}`);
|
|
220
|
-
const [red, green, blue] = deviceStatus.color.split(':');
|
|
235
|
+
await this.debugLog(`color: ${JSON.stringify(this.deviceStatus.color)}`);
|
|
236
|
+
const [red, green, blue] = this.deviceStatus.color.split(':');
|
|
221
237
|
await this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`);
|
|
222
238
|
const [hue, saturation] = rgb2hs(red, green, blue);
|
|
223
239
|
await this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`);
|
|
@@ -231,9 +247,9 @@ export class StripLight extends deviceBase {
|
|
|
231
247
|
await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
|
|
232
248
|
|
|
233
249
|
// Firmware Version
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
250
|
+
if (this.deviceStatus.version) {
|
|
251
|
+
const version = this.deviceStatus.version.toString();
|
|
252
|
+
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
237
253
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
238
254
|
this.accessory
|
|
239
255
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
@@ -246,22 +262,23 @@ export class StripLight extends deviceBase {
|
|
|
246
262
|
}
|
|
247
263
|
}
|
|
248
264
|
|
|
249
|
-
async parseStatusWebhook(
|
|
265
|
+
async parseStatusWebhook(): Promise<void> {
|
|
250
266
|
await this.debugLog('parseStatusWebhook');
|
|
251
|
-
await this.debugLog(`(powerState, brightness, color) = Webhook:(${
|
|
252
|
-
+ `
|
|
267
|
+
await this.debugLog(`(powerState, brightness, color) = Webhook:(${this.webhookContext.powerState}, ${this.webhookContext.brightness},`
|
|
268
|
+
+ ` ${this.webhookContext.color}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.Hue},`
|
|
269
|
+
+ ` ${this.LightBulb.Saturation})`);
|
|
253
270
|
|
|
254
271
|
// On
|
|
255
|
-
this.LightBulb.On =
|
|
272
|
+
this.LightBulb.On = this.webhookContext.powerState === 'ON' ? true : false;
|
|
256
273
|
await this.debugLog(`On: ${this.LightBulb.On}`);
|
|
257
274
|
|
|
258
275
|
// Brightness
|
|
259
|
-
this.LightBulb.Brightness =
|
|
276
|
+
this.LightBulb.Brightness = this.webhookContext.brightness;
|
|
260
277
|
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
261
278
|
|
|
262
279
|
// Color, Hue & Brightness
|
|
263
|
-
await this.debugLog(`color: ${JSON.stringify(
|
|
264
|
-
const [red, green, blue] =
|
|
280
|
+
await this.debugLog(`color: ${JSON.stringify(this.webhookContext.color)}`);
|
|
281
|
+
const [red, green, blue] = this.webhookContext.color.split(':');
|
|
265
282
|
await this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`);
|
|
266
283
|
const [hue, saturation] = rgb2hs(red, green, blue);
|
|
267
284
|
await this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`);
|
|
@@ -304,7 +321,8 @@ export class StripLight extends deviceBase {
|
|
|
304
321
|
const serviceData = await this.monitorAdvertisementPackets(switchbot) as stripLightServiceData;
|
|
305
322
|
// Update HomeKit
|
|
306
323
|
if (serviceData.model === SwitchBotBLEModel.StripLight && serviceData.modelName === SwitchBotBLEModelName.StripLight) {
|
|
307
|
-
|
|
324
|
+
this.serviceData = serviceData;
|
|
325
|
+
await this.BLEparseStatus();
|
|
308
326
|
await this.updateHomeKitCharacteristics();
|
|
309
327
|
} else {
|
|
310
328
|
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
@@ -322,7 +340,8 @@ export class StripLight extends deviceBase {
|
|
|
322
340
|
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
|
|
323
341
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
324
342
|
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
325
|
-
|
|
343
|
+
this.deviceStatus = deviceStatus.body;
|
|
344
|
+
await this.openAPIparseStatus();
|
|
326
345
|
await this.updateHomeKitCharacteristics();
|
|
327
346
|
} else {
|
|
328
347
|
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
@@ -337,10 +356,11 @@ export class StripLight extends deviceBase {
|
|
|
337
356
|
async registerWebhook() {
|
|
338
357
|
if (this.device.webhook) {
|
|
339
358
|
await this.debugLog('is listening webhook.');
|
|
340
|
-
this.
|
|
359
|
+
this.webhookEventHandler[this.device.deviceId] = async (context: stripLightWebhookContext) => {
|
|
341
360
|
try {
|
|
342
361
|
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
343
|
-
|
|
362
|
+
this.webhookContext = context;
|
|
363
|
+
await this.parseStatusWebhook();
|
|
344
364
|
await this.updateHomeKitCharacteristics();
|
|
345
365
|
} catch (e: any) {
|
|
346
366
|
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
package/src/device/lock.ts
CHANGED
|
@@ -42,6 +42,15 @@ export class Lock extends deviceBase {
|
|
|
42
42
|
On: CharacteristicValue;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
+
// OpenAPI
|
|
46
|
+
deviceStatus!: lockStatus | lockProStatus;
|
|
47
|
+
|
|
48
|
+
//Webhook
|
|
49
|
+
webhookContext!: lockWebhookContext | lockProWebhookContext;
|
|
50
|
+
|
|
51
|
+
// BLE
|
|
52
|
+
serviceData!: lockServiceData | lockProServiceData;
|
|
53
|
+
|
|
45
54
|
// Updates
|
|
46
55
|
lockUpdateInProgress!: boolean;
|
|
47
56
|
doLockUpdate!: Subject<void>;
|
|
@@ -153,12 +162,11 @@ export class Lock extends deviceBase {
|
|
|
153
162
|
}
|
|
154
163
|
|
|
155
164
|
// Retrieve initial values and updateHomekit
|
|
165
|
+
this.debugLog('Retrieve initial values and update Homekit');
|
|
156
166
|
this.refreshStatus();
|
|
157
167
|
|
|
158
|
-
// Update Homekit
|
|
159
|
-
this.updateHomeKitCharacteristics();
|
|
160
|
-
|
|
161
168
|
//regisiter webhook event handler
|
|
169
|
+
this.debugLog('Registering Webhook Event Handler');
|
|
162
170
|
this.registerWebhook();
|
|
163
171
|
|
|
164
172
|
// Start an update interval
|
|
@@ -188,57 +196,70 @@ export class Lock extends deviceBase {
|
|
|
188
196
|
});
|
|
189
197
|
}
|
|
190
198
|
|
|
191
|
-
async BLEparseStatus(
|
|
199
|
+
async BLEparseStatus(): Promise<void> {
|
|
192
200
|
await this.debugLog('BLEparseStatus');
|
|
201
|
+
await this.debugLog(`(lockState) = BLE:(${this.serviceData.status}), current:(${this.LockMechanism.LockCurrentState})`);
|
|
202
|
+
|
|
193
203
|
// LockCurrentState
|
|
194
|
-
this.LockMechanism.LockCurrentState = serviceData.status === 'locked'
|
|
204
|
+
this.LockMechanism.LockCurrentState = this.serviceData.status === 'locked'
|
|
195
205
|
? this.hap.Characteristic.LockCurrentState.SECURED : this.hap.Characteristic.LockCurrentState.UNSECURED;
|
|
196
206
|
await this.debugLog(`LockCurrentState: ${this.LockMechanism.LockCurrentState}`);
|
|
207
|
+
|
|
197
208
|
// LockTargetState
|
|
198
|
-
this.LockMechanism.LockTargetState = serviceData.status === 'locked'
|
|
209
|
+
this.LockMechanism.LockTargetState = this.serviceData.status === 'locked'
|
|
199
210
|
? this.hap.Characteristic.LockTargetState.SECURED : this.hap.Characteristic.LockTargetState.UNSECURED;
|
|
200
211
|
await this.debugLog(`LockTargetState: ${this.LockMechanism.LockTargetState}`);
|
|
212
|
+
|
|
201
213
|
// Contact Sensor
|
|
202
214
|
if (!this.device.lock?.hide_contactsensor && this.ContactSensor?.Service) {
|
|
203
|
-
this.ContactSensor.ContactSensorState = serviceData.door_open === 'opened'
|
|
215
|
+
this.ContactSensor.ContactSensorState = this.serviceData.door_open === 'opened'
|
|
204
216
|
? this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED : this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
205
217
|
await this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`);
|
|
206
218
|
}
|
|
219
|
+
|
|
207
220
|
// BatteryLevel
|
|
208
|
-
this.Battery.BatteryLevel =
|
|
221
|
+
this.Battery.BatteryLevel = this.serviceData.battery;
|
|
209
222
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
223
|
+
|
|
210
224
|
// StatusLowBattery
|
|
211
225
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
212
226
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
213
227
|
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
214
228
|
}
|
|
215
229
|
|
|
216
|
-
async openAPIparseStatus(
|
|
230
|
+
async openAPIparseStatus(): Promise<void> {
|
|
217
231
|
await this.debugLog('openAPIparseStatus');
|
|
232
|
+
await this.debugLog(`(lockState) = OpenAPI:(${this.deviceStatus.lockState}), current:(${this.LockMechanism.LockCurrentState})`);
|
|
233
|
+
|
|
218
234
|
// LockCurrentState
|
|
219
|
-
this.LockMechanism.LockCurrentState = deviceStatus.lockState === 'locked'
|
|
235
|
+
this.LockMechanism.LockCurrentState = this.deviceStatus.lockState === 'locked'
|
|
220
236
|
? this.hap.Characteristic.LockCurrentState.SECURED : this.hap.Characteristic.LockCurrentState.UNSECURED;
|
|
221
237
|
await this.debugLog(`LockCurrentState: ${this.LockMechanism.LockCurrentState}`);
|
|
238
|
+
|
|
222
239
|
// LockTargetState
|
|
223
|
-
this.LockMechanism.LockTargetState = deviceStatus.lockState === 'locked'
|
|
240
|
+
this.LockMechanism.LockTargetState = this.deviceStatus.lockState === 'locked'
|
|
224
241
|
? this.hap.Characteristic.LockTargetState.SECURED : this.hap.Characteristic.LockTargetState.UNSECURED;
|
|
225
242
|
await this.debugLog(`LockTargetState: ${this.LockMechanism.LockTargetState}`);
|
|
243
|
+
|
|
226
244
|
// ContactSensorState
|
|
227
245
|
if (!this.device.lock?.hide_contactsensor && this.ContactSensor?.Service) {
|
|
228
|
-
this.ContactSensor.ContactSensorState = deviceStatus.doorState === 'opened'
|
|
246
|
+
this.ContactSensor.ContactSensorState = this.deviceStatus.doorState === 'opened'
|
|
229
247
|
? this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED : this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
230
248
|
await this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`);
|
|
231
249
|
}
|
|
250
|
+
|
|
232
251
|
// BatteryLevel
|
|
233
|
-
this.Battery.BatteryLevel =
|
|
252
|
+
this.Battery.BatteryLevel = this.deviceStatus.battery;
|
|
234
253
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
254
|
+
|
|
235
255
|
// StatusLowBattery
|
|
236
256
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
237
257
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
238
258
|
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
259
|
+
|
|
239
260
|
// Firmware Version
|
|
240
|
-
if (deviceStatus.version) {
|
|
241
|
-
const version = deviceStatus.version.toString();
|
|
261
|
+
if (this.deviceStatus.version) {
|
|
262
|
+
const version = this.deviceStatus.version.toString();
|
|
242
263
|
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
243
264
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
244
265
|
this.accessory
|
|
@@ -252,15 +273,17 @@ export class Lock extends deviceBase {
|
|
|
252
273
|
}
|
|
253
274
|
}
|
|
254
275
|
|
|
255
|
-
async parseStatusWebhook(
|
|
276
|
+
async parseStatusWebhook(): Promise<void> {
|
|
256
277
|
await this.debugLog('parseStatusWebhook');
|
|
257
|
-
await this.debugLog(`(lockState) = Webhook:(${
|
|
278
|
+
await this.debugLog(`(lockState) = Webhook:(${this.webhookContext.lockState}), current:(${this.LockMechanism.LockCurrentState})`);
|
|
279
|
+
|
|
258
280
|
// LockCurrentState
|
|
259
|
-
this.LockMechanism.LockCurrentState =
|
|
281
|
+
this.LockMechanism.LockCurrentState = this.webhookContext.lockState === 'LOCKED'
|
|
260
282
|
? this.hap.Characteristic.LockCurrentState.SECURED : this.hap.Characteristic.LockCurrentState.UNSECURED;
|
|
261
283
|
await this.debugLog(`LockCurrentState: ${this.LockMechanism.LockCurrentState}`);
|
|
284
|
+
|
|
262
285
|
// LockTargetState
|
|
263
|
-
this.LockMechanism.LockTargetState =
|
|
286
|
+
this.LockMechanism.LockTargetState = this.webhookContext.lockState === 'LOCKED'
|
|
264
287
|
? this.hap.Characteristic.LockTargetState.SECURED : this.hap.Characteristic.LockTargetState.UNSECURED;
|
|
265
288
|
await this.debugLog(`LockTargetState: ${this.LockMechanism.LockTargetState}`);
|
|
266
289
|
}
|
|
@@ -295,7 +318,8 @@ export class Lock extends deviceBase {
|
|
|
295
318
|
// Update HomeKit
|
|
296
319
|
if ((serviceData.model === SwitchBotBLEModel.Lock || SwitchBotBLEModel.LockPro)
|
|
297
320
|
&& (serviceData.modelName === SwitchBotBLEModelName.Lock || SwitchBotBLEModelName.LockPro)) {
|
|
298
|
-
|
|
321
|
+
this.serviceData = serviceData;
|
|
322
|
+
await this.BLEparseStatus();
|
|
299
323
|
await this.updateHomeKitCharacteristics();
|
|
300
324
|
} else {
|
|
301
325
|
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
@@ -313,7 +337,8 @@ export class Lock extends deviceBase {
|
|
|
313
337
|
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
|
|
314
338
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
315
339
|
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
316
|
-
|
|
340
|
+
this.deviceStatus = deviceStatus.body;
|
|
341
|
+
await this.openAPIparseStatus();
|
|
317
342
|
await this.updateHomeKitCharacteristics();
|
|
318
343
|
} else {
|
|
319
344
|
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
@@ -328,10 +353,11 @@ export class Lock extends deviceBase {
|
|
|
328
353
|
async registerWebhook() {
|
|
329
354
|
if (this.device.webhook) {
|
|
330
355
|
await this.debugLog('is listening webhook.');
|
|
331
|
-
this.
|
|
356
|
+
this.webhookEventHandler[this.device.deviceId] = async (context: lockWebhookContext | lockProWebhookContext) => {
|
|
332
357
|
try {
|
|
333
358
|
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
334
|
-
|
|
359
|
+
this.webhookContext = context;
|
|
360
|
+
await this.parseStatusWebhook();
|
|
335
361
|
await this.updateHomeKitCharacteristics();
|
|
336
362
|
} catch (e: any) {
|
|
337
363
|
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|