@switchbot/homebridge-switchbot 2.0.0-beta.17 → 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 +14 -4
- 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
|
@@ -22,6 +22,7 @@ class StripLight {
|
|
|
22
22
|
this.device = device;
|
|
23
23
|
// default placeholders
|
|
24
24
|
this.logs(device);
|
|
25
|
+
this.openAPI();
|
|
25
26
|
this.scan(device);
|
|
26
27
|
this.refreshRate(device);
|
|
27
28
|
this.config(device);
|
|
@@ -118,9 +119,10 @@ class StripLight {
|
|
|
118
119
|
await this.pushChanges();
|
|
119
120
|
}
|
|
120
121
|
catch (e) {
|
|
121
|
-
this.errorLog(
|
|
122
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges`);
|
|
122
123
|
if (this.deviceLogging.includes('debug')) {
|
|
123
|
-
this.errorLog(
|
|
124
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges,`
|
|
125
|
+
+ ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
124
126
|
}
|
|
125
127
|
this.apiError(e);
|
|
126
128
|
}
|
|
@@ -143,7 +145,7 @@ class StripLight {
|
|
|
143
145
|
}
|
|
144
146
|
}
|
|
145
147
|
async BLEparseStatus() {
|
|
146
|
-
this.debugLog(
|
|
148
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE parseStatus`);
|
|
147
149
|
// State
|
|
148
150
|
switch (this.state) {
|
|
149
151
|
case 'on':
|
|
@@ -152,7 +154,7 @@ class StripLight {
|
|
|
152
154
|
default:
|
|
153
155
|
this.On = false;
|
|
154
156
|
}
|
|
155
|
-
this.debugLog(
|
|
157
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
156
158
|
}
|
|
157
159
|
async openAPIparseStatus() {
|
|
158
160
|
switch (this.power) {
|
|
@@ -162,25 +164,26 @@ class StripLight {
|
|
|
162
164
|
default:
|
|
163
165
|
this.On = false;
|
|
164
166
|
}
|
|
165
|
-
this.debugLog(
|
|
167
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
166
168
|
// Brightness
|
|
167
169
|
this.Brightness = Number(this.brightness);
|
|
168
|
-
this.debugLog(
|
|
170
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
169
171
|
// Color, Hue & Brightness
|
|
170
172
|
if (this.color) {
|
|
171
|
-
this.debugLog(
|
|
173
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${(0, super_stringify_1.default)(this.color)}`);
|
|
172
174
|
const [red, green, blue] = this.color.split(':');
|
|
173
|
-
this.debugLog(
|
|
174
|
-
this.debugLog(
|
|
175
|
-
this.debugLog(
|
|
175
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${(0, super_stringify_1.default)(red)}`);
|
|
176
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${(0, super_stringify_1.default)(green)}`);
|
|
177
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${(0, super_stringify_1.default)(blue)}`);
|
|
176
178
|
const [hue, saturation] = (0, settings_1.rgb2hs)(Number(red), Number(green), Number(blue));
|
|
177
|
-
this.debugLog(
|
|
179
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
180
|
+
+ ` hs: ${(0, super_stringify_1.default)((0, settings_1.rgb2hs)(Number(red), Number(green), Number(blue)))}`);
|
|
178
181
|
// Hue
|
|
179
182
|
this.Hue = hue;
|
|
180
|
-
this.debugLog(
|
|
183
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
181
184
|
// Saturation
|
|
182
185
|
this.Saturation = saturation;
|
|
183
|
-
this.debugLog(
|
|
186
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
184
187
|
}
|
|
185
188
|
}
|
|
186
189
|
async refreshStatus() {
|
|
@@ -192,14 +195,14 @@ class StripLight {
|
|
|
192
195
|
}
|
|
193
196
|
}
|
|
194
197
|
async BLERefreshStatus() {
|
|
195
|
-
this.debugLog(
|
|
198
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE refreshStatus`);
|
|
196
199
|
const switchbot = await this.platform.connectBLE();
|
|
197
200
|
// Convert to BLE Address
|
|
198
201
|
this.device.bleMac = this.device
|
|
199
202
|
.deviceId.match(/.{1,2}/g)
|
|
200
203
|
.join(':')
|
|
201
204
|
.toLowerCase();
|
|
202
|
-
this.debugLog(
|
|
205
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
203
206
|
this.getCustomBLEAddress(switchbot);
|
|
204
207
|
// Start to monitor advertisement packets
|
|
205
208
|
if (switchbot !== false) {
|
|
@@ -215,10 +218,10 @@ class StripLight {
|
|
|
215
218
|
if (this.deviceLogging.includes('debug')) {
|
|
216
219
|
this.infoLog(this.address);
|
|
217
220
|
this.infoLog(this.device.bleMac);
|
|
218
|
-
this.infoLog(
|
|
219
|
-
this.infoLog(
|
|
221
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
|
|
222
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
|
|
220
223
|
}
|
|
221
|
-
this.errorLog(
|
|
224
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${(0, super_stringify_1.default)(ad.serviceData)}`);
|
|
222
225
|
this.serviceData = ad.serviceData;
|
|
223
226
|
//this.state = ad.serviceData.state;
|
|
224
227
|
//this.delay = ad.serviceData.delay;
|
|
@@ -227,19 +230,19 @@ class StripLight {
|
|
|
227
230
|
//this.wifiRssi = ad.serviceData.wifiRssi;
|
|
228
231
|
//this.overload = ad.serviceData.overload;
|
|
229
232
|
//this.currentPower = ad.serviceData.currentPower;
|
|
230
|
-
this.debugLog(
|
|
233
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${(0, super_stringify_1.default)(ad.serviceData)}`);
|
|
231
234
|
/*this.debugLog(
|
|
232
|
-
|
|
235
|
+
`${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
|
|
233
236
|
`delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
|
|
234
237
|
`wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
|
|
235
238
|
);*/
|
|
236
239
|
if (this.serviceData) {
|
|
237
240
|
this.connected = true;
|
|
238
|
-
this.debugLog(
|
|
241
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
239
242
|
}
|
|
240
243
|
else {
|
|
241
244
|
this.connected = false;
|
|
242
|
-
this.debugLog(
|
|
245
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
243
246
|
}
|
|
244
247
|
};
|
|
245
248
|
// Wait 2 seconds
|
|
@@ -253,21 +256,22 @@ class StripLight {
|
|
|
253
256
|
this.updateHomeKitCharacteristics();
|
|
254
257
|
}
|
|
255
258
|
else {
|
|
256
|
-
this.errorLog(
|
|
259
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
257
260
|
if (this.platform.config.credentials?.token) {
|
|
258
|
-
this.warnLog(
|
|
261
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
259
262
|
this.SwitchToOpenAPI = true;
|
|
260
263
|
await this.openAPIRefreshStatus();
|
|
261
264
|
}
|
|
262
265
|
}
|
|
263
266
|
})
|
|
264
267
|
.catch(async (e) => {
|
|
265
|
-
this.errorLog(
|
|
268
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
266
269
|
if (this.deviceLogging.includes('debug')) {
|
|
267
|
-
this.errorLog(
|
|
270
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
271
|
+
+ ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
268
272
|
}
|
|
269
273
|
if (this.platform.config.credentials?.token) {
|
|
270
|
-
this.warnLog(
|
|
274
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
271
275
|
this.SwitchToOpenAPI = true;
|
|
272
276
|
await this.openAPIRefreshStatus();
|
|
273
277
|
}
|
|
@@ -280,7 +284,7 @@ class StripLight {
|
|
|
280
284
|
}
|
|
281
285
|
async getCustomBLEAddress(switchbot) {
|
|
282
286
|
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
283
|
-
this.debugLog(
|
|
287
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} customBLEaddress: ${this.device.customBLEaddress}`);
|
|
284
288
|
(async () => {
|
|
285
289
|
// Start to monitor advertisement packets
|
|
286
290
|
await switchbot.startScan({
|
|
@@ -288,7 +292,7 @@ class StripLight {
|
|
|
288
292
|
});
|
|
289
293
|
// Set an event handler
|
|
290
294
|
switchbot.onadvertisement = (ad) => {
|
|
291
|
-
this.warnLog(
|
|
295
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${(0, super_stringify_1.default)(ad, null, ' ')}`);
|
|
292
296
|
};
|
|
293
297
|
await switchbot.wait(10000);
|
|
294
298
|
// Stop to monitor
|
|
@@ -297,67 +301,73 @@ class StripLight {
|
|
|
297
301
|
}
|
|
298
302
|
}
|
|
299
303
|
async BLEconnection(switchbot) {
|
|
300
|
-
this.errorLog(
|
|
304
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
301
305
|
if (this.platform.config.credentials?.token) {
|
|
302
|
-
this.warnLog(
|
|
306
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
303
307
|
this.SwitchToOpenAPI = true;
|
|
304
308
|
await this.openAPIRefreshStatus();
|
|
305
309
|
}
|
|
306
310
|
}
|
|
307
311
|
async openAPIRefreshStatus() {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
312
|
+
if (this.OpenAPI) {
|
|
313
|
+
try {
|
|
314
|
+
const t = Date.now();
|
|
315
|
+
const nonce = 'requestID';
|
|
316
|
+
const data = this.platform.config.credentials?.token + t + nonce;
|
|
317
|
+
const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
318
|
+
const sign = signTerm.toString('base64');
|
|
319
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
320
|
+
const options = {
|
|
321
|
+
hostname: settings_1.HostDomain,
|
|
322
|
+
port: 443,
|
|
323
|
+
path: `${settings_1.DevicePath}/${this.device.deviceId}/status`,
|
|
324
|
+
method: 'GET',
|
|
325
|
+
headers: {
|
|
326
|
+
Authorization: this.platform.config.credentials?.token,
|
|
327
|
+
sign: sign,
|
|
328
|
+
nonce: nonce,
|
|
329
|
+
t: t,
|
|
330
|
+
'Content-Type': 'application/json',
|
|
331
|
+
},
|
|
332
|
+
};
|
|
333
|
+
const req = https_1.default.request(options, (res) => {
|
|
334
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
335
|
+
let rawData = '';
|
|
336
|
+
res.on('data', (d) => {
|
|
337
|
+
rawData += d;
|
|
338
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
339
|
+
});
|
|
340
|
+
res.on('end', () => {
|
|
341
|
+
try {
|
|
342
|
+
this.deviceStatus = JSON.parse(rawData);
|
|
343
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${(0, super_stringify_1.default)(this.deviceStatus)}`);
|
|
344
|
+
this.power = this.deviceStatus.body.power;
|
|
345
|
+
this.color = this.deviceStatus.body.color;
|
|
346
|
+
this.brightness = this.deviceStatus.body.brightness;
|
|
347
|
+
this.parseStatus();
|
|
348
|
+
this.updateHomeKitCharacteristics();
|
|
349
|
+
}
|
|
350
|
+
catch (e) {
|
|
351
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
352
|
+
}
|
|
353
|
+
});
|
|
334
354
|
});
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
this.deviceStatus = JSON.parse(rawData);
|
|
338
|
-
this.debugLog(`Strip Light: ${this.accessory.displayName} refreshStatus: ${(0, super_stringify_1.default)(this.deviceStatus)}`);
|
|
339
|
-
this.power = this.deviceStatus.body.power;
|
|
340
|
-
this.color = this.deviceStatus.body.color;
|
|
341
|
-
this.brightness = this.deviceStatus.body.brightness;
|
|
342
|
-
this.parseStatus();
|
|
343
|
-
this.updateHomeKitCharacteristics();
|
|
344
|
-
}
|
|
345
|
-
catch (e) {
|
|
346
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} error message: ${e.message}`);
|
|
347
|
-
}
|
|
355
|
+
req.on('error', (e) => {
|
|
356
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
348
357
|
});
|
|
349
|
-
|
|
350
|
-
req.on('error', (e) => {
|
|
351
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} error message: ${e.message}`);
|
|
352
|
-
});
|
|
353
|
-
req.end();
|
|
354
|
-
}
|
|
355
|
-
catch (e) {
|
|
356
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
357
|
-
if (this.deviceLogging.includes('debug')) {
|
|
358
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
358
|
+
req.end();
|
|
359
359
|
}
|
|
360
|
-
|
|
360
|
+
catch (e) {
|
|
361
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
362
|
+
if (this.deviceLogging.includes('debug')) {
|
|
363
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
364
|
+
+ ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
365
|
+
}
|
|
366
|
+
this.apiError(e);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI is disabled, commands will not be sent.`);
|
|
361
371
|
}
|
|
362
372
|
}
|
|
363
373
|
/**
|
|
@@ -371,82 +381,88 @@ class StripLight {
|
|
|
371
381
|
*
|
|
372
382
|
*/
|
|
373
383
|
async pushChanges() {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
.
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
384
|
+
if (this.OpenAPI) {
|
|
385
|
+
try {
|
|
386
|
+
if (this.On !== this.accessory.context.On) {
|
|
387
|
+
// Make Push On request to the API
|
|
388
|
+
const t = Date.now();
|
|
389
|
+
const nonce = 'requestID';
|
|
390
|
+
const data = this.platform.config.credentials?.token + t + nonce;
|
|
391
|
+
const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
392
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
393
|
+
.digest();
|
|
394
|
+
const sign = signTerm.toString('base64');
|
|
395
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
396
|
+
let command = '';
|
|
397
|
+
if (this.On) {
|
|
398
|
+
command = 'turnOn';
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
command = 'turnOff';
|
|
402
|
+
}
|
|
403
|
+
const body = (0, super_stringify_1.default)({
|
|
404
|
+
'command': `${command}`,
|
|
405
|
+
'parameter': 'default',
|
|
406
|
+
'commandType': 'command',
|
|
407
|
+
});
|
|
408
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
409
|
+
const options = {
|
|
410
|
+
hostname: settings_1.HostDomain,
|
|
411
|
+
port: 443,
|
|
412
|
+
path: `${settings_1.DevicePath}/${this.device.deviceId}/commands`,
|
|
413
|
+
method: 'POST',
|
|
414
|
+
headers: {
|
|
415
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
416
|
+
'sign': sign,
|
|
417
|
+
'nonce': nonce,
|
|
418
|
+
't': t,
|
|
419
|
+
'Content-Type': 'application/json',
|
|
420
|
+
'Content-Length': body.length,
|
|
421
|
+
},
|
|
422
|
+
};
|
|
423
|
+
const req = https_1.default.request(options, res => {
|
|
424
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
425
|
+
this.statusCode({ res });
|
|
426
|
+
res.on('data', d => {
|
|
427
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
428
|
+
});
|
|
429
|
+
});
|
|
430
|
+
req.on('error', (e) => {
|
|
431
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
432
|
+
});
|
|
433
|
+
req.write(body);
|
|
434
|
+
req.end();
|
|
435
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushchanges: ${(0, super_stringify_1.default)(req)}`);
|
|
436
|
+
}
|
|
437
|
+
// Push Brightness Update
|
|
386
438
|
if (this.On) {
|
|
387
|
-
|
|
439
|
+
await this.pushBrightnessChanges();
|
|
388
440
|
}
|
|
389
|
-
|
|
390
|
-
|
|
441
|
+
// Push Hue & Saturation Update
|
|
442
|
+
if (this.On) {
|
|
443
|
+
await this.pushHueSaturationChanges();
|
|
391
444
|
}
|
|
392
|
-
const body = (0, super_stringify_1.default)({
|
|
393
|
-
'command': `${command}`,
|
|
394
|
-
'parameter': 'default',
|
|
395
|
-
'commandType': 'command',
|
|
396
|
-
});
|
|
397
|
-
this.infoLog(`Strip Light: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
398
|
-
const options = {
|
|
399
|
-
hostname: settings_1.HostDomain,
|
|
400
|
-
port: 443,
|
|
401
|
-
path: `${settings_1.DevicePath}/${this.device.deviceId}/commands`,
|
|
402
|
-
method: 'POST',
|
|
403
|
-
headers: {
|
|
404
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
405
|
-
'sign': sign,
|
|
406
|
-
'nonce': nonce,
|
|
407
|
-
't': t,
|
|
408
|
-
'Content-Type': 'application/json',
|
|
409
|
-
'Content-Length': body.length,
|
|
410
|
-
},
|
|
411
|
-
};
|
|
412
|
-
const req = https_1.default.request(options, res => {
|
|
413
|
-
this.debugLog(`Strip Light: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
414
|
-
this.statusCode({ res });
|
|
415
|
-
res.on('data', d => {
|
|
416
|
-
this.debugLog(`Strip Light: ${this.accessory.displayName} d: ${d}`);
|
|
417
|
-
});
|
|
418
|
-
});
|
|
419
|
-
req.on('error', (e) => {
|
|
420
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} error message: ${e.message}`);
|
|
421
|
-
});
|
|
422
|
-
req.write(body);
|
|
423
|
-
req.end();
|
|
424
|
-
this.debugLog(`Strip Light: ${this.accessory.displayName} pushchanges: ${(0, super_stringify_1.default)(req)}`);
|
|
425
|
-
}
|
|
426
|
-
// Push Brightness Update
|
|
427
|
-
if (this.On) {
|
|
428
|
-
await this.pushBrightnessChanges();
|
|
429
445
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
446
|
+
catch (e) {
|
|
447
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
448
|
+
if (this.deviceLogging.includes('debug')) {
|
|
449
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
450
|
+
+ ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
451
|
+
}
|
|
452
|
+
this.apiError(e);
|
|
433
453
|
}
|
|
434
454
|
}
|
|
435
|
-
|
|
436
|
-
this.
|
|
437
|
-
if (this.deviceLogging.includes('debug')) {
|
|
438
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
439
|
-
}
|
|
440
|
-
this.apiError(e);
|
|
455
|
+
else {
|
|
456
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI is disabled, commands will not be sent.`);
|
|
441
457
|
}
|
|
442
458
|
}
|
|
443
459
|
async pushHueSaturationChanges() {
|
|
444
460
|
try {
|
|
445
461
|
if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
|
|
446
|
-
this.debugLog(
|
|
447
|
-
this.debugLog(
|
|
462
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${(0, super_stringify_1.default)(this.Hue)}`);
|
|
463
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${(0, super_stringify_1.default)(this.Saturation)}`);
|
|
448
464
|
const [red, green, blue] = (0, settings_1.hs2rgb)(Number(this.Hue), Number(this.Saturation));
|
|
449
|
-
this.debugLog(
|
|
465
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${(0, super_stringify_1.default)([red, green, blue])}`);
|
|
450
466
|
// Make Push On request to the API
|
|
451
467
|
const t = Date.now();
|
|
452
468
|
const nonce = 'requestID';
|
|
@@ -455,13 +471,13 @@ class StripLight {
|
|
|
455
471
|
.update(Buffer.from(data, 'utf-8'))
|
|
456
472
|
.digest();
|
|
457
473
|
const sign = signTerm.toString('base64');
|
|
458
|
-
this.debugLog(
|
|
474
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
459
475
|
const body = (0, super_stringify_1.default)({
|
|
460
476
|
'command': 'setColor',
|
|
461
477
|
'parameter': `${red}:${green}:${blue}`,
|
|
462
478
|
'commandType': 'command',
|
|
463
479
|
});
|
|
464
|
-
this.infoLog(
|
|
480
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
465
481
|
const options = {
|
|
466
482
|
hostname: settings_1.HostDomain,
|
|
467
483
|
port: 443,
|
|
@@ -477,29 +493,29 @@ class StripLight {
|
|
|
477
493
|
},
|
|
478
494
|
};
|
|
479
495
|
const req = https_1.default.request(options, res => {
|
|
480
|
-
this.debugLog(
|
|
496
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
481
497
|
this.statusCode({ res });
|
|
482
498
|
res.on('data', d => {
|
|
483
|
-
this.debugLog(
|
|
499
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
484
500
|
});
|
|
485
501
|
});
|
|
486
502
|
req.on('error', (e) => {
|
|
487
|
-
this.errorLog(
|
|
503
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
488
504
|
});
|
|
489
505
|
req.write(body);
|
|
490
506
|
req.end();
|
|
491
|
-
this.debugLog(
|
|
507
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges: ${(0, super_stringify_1.default)(req)}`);
|
|
492
508
|
}
|
|
493
509
|
else {
|
|
494
|
-
this.debugLog(
|
|
510
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes.` +
|
|
495
511
|
`Hue: ${this.Hue}, HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, `
|
|
496
512
|
+ `SaturationCached: ${this.accessory.context.Saturation}`);
|
|
497
513
|
}
|
|
498
514
|
}
|
|
499
515
|
catch (e) {
|
|
500
|
-
this.errorLog(
|
|
516
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushHueSaturationChanges with OpenAPI Connection`);
|
|
501
517
|
if (this.deviceLogging.includes('debug')) {
|
|
502
|
-
this.errorLog(
|
|
518
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushHueSaturationChanges with OpenAPI Connection,`
|
|
503
519
|
+ ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
504
520
|
}
|
|
505
521
|
this.apiError(e);
|
|
@@ -516,13 +532,13 @@ class StripLight {
|
|
|
516
532
|
.update(Buffer.from(data, 'utf-8'))
|
|
517
533
|
.digest();
|
|
518
534
|
const sign = signTerm.toString('base64');
|
|
519
|
-
this.debugLog(
|
|
535
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
520
536
|
const body = (0, super_stringify_1.default)({
|
|
521
537
|
'command': 'setBrightness',
|
|
522
538
|
'parameter': `${this.Brightness}`,
|
|
523
539
|
'commandType': 'command',
|
|
524
540
|
});
|
|
525
|
-
this.infoLog(
|
|
541
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
526
542
|
const options = {
|
|
527
543
|
hostname: settings_1.HostDomain,
|
|
528
544
|
port: 443,
|
|
@@ -538,28 +554,28 @@ class StripLight {
|
|
|
538
554
|
},
|
|
539
555
|
};
|
|
540
556
|
const req = https_1.default.request(options, res => {
|
|
541
|
-
this.debugLog(
|
|
557
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
542
558
|
this.statusCode({ res });
|
|
543
559
|
res.on('data', d => {
|
|
544
|
-
this.debugLog(
|
|
560
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
545
561
|
});
|
|
546
562
|
});
|
|
547
563
|
req.on('error', (e) => {
|
|
548
|
-
this.errorLog(
|
|
564
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
549
565
|
});
|
|
550
566
|
req.write(body);
|
|
551
567
|
req.end();
|
|
552
|
-
this.debugLog(
|
|
568
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges: ${(0, super_stringify_1.default)(req)}`);
|
|
553
569
|
}
|
|
554
570
|
else {
|
|
555
|
-
this.debugLog(
|
|
571
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes.` + `Brightness: ${this.Brightness}, `
|
|
556
572
|
+ `BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
557
573
|
}
|
|
558
574
|
}
|
|
559
575
|
catch (e) {
|
|
560
|
-
this.errorLog(
|
|
576
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushBrightnessChanges with OpenAPI Connection`);
|
|
561
577
|
if (this.deviceLogging.includes('debug')) {
|
|
562
|
-
this.errorLog(
|
|
578
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushBrightnessChanges with OpenAPI Connection,`
|
|
563
579
|
+ ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
564
580
|
}
|
|
565
581
|
this.apiError(e);
|
|
@@ -567,36 +583,36 @@ class StripLight {
|
|
|
567
583
|
}
|
|
568
584
|
async updateHomeKitCharacteristics() {
|
|
569
585
|
if (this.On === undefined) {
|
|
570
|
-
this.debugLog(
|
|
586
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
571
587
|
}
|
|
572
588
|
else {
|
|
573
589
|
this.accessory.context.On = this.On;
|
|
574
590
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
575
|
-
this.debugLog(
|
|
591
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
576
592
|
}
|
|
577
593
|
if (this.Brightness === undefined) {
|
|
578
|
-
this.debugLog(
|
|
594
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
579
595
|
}
|
|
580
596
|
else {
|
|
581
597
|
this.accessory.context.Brightness = this.Brightness;
|
|
582
598
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, this.Brightness);
|
|
583
|
-
this.debugLog(
|
|
599
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
|
|
584
600
|
}
|
|
585
601
|
if (this.Hue === undefined) {
|
|
586
|
-
this.debugLog(
|
|
602
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
587
603
|
}
|
|
588
604
|
else {
|
|
589
605
|
this.accessory.context.Hue = this.Hue;
|
|
590
606
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, this.Hue);
|
|
591
|
-
this.debugLog(
|
|
607
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
|
|
592
608
|
}
|
|
593
609
|
if (this.Saturation === undefined) {
|
|
594
|
-
this.debugLog(
|
|
610
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
595
611
|
}
|
|
596
612
|
else {
|
|
597
613
|
this.accessory.context.Saturation = this.Saturation;
|
|
598
614
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
|
|
599
|
-
this.debugLog(
|
|
615
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
|
|
600
616
|
}
|
|
601
617
|
}
|
|
602
618
|
apiError(e) {
|
|
@@ -609,34 +625,34 @@ class StripLight {
|
|
|
609
625
|
async statusCode({ res }) {
|
|
610
626
|
switch (res.statusCode) {
|
|
611
627
|
case 151:
|
|
612
|
-
this.errorLog(
|
|
628
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
613
629
|
break;
|
|
614
630
|
case 152:
|
|
615
|
-
this.errorLog(
|
|
631
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
|
|
616
632
|
break;
|
|
617
633
|
case 160:
|
|
618
|
-
this.errorLog(
|
|
634
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
|
|
619
635
|
break;
|
|
620
636
|
case 161:
|
|
621
|
-
this.errorLog(
|
|
637
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
|
|
622
638
|
this.offlineOff();
|
|
623
639
|
break;
|
|
624
640
|
case 171:
|
|
625
|
-
this.errorLog(
|
|
641
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
|
|
626
642
|
this.offlineOff();
|
|
627
643
|
break;
|
|
628
644
|
case 190:
|
|
629
|
-
this.errorLog(
|
|
645
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
630
646
|
` Or command: ${(0, super_stringify_1.default)(res)} format is invalid`);
|
|
631
647
|
break;
|
|
632
648
|
case 100:
|
|
633
649
|
if (this.platform.debugMode) {
|
|
634
|
-
this.debugLog(
|
|
650
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
|
|
635
651
|
}
|
|
636
652
|
break;
|
|
637
653
|
default:
|
|
638
654
|
if (this.platform.debugMode) {
|
|
639
|
-
this.debugLog(
|
|
655
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
|
|
640
656
|
}
|
|
641
657
|
}
|
|
642
658
|
}
|
|
@@ -650,7 +666,7 @@ class StripLight {
|
|
|
650
666
|
* Handle requests to set the value of the "On" characteristic
|
|
651
667
|
*/
|
|
652
668
|
async OnSet(value) {
|
|
653
|
-
this.debugLog(
|
|
669
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${value}`);
|
|
654
670
|
this.On = value;
|
|
655
671
|
this.doStripLightUpdate.next();
|
|
656
672
|
}
|
|
@@ -658,7 +674,7 @@ class StripLight {
|
|
|
658
674
|
* Handle requests to set the value of the "Brightness" characteristic
|
|
659
675
|
*/
|
|
660
676
|
async BrightnessSet(value) {
|
|
661
|
-
this.debugLog(
|
|
677
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${value}`);
|
|
662
678
|
this.Brightness = value;
|
|
663
679
|
this.doStripLightUpdate.next();
|
|
664
680
|
}
|
|
@@ -666,7 +682,7 @@ class StripLight {
|
|
|
666
682
|
* Handle requests to set the value of the "Hue" characteristic
|
|
667
683
|
*/
|
|
668
684
|
async HueSet(value) {
|
|
669
|
-
this.debugLog(
|
|
685
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${value}`);
|
|
670
686
|
this.Hue = value;
|
|
671
687
|
this.doStripLightUpdate.next();
|
|
672
688
|
}
|
|
@@ -674,7 +690,7 @@ class StripLight {
|
|
|
674
690
|
* Handle requests to set the value of the "Saturation" characteristic
|
|
675
691
|
*/
|
|
676
692
|
async SaturationSet(value) {
|
|
677
|
-
this.debugLog(
|
|
693
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${value}`);
|
|
678
694
|
this.Saturation = value;
|
|
679
695
|
this.doStripLightUpdate.next();
|
|
680
696
|
}
|
|
@@ -686,6 +702,9 @@ class StripLight {
|
|
|
686
702
|
if (device.ble) {
|
|
687
703
|
config['ble'] = device.ble;
|
|
688
704
|
}
|
|
705
|
+
if (device.openAPI !== undefined) {
|
|
706
|
+
config['openAPI'] = device.openAPI;
|
|
707
|
+
}
|
|
689
708
|
if (device.logging !== undefined) {
|
|
690
709
|
config['logging'] = device.logging;
|
|
691
710
|
}
|
|
@@ -699,56 +718,66 @@ class StripLight {
|
|
|
699
718
|
config['offline'] = device.offline;
|
|
700
719
|
}
|
|
701
720
|
if (Object.entries(config).length !== 0) {
|
|
702
|
-
this.infoLog(
|
|
721
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${(0, super_stringify_1.default)(config)}`);
|
|
703
722
|
}
|
|
704
723
|
}
|
|
705
724
|
async refreshRate(device) {
|
|
706
725
|
if (device.refreshRate) {
|
|
707
726
|
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
708
|
-
this.debugLog(
|
|
727
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
709
728
|
}
|
|
710
729
|
else if (this.platform.config.options.refreshRate) {
|
|
711
730
|
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
712
|
-
this.debugLog(
|
|
731
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
async openAPI() {
|
|
735
|
+
if (!this.device.openAPI) {
|
|
736
|
+
this.OpenAPI = true;
|
|
737
|
+
}
|
|
738
|
+
else {
|
|
739
|
+
this.OpenAPI = this.device.openAPI;
|
|
713
740
|
}
|
|
741
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
|
|
714
742
|
}
|
|
715
743
|
async scan(device) {
|
|
716
744
|
if (device.scanDuration) {
|
|
717
745
|
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
718
746
|
if (device.ble) {
|
|
719
|
-
this.debugLog(
|
|
747
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
720
748
|
}
|
|
721
749
|
}
|
|
722
750
|
else {
|
|
723
751
|
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
724
752
|
if (this.device.ble) {
|
|
725
|
-
this.debugLog(
|
|
753
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
726
754
|
}
|
|
727
755
|
}
|
|
728
756
|
}
|
|
729
757
|
async logs(device) {
|
|
730
758
|
if (this.platform.debugMode) {
|
|
731
759
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
732
|
-
this.debugLog(
|
|
760
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
733
761
|
}
|
|
734
762
|
else if (device.logging) {
|
|
735
763
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
736
|
-
this.debugLog(
|
|
764
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
737
765
|
}
|
|
738
766
|
else if (this.platform.config.options?.logging) {
|
|
739
767
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
740
|
-
this.debugLog(
|
|
768
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
741
769
|
}
|
|
742
770
|
else {
|
|
743
771
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
744
|
-
this.debugLog(
|
|
772
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
745
773
|
}
|
|
746
774
|
}
|
|
747
775
|
FirmwareRevision(accessory, device) {
|
|
748
776
|
let FirmwareRevision;
|
|
749
|
-
this.debugLog(
|
|
750
|
-
|
|
751
|
-
this.debugLog(
|
|
777
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
778
|
+
+ `accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
779
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
780
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
752
781
|
if (accessory.context.FirmwareRevision) {
|
|
753
782
|
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
754
783
|
}
|