@switchbot/homebridge-switchbot 1.3.1-beta.9 → 1.4.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/CHANGELOG.md +18 -2
- package/config.schema.json +82 -32
- package/dist/devices/bots.d.ts +15 -3
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +227 -165
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +14 -3
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +163 -105
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +13 -3
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +102 -63
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +14 -5
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +180 -140
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +14 -3
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +173 -133
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +17 -13
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +150 -105
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +13 -3
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +89 -45
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +15 -3
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +115 -53
- package/dist/devices/plugs.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +13 -3
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +97 -46
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +13 -3
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +85 -31
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +12 -3
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +73 -24
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +12 -3
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +83 -35
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +12 -3
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +74 -25
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +12 -3
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +80 -31
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +12 -3
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +90 -42
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +12 -3
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +73 -24
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +12 -3
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +73 -24
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +10 -10
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +290 -307
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +9 -6
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/nodemon.json +1 -1
- package/package.json +6 -6
- package/src/devices/bots.ts +221 -152
- package/src/devices/colorbulb.ts +172 -108
- package/src/devices/contact.ts +109 -64
- package/src/devices/curtains.ts +190 -146
- package/src/devices/humidifiers.ts +181 -135
- package/src/devices/meters.ts +156 -105
- package/src/devices/motion.ts +95 -45
- package/src/devices/plugs.ts +121 -53
- package/src/irdevices/airconditioners.ts +102 -46
- package/src/irdevices/airpurifiers.ts +91 -31
- package/src/irdevices/cameras.ts +79 -24
- package/src/irdevices/fans.ts +89 -36
- package/src/irdevices/lights.ts +80 -25
- package/src/irdevices/others.ts +86 -31
- package/src/irdevices/tvs.ts +96 -42
- package/src/irdevices/vacuumcleaners.ts +79 -24
- package/src/irdevices/waterheaters.ts +79 -24
- package/src/platform.ts +285 -302
- package/src/settings.ts +10 -6
- package/dist/devices/indoorcam.d.ts +0 -64
- package/dist/devices/indoorcam.d.ts.map +0 -1
- package/dist/devices/indoorcam.js +0 -249
- package/dist/devices/indoorcam.js.map +0 -1
- package/src/devices/indoorcam.ts +0 -309
package/src/devices/contact.ts
CHANGED
|
@@ -2,7 +2,7 @@ import Switchbot from 'node-switchbot';
|
|
|
2
2
|
import { interval, Subject } from 'rxjs';
|
|
3
3
|
import { skipWhile } from 'rxjs/operators';
|
|
4
4
|
import { SwitchBotPlatform } from '../platform';
|
|
5
|
-
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
5
|
+
import { Service, PlatformAccessory, CharacteristicValue, HAPStatus } from 'homebridge';
|
|
6
6
|
import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse } from '../settings';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -37,8 +37,8 @@ export class Contact {
|
|
|
37
37
|
lightLevel!: serviceData['lightLevel'];
|
|
38
38
|
|
|
39
39
|
// Config
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
deviceLogging!: string;
|
|
41
|
+
deviceRefreshRate!: number;
|
|
42
42
|
|
|
43
43
|
// Updates
|
|
44
44
|
contactUbpdateInProgress!: boolean;
|
|
@@ -49,14 +49,16 @@ export class Contact {
|
|
|
49
49
|
private accessory: PlatformAccessory,
|
|
50
50
|
public device: device & devicesConfig,
|
|
51
51
|
) {
|
|
52
|
+
// default placeholders
|
|
53
|
+
this.refreshRate();
|
|
54
|
+
this.logs();
|
|
55
|
+
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
56
|
+
|
|
52
57
|
// Contact Config
|
|
53
|
-
this.
|
|
58
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline},`
|
|
54
59
|
+ ` hide_lightsensor: ${device.contact?.hide_lightsensor}, hide_motionsensor: ${device.contact?.hide_motionsensor})`);
|
|
55
60
|
|
|
56
61
|
|
|
57
|
-
// default placeholders
|
|
58
|
-
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
59
|
-
|
|
60
62
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
61
63
|
this.doContactUpdate = new Subject();
|
|
62
64
|
this.contactUbpdateInProgress = false;
|
|
@@ -90,11 +92,11 @@ export class Contact {
|
|
|
90
92
|
|
|
91
93
|
// Motion Sensor Service
|
|
92
94
|
if (device.contact?.hide_motionsensor) {
|
|
93
|
-
this.
|
|
95
|
+
this.debugLog(`Contact Sensor: ${accessory.displayName} Removing Motion Sensor Service`);
|
|
94
96
|
this.motionService = this.accessory.getService(this.platform.Service.MotionSensor);
|
|
95
97
|
accessory.removeService(this.motionService!);
|
|
96
98
|
} else if (!this.motionService) {
|
|
97
|
-
this.
|
|
99
|
+
this.debugLog(`Contact Sensor: ${accessory.displayName} Add Motion Sensor Service`);
|
|
98
100
|
(this.motionService =
|
|
99
101
|
this.accessory.getService(this.platform.Service.MotionSensor) ||
|
|
100
102
|
this.accessory.addService(this.platform.Service.MotionSensor)), `${accessory.displayName} Motion Sensor`;
|
|
@@ -102,16 +104,16 @@ export class Contact {
|
|
|
102
104
|
this.motionService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Motion Sensor`);
|
|
103
105
|
|
|
104
106
|
} else {
|
|
105
|
-
this.
|
|
107
|
+
this.debugLog(`Contact Sensor: ${accessory.displayName} Motion Sensor Service Not Added`);
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
// Light Sensor Service
|
|
109
111
|
if (device.contact?.hide_lightsensor) {
|
|
110
|
-
this.
|
|
112
|
+
this.debugLog(`Contact Sensor: ${accessory.displayName} Removing Light Sensor Service`);
|
|
111
113
|
this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor);
|
|
112
114
|
accessory.removeService(this.lightSensorService!);
|
|
113
115
|
} else if (!this.lightSensorService) {
|
|
114
|
-
this.
|
|
116
|
+
this.debugLog(`Contact Sensor: ${accessory.displayName} Add Light Sensor Service`);
|
|
115
117
|
(this.lightSensorService =
|
|
116
118
|
this.accessory.getService(this.platform.Service.LightSensor) ||
|
|
117
119
|
this.accessory.addService(this.platform.Service.LightSensor)), `${accessory.displayName} Light Sensor`;
|
|
@@ -119,7 +121,7 @@ export class Contact {
|
|
|
119
121
|
this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
|
|
120
122
|
|
|
121
123
|
} else {
|
|
122
|
-
this.
|
|
124
|
+
this.debugLog(`Contact Sensor: ${accessory.displayName} Light Sensor Service Not Added`);
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
if (device.ble) {
|
|
@@ -134,13 +136,31 @@ export class Contact {
|
|
|
134
136
|
this.updateHomeKitCharacteristics();
|
|
135
137
|
|
|
136
138
|
// Start an update interval
|
|
137
|
-
interval(this.
|
|
139
|
+
interval(this.deviceRefreshRate * 1000)
|
|
138
140
|
.pipe(skipWhile(() => this.contactUbpdateInProgress))
|
|
139
141
|
.subscribe(() => {
|
|
140
142
|
this.refreshStatus();
|
|
141
143
|
});
|
|
142
144
|
}
|
|
143
145
|
|
|
146
|
+
refreshRate() {
|
|
147
|
+
if (this.device.refreshRate) {
|
|
148
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
|
|
149
|
+
} else if (this.platform.config.options!.refreshRate) {
|
|
150
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
logs() {
|
|
155
|
+
if (this.device.logging) {
|
|
156
|
+
this.deviceLogging = this.accessory.context.logging = this.device.logging;
|
|
157
|
+
} else if (this.platform.config.options?.logging) {
|
|
158
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
159
|
+
} else {
|
|
160
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
144
164
|
/**
|
|
145
165
|
* Parse the device status from the SwitchBot api
|
|
146
166
|
*/
|
|
@@ -153,7 +173,7 @@ export class Contact {
|
|
|
153
173
|
}
|
|
154
174
|
|
|
155
175
|
private async BLEparseStatus() {
|
|
156
|
-
this.
|
|
176
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} BLE parseStatus`);
|
|
157
177
|
if (this.device.contact?.hide_motionsensor) {
|
|
158
178
|
// Movement
|
|
159
179
|
this.MotionDetected = Boolean(this.movement);
|
|
@@ -169,7 +189,7 @@ export class Contact {
|
|
|
169
189
|
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
170
190
|
break;
|
|
171
191
|
default:
|
|
172
|
-
this.
|
|
192
|
+
this.errorLog(`Contact Sensor: ${this.accessory.displayName} timeout no closed, doorstate: ${this.doorState}`);
|
|
173
193
|
}
|
|
174
194
|
if (this.device.contact?.hide_lightsensor) {// Light Level
|
|
175
195
|
switch (this.lightLevel) {
|
|
@@ -189,26 +209,26 @@ export class Contact {
|
|
|
189
209
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
190
210
|
}
|
|
191
211
|
|
|
192
|
-
this.
|
|
212
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}, MotionDetected: `
|
|
193
213
|
+ `${this.MotionDetected}, CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}, BatteryLevel: ${this.BatteryLevel}`);
|
|
194
214
|
}
|
|
195
215
|
|
|
196
216
|
private async openAPIparseStatus() {
|
|
197
217
|
if (this.platform.config.credentials?.openToken) {
|
|
198
|
-
this.
|
|
218
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
199
219
|
if (this.deviceStatus.body.openState === 'open') {
|
|
200
220
|
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
|
|
201
|
-
this.
|
|
221
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
202
222
|
} else if (this.deviceStatus.body.openState === 'close') {
|
|
203
223
|
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
204
|
-
this.
|
|
224
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
205
225
|
} else {
|
|
206
|
-
this.
|
|
226
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} openState: ${this.deviceStatus.body.openState}`);
|
|
207
227
|
}
|
|
208
228
|
if (this.device.contact?.hide_motionsensor) {
|
|
209
229
|
this.MotionDetected = Boolean(this.deviceStatus.body.moveDetected);
|
|
210
230
|
}
|
|
211
|
-
this.
|
|
231
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
212
232
|
}
|
|
213
233
|
}
|
|
214
234
|
|
|
@@ -226,12 +246,12 @@ export class Contact {
|
|
|
226
246
|
private connectBLE() {
|
|
227
247
|
const switchbot = new Switchbot();
|
|
228
248
|
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
229
|
-
this.
|
|
249
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
230
250
|
return switchbot;
|
|
231
251
|
}
|
|
232
252
|
|
|
233
253
|
private async BLERefreshStatus() {
|
|
234
|
-
this.
|
|
254
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} BLE refreshStatus`);
|
|
235
255
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
236
256
|
const switchbot = this.connectBLE();
|
|
237
257
|
// Start to monitor advertisement packets
|
|
@@ -246,16 +266,16 @@ export class Contact {
|
|
|
246
266
|
this.doorState = ad.serviceData.doorState;
|
|
247
267
|
this.lightLevel = ad.serviceData.lightLevel;
|
|
248
268
|
this.battery = ad.serviceData.battery;
|
|
249
|
-
this.
|
|
250
|
-
this.
|
|
269
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
270
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, doorState: `
|
|
251
271
|
+ `${ad.serviceData.doorState}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`);
|
|
252
272
|
|
|
253
273
|
if (this.serviceData) {
|
|
254
274
|
this.connected = true;
|
|
255
|
-
this.
|
|
275
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
256
276
|
} else {
|
|
257
277
|
this.connected = false;
|
|
258
|
-
this.
|
|
278
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
259
279
|
}
|
|
260
280
|
};
|
|
261
281
|
// Wait 10 seconds
|
|
@@ -267,49 +287,49 @@ export class Contact {
|
|
|
267
287
|
this.parseStatus();
|
|
268
288
|
this.updateHomeKitCharacteristics();
|
|
269
289
|
} else {
|
|
270
|
-
this.
|
|
290
|
+
this.errorLog(`Contact Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
271
291
|
if (this.platform.config.credentials?.openToken) {
|
|
272
|
-
this.
|
|
292
|
+
this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
273
293
|
await this.openAPIRefreshStatus();
|
|
274
294
|
}
|
|
275
295
|
}
|
|
276
296
|
}).catch(async (e: any) => {
|
|
277
|
-
this.
|
|
278
|
-
if (this.
|
|
279
|
-
this.
|
|
297
|
+
this.errorLog(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
298
|
+
if (this.deviceLogging === 'debug') {
|
|
299
|
+
this.errorLog(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
280
300
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
281
301
|
}
|
|
282
|
-
if (this.
|
|
283
|
-
this.
|
|
302
|
+
if (this.platform.debugMode) {
|
|
303
|
+
this.errorLog(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
284
304
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
285
305
|
}
|
|
286
306
|
if (this.platform.config.credentials?.openToken) {
|
|
287
|
-
this.
|
|
307
|
+
this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
288
308
|
await this.openAPIRefreshStatus();
|
|
289
309
|
}
|
|
290
|
-
this.apiError(
|
|
310
|
+
this.apiError();
|
|
291
311
|
});
|
|
292
312
|
}
|
|
293
313
|
|
|
294
314
|
private async openAPIRefreshStatus() {
|
|
295
315
|
if (this.platform.config.credentials?.openToken) {
|
|
296
|
-
this.
|
|
316
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} OpenAPI refreshStatus`);
|
|
297
317
|
try {
|
|
298
318
|
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
299
|
-
this.
|
|
319
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
300
320
|
this.parseStatus();
|
|
301
321
|
this.updateHomeKitCharacteristics();
|
|
302
322
|
} catch (e: any) {
|
|
303
|
-
this.
|
|
304
|
-
if (this.
|
|
305
|
-
this.
|
|
323
|
+
this.errorLog(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
324
|
+
if (this.deviceLogging === 'debug') {
|
|
325
|
+
this.errorLog(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
306
326
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
307
327
|
}
|
|
308
|
-
if (this.
|
|
309
|
-
this.
|
|
328
|
+
if (this.platform.debugMode) {
|
|
329
|
+
this.errorLog(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
310
330
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
311
331
|
}
|
|
312
|
-
this.apiError(
|
|
332
|
+
this.apiError();
|
|
313
333
|
}
|
|
314
334
|
}
|
|
315
335
|
}
|
|
@@ -319,55 +339,80 @@ export class Contact {
|
|
|
319
339
|
*/
|
|
320
340
|
updateHomeKitCharacteristics() {
|
|
321
341
|
if (this.ContactSensorState === undefined) {
|
|
322
|
-
this.
|
|
342
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
323
343
|
} else {
|
|
324
344
|
this.service.updateCharacteristic(this.platform.Characteristic.ContactSensorState, this.ContactSensorState);
|
|
325
|
-
this.
|
|
345
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} updateCharacteristic ContactSensorState: ${this.ContactSensorState}`);
|
|
326
346
|
}
|
|
327
347
|
if (!this.device.contact?.hide_motionsensor) {
|
|
328
348
|
if (this.MotionDetected === undefined) {
|
|
329
|
-
this.
|
|
349
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
330
350
|
} else {
|
|
331
351
|
this.motionService?.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected);
|
|
332
|
-
this.
|
|
352
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`);
|
|
333
353
|
}
|
|
334
354
|
}
|
|
335
355
|
if (!this.device.contact?.hide_lightsensor) {
|
|
336
356
|
if (this.CurrentAmbientLightLevel === undefined) {
|
|
337
|
-
this.
|
|
357
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
338
358
|
} else {
|
|
339
359
|
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
|
|
340
|
-
this.
|
|
360
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName}`
|
|
341
361
|
+ ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
342
362
|
}
|
|
343
363
|
}
|
|
344
364
|
if (this.device.ble) {
|
|
345
365
|
if (this.BatteryLevel === undefined) {
|
|
346
|
-
this.
|
|
366
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
347
367
|
} else {
|
|
348
368
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
349
|
-
this.
|
|
369
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
350
370
|
}
|
|
351
371
|
if (this.StatusLowBattery === undefined) {
|
|
352
|
-
this.
|
|
372
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
353
373
|
} else {
|
|
354
374
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
355
|
-
this.
|
|
375
|
+
this.debugLog(`Contact Sensor: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
356
376
|
}
|
|
357
377
|
}
|
|
358
378
|
}
|
|
359
379
|
|
|
360
|
-
public apiError(
|
|
361
|
-
this.
|
|
362
|
-
|
|
363
|
-
|
|
380
|
+
public apiError() {
|
|
381
|
+
throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Logging for Device
|
|
386
|
+
*/
|
|
387
|
+
infoLog(...log: any[]) {
|
|
388
|
+
if (this.enablingDeviceLogging()) {
|
|
389
|
+
this.platform.log.info(String(...log));
|
|
364
390
|
}
|
|
365
|
-
|
|
366
|
-
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
warnLog(...log: any[]) {
|
|
394
|
+
if (this.enablingDeviceLogging()) {
|
|
395
|
+
this.platform.log.warn(String(...log));
|
|
367
396
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
errorLog(...log: any[]) {
|
|
400
|
+
if (this.enablingDeviceLogging()) {
|
|
401
|
+
this.platform.log.error(String(...log));
|
|
371
402
|
}
|
|
372
403
|
}
|
|
404
|
+
|
|
405
|
+
debugLog(...log: any[]) {
|
|
406
|
+
if (this.enablingDeviceLogging()) {
|
|
407
|
+
if (this.deviceLogging === 'debug') {
|
|
408
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
409
|
+
} else {
|
|
410
|
+
this.platform.log.debug(String(...log));
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
enablingDeviceLogging(): boolean {
|
|
416
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
417
|
+
}
|
|
373
418
|
}
|