@switchbot/homebridge-switchbot 3.5.1-beta.2 → 3.5.1-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/device/blindtilt.d.ts +15 -6
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +203 -255
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -4
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +196 -218
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +9 -4
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +202 -247
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +10 -5
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +329 -378
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +9 -4
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +99 -142
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +19 -7
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +203 -264
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +28 -32
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +186 -225
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +9 -4
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +198 -227
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +9 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +106 -231
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +12 -4
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +192 -232
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +9 -4
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +91 -157
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -5
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +287 -367
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +10 -5
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +171 -216
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +9 -4
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +93 -158
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +9 -4
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +94 -155
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +9 -4
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +84 -142
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -4
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +99 -124
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +9 -6
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +170 -253
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +12 -4
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +102 -128
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +2 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +2 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +2 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +2 -1
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +1 -1
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +2 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +2 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +2 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +2 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +2 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +5 -7
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +51 -34
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +49 -191
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +19 -0
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +279 -0
- package/dist/types/bledevicestatus.d.ts.map +1 -0
- package/dist/types/bledevicestatus.js +2 -0
- package/dist/types/bledevicestatus.js.map +1 -0
- package/dist/types/devicelist.d.ts +89 -0
- package/dist/types/devicelist.d.ts.map +1 -0
- package/dist/types/devicelist.js +6 -0
- package/dist/types/devicelist.js.map +1 -0
- package/dist/types/deviceresponse.d.ts +13 -0
- package/dist/types/deviceresponse.d.ts.map +1 -0
- package/dist/types/deviceresponse.js +2 -0
- package/dist/types/deviceresponse.js.map +1 -0
- package/dist/types/devicestatus.d.ts +149 -0
- package/dist/types/devicestatus.d.ts.map +1 -0
- package/dist/types/devicestatus.js +3 -0
- package/dist/types/devicestatus.js.map +1 -0
- package/dist/types/devicewebhookstatus.d.ts +156 -0
- package/dist/types/devicewebhookstatus.d.ts.map +1 -0
- package/dist/types/devicewebhookstatus.js +2 -0
- package/dist/types/devicewebhookstatus.js.map +1 -0
- package/dist/types/irdevicelist.d.ts +10 -0
- package/dist/types/irdevicelist.d.ts.map +1 -0
- package/dist/types/irdevicelist.js +2 -0
- package/dist/types/irdevicelist.js.map +1 -0
- package/dist/types/pushbody.d.ts +6 -0
- package/dist/types/pushbody.d.ts.map +1 -0
- package/dist/types/pushbody.js +2 -0
- package/dist/types/pushbody.js.map +1 -0
- package/dist/utils.d.ts +25 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +28 -0
- package/dist/utils.js.map +1 -1
- package/package.json +10 -10
- package/src/device/blindtilt.ts +223 -263
- package/src/device/bot.ts +208 -221
- package/src/device/ceilinglight.ts +210 -257
- package/src/device/colorbulb.ts +334 -397
- package/src/device/contact.ts +111 -146
- package/src/device/curtain.ts +220 -283
- package/src/device/device.ts +194 -245
- package/src/device/fan.ts +214 -230
- package/src/device/hub.ts +126 -246
- package/src/device/humidifier.ts +216 -243
- package/src/device/iosensor.ts +114 -166
- package/src/device/lightstrip.ts +302 -377
- package/src/device/lock.ts +187 -221
- package/src/device/meter.ts +116 -177
- package/src/device/meterplus.ts +117 -174
- package/src/device/motion.ts +99 -144
- package/src/device/plug.ts +110 -128
- package/src/device/robotvacuumcleaner.ts +189 -252
- package/src/device/waterdetector.ts +120 -138
- package/src/irdevice/airconditioner.ts +2 -1
- package/src/irdevice/airpurifier.ts +2 -1
- package/src/irdevice/camera.ts +2 -1
- package/src/irdevice/fan.ts +2 -1
- package/src/irdevice/irdevice.ts +3 -2
- package/src/irdevice/light.ts +2 -1
- package/src/irdevice/other.ts +2 -1
- package/src/irdevice/tv.ts +2 -1
- package/src/irdevice/vacuumcleaner.ts +2 -1
- package/src/irdevice/waterheater.ts +2 -1
- package/src/platform.ts +52 -34
- package/src/settings.ts +30 -239
- package/src/types/bledevicestatus.ts +305 -0
- package/src/types/devicelist.ts +124 -0
- package/src/types/deviceresponse.ts +15 -0
- package/src/types/devicestatus.ts +178 -0
- package/src/types/devicewebhookstatus.ts +196 -0
- package/src/types/irdevicelist.ts +15 -0
- package/src/types/pushbody.ts +9 -0
- package/src/utils.ts +33 -0
package/src/device/motion.ts
CHANGED
|
@@ -5,10 +5,15 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { deviceBase } from './device.js';
|
|
7
7
|
import { Subject, interval, skipWhile } from 'rxjs';
|
|
8
|
+
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
8
9
|
|
|
10
|
+
import type { devicesConfig } from '../settings.js';
|
|
11
|
+
import type { device } from '../types/devicelist.js';
|
|
9
12
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
13
|
+
import type { motionSensorServiceData } from '../types/bledevicestatus.js';
|
|
14
|
+
import type { motionSensorStatus } from '../types/devicestatus.js';
|
|
15
|
+
import type { motionSensorWebhookContext } from '../types/devicewebhookstatus.js';
|
|
10
16
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
11
|
-
import type { device, devicesConfig, serviceData, deviceStatus } from '../settings.js';
|
|
12
17
|
|
|
13
18
|
/**
|
|
14
19
|
* Platform Accessory
|
|
@@ -128,97 +133,64 @@ export class Motion extends deviceBase {
|
|
|
128
133
|
// Retrieve initial values and updateHomekit
|
|
129
134
|
this.updateHomeKitCharacteristics();
|
|
130
135
|
|
|
136
|
+
//regisiter webhook event handler
|
|
137
|
+
this.registerWebhook();
|
|
138
|
+
|
|
131
139
|
// Start an update interval
|
|
132
140
|
interval(this.deviceRefreshRate * 1000)
|
|
133
141
|
.pipe(skipWhile(() => this.motionUbpdateInProgress))
|
|
134
142
|
.subscribe(async () => {
|
|
135
143
|
await this.refreshStatus();
|
|
136
144
|
});
|
|
137
|
-
|
|
138
|
-
//regisiter webhook event handler
|
|
139
|
-
this.registerWebhook(accessory, device);
|
|
140
145
|
}
|
|
141
146
|
|
|
142
|
-
async BLEparseStatus(serviceData:
|
|
143
|
-
this.debugLog(
|
|
147
|
+
async BLEparseStatus(serviceData: motionSensorServiceData): Promise<void> {
|
|
148
|
+
await this.debugLog('BLEparseStatus');
|
|
144
149
|
// Movement
|
|
145
|
-
this.MotionSensor.MotionDetected = serviceData.movement
|
|
146
|
-
this.debugLog(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
switch (serviceData.lightLevel) {
|
|
155
|
-
case 'dark':
|
|
156
|
-
case 1:
|
|
157
|
-
this.LightSensor!.CurrentAmbientLightLevel = set_minLux;
|
|
158
|
-
break;
|
|
159
|
-
default:
|
|
160
|
-
this.LightSensor!.CurrentAmbientLightLevel = set_maxLux;
|
|
161
|
-
}
|
|
162
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel},`
|
|
163
|
-
+ ` CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
|
|
164
|
-
if (this.LightSensor!.CurrentAmbientLightLevel !== this.accessory.context.CurrentAmbientLightLevel) {
|
|
165
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
166
|
-
+ ` CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
|
|
167
|
-
}
|
|
150
|
+
this.MotionSensor.MotionDetected = serviceData.movement;
|
|
151
|
+
await this.debugLog(`MotionDetected: ${this.MotionSensor.MotionDetected}`);
|
|
152
|
+
// CurrentAmbientLightLevel
|
|
153
|
+
if (!this.device.motion?.hide_lightsensor && this.LightSensor?.Service) {
|
|
154
|
+
const set_minLux = this.device.blindTilt?.set_minLux ?? 1;
|
|
155
|
+
const set_maxLux = this.device.blindTilt?.set_maxLux ?? 6001;
|
|
156
|
+
const lightLevel = serviceData.lightLevel === 'bright' ? set_maxLux : set_minLux;
|
|
157
|
+
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2);
|
|
158
|
+
await this.debugLog(`LightLevel: ${serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
168
159
|
}
|
|
169
|
-
//
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
this.Battery.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
} else {
|
|
177
|
-
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
178
|
-
}
|
|
179
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
|
|
180
|
-
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
160
|
+
// BatteryLevel
|
|
161
|
+
this.Battery.BatteryLevel = serviceData.battery;
|
|
162
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
163
|
+
// StatusLowBattery
|
|
164
|
+
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
165
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
166
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
181
167
|
}
|
|
182
168
|
|
|
183
|
-
async openAPIparseStatus(deviceStatus:
|
|
184
|
-
this.debugLog(
|
|
169
|
+
async openAPIparseStatus(deviceStatus: motionSensorStatus): Promise<void> {
|
|
170
|
+
await this.debugLog('openAPIparseStatus');
|
|
185
171
|
// Motion State
|
|
186
|
-
this.MotionSensor.MotionDetected = deviceStatus.
|
|
187
|
-
this.debugLog(
|
|
188
|
-
//
|
|
189
|
-
if (!this.device.motion?.hide_lightsensor) {
|
|
190
|
-
const set_minLux = this.device.
|
|
191
|
-
const set_maxLux = this.device.
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
break;
|
|
196
|
-
case 'bright':
|
|
197
|
-
default:
|
|
198
|
-
this.LightSensor!.CurrentAmbientLightLevel = set_maxLux;
|
|
199
|
-
}
|
|
200
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
201
|
-
+ ` CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// Battery
|
|
205
|
-
this.Battery.BatteryLevel = Number(deviceStatus.body.battery);
|
|
206
|
-
if (this.Battery.BatteryLevel < 10) {
|
|
207
|
-
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
208
|
-
} else {
|
|
209
|
-
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
172
|
+
this.MotionSensor.MotionDetected = deviceStatus.moveDetected;
|
|
173
|
+
await this.debugLog(`MotionDetected: ${this.MotionSensor.MotionDetected}`);
|
|
174
|
+
// CurrentAmbientLightLevel
|
|
175
|
+
if (!this.device.motion?.hide_lightsensor && this.LightSensor?.Service) {
|
|
176
|
+
const set_minLux = this.device.blindTilt?.set_minLux ?? 1;
|
|
177
|
+
const set_maxLux = this.device.blindTilt?.set_maxLux ?? 6001;
|
|
178
|
+
const lightLevel = deviceStatus.brightness === 'bright' ? set_maxLux : set_minLux;
|
|
179
|
+
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2);
|
|
180
|
+
await this.debugLog(`LightLevel: ${deviceStatus.brightness}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
210
181
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
182
|
+
// BatteryLevel
|
|
183
|
+
this.Battery.BatteryLevel = Number(deviceStatus.battery);
|
|
184
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
185
|
+
// StatusLowBattery
|
|
186
|
+
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
187
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
188
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
189
|
+
// FirmwareVersion
|
|
190
|
+
const version = deviceStatus.version.toString();
|
|
191
|
+
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
192
|
+
if (deviceStatus.version) {
|
|
193
|
+
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
222
194
|
this.accessory
|
|
223
195
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
224
196
|
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
@@ -226,29 +198,36 @@ export class Motion extends deviceBase {
|
|
|
226
198
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
227
199
|
.updateValue(deviceVersion);
|
|
228
200
|
this.accessory.context.deviceVersion = deviceVersion;
|
|
229
|
-
this.
|
|
201
|
+
await this.debugLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
|
|
230
202
|
}
|
|
231
203
|
}
|
|
232
204
|
|
|
205
|
+
async parseStatusWebhook(context: motionSensorWebhookContext): Promise<void> {
|
|
206
|
+
await this.debugLog('parseStatusWebhook');
|
|
207
|
+
await this.debugLog(`(detectionState) = Webhook: (${context.detectionState}), current: (${this.MotionSensor.MotionDetected})`);
|
|
208
|
+
// MotionDetected
|
|
209
|
+
this.MotionSensor.MotionDetected = context.detectionState === 'DETECTED' ? true : false;
|
|
210
|
+
await this.debugLog(`MotionDetected: ${this.MotionSensor.MotionDetected}`);
|
|
211
|
+
}
|
|
212
|
+
|
|
233
213
|
/**
|
|
234
214
|
* Asks the SwitchBot API for the latest device information
|
|
235
215
|
*/
|
|
236
216
|
async refreshStatus(): Promise<void> {
|
|
237
217
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
238
|
-
this.errorLog(
|
|
218
|
+
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
239
219
|
} else if (this.BLE) {
|
|
240
220
|
await this.BLERefreshStatus();
|
|
241
221
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
242
222
|
await this.openAPIRefreshStatus();
|
|
243
223
|
} else {
|
|
244
224
|
await this.offlineOff();
|
|
245
|
-
this.debugWarnLog(
|
|
246
|
-
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
225
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
247
226
|
}
|
|
248
227
|
}
|
|
249
228
|
|
|
250
229
|
async BLERefreshStatus(): Promise<void> {
|
|
251
|
-
this.debugLog(
|
|
230
|
+
await this.debugLog('BLERefreshStatus');
|
|
252
231
|
const switchbot = await this.switchbotBLE();
|
|
253
232
|
|
|
254
233
|
if (switchbot === undefined) {
|
|
@@ -257,13 +236,13 @@ export class Motion extends deviceBase {
|
|
|
257
236
|
// Start to monitor advertisement packets
|
|
258
237
|
(async () => {
|
|
259
238
|
// Start to monitor advertisement packets
|
|
260
|
-
const serviceData
|
|
239
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as motionSensorServiceData;
|
|
261
240
|
// Update HomeKit
|
|
262
|
-
if (serviceData.model
|
|
241
|
+
if (serviceData.model === SwitchBotBLEModel.MotionSensor && serviceData.modelName === SwitchBotBLEModelName.MotionSensor) {
|
|
263
242
|
await this.BLEparseStatus(serviceData);
|
|
264
243
|
await this.updateHomeKitCharacteristics();
|
|
265
244
|
} else {
|
|
266
|
-
this.errorLog(
|
|
245
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
267
246
|
await this.BLERefreshConnection(switchbot);
|
|
268
247
|
}
|
|
269
248
|
})();
|
|
@@ -271,42 +250,39 @@ export class Motion extends deviceBase {
|
|
|
271
250
|
}
|
|
272
251
|
|
|
273
252
|
async openAPIRefreshStatus(): Promise<void> {
|
|
274
|
-
this.debugLog(
|
|
253
|
+
await this.debugLog('openAPIRefreshStatus');
|
|
275
254
|
try {
|
|
276
255
|
const { body, statusCode } = await this.deviceRefreshStatus();
|
|
277
256
|
const deviceStatus: any = await body.json();
|
|
278
|
-
await this.
|
|
279
|
-
if (
|
|
280
|
-
await this.
|
|
281
|
-
await this.openAPIparseStatus(deviceStatus);
|
|
257
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
|
|
258
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
259
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
260
|
+
await this.openAPIparseStatus(deviceStatus.body);
|
|
282
261
|
await this.updateHomeKitCharacteristics();
|
|
283
262
|
} else {
|
|
284
|
-
await this.
|
|
263
|
+
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
264
|
+
await this.debugWarnLog(statusCode, deviceStatus);
|
|
285
265
|
}
|
|
286
266
|
} catch (e: any) {
|
|
287
267
|
await this.apiError(e);
|
|
288
|
-
await this.
|
|
268
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
289
269
|
}
|
|
290
270
|
}
|
|
291
271
|
|
|
292
|
-
async registerWebhook(
|
|
293
|
-
if (device.webhook) {
|
|
294
|
-
this.debugLog(
|
|
295
|
-
this.platform.webhookEventHandler[device.deviceId] = async (context) => {
|
|
272
|
+
async registerWebhook() {
|
|
273
|
+
if (this.device.webhook) {
|
|
274
|
+
await this.debugLog('is listening webhook.');
|
|
275
|
+
this.platform.webhookEventHandler[this.device.deviceId] = async (context: motionSensorWebhookContext) => {
|
|
296
276
|
try {
|
|
297
|
-
this.debugLog(
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} (detectionState) = Webhook: (${detectionState}),`
|
|
301
|
-
+ ` current: (${MotionDetected})`);
|
|
302
|
-
this.MotionSensor.MotionDetected = detectionState === 'DETECTED' ? true : false;
|
|
303
|
-
this.updateHomeKitCharacteristics();
|
|
277
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
278
|
+
await this.parseStatusWebhook(context);
|
|
279
|
+
await this.updateHomeKitCharacteristics();
|
|
304
280
|
} catch (e: any) {
|
|
305
|
-
this.errorLog(
|
|
281
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
306
282
|
}
|
|
307
283
|
};
|
|
308
284
|
} else {
|
|
309
|
-
this.debugLog(
|
|
285
|
+
await this.debugLog('is not listening webhook.');
|
|
310
286
|
}
|
|
311
287
|
}
|
|
312
288
|
|
|
@@ -314,47 +290,26 @@ export class Motion extends deviceBase {
|
|
|
314
290
|
* Updates the status for each of the HomeKit Characteristics
|
|
315
291
|
*/
|
|
316
292
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
this.
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
this.
|
|
329
|
-
|
|
330
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
331
|
-
}
|
|
332
|
-
if (this.Battery.StatusLowBattery === undefined) {
|
|
333
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
334
|
-
} else {
|
|
335
|
-
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
336
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
337
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
338
|
-
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
339
|
-
}
|
|
340
|
-
if (this.BLE) {
|
|
341
|
-
if (this.LightSensor!.CurrentAmbientLightLevel === undefined) {
|
|
342
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
343
|
-
+ ` CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
|
|
344
|
-
} else {
|
|
345
|
-
this.accessory.context.CurrentAmbientLightLevel = this.LightSensor!.CurrentAmbientLightLevel;
|
|
346
|
-
this.LightSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.LightSensor!.CurrentAmbientLightLevel);
|
|
347
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
348
|
-
+ ` updateCharacteristic CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
|
|
349
|
-
}
|
|
293
|
+
// MotionDetected
|
|
294
|
+
await this.updateCharacteristic(this.MotionSensor.Service, this.hap.Characteristic.MotionDetected,
|
|
295
|
+
this.MotionSensor.MotionDetected, 'MotionDetected');
|
|
296
|
+
// BatteryLevel
|
|
297
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.BatteryLevel,
|
|
298
|
+
this.Battery.BatteryLevel, 'BatteryLevel');
|
|
299
|
+
// StatusLowBattery
|
|
300
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.StatusLowBattery,
|
|
301
|
+
this.Battery.StatusLowBattery, 'StatusLowBattery');
|
|
302
|
+
// CurrentAmbientLightLevel
|
|
303
|
+
if (!this.device.motion?.hide_lightsensor && this.LightSensor?.Service) {
|
|
304
|
+
await this.updateCharacteristic(this.LightSensor.Service, this.hap.Characteristic.CurrentAmbientLightLevel,
|
|
305
|
+
this.LightSensor.CurrentAmbientLightLevel, 'CurrentAmbientLightLevel');
|
|
350
306
|
}
|
|
351
307
|
}
|
|
352
308
|
|
|
353
309
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
354
|
-
this.errorLog(
|
|
355
|
-
+ ` ${JSON.stringify(switchbot)}`);
|
|
310
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
|
|
356
311
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
357
|
-
this.warnLog(
|
|
312
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
358
313
|
await this.openAPIRefreshStatus();
|
|
359
314
|
}
|
|
360
315
|
}
|
|
@@ -369,8 +324,8 @@ export class Motion extends deviceBase {
|
|
|
369
324
|
this.MotionSensor.Service.updateCharacteristic(this.hap.Characteristic.MotionDetected, e);
|
|
370
325
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
371
326
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
372
|
-
if (this.
|
|
373
|
-
this.LightSensor
|
|
327
|
+
if (!this.device.motion?.hide_lightsensor && this.LightSensor?.Service) {
|
|
328
|
+
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e);
|
|
374
329
|
}
|
|
375
330
|
}
|
|
376
331
|
}
|