@switchbot/homebridge-switchbot 2.10.1-beta.0 → 2.10.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +23 -0
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +23 -0
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +23 -0
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +36 -0
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +25 -0
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +22 -0
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +92 -6
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +24 -0
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +24 -0
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +35 -0
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +21 -0
- package/dist/device/lock.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +21 -0
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +21 -0
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +22 -0
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/package.json +1 -1
- package/src/device/blindtilt.ts +23 -0
- package/src/device/bot.ts +23 -0
- package/src/device/ceilinglight.ts +23 -0
- package/src/device/colorbulb.ts +43 -0
- package/src/device/contact.ts +25 -0
- package/src/device/curtain.ts +22 -0
- package/src/device/hub.ts +94 -6
- package/src/device/humidifier.ts +24 -0
- package/src/device/iosensor.ts +24 -0
- package/src/device/lightstrip.ts +42 -0
- package/src/device/lock.ts +21 -0
- package/src/device/motion.ts +21 -0
- package/src/device/plug.ts +21 -0
- package/src/device/robotvacuumcleaner.ts +22 -0
package/src/device/hub.ts
CHANGED
|
@@ -165,14 +165,102 @@ export class Hub {
|
|
|
165
165
|
try {
|
|
166
166
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
167
167
|
if (context.scale === 'CELSIUS') {
|
|
168
|
-
const { temperature, humidity } = context;
|
|
169
|
-
const { CurrentTemperature, CurrentRelativeHumidity } = this;
|
|
168
|
+
const { temperature, humidity, lightLevel } = context;
|
|
169
|
+
const { CurrentTemperature, CurrentRelativeHumidity, CurrentAmbientLightLevel } = this;
|
|
170
170
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
171
|
-
'(temperature, humidity) = ' +
|
|
172
|
-
`Webhook:(${temperature}, ${humidity}), ` +
|
|
173
|
-
`current:(${CurrentTemperature}, ${CurrentRelativeHumidity})`);
|
|
171
|
+
'(temperature, humidity, lightLevel) = ' +
|
|
172
|
+
`Webhook:(${temperature}, ${humidity}, ${lightLevel}), ` +
|
|
173
|
+
`current:(${CurrentTemperature}, ${CurrentRelativeHumidity}, ${CurrentAmbientLightLevel})`);
|
|
174
174
|
this.CurrentRelativeHumidity = humidity;
|
|
175
175
|
this.CurrentTemperature = temperature;
|
|
176
|
+
this.set_minLux = this.minLux();
|
|
177
|
+
this.set_maxLux = this.maxLux();
|
|
178
|
+
this.spaceBetweenLevels = 19;
|
|
179
|
+
switch (lightLevel) {
|
|
180
|
+
case 1:
|
|
181
|
+
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
182
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
183
|
+
break;
|
|
184
|
+
case 2:
|
|
185
|
+
this.CurrentAmbientLightLevel = (this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels;
|
|
186
|
+
this.debugLog(
|
|
187
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel},` +
|
|
188
|
+
` Calculation: ${(this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels}`,
|
|
189
|
+
);
|
|
190
|
+
break;
|
|
191
|
+
case 3:
|
|
192
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 2;
|
|
193
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
194
|
+
break;
|
|
195
|
+
case 4:
|
|
196
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 3;
|
|
197
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
198
|
+
break;
|
|
199
|
+
case 5:
|
|
200
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 4;
|
|
201
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
202
|
+
break;
|
|
203
|
+
case 6:
|
|
204
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 5;
|
|
205
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
206
|
+
break;
|
|
207
|
+
case 7:
|
|
208
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 6;
|
|
209
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
210
|
+
break;
|
|
211
|
+
case 8:
|
|
212
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 7;
|
|
213
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
214
|
+
break;
|
|
215
|
+
case 9:
|
|
216
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 8;
|
|
217
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
218
|
+
break;
|
|
219
|
+
case 10:
|
|
220
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 9;
|
|
221
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
222
|
+
break;
|
|
223
|
+
case 11:
|
|
224
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 10;
|
|
225
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
226
|
+
break;
|
|
227
|
+
case 12:
|
|
228
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 11;
|
|
229
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
230
|
+
break;
|
|
231
|
+
case 13:
|
|
232
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 12;
|
|
233
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
234
|
+
break;
|
|
235
|
+
case 14:
|
|
236
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 13;
|
|
237
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
238
|
+
break;
|
|
239
|
+
case 15:
|
|
240
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 14;
|
|
241
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
242
|
+
break;
|
|
243
|
+
case 16:
|
|
244
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 15;
|
|
245
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
246
|
+
break;
|
|
247
|
+
case 17:
|
|
248
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 16;
|
|
249
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
250
|
+
break;
|
|
251
|
+
case 18:
|
|
252
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 17;
|
|
253
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
254
|
+
break;
|
|
255
|
+
case 19:
|
|
256
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 18;
|
|
257
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
258
|
+
break;
|
|
259
|
+
case 20:
|
|
260
|
+
default:
|
|
261
|
+
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
262
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
263
|
+
}
|
|
176
264
|
this.updateHomeKitCharacteristics();
|
|
177
265
|
}
|
|
178
266
|
} catch (e: any) {
|
|
@@ -300,7 +388,7 @@ export class Hub {
|
|
|
300
388
|
case 20:
|
|
301
389
|
default:
|
|
302
390
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
303
|
-
this.debugLog();
|
|
391
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
304
392
|
}
|
|
305
393
|
this.debugLog(
|
|
306
394
|
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel},` +
|
package/src/device/humidifier.ts
CHANGED
|
@@ -164,6 +164,30 @@ export class Humidifier {
|
|
|
164
164
|
this.refreshStatus();
|
|
165
165
|
});
|
|
166
166
|
|
|
167
|
+
//regisiter webhook event handler
|
|
168
|
+
if (this.device.webhook) {
|
|
169
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
|
|
170
|
+
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
171
|
+
try {
|
|
172
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
173
|
+
if (context.scale === 'CELSIUS') {
|
|
174
|
+
const { temperature, humidity } = context;
|
|
175
|
+
const { CurrentTemperature, CurrentRelativeHumidity } = this;
|
|
176
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
177
|
+
'(temperature, humidity) = ' +
|
|
178
|
+
`Webhook:(${temperature}, ${humidity}), ` +
|
|
179
|
+
`current:(${CurrentTemperature}, ${CurrentRelativeHumidity})`);
|
|
180
|
+
this.CurrentRelativeHumidity = humidity;
|
|
181
|
+
this.CurrentTemperature = temperature;
|
|
182
|
+
this.updateHomeKitCharacteristics();
|
|
183
|
+
}
|
|
184
|
+
} catch (e: any) {
|
|
185
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
186
|
+
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
167
191
|
// Watch for Humidifier change events
|
|
168
192
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
169
193
|
this.doHumidifierUpdate
|
package/src/device/iosensor.ts
CHANGED
|
@@ -169,6 +169,30 @@ export class IOSensor {
|
|
|
169
169
|
.subscribe(async () => {
|
|
170
170
|
await this.refreshStatus();
|
|
171
171
|
});
|
|
172
|
+
|
|
173
|
+
//regisiter webhook event handler
|
|
174
|
+
if (this.device.webhook) {
|
|
175
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
|
|
176
|
+
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
177
|
+
try {
|
|
178
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
179
|
+
if (context.scale === 'CELSIUS') {
|
|
180
|
+
const { temperature, humidity } = context;
|
|
181
|
+
const { CurrentTemperature, CurrentRelativeHumidity } = this;
|
|
182
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
183
|
+
'(temperature, humidity) = ' +
|
|
184
|
+
`Webhook:(${temperature}, ${humidity}), ` +
|
|
185
|
+
`current:(${CurrentTemperature}, ${CurrentRelativeHumidity})`);
|
|
186
|
+
this.CurrentRelativeHumidity = humidity;
|
|
187
|
+
this.CurrentTemperature = temperature;
|
|
188
|
+
this.updateHomeKitCharacteristics();
|
|
189
|
+
}
|
|
190
|
+
} catch (e: any) {
|
|
191
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
192
|
+
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}
|
|
172
196
|
}
|
|
173
197
|
|
|
174
198
|
/**
|
package/src/device/lightstrip.ts
CHANGED
|
@@ -183,6 +183,48 @@ export class StripLight {
|
|
|
183
183
|
await this.refreshStatus();
|
|
184
184
|
});
|
|
185
185
|
|
|
186
|
+
//regisiter webhook event handler
|
|
187
|
+
if (this.device.webhook) {
|
|
188
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
|
|
189
|
+
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
190
|
+
try {
|
|
191
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
192
|
+
const { powerState, brightness, color, colorTemperature } = context;
|
|
193
|
+
const { On, Brightness, Hue, Saturation, ColorTemperature } = this;
|
|
194
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
195
|
+
'(powerState, brightness, color, colorTemperature) = ' +
|
|
196
|
+
`Webhook:(${powerState}, ${brightness}, ${color}, ${colorTemperature}), ` +
|
|
197
|
+
`current:(${On}, ${Brightness}, ${Hue}, ${Saturation}, ${ColorTemperature})`);
|
|
198
|
+
this.On = powerState === 'ON' ? true : false;
|
|
199
|
+
this.Brightness = brightness;
|
|
200
|
+
|
|
201
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(color)}`);
|
|
202
|
+
const [red, green, blue] = color!.split(':');
|
|
203
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
204
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
205
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
206
|
+
|
|
207
|
+
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
208
|
+
this.debugLog(
|
|
209
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` + ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`,
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
// Hue
|
|
213
|
+
this.Hue = hue;
|
|
214
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
215
|
+
|
|
216
|
+
// Saturation
|
|
217
|
+
this.Saturation = saturation;
|
|
218
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
219
|
+
|
|
220
|
+
this.updateHomeKitCharacteristics();
|
|
221
|
+
} catch (e: any) {
|
|
222
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
223
|
+
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
186
228
|
// Watch for Bulb change events
|
|
187
229
|
// We put in a debounce of 1000ms so we don't make duplicate calls
|
|
188
230
|
this.doStripLightUpdate
|
package/src/device/lock.ts
CHANGED
|
@@ -132,6 +132,27 @@ export class Lock {
|
|
|
132
132
|
await this.refreshStatus();
|
|
133
133
|
});
|
|
134
134
|
|
|
135
|
+
//regisiter webhook event handler
|
|
136
|
+
if (this.device.webhook) {
|
|
137
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
|
|
138
|
+
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
139
|
+
try {
|
|
140
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
141
|
+
const { lockState } = context;
|
|
142
|
+
const { LockCurrentState } = this;
|
|
143
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
144
|
+
'(lockState) = ' +
|
|
145
|
+
`Webhook:(${lockState}), ` +
|
|
146
|
+
`current:(${LockCurrentState})`);
|
|
147
|
+
this.LockCurrentState = lockState === 'LOCKED' ? 1 : 0;
|
|
148
|
+
this.updateHomeKitCharacteristics();
|
|
149
|
+
} catch (e: any) {
|
|
150
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
151
|
+
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
135
156
|
// Watch for Lock change events
|
|
136
157
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
137
158
|
this.doLockUpdate
|
package/src/device/motion.ts
CHANGED
|
@@ -131,6 +131,27 @@ export class Motion {
|
|
|
131
131
|
.subscribe(async () => {
|
|
132
132
|
await this.refreshStatus();
|
|
133
133
|
});
|
|
134
|
+
|
|
135
|
+
//regisiter webhook event handler
|
|
136
|
+
if (this.device.webhook) {
|
|
137
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
|
|
138
|
+
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
139
|
+
try {
|
|
140
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
141
|
+
const { detectionState } = context;
|
|
142
|
+
const { MotionDetected } = this;
|
|
143
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
144
|
+
'(detectionState) = ' +
|
|
145
|
+
`Webhook:(${detectionState}), ` +
|
|
146
|
+
`current:(${MotionDetected})`);
|
|
147
|
+
this.MotionDetected = detectionState === 'DETECTED' ? true : false;
|
|
148
|
+
this.updateHomeKitCharacteristics();
|
|
149
|
+
} catch (e: any) {
|
|
150
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
151
|
+
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}
|
|
134
155
|
}
|
|
135
156
|
|
|
136
157
|
/**
|
package/src/device/plug.ts
CHANGED
|
@@ -88,6 +88,27 @@ export class Plug {
|
|
|
88
88
|
await this.refreshStatus();
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
+
//regisiter webhook event handler
|
|
92
|
+
if (this.device.webhook) {
|
|
93
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
|
|
94
|
+
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
95
|
+
try {
|
|
96
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
97
|
+
const { powerState } = context;
|
|
98
|
+
const { On } = this;
|
|
99
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
100
|
+
'(powerState) = ' +
|
|
101
|
+
`Webhook:(${powerState}), ` +
|
|
102
|
+
`current:(${On})`);
|
|
103
|
+
this.On = powerState === 'ON' ? true : false;
|
|
104
|
+
this.updateHomeKitCharacteristics();
|
|
105
|
+
} catch (e: any) {
|
|
106
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
107
|
+
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
91
112
|
// Watch for Plug change events
|
|
92
113
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
93
114
|
this.doPlugUpdate
|
|
@@ -120,6 +120,28 @@ export class RobotVacuumCleaner {
|
|
|
120
120
|
await this.refreshStatus();
|
|
121
121
|
});
|
|
122
122
|
|
|
123
|
+
//regisiter webhook event handler
|
|
124
|
+
if (this.device.webhook) {
|
|
125
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
|
|
126
|
+
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
127
|
+
try {
|
|
128
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
129
|
+
const { onlineStatus, battery } = context;
|
|
130
|
+
const { On, BatteryLevel } = this;
|
|
131
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
132
|
+
'(onlineStatus, battery) = ' +
|
|
133
|
+
`Webhook:(${onlineStatus}, ${battery}), ` +
|
|
134
|
+
`current:(${On}, ${BatteryLevel})`);
|
|
135
|
+
this.On = onlineStatus === 'online' ? true : false;
|
|
136
|
+
this.BatteryLevel = battery;
|
|
137
|
+
this.updateHomeKitCharacteristics();
|
|
138
|
+
} catch (e: any) {
|
|
139
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
140
|
+
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
123
145
|
// Watch for Plug change events
|
|
124
146
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
125
147
|
this.doRobotVacuumCleanerUpdate
|