@switchbot/homebridge-switchbot 2.0.0-beta.18 → 2.0.0-beta.19
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 +1 -1
- package/config.schema.json +11 -2
- package/dist/device/bot.d.ts +2 -0
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +201 -163
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +2 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +250 -218
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +2 -0
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +85 -66
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +2 -0
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +166 -136
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +126 -115
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +2 -0
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +156 -130
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +2 -0
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +85 -64
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +2 -0
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +78 -59
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +2 -0
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +76 -57
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +2 -0
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +133 -107
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +2 -0
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +224 -195
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -0
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +127 -105
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +2 -0
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +83 -66
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +8 -6
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +83 -68
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +7 -5
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +90 -75
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +8 -6
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +83 -68
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +8 -6
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +93 -78
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -6
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +68 -52
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +8 -6
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +83 -69
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +2 -0
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +75 -60
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/settings.d.ts +12 -11
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +1 -1
- package/src/device/bot.ts +200 -163
- package/src/device/colorbulb.ts +252 -221
- package/src/device/contact.ts +85 -66
- package/src/device/curtain.ts +165 -136
- package/src/device/humidifier.ts +126 -115
- package/src/device/lock.ts +156 -131
- package/src/device/meter.ts +85 -64
- package/src/device/meterplus.ts +78 -59
- package/src/device/motion.ts +76 -57
- package/src/device/plug.ts +132 -107
- package/src/device/striplight.ts +226 -198
- package/src/irdevice/airconditioner.ts +126 -103
- package/src/irdevice/airpurifier.ts +84 -66
- package/src/irdevice/camera.ts +84 -68
- package/src/irdevice/fan.ts +91 -75
- package/src/irdevice/light.ts +84 -68
- package/src/irdevice/other.ts +94 -78
- package/src/irdevice/tv.ts +69 -53
- package/src/irdevice/vacuumcleaner.ts +83 -68
- package/src/irdevice/waterheater.ts +76 -60
- package/src/settings.ts +12 -11
package/src/device/contact.ts
CHANGED
|
@@ -45,6 +45,7 @@ export class Contact {
|
|
|
45
45
|
lightLevel!: serviceData['lightLevel'];
|
|
46
46
|
|
|
47
47
|
// Config
|
|
48
|
+
OpenAPI?: boolean;
|
|
48
49
|
set_minLux!: number;
|
|
49
50
|
set_maxLux!: number;
|
|
50
51
|
scanDuration!: number;
|
|
@@ -58,6 +59,7 @@ export class Contact {
|
|
|
58
59
|
constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
|
|
59
60
|
// default placeholders
|
|
60
61
|
this.logs(device);
|
|
62
|
+
this.openAPI();
|
|
61
63
|
this.scan(device);
|
|
62
64
|
this.refreshRate(device);
|
|
63
65
|
this.config(device);
|
|
@@ -99,49 +101,49 @@ export class Contact {
|
|
|
99
101
|
|
|
100
102
|
// Motion Sensor Service
|
|
101
103
|
if (device.contact?.hide_motionsensor) {
|
|
102
|
-
this.debugLog(
|
|
104
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Motion Sensor Service`);
|
|
103
105
|
this.motionService = this.accessory.getService(this.platform.Service.MotionSensor);
|
|
104
106
|
accessory.removeService(this.motionService!);
|
|
105
107
|
} else if (!this.motionService) {
|
|
106
|
-
this.debugLog(
|
|
108
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Motion Sensor Service`);
|
|
107
109
|
(this.motionService =
|
|
108
110
|
this.accessory.getService(this.platform.Service.MotionSensor) || this.accessory.addService(this.platform.Service.MotionSensor)),
|
|
109
111
|
`${accessory.displayName} Motion Sensor`;
|
|
110
112
|
|
|
111
113
|
this.motionService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Motion Sensor`);
|
|
112
114
|
} else {
|
|
113
|
-
this.debugLog(
|
|
115
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Motion Sensor Service Not Added`);
|
|
114
116
|
}
|
|
115
117
|
|
|
116
118
|
// Light Sensor Service
|
|
117
119
|
if (device.contact?.hide_lightsensor) {
|
|
118
|
-
this.debugLog(
|
|
120
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
|
|
119
121
|
this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor);
|
|
120
122
|
accessory.removeService(this.lightSensorService!);
|
|
121
123
|
} else if (!this.lightSensorService) {
|
|
122
|
-
this.debugLog(
|
|
124
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
|
|
123
125
|
(this.lightSensorService =
|
|
124
126
|
this.accessory.getService(this.platform.Service.LightSensor) || this.accessory.addService(this.platform.Service.LightSensor)),
|
|
125
127
|
`${accessory.displayName} Light Sensor`;
|
|
126
128
|
|
|
127
129
|
this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
|
|
128
130
|
} else {
|
|
129
|
-
this.debugLog(
|
|
131
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Light Sensor Service Not Added`);
|
|
130
132
|
}
|
|
131
133
|
|
|
132
134
|
// Battery Service
|
|
133
135
|
if (!device.ble) {
|
|
134
|
-
this.debugLog(
|
|
136
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Battery Service`);
|
|
135
137
|
this.batteryService = this.accessory.getService(this.platform.Service.Battery);
|
|
136
138
|
accessory.removeService(this.batteryService!);
|
|
137
139
|
} else if (device.ble && !this.batteryService) {
|
|
138
|
-
this.debugLog(
|
|
140
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
|
|
139
141
|
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
|
|
140
142
|
`${accessory.displayName} Battery`;
|
|
141
143
|
|
|
142
144
|
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
143
145
|
} else {
|
|
144
|
-
this.debugLog(
|
|
146
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
|
|
145
147
|
}
|
|
146
148
|
|
|
147
149
|
// Retrieve initial values and updateHomekit
|
|
@@ -167,7 +169,7 @@ export class Contact {
|
|
|
167
169
|
}
|
|
168
170
|
|
|
169
171
|
async BLEparseStatus(): Promise<void> {
|
|
170
|
-
this.debugLog(
|
|
172
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE parseStatus`);
|
|
171
173
|
// Door State
|
|
172
174
|
switch (this.doorState) {
|
|
173
175
|
case 'open':
|
|
@@ -179,12 +181,12 @@ export class Contact {
|
|
|
179
181
|
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
180
182
|
break;
|
|
181
183
|
default:
|
|
182
|
-
this.errorLog(
|
|
184
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} timeout no closed, doorstate: ${this.doorState}`);
|
|
183
185
|
}
|
|
184
186
|
// Movement
|
|
185
187
|
if (!this.device.contact?.hide_motionsensor) {
|
|
186
188
|
this.MotionDetected = Boolean(this.movement);
|
|
187
|
-
this.debugLog(
|
|
189
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
188
190
|
}
|
|
189
191
|
// Light Level
|
|
190
192
|
if (!this.device.contact?.hide_lightsensor) {
|
|
@@ -199,7 +201,7 @@ export class Contact {
|
|
|
199
201
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
200
202
|
}
|
|
201
203
|
this.debugLog(
|
|
202
|
-
|
|
204
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
|
|
203
205
|
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
204
206
|
);
|
|
205
207
|
}
|
|
@@ -213,7 +215,8 @@ export class Contact {
|
|
|
213
215
|
} else {
|
|
214
216
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
215
217
|
}
|
|
216
|
-
this.debugLog(
|
|
218
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, `
|
|
219
|
+
+ `StatusLowBattery: ${this.StatusLowBattery}`);
|
|
217
220
|
}
|
|
218
221
|
|
|
219
222
|
async openAPIparseStatus(): Promise<void> {
|
|
@@ -221,21 +224,21 @@ export class Contact {
|
|
|
221
224
|
this.SwitchToOpenAPI = false;
|
|
222
225
|
}
|
|
223
226
|
if (this.platform.config.credentials?.token) {
|
|
224
|
-
this.debugLog(
|
|
227
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
225
228
|
// Contact State
|
|
226
229
|
if (this.openState === 'open') {
|
|
227
230
|
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
|
|
228
|
-
this.debugLog(
|
|
231
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
229
232
|
} else if (this.openState === 'close') {
|
|
230
233
|
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
231
|
-
this.debugLog(
|
|
234
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
232
235
|
} else {
|
|
233
|
-
this.debugLog(
|
|
236
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openState: ${this.openState}`);
|
|
234
237
|
}
|
|
235
238
|
// Motion State
|
|
236
239
|
if (!this.device.contact?.hide_motionsensor) {
|
|
237
240
|
this.MotionDetected = this.moveDetected!;
|
|
238
|
-
this.debugLog(
|
|
241
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
239
242
|
}
|
|
240
243
|
// Light Level
|
|
241
244
|
if (!this.device.contact?.hide_lightsensor) {
|
|
@@ -249,7 +252,7 @@ export class Contact {
|
|
|
249
252
|
default:
|
|
250
253
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
251
254
|
}
|
|
252
|
-
this.debugLog(
|
|
255
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
253
256
|
}
|
|
254
257
|
}
|
|
255
258
|
}
|
|
@@ -266,7 +269,7 @@ export class Contact {
|
|
|
266
269
|
}
|
|
267
270
|
|
|
268
271
|
async BLERefreshStatus(): Promise<void> {
|
|
269
|
-
this.debugLog(
|
|
272
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE refreshStatus`);
|
|
270
273
|
const switchbot = await this.platform.connectBLE();
|
|
271
274
|
// Convert to BLE Address
|
|
272
275
|
this.device.bleMac =
|
|
@@ -275,7 +278,7 @@ export class Contact {
|
|
|
275
278
|
.deviceId!.match(/.{1,2}/g)!
|
|
276
279
|
.join(':')
|
|
277
280
|
.toLowerCase();
|
|
278
|
-
this.debugLog(
|
|
281
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
279
282
|
this.getCustomBLEAddress(switchbot);
|
|
280
283
|
// Start to monitor advertisement packets
|
|
281
284
|
if (switchbot !== false) {
|
|
@@ -291,26 +294,26 @@ export class Contact {
|
|
|
291
294
|
if (this.deviceLogging.includes('debug')) {
|
|
292
295
|
this.infoLog(this.address);
|
|
293
296
|
this.infoLog(this.device.bleMac);
|
|
294
|
-
this.infoLog(
|
|
295
|
-
this.infoLog(
|
|
297
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
|
|
298
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
|
|
296
299
|
}
|
|
297
300
|
this.serviceData = ad.serviceData;
|
|
298
301
|
this.movement = ad.serviceData.movement;
|
|
299
302
|
this.doorState = ad.serviceData.doorState;
|
|
300
303
|
this.lightLevel = ad.serviceData.lightLevel;
|
|
301
304
|
this.battery = ad.serviceData.battery;
|
|
302
|
-
this.debugLog(
|
|
305
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
|
|
303
306
|
this.debugLog(
|
|
304
|
-
|
|
307
|
+
`${this.device.deviceType}: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, doorState: ` +
|
|
305
308
|
`${ad.serviceData.doorState}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`,
|
|
306
309
|
);
|
|
307
310
|
|
|
308
311
|
if (this.serviceData) {
|
|
309
312
|
this.connected = true;
|
|
310
|
-
this.debugLog(
|
|
313
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
311
314
|
} else {
|
|
312
315
|
this.connected = false;
|
|
313
|
-
this.debugLog(
|
|
316
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
314
317
|
}
|
|
315
318
|
};
|
|
316
319
|
// Wait 2 seconds
|
|
@@ -327,15 +330,15 @@ export class Contact {
|
|
|
327
330
|
}
|
|
328
331
|
})
|
|
329
332
|
.catch(async (e: any) => {
|
|
330
|
-
this.errorLog(
|
|
333
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
331
334
|
if (this.deviceLogging.includes('debug')) {
|
|
332
335
|
this.errorLog(
|
|
333
|
-
|
|
336
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` +
|
|
334
337
|
` Error Message: ${superStringify(e.message)}`,
|
|
335
338
|
);
|
|
336
339
|
}
|
|
337
340
|
if (this.platform.config.credentials?.token) {
|
|
338
|
-
this.warnLog(
|
|
341
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
339
342
|
this.SwitchToOpenAPI = true;
|
|
340
343
|
await this.openAPIRefreshStatus();
|
|
341
344
|
}
|
|
@@ -355,7 +358,7 @@ export class Contact {
|
|
|
355
358
|
});
|
|
356
359
|
// Set an event handler
|
|
357
360
|
switchbot.onadvertisement = (ad: any) => {
|
|
358
|
-
this.warnLog(
|
|
361
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
|
|
359
362
|
};
|
|
360
363
|
await switchbot.wait(10000);
|
|
361
364
|
// Stop to monitor
|
|
@@ -365,24 +368,24 @@ export class Contact {
|
|
|
365
368
|
}
|
|
366
369
|
|
|
367
370
|
async BLEconnection(switchbot: any): Promise<void> {
|
|
368
|
-
this.errorLog(
|
|
371
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
369
372
|
if (this.platform.config.credentials?.token) {
|
|
370
|
-
this.warnLog(
|
|
373
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
371
374
|
this.SwitchToOpenAPI = true;
|
|
372
375
|
await this.openAPIRefreshStatus();
|
|
373
376
|
}
|
|
374
377
|
}
|
|
375
378
|
|
|
376
379
|
async openAPIRefreshStatus(): Promise<void> {
|
|
377
|
-
if (this.platform.config.credentials?.token) {
|
|
378
|
-
this.debugLog(
|
|
380
|
+
if (this.platform.config.credentials?.token && this.OpenAPI) {
|
|
381
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI refreshStatus`);
|
|
379
382
|
try {
|
|
380
383
|
const t = Date.now();
|
|
381
384
|
const nonce = 'requestID';
|
|
382
385
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
383
386
|
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
384
387
|
const sign = signTerm.toString('base64');
|
|
385
|
-
this.debugLog(
|
|
388
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
386
389
|
const options = {
|
|
387
390
|
hostname: HostDomain,
|
|
388
391
|
port: 443,
|
|
@@ -397,40 +400,42 @@ export class Contact {
|
|
|
397
400
|
},
|
|
398
401
|
};
|
|
399
402
|
const req = https.request(options, (res) => {
|
|
400
|
-
this.debugLog(
|
|
403
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
401
404
|
let rawData = '';
|
|
402
405
|
res.on('data', (d) => {
|
|
403
406
|
rawData += d;
|
|
404
|
-
this.debugLog(
|
|
407
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
405
408
|
});
|
|
406
409
|
res.on('end', () => {
|
|
407
410
|
try {
|
|
408
411
|
this.deviceStatus = JSON.parse(rawData);
|
|
409
|
-
this.debugLog(
|
|
412
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
|
|
410
413
|
this.openState = this.deviceStatus.body.openState;
|
|
411
414
|
this.moveDetected = this.deviceStatus.body.moveDetected;
|
|
412
415
|
this.brightness = this.deviceStatus.body.brightness;
|
|
413
416
|
this.parseStatus();
|
|
414
417
|
this.updateHomeKitCharacteristics();
|
|
415
418
|
} catch (e: any) {
|
|
416
|
-
this.errorLog(
|
|
419
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
417
420
|
}
|
|
418
421
|
});
|
|
419
422
|
});
|
|
420
423
|
req.on('error', (e: any) => {
|
|
421
|
-
this.errorLog(
|
|
424
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
422
425
|
});
|
|
423
426
|
req.end();
|
|
424
427
|
} catch (e: any) {
|
|
425
|
-
this.errorLog(
|
|
428
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
426
429
|
if (this.deviceLogging.includes('debug')) {
|
|
427
430
|
this.errorLog(
|
|
428
|
-
|
|
431
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
|
|
429
432
|
` Error Message: ${superStringify(e.message)}`,
|
|
430
433
|
);
|
|
431
434
|
}
|
|
432
435
|
this.apiError(e);
|
|
433
436
|
}
|
|
437
|
+
} else {
|
|
438
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI is disabled, commands will not be sent.`);
|
|
434
439
|
}
|
|
435
440
|
}
|
|
436
441
|
|
|
@@ -439,41 +444,42 @@ export class Contact {
|
|
|
439
444
|
*/
|
|
440
445
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
441
446
|
if (this.ContactSensorState === undefined) {
|
|
442
|
-
this.debugLog(
|
|
447
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
443
448
|
} else {
|
|
444
449
|
this.contactSensorservice.updateCharacteristic(this.platform.Characteristic.ContactSensorState, this.ContactSensorState);
|
|
445
|
-
this.debugLog(
|
|
450
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ContactSensorState: ${this.ContactSensorState}`);
|
|
446
451
|
}
|
|
447
452
|
if (!this.device.contact?.hide_motionsensor) {
|
|
448
453
|
if (this.MotionDetected === undefined) {
|
|
449
|
-
this.debugLog(
|
|
454
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
450
455
|
} else {
|
|
451
456
|
this.motionService?.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected);
|
|
452
|
-
this.debugLog(
|
|
457
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`);
|
|
453
458
|
}
|
|
454
459
|
}
|
|
455
460
|
if (!this.device.contact?.hide_lightsensor) {
|
|
456
461
|
if (this.CurrentAmbientLightLevel === undefined) {
|
|
457
|
-
this.debugLog(
|
|
462
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
458
463
|
} else {
|
|
459
464
|
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
|
|
460
465
|
this.debugLog(
|
|
461
|
-
|
|
466
|
+
`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
467
|
+
+ ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
462
468
|
);
|
|
463
469
|
}
|
|
464
470
|
}
|
|
465
471
|
if (this.device.ble) {
|
|
466
472
|
if (this.BatteryLevel === undefined) {
|
|
467
|
-
this.debugLog(
|
|
473
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
468
474
|
} else {
|
|
469
475
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
470
|
-
this.debugLog(
|
|
476
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
471
477
|
}
|
|
472
478
|
if (this.StatusLowBattery === undefined) {
|
|
473
|
-
this.debugLog(
|
|
479
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
474
480
|
} else {
|
|
475
481
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
476
|
-
this.debugLog(
|
|
482
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
477
483
|
}
|
|
478
484
|
}
|
|
479
485
|
}
|
|
@@ -501,6 +507,9 @@ export class Contact {
|
|
|
501
507
|
if (device.ble) {
|
|
502
508
|
config['ble'] = device.ble;
|
|
503
509
|
}
|
|
510
|
+
if (device.openAPI !== undefined) {
|
|
511
|
+
config['openAPI'] = device.openAPI;
|
|
512
|
+
}
|
|
504
513
|
if (device.logging !== undefined) {
|
|
505
514
|
config['logging'] = device.logging;
|
|
506
515
|
}
|
|
@@ -511,30 +520,39 @@ export class Contact {
|
|
|
511
520
|
config['scanDuration'] = device.scanDuration;
|
|
512
521
|
}
|
|
513
522
|
if (Object.entries(config).length !== 0) {
|
|
514
|
-
this.infoLog(
|
|
523
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
515
524
|
}
|
|
516
525
|
}
|
|
517
526
|
|
|
518
527
|
async refreshRate(device: device & devicesConfig): Promise<void> {
|
|
519
528
|
if (device.refreshRate) {
|
|
520
529
|
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
521
|
-
this.debugLog(
|
|
530
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
522
531
|
} else if (this.platform.config.options!.refreshRate) {
|
|
523
532
|
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
524
|
-
this.debugLog(
|
|
533
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
async openAPI() {
|
|
538
|
+
if (!this.device.openAPI) {
|
|
539
|
+
this.OpenAPI = true;
|
|
540
|
+
} else {
|
|
541
|
+
this.OpenAPI = this.device.openAPI;
|
|
525
542
|
}
|
|
543
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
|
|
526
544
|
}
|
|
527
545
|
|
|
528
546
|
async scan(device: device & devicesConfig): Promise<void> {
|
|
529
547
|
if (device.scanDuration) {
|
|
530
548
|
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
531
549
|
if (device.ble) {
|
|
532
|
-
this.debugLog(
|
|
550
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
533
551
|
}
|
|
534
552
|
} else {
|
|
535
553
|
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
536
554
|
if (this.device.ble) {
|
|
537
|
-
this.debugLog(
|
|
555
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
538
556
|
}
|
|
539
557
|
}
|
|
540
558
|
}
|
|
@@ -542,24 +560,25 @@ export class Contact {
|
|
|
542
560
|
async logs(device: device & devicesConfig): Promise<void> {
|
|
543
561
|
if (this.platform.debugMode) {
|
|
544
562
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
545
|
-
this.debugLog(
|
|
563
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
546
564
|
} else if (device.logging) {
|
|
547
565
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
548
|
-
this.debugLog(
|
|
566
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
549
567
|
} else if (this.platform.config.options?.logging) {
|
|
550
568
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
551
|
-
this.debugLog(
|
|
569
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
552
570
|
} else {
|
|
553
571
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
554
|
-
this.debugLog(
|
|
572
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
555
573
|
}
|
|
556
574
|
}
|
|
557
575
|
|
|
558
576
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
559
577
|
let FirmwareRevision: string;
|
|
560
|
-
this.debugLog(
|
|
561
|
-
|
|
562
|
-
this.debugLog(
|
|
578
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
579
|
+
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
580
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
581
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
563
582
|
if (accessory.context.FirmwareRevision) {
|
|
564
583
|
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
565
584
|
} else if (device.firmware) {
|