@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/plug.ts
CHANGED
|
@@ -35,6 +35,7 @@ export class Plug {
|
|
|
35
35
|
currentPower: serviceData['currentPower'];
|
|
36
36
|
|
|
37
37
|
// Config
|
|
38
|
+
OpenAPI?: boolean;
|
|
38
39
|
scanDuration!: number;
|
|
39
40
|
deviceLogging!: string;
|
|
40
41
|
deviceRefreshRate!: number;
|
|
@@ -114,9 +115,10 @@ export class Plug {
|
|
|
114
115
|
try {
|
|
115
116
|
await this.pushChanges();
|
|
116
117
|
} catch (e: any) {
|
|
117
|
-
this.errorLog(
|
|
118
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges`);
|
|
118
119
|
if (this.deviceLogging.includes('debug')) {
|
|
119
|
-
this.errorLog(
|
|
120
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges,`
|
|
121
|
+
+ ` Error Message: ${superStringify(e.message)}`);
|
|
120
122
|
}
|
|
121
123
|
this.apiError(e);
|
|
122
124
|
}
|
|
@@ -133,7 +135,7 @@ export class Plug {
|
|
|
133
135
|
}
|
|
134
136
|
|
|
135
137
|
async BLEparseStatus(): Promise<void> {
|
|
136
|
-
this.debugLog(
|
|
138
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE parseStatus`);
|
|
137
139
|
// State
|
|
138
140
|
switch (this.state) {
|
|
139
141
|
case 'on':
|
|
@@ -142,7 +144,7 @@ export class Plug {
|
|
|
142
144
|
default:
|
|
143
145
|
this.On = false;
|
|
144
146
|
}
|
|
145
|
-
this.debugLog(
|
|
147
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
146
148
|
}
|
|
147
149
|
|
|
148
150
|
async openAPIparseStatus() {
|
|
@@ -153,7 +155,7 @@ export class Plug {
|
|
|
153
155
|
default:
|
|
154
156
|
this.On = false;
|
|
155
157
|
}
|
|
156
|
-
this.debugLog(
|
|
158
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
157
159
|
}
|
|
158
160
|
|
|
159
161
|
async refreshStatus(): Promise<void> {
|
|
@@ -165,14 +167,14 @@ export class Plug {
|
|
|
165
167
|
}
|
|
166
168
|
|
|
167
169
|
async BLERefreshStatus(): Promise<void> {
|
|
168
|
-
this.debugLog(
|
|
170
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE refreshStatus`);
|
|
169
171
|
const switchbot = await this.platform.connectBLE();
|
|
170
172
|
// Convert to BLE Address
|
|
171
173
|
this.device.bleMac = this.device
|
|
172
174
|
.deviceId!.match(/.{1,2}/g)!
|
|
173
175
|
.join(':')
|
|
174
176
|
.toLowerCase();
|
|
175
|
-
this.debugLog(
|
|
177
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
176
178
|
this.getCustomBLEAddress(switchbot);
|
|
177
179
|
// Start to monitor advertisement packets
|
|
178
180
|
if (switchbot !== false) {
|
|
@@ -188,8 +190,8 @@ export class Plug {
|
|
|
188
190
|
if (this.deviceLogging.includes('debug')) {
|
|
189
191
|
this.infoLog(this.address);
|
|
190
192
|
this.infoLog(this.device.bleMac);
|
|
191
|
-
this.infoLog(
|
|
192
|
-
this.infoLog(
|
|
193
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
|
|
194
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
|
|
193
195
|
}
|
|
194
196
|
this.serviceData = ad.serviceData;
|
|
195
197
|
this.state = ad.serviceData.state;
|
|
@@ -199,19 +201,19 @@ export class Plug {
|
|
|
199
201
|
this.wifiRssi = ad.serviceData.wifiRssi;
|
|
200
202
|
this.overload = ad.serviceData.overload;
|
|
201
203
|
this.currentPower = ad.serviceData.currentPower;
|
|
202
|
-
this.debugLog(
|
|
204
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
|
|
203
205
|
this.debugLog(
|
|
204
|
-
|
|
206
|
+
`${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
|
|
205
207
|
`delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
|
|
206
208
|
`wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
|
|
207
209
|
);
|
|
208
210
|
|
|
209
211
|
if (this.serviceData) {
|
|
210
212
|
this.connected = true;
|
|
211
|
-
this.debugLog(
|
|
213
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
212
214
|
} else {
|
|
213
215
|
this.connected = false;
|
|
214
|
-
this.debugLog(
|
|
216
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
215
217
|
}
|
|
216
218
|
};
|
|
217
219
|
// Wait 2 seconds
|
|
@@ -228,14 +230,15 @@ export class Plug {
|
|
|
228
230
|
}
|
|
229
231
|
})
|
|
230
232
|
.catch(async (e: any) => {
|
|
231
|
-
this.errorLog(
|
|
233
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
232
234
|
if (this.deviceLogging.includes('debug')) {
|
|
233
235
|
this.errorLog(
|
|
234
|
-
|
|
236
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
237
|
+
+ ` Error Message: ${superStringify(e.message)}`,
|
|
235
238
|
);
|
|
236
239
|
}
|
|
237
240
|
if (this.platform.config.credentials?.token) {
|
|
238
|
-
this.warnLog(
|
|
241
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
239
242
|
this.SwitchToOpenAPI = true;
|
|
240
243
|
await this.openAPIRefreshStatus();
|
|
241
244
|
}
|
|
@@ -263,7 +266,7 @@ export class Plug {
|
|
|
263
266
|
});
|
|
264
267
|
// Set an event handler
|
|
265
268
|
switchbot.onadvertisement = (ad: any) => {
|
|
266
|
-
this.warnLog(
|
|
269
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
|
|
267
270
|
};
|
|
268
271
|
await switchbot.wait(10000);
|
|
269
272
|
// Stop to monitor
|
|
@@ -273,66 +276,71 @@ export class Plug {
|
|
|
273
276
|
}
|
|
274
277
|
|
|
275
278
|
async BLEconnection(switchbot: any): Promise<void> {
|
|
276
|
-
this.errorLog(
|
|
279
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
277
280
|
if (this.platform.config.credentials?.token) {
|
|
278
|
-
this.warnLog(
|
|
281
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
279
282
|
this.SwitchToOpenAPI = true;
|
|
280
283
|
await this.openAPIRefreshStatus();
|
|
281
284
|
}
|
|
282
285
|
}
|
|
283
286
|
|
|
284
287
|
async openAPIRefreshStatus() {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
288
|
+
if (this.OpenAPI) {
|
|
289
|
+
try {
|
|
290
|
+
const t = Date.now();
|
|
291
|
+
const nonce = 'requestID';
|
|
292
|
+
const data = this.platform.config.credentials?.token + t + nonce;
|
|
293
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
294
|
+
const sign = signTerm.toString('base64');
|
|
295
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
296
|
+
const options = {
|
|
297
|
+
hostname: HostDomain,
|
|
298
|
+
port: 443,
|
|
299
|
+
path: `${DevicePath}/${this.device.deviceId}/status`,
|
|
300
|
+
method: 'GET',
|
|
301
|
+
headers: {
|
|
302
|
+
Authorization: this.platform.config.credentials?.token,
|
|
303
|
+
sign: sign,
|
|
304
|
+
nonce: nonce,
|
|
305
|
+
t: t,
|
|
306
|
+
'Content-Type': 'application/json',
|
|
307
|
+
},
|
|
308
|
+
};
|
|
309
|
+
const req = https.request(options, (res) => {
|
|
310
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
311
|
+
let rawData = '';
|
|
312
|
+
res.on('data', (d) => {
|
|
313
|
+
rawData += d;
|
|
314
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
315
|
+
});
|
|
316
|
+
res.on('end', () => {
|
|
317
|
+
try {
|
|
318
|
+
this.deviceStatus = JSON.parse(rawData);
|
|
319
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
|
|
320
|
+
this.power = this.deviceStatus.body.power;
|
|
321
|
+
this.parseStatus();
|
|
322
|
+
this.updateHomeKitCharacteristics();
|
|
323
|
+
} catch (e: any) {
|
|
324
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
325
|
+
}
|
|
326
|
+
});
|
|
311
327
|
});
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
this.deviceStatus = JSON.parse(rawData);
|
|
315
|
-
this.debugLog(`Plug: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
|
|
316
|
-
this.power = this.deviceStatus.body.power;
|
|
317
|
-
this.parseStatus();
|
|
318
|
-
this.updateHomeKitCharacteristics();
|
|
319
|
-
} catch (e: any) {
|
|
320
|
-
this.errorLog(`Plug: ${this.accessory.displayName} error message: ${e.message}`);
|
|
321
|
-
}
|
|
328
|
+
req.on('error', (e: any) => {
|
|
329
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
322
330
|
});
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
this.errorLog(
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
);
|
|
331
|
+
req.end();
|
|
332
|
+
} catch (e: any) {
|
|
333
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
334
|
+
if (this.deviceLogging.includes('debug')) {
|
|
335
|
+
this.errorLog(
|
|
336
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
337
|
+
+ ` Error Message: ${superStringify(e.message)}`,
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
this.apiError(e);
|
|
334
341
|
}
|
|
335
|
-
|
|
342
|
+
} else {
|
|
343
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI is disabled, commands will not be sent.`);
|
|
336
344
|
}
|
|
337
345
|
}
|
|
338
346
|
|
|
@@ -355,40 +363,42 @@ export class Plug {
|
|
|
355
363
|
}
|
|
356
364
|
|
|
357
365
|
async BLEpushChanges(): Promise<void> {
|
|
358
|
-
this.debugLog(
|
|
359
|
-
this.debugLog(
|
|
366
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE pushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`);
|
|
367
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE pushChanges`);
|
|
360
368
|
const switchbot = await this.platform.connectBLE();
|
|
361
369
|
// Convert to BLE Address
|
|
362
370
|
this.device.bleMac = this.device
|
|
363
371
|
.deviceId!.match(/.{1,2}/g)!
|
|
364
372
|
.join(':')
|
|
365
373
|
.toLowerCase();
|
|
366
|
-
this.debugLog(
|
|
374
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
367
375
|
switchbot
|
|
368
376
|
.discover({
|
|
369
377
|
model: this.BLEmodel(),
|
|
370
378
|
id: this.device.bleMac,
|
|
371
379
|
})
|
|
372
380
|
.then((device_list: any) => {
|
|
373
|
-
this.infoLog(
|
|
381
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
374
382
|
return this.turnOnOff(device_list);
|
|
375
383
|
})
|
|
376
384
|
.then(() => {
|
|
377
|
-
this.debugLog(
|
|
385
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
378
386
|
this.On = false;
|
|
379
387
|
})
|
|
380
388
|
.catch(async (e: any) => {
|
|
381
|
-
this.errorLog(
|
|
389
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
382
390
|
if (this.deviceLogging.includes('debug')) {
|
|
383
391
|
this.errorLog(
|
|
384
|
-
|
|
392
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
393
|
+
+ ` Error Message: ${superStringify(e.message)}`,
|
|
385
394
|
);
|
|
386
395
|
}
|
|
387
396
|
if (this.platform.debugMode) {
|
|
388
|
-
this.errorLog(
|
|
397
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
398
|
+
+ ` Error: ${superStringify(e)}`);
|
|
389
399
|
}
|
|
390
400
|
if (this.platform.config.credentials?.token) {
|
|
391
|
-
this.warnLog(
|
|
401
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
392
402
|
await this.openAPIpushChanges();
|
|
393
403
|
}
|
|
394
404
|
this.apiError(e);
|
|
@@ -409,10 +419,10 @@ export class Plug {
|
|
|
409
419
|
}
|
|
410
420
|
|
|
411
421
|
async openAPIpushChanges() {
|
|
412
|
-
if (this.platform.config.credentials?.token) {
|
|
422
|
+
if (this.platform.config.credentials?.token && this.OpenAPI) {
|
|
413
423
|
if (this.On !== this.accessory.context.On) {
|
|
414
424
|
// Make Push On request to the API
|
|
415
|
-
this.debugLog(
|
|
425
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI pushChanges`);
|
|
416
426
|
const t = Date.now();
|
|
417
427
|
const nonce = 'requestID';
|
|
418
428
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
@@ -420,7 +430,7 @@ export class Plug {
|
|
|
420
430
|
.update(Buffer.from(data, 'utf-8'))
|
|
421
431
|
.digest();
|
|
422
432
|
const sign = signTerm.toString('base64');
|
|
423
|
-
this.debugLog(
|
|
433
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
424
434
|
|
|
425
435
|
let command = '';
|
|
426
436
|
if (this.On) {
|
|
@@ -433,7 +443,7 @@ export class Plug {
|
|
|
433
443
|
'parameter': 'default',
|
|
434
444
|
'commandType': 'command',
|
|
435
445
|
});
|
|
436
|
-
this.infoLog(
|
|
446
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
437
447
|
const options = {
|
|
438
448
|
hostname: HostDomain,
|
|
439
449
|
port: 443,
|
|
@@ -449,34 +459,36 @@ export class Plug {
|
|
|
449
459
|
},
|
|
450
460
|
};
|
|
451
461
|
const req = https.request(options, res => {
|
|
452
|
-
this.debugLog(
|
|
462
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
453
463
|
this.statusCode({ res });
|
|
454
464
|
res.on('data', d => {
|
|
455
|
-
this.debugLog(
|
|
465
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
456
466
|
});
|
|
457
467
|
});
|
|
458
468
|
req.on('error', (e: any) => {
|
|
459
|
-
this.errorLog(
|
|
469
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
460
470
|
});
|
|
461
471
|
req.write(body);
|
|
462
472
|
req.end();
|
|
463
|
-
this.debugLog(
|
|
473
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges: ${superStringify(req)}`);
|
|
464
474
|
}
|
|
465
475
|
interval(5000)
|
|
466
476
|
.pipe(take(1))
|
|
467
477
|
.subscribe(async () => {
|
|
468
478
|
await this.refreshStatus();
|
|
469
479
|
});
|
|
480
|
+
} else {
|
|
481
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI is disabled, commands will not be sent.`);
|
|
470
482
|
}
|
|
471
483
|
}
|
|
472
484
|
|
|
473
485
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
474
486
|
if (this.On === undefined) {
|
|
475
|
-
this.debugLog(
|
|
487
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
476
488
|
} else {
|
|
477
489
|
this.accessory.context.On = this.On;
|
|
478
490
|
this.outletService.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
479
|
-
this.debugLog(
|
|
491
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
480
492
|
}
|
|
481
493
|
}
|
|
482
494
|
|
|
@@ -488,33 +500,33 @@ export class Plug {
|
|
|
488
500
|
async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
|
|
489
501
|
switch (res.statusCode) {
|
|
490
502
|
case 151:
|
|
491
|
-
this.errorLog(
|
|
503
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
492
504
|
break;
|
|
493
505
|
case 152:
|
|
494
|
-
this.errorLog(
|
|
506
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
|
|
495
507
|
break;
|
|
496
508
|
case 160:
|
|
497
|
-
this.errorLog(
|
|
509
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
|
|
498
510
|
break;
|
|
499
511
|
case 161:
|
|
500
|
-
this.errorLog(
|
|
512
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
|
|
501
513
|
this.offlineOff();
|
|
502
514
|
break;
|
|
503
515
|
case 171:
|
|
504
|
-
this.errorLog(
|
|
516
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
505
517
|
this.offlineOff();
|
|
506
518
|
break;
|
|
507
519
|
case 190:
|
|
508
520
|
this.errorLog(
|
|
509
|
-
|
|
521
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
510
522
|
` Or command: ${superStringify(res)} format is invalid`,
|
|
511
523
|
);
|
|
512
524
|
break;
|
|
513
525
|
case 100:
|
|
514
|
-
this.debugLog(
|
|
526
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
|
|
515
527
|
break;
|
|
516
528
|
default:
|
|
517
|
-
this.debugLog(
|
|
529
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
|
|
518
530
|
}
|
|
519
531
|
}
|
|
520
532
|
|
|
@@ -529,7 +541,7 @@ export class Plug {
|
|
|
529
541
|
* Handle requests to set the value of the "On" characteristic
|
|
530
542
|
*/
|
|
531
543
|
async handleOnSet(value: CharacteristicValue): Promise<void> {
|
|
532
|
-
this.debugLog(
|
|
544
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} - Set On: ${value}`);
|
|
533
545
|
|
|
534
546
|
this.On = value;
|
|
535
547
|
this.doPlugUpdate.next();
|
|
@@ -577,6 +589,9 @@ export class Plug {
|
|
|
577
589
|
if (device.ble !== undefined) {
|
|
578
590
|
config['ble'] = device.ble;
|
|
579
591
|
}
|
|
592
|
+
if (device.openAPI !== undefined) {
|
|
593
|
+
config['openAPI'] = device.openAPI;
|
|
594
|
+
}
|
|
580
595
|
if (device.logging !== undefined) {
|
|
581
596
|
config['logging'] = device.logging;
|
|
582
597
|
}
|
|
@@ -590,30 +605,39 @@ export class Plug {
|
|
|
590
605
|
config['offline'] = device.offline;
|
|
591
606
|
}
|
|
592
607
|
if (Object.entries(config).length !== 0) {
|
|
593
|
-
this.infoLog(
|
|
608
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
594
609
|
}
|
|
595
610
|
}
|
|
596
611
|
|
|
597
612
|
async refreshRate(device: device & devicesConfig): Promise<void> {
|
|
598
613
|
if (device.refreshRate) {
|
|
599
614
|
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
600
|
-
this.debugLog(
|
|
615
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
601
616
|
} else if (this.platform.config.options!.refreshRate) {
|
|
602
617
|
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
603
|
-
this.debugLog(
|
|
618
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
async openAPI() {
|
|
623
|
+
if (!this.device.openAPI) {
|
|
624
|
+
this.OpenAPI = true;
|
|
625
|
+
} else {
|
|
626
|
+
this.OpenAPI = this.device.openAPI;
|
|
604
627
|
}
|
|
628
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
|
|
605
629
|
}
|
|
606
630
|
|
|
607
631
|
async scan(device: device & devicesConfig): Promise<void> {
|
|
608
632
|
if (device.scanDuration) {
|
|
609
633
|
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
610
634
|
if (device.ble) {
|
|
611
|
-
this.debugLog(
|
|
635
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
612
636
|
}
|
|
613
637
|
} else {
|
|
614
638
|
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
615
639
|
if (this.device.ble) {
|
|
616
|
-
this.debugLog(
|
|
640
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
617
641
|
}
|
|
618
642
|
}
|
|
619
643
|
}
|
|
@@ -621,24 +645,25 @@ export class Plug {
|
|
|
621
645
|
async logs(device: device & devicesConfig): Promise<void> {
|
|
622
646
|
if (this.platform.debugMode) {
|
|
623
647
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
624
|
-
this.debugLog(
|
|
648
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
625
649
|
} else if (device.logging) {
|
|
626
650
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
627
|
-
this.debugLog(
|
|
651
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
628
652
|
} else if (this.platform.config.options?.logging) {
|
|
629
653
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
630
|
-
this.debugLog(
|
|
654
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
631
655
|
} else {
|
|
632
656
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
633
|
-
this.debugLog(
|
|
657
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
634
658
|
}
|
|
635
659
|
}
|
|
636
660
|
|
|
637
661
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
638
662
|
let FirmwareRevision: string;
|
|
639
|
-
this.debugLog(
|
|
640
|
-
|
|
641
|
-
this.debugLog(
|
|
663
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
664
|
+
+` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
665
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
666
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
642
667
|
if (accessory.context.FirmwareRevision) {
|
|
643
668
|
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
644
669
|
} else if (device.firmware) {
|