@switchbot/homebridge-switchbot 3.5.1-beta.1 → 3.5.1-beta.10
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/README.md +16 -0
- package/dist/device/blindtilt.d.ts +15 -6
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +203 -255
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -4
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +196 -218
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +9 -4
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +202 -247
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +10 -5
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +329 -378
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +9 -4
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +99 -142
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +19 -7
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +203 -264
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +28 -32
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +186 -225
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +9 -4
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +198 -227
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +9 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +106 -231
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +12 -4
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +192 -232
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +9 -4
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +91 -157
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -5
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +287 -367
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +10 -5
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +171 -216
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +9 -4
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +93 -158
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +9 -4
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +94 -155
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +9 -4
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +84 -142
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -4
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +99 -124
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +9 -6
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +170 -253
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +12 -4
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +105 -129
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +2 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +2 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +2 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +2 -1
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +1 -1
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +2 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +2 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +2 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +2 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +2 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +14 -14
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +102 -86
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +49 -191
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +19 -0
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +279 -0
- package/dist/types/bledevicestatus.d.ts.map +1 -0
- package/dist/types/bledevicestatus.js +2 -0
- package/dist/types/bledevicestatus.js.map +1 -0
- package/dist/types/devicelist.d.ts +89 -0
- package/dist/types/devicelist.d.ts.map +1 -0
- package/dist/types/devicelist.js +6 -0
- package/dist/types/devicelist.js.map +1 -0
- package/dist/types/deviceresponse.d.ts +13 -0
- package/dist/types/deviceresponse.d.ts.map +1 -0
- package/dist/types/deviceresponse.js +2 -0
- package/dist/types/deviceresponse.js.map +1 -0
- package/dist/types/devicestatus.d.ts +149 -0
- package/dist/types/devicestatus.d.ts.map +1 -0
- package/dist/types/devicestatus.js +3 -0
- package/dist/types/devicestatus.js.map +1 -0
- package/dist/types/devicewebhookstatus.d.ts +156 -0
- package/dist/types/devicewebhookstatus.d.ts.map +1 -0
- package/dist/types/devicewebhookstatus.js +2 -0
- package/dist/types/devicewebhookstatus.js.map +1 -0
- package/dist/types/irdevicelist.d.ts +10 -0
- package/dist/types/irdevicelist.d.ts.map +1 -0
- package/dist/types/irdevicelist.js +2 -0
- package/dist/types/irdevicelist.js.map +1 -0
- package/dist/types/pushbody.d.ts +6 -0
- package/dist/types/pushbody.d.ts.map +1 -0
- package/dist/types/pushbody.js +2 -0
- package/dist/types/pushbody.js.map +1 -0
- package/dist/utils.d.ts +25 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +28 -0
- package/dist/utils.js.map +1 -1
- package/package.json +10 -10
- package/src/device/blindtilt.ts +224 -264
- package/src/device/bot.ts +208 -221
- package/src/device/ceilinglight.ts +210 -257
- package/src/device/colorbulb.ts +334 -397
- package/src/device/contact.ts +111 -146
- package/src/device/curtain.ts +220 -283
- package/src/device/device.ts +194 -245
- package/src/device/fan.ts +214 -230
- package/src/device/hub.ts +126 -246
- package/src/device/humidifier.ts +216 -243
- package/src/device/iosensor.ts +114 -166
- package/src/device/lightstrip.ts +302 -377
- package/src/device/lock.ts +187 -221
- package/src/device/meter.ts +116 -177
- package/src/device/meterplus.ts +117 -174
- package/src/device/motion.ts +99 -144
- package/src/device/plug.ts +110 -128
- package/src/device/robotvacuumcleaner.ts +189 -252
- package/src/device/waterdetector.ts +123 -139
- package/src/irdevice/airconditioner.ts +2 -1
- package/src/irdevice/airpurifier.ts +2 -1
- package/src/irdevice/camera.ts +2 -1
- package/src/irdevice/fan.ts +2 -1
- package/src/irdevice/irdevice.ts +3 -2
- package/src/irdevice/light.ts +2 -1
- package/src/irdevice/other.ts +2 -1
- package/src/irdevice/tv.ts +2 -1
- package/src/irdevice/vacuumcleaner.ts +2 -1
- package/src/irdevice/waterheater.ts +2 -1
- package/src/platform.ts +104 -87
- package/src/settings.ts +30 -239
- package/src/types/bledevicestatus.ts +305 -0
- package/src/types/devicelist.ts +124 -0
- package/src/types/deviceresponse.ts +15 -0
- package/src/types/devicestatus.ts +178 -0
- package/src/types/devicewebhookstatus.ts +196 -0
- package/src/types/irdevicelist.ts +15 -0
- package/src/types/pushbody.ts +9 -0
- package/src/utils.ts +33 -0
package/dist/platform.js
CHANGED
|
@@ -32,13 +32,13 @@ import { AirConditioner } from './irdevice/airconditioner.js';
|
|
|
32
32
|
import { Buffer } from 'buffer';
|
|
33
33
|
import { request } from 'undici';
|
|
34
34
|
import asyncmqtt from 'async-mqtt';
|
|
35
|
-
import { sleep } from './utils.js';
|
|
36
35
|
import { createServer } from 'http';
|
|
37
36
|
import { queueScheduler } from 'rxjs';
|
|
38
37
|
import fakegato from 'fakegato-history';
|
|
39
38
|
import crypto, { randomUUID } from 'crypto';
|
|
40
39
|
import { readFileSync, writeFileSync } from 'fs';
|
|
41
40
|
import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes';
|
|
41
|
+
import { isBlindTiltDevice, isCurtainDevice, sleep } from './utils.js';
|
|
42
42
|
import { PLATFORM_NAME, PLUGIN_NAME, Devices, setupWebhook, updateWebhook, deleteWebhook, queryWebhook } from './settings.js';
|
|
43
43
|
/**
|
|
44
44
|
* HomebridgePlatform
|
|
@@ -128,29 +128,29 @@ export class SwitchBotPlatform {
|
|
|
128
128
|
try {
|
|
129
129
|
const { connectAsync } = asyncmqtt;
|
|
130
130
|
this.mqttClient = await connectAsync(this.config.options?.mqttURL, this.config.options.mqttOptions || {});
|
|
131
|
-
this.debugLog('MQTT connection has been established successfully.');
|
|
132
|
-
this.mqttClient.on('error', (e) => {
|
|
133
|
-
this.errorLog(`Failed to publish MQTT messages. ${e}`);
|
|
131
|
+
await this.debugLog('MQTT connection has been established successfully.');
|
|
132
|
+
this.mqttClient.on('error', async (e) => {
|
|
133
|
+
await this.errorLog(`Failed to publish MQTT messages. ${e}`);
|
|
134
134
|
});
|
|
135
135
|
if (!this.config.options?.webhookURL) {
|
|
136
136
|
// receive webhook events via MQTT
|
|
137
|
-
this.infoLog(`Webhook is configured to be received through ${this.config.options.mqttURL}/homebridge-switchbot/webhook.`);
|
|
137
|
+
await this.infoLog(`Webhook is configured to be received through ${this.config.options.mqttURL}/homebridge-switchbot/webhook.`);
|
|
138
138
|
this.mqttClient.subscribe('homebridge-switchbot/webhook/+');
|
|
139
139
|
this.mqttClient.on('message', async (topic, message) => {
|
|
140
140
|
try {
|
|
141
|
-
this.debugLog(`Received Webhook via MQTT: ${topic}=${message}`);
|
|
141
|
+
await this.debugLog(`Received Webhook via MQTT: ${topic}=${message}`);
|
|
142
142
|
const context = JSON.parse(message.toString());
|
|
143
|
-
|
|
143
|
+
this.webhookEventHandler[context.deviceMac]?.(context);
|
|
144
144
|
}
|
|
145
145
|
catch (e) {
|
|
146
|
-
this.errorLog(`Failed to handle webhook event. Error:${e}`);
|
|
146
|
+
await this.errorLog(`Failed to handle webhook event. Error:${e}`);
|
|
147
147
|
}
|
|
148
148
|
});
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
catch (e) {
|
|
152
152
|
this.mqttClient = null;
|
|
153
|
-
this.errorLog(`Failed to establish MQTT connection. ${e}`);
|
|
153
|
+
await this.errorLog(`Failed to establish MQTT connection. ${e}`);
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
}
|
|
@@ -177,7 +177,7 @@ export class SwitchBotPlatform {
|
|
|
177
177
|
const options = this.config.options?.mqttPubOptions || {};
|
|
178
178
|
this.mqttClient?.publish(`homebridge-switchbot/webhook/${mac}`, `${JSON.stringify(body.context)}`, options);
|
|
179
179
|
}
|
|
180
|
-
|
|
180
|
+
this.webhookEventHandler[body.context.deviceMac]?.(body.context);
|
|
181
181
|
}
|
|
182
182
|
catch (e) {
|
|
183
183
|
this.errorLog(`Failed to handle webhook event. Error:${e}`);
|
|
@@ -275,9 +275,7 @@ export class SwitchBotPlatform {
|
|
|
275
275
|
}),
|
|
276
276
|
});
|
|
277
277
|
const response = await body.json();
|
|
278
|
-
this.debugLog(`deleteWebhook: url:${url}`);
|
|
279
|
-
this.debugLog(`deleteWebhook: body:${JSON.stringify(response)}`);
|
|
280
|
-
this.debugLog(`deleteWebhook: statusCode:${statusCode}`);
|
|
278
|
+
this.debugLog(`deleteWebhook: url:${url}, body:${JSON.stringify(response)}, statusCode:${statusCode}`);
|
|
281
279
|
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
282
280
|
this.errorLog(`Failed to delete webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
|
|
283
281
|
}
|
|
@@ -1330,16 +1328,18 @@ export class SwitchBotPlatform {
|
|
|
1330
1328
|
if (!device.external) {
|
|
1331
1329
|
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1332
1330
|
}
|
|
1333
|
-
if (device
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
else {
|
|
1338
|
-
if (device.master) {
|
|
1339
|
-
this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1331
|
+
if (isBlindTiltDevice(device)) {
|
|
1332
|
+
if (device.group && !device.curtain?.disable_group) {
|
|
1333
|
+
this.debugLog('Your Curtains are grouped, ' +
|
|
1334
|
+
`, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1340
1335
|
}
|
|
1341
1336
|
else {
|
|
1342
|
-
|
|
1337
|
+
if (device.master) {
|
|
1338
|
+
this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1339
|
+
}
|
|
1340
|
+
else {
|
|
1341
|
+
this.errorLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1342
|
+
}
|
|
1343
1343
|
}
|
|
1344
1344
|
}
|
|
1345
1345
|
// create a new accessory
|
|
@@ -1399,16 +1399,18 @@ export class SwitchBotPlatform {
|
|
|
1399
1399
|
if (!device.external) {
|
|
1400
1400
|
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1401
1401
|
}
|
|
1402
|
-
if (device
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
else {
|
|
1407
|
-
if (device.master) {
|
|
1408
|
-
this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1402
|
+
if (isCurtainDevice(device)) {
|
|
1403
|
+
if (device.group && !device.curtain?.disable_group) {
|
|
1404
|
+
this.debugLog('Your Curtains are grouped, ' +
|
|
1405
|
+
`, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1409
1406
|
}
|
|
1410
1407
|
else {
|
|
1411
|
-
|
|
1408
|
+
if (device.master) {
|
|
1409
|
+
this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1410
|
+
}
|
|
1411
|
+
else {
|
|
1412
|
+
this.errorLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1413
|
+
}
|
|
1412
1414
|
}
|
|
1413
1415
|
}
|
|
1414
1416
|
// create a new accessory
|
|
@@ -1844,9 +1846,6 @@ export class SwitchBotPlatform {
|
|
|
1844
1846
|
existingAccessory.context.model = device.remoteType;
|
|
1845
1847
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1846
1848
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1847
|
-
if (device.version && !device.firmware) {
|
|
1848
|
-
existingAccessory.context.version = device.version;
|
|
1849
|
-
}
|
|
1850
1849
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1851
1850
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1852
1851
|
existingAccessory.context.connectionType = device.connectionType;
|
|
@@ -2341,16 +2340,32 @@ export class SwitchBotPlatform {
|
|
|
2341
2340
|
}
|
|
2342
2341
|
}
|
|
2343
2342
|
async registerCurtains(device) {
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2343
|
+
/*function isCurtainDevice(device: device & devicesConfig): device is (curtain | curtain3) & devicesConfig {
|
|
2344
|
+
return device.deviceType === 'Curtain' || device.deviceType === 'Curtain3';
|
|
2345
|
+
}
|
|
2346
|
+
|
|
2347
|
+
function isBlindTiltDevice(device: device & devicesConfig): device is blindTilt & devicesConfig {
|
|
2348
|
+
return device.deviceType === 'Blind Tilt';
|
|
2349
|
+
}*/
|
|
2350
|
+
let registerWindowCovering;
|
|
2351
|
+
if (isCurtainDevice(device)) {
|
|
2352
|
+
this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds}, master: `
|
|
2353
|
+
+ `${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}, connectionType: ${device.connectionType}`);
|
|
2354
|
+
registerWindowCovering = await this.registerWindowCovering(device);
|
|
2355
|
+
}
|
|
2356
|
+
else if (isBlindTiltDevice(device)) {
|
|
2357
|
+
this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, blindTiltDevicesIds: ${device.blindTiltDevicesIds},`
|
|
2358
|
+
+ ` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group},`
|
|
2359
|
+
+ ` connectionType: ${device.connectionType}`);
|
|
2360
|
+
registerWindowCovering = await this.registerWindowCovering(device);
|
|
2361
|
+
}
|
|
2362
|
+
else {
|
|
2363
|
+
registerWindowCovering = false;
|
|
2353
2364
|
}
|
|
2365
|
+
return registerWindowCovering;
|
|
2366
|
+
}
|
|
2367
|
+
async registerWindowCovering(device) {
|
|
2368
|
+
this.debugLog(device.master);
|
|
2354
2369
|
let registerCurtain;
|
|
2355
2370
|
if (device.master && device.group) {
|
|
2356
2371
|
// OpenAPI: Master Curtains/Blind Tilt in Group
|
|
@@ -2524,67 +2539,67 @@ export class SwitchBotPlatform {
|
|
|
2524
2539
|
async statusCode(statusCode) {
|
|
2525
2540
|
switch (statusCode) {
|
|
2526
2541
|
case 151:
|
|
2527
|
-
this.errorLog(`Command not supported by this device type, statusCode: ${statusCode}, Submit Feature Request Here: ` +
|
|
2542
|
+
await this.errorLog(`Command not supported by this device type, statusCode: ${statusCode}, Submit Feature Request Here: ` +
|
|
2528
2543
|
'https://tinyurl.com/SwitchBotFeatureRequest');
|
|
2529
2544
|
break;
|
|
2530
2545
|
case 152:
|
|
2531
|
-
this.errorLog(`Device not found, statusCode: ${statusCode}`);
|
|
2546
|
+
await this.errorLog(`Device not found, statusCode: ${statusCode}`);
|
|
2532
2547
|
break;
|
|
2533
2548
|
case 160:
|
|
2534
|
-
this.errorLog(`Command is not supported, statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`);
|
|
2549
|
+
await this.errorLog(`Command is not supported, statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`);
|
|
2535
2550
|
break;
|
|
2536
2551
|
case 161:
|
|
2537
|
-
this.errorLog(`Device is offline, statusCode: ${statusCode}`);
|
|
2552
|
+
await this.errorLog(`Device is offline, statusCode: ${statusCode}`);
|
|
2538
2553
|
break;
|
|
2539
2554
|
case 171:
|
|
2540
|
-
this.errorLog(`is offline, statusCode: ${statusCode}`);
|
|
2555
|
+
await this.errorLog(`is offline, statusCode: ${statusCode}`);
|
|
2541
2556
|
break;
|
|
2542
2557
|
case 190:
|
|
2543
|
-
this.errorLog(`Requests reached the daily limit, statusCode: ${statusCode}`);
|
|
2558
|
+
await this.errorLog(`Requests reached the daily limit, statusCode: ${statusCode}`);
|
|
2544
2559
|
break;
|
|
2545
2560
|
case 100:
|
|
2546
|
-
this.debugLog(`Command successfully sent, statusCode: ${statusCode}`);
|
|
2561
|
+
await this.debugLog(`Command successfully sent, statusCode: ${statusCode}`);
|
|
2547
2562
|
break;
|
|
2548
2563
|
case 200:
|
|
2549
|
-
this.debugLog(`Request successful, statusCode: ${statusCode}`);
|
|
2564
|
+
await this.debugLog(`Request successful, statusCode: ${statusCode}`);
|
|
2550
2565
|
break;
|
|
2551
2566
|
case 400:
|
|
2552
|
-
this.errorLog('Bad Request, The client has issued an invalid request. This is commonly used to specify validation errors in a request '
|
|
2567
|
+
await this.errorLog('Bad Request, The client has issued an invalid request. This is commonly used to specify validation errors in a request '
|
|
2553
2568
|
+ `payload, statusCode: ${statusCode}`);
|
|
2554
2569
|
break;
|
|
2555
2570
|
case 401:
|
|
2556
|
-
this.errorLog('Unauthorized, Authorization for the API is required, but the request has not been authenticated, '
|
|
2571
|
+
await this.errorLog('Unauthorized, Authorization for the API is required, but the request has not been authenticated, '
|
|
2557
2572
|
+ `statusCode: ${statusCode}`);
|
|
2558
2573
|
break;
|
|
2559
2574
|
case 403:
|
|
2560
|
-
this.errorLog('Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not '
|
|
2575
|
+
await this.errorLog('Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not '
|
|
2561
2576
|
+ `found, statusCode: ${statusCode}`);
|
|
2562
2577
|
break;
|
|
2563
2578
|
case 404:
|
|
2564
|
-
this.errorLog(`Not Found, Specifies the requested path does not exist, statusCode: ${statusCode}`);
|
|
2579
|
+
await this.errorLog(`Not Found, Specifies the requested path does not exist, statusCode: ${statusCode}`);
|
|
2565
2580
|
break;
|
|
2566
2581
|
case 406:
|
|
2567
|
-
this.errorLog('Not Acceptable, The client has requested a MIME type via the Accept header for a value not supported by the server, '
|
|
2582
|
+
await this.errorLog('Not Acceptable, The client has requested a MIME type via the Accept header for a value not supported by the server, '
|
|
2568
2583
|
+ `statusCode: ${statusCode}`);
|
|
2569
2584
|
break;
|
|
2570
2585
|
case 415:
|
|
2571
|
-
this.errorLog('Unsupported Media Type, The client has defined a contentType header that is not supported by the server, '
|
|
2586
|
+
await this.errorLog('Unsupported Media Type, The client has defined a contentType header that is not supported by the server, '
|
|
2572
2587
|
+ `statusCode: ${statusCode}`);
|
|
2573
2588
|
break;
|
|
2574
2589
|
case 422:
|
|
2575
|
-
this.errorLog('Unprocessable Entity, The client has made a valid request, but the server cannot process it. This is often used for '
|
|
2590
|
+
await this.errorLog('Unprocessable Entity, The client has made a valid request, but the server cannot process it. This is often used for '
|
|
2576
2591
|
+ `APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
2577
2592
|
break;
|
|
2578
2593
|
case 429:
|
|
2579
|
-
this.errorLog('Too Many Requests, The client has exceeded the number of requests allowed for a given time window, '
|
|
2594
|
+
await this.errorLog('Too Many Requests, The client has exceeded the number of requests allowed for a given time window, '
|
|
2580
2595
|
+ `statusCode: ${statusCode}`);
|
|
2581
2596
|
break;
|
|
2582
2597
|
case 500:
|
|
2583
|
-
this.errorLog('Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, '
|
|
2598
|
+
await this.errorLog('Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, '
|
|
2584
2599
|
+ `statusCode: ${statusCode}`);
|
|
2585
2600
|
break;
|
|
2586
2601
|
default:
|
|
2587
|
-
this.errorLog(`Unknown statusCode, statusCode: ${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
2602
|
+
await this.errorLog(`Unknown statusCode, statusCode: ${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
2588
2603
|
}
|
|
2589
2604
|
}
|
|
2590
2605
|
async retryRequest(deviceMaxRetries, deviceDelayBetweenRetries, url, options) {
|
|
@@ -2598,34 +2613,35 @@ export class SwitchBotPlatform {
|
|
|
2598
2613
|
return { body, statusCode };
|
|
2599
2614
|
}
|
|
2600
2615
|
else {
|
|
2601
|
-
this.debugLog(`Received status code: ${statusCode}`);
|
|
2616
|
+
await this.debugLog(`Received status code: ${statusCode}`);
|
|
2602
2617
|
}
|
|
2603
2618
|
}
|
|
2604
2619
|
catch (error) {
|
|
2605
|
-
this.errorLog(`Error making request: ${error.message}`);
|
|
2620
|
+
await this.errorLog(`Error making request: ${error.message}`);
|
|
2606
2621
|
}
|
|
2607
2622
|
retryCount++;
|
|
2608
|
-
this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`);
|
|
2623
|
+
await this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`);
|
|
2609
2624
|
await sleep(delayBetweenRetries);
|
|
2610
2625
|
}
|
|
2611
2626
|
return { body: null, statusCode: -1 };
|
|
2612
2627
|
}
|
|
2613
2628
|
// BLE Connection
|
|
2614
|
-
async connectBLE() {
|
|
2629
|
+
async connectBLE(accessory, device) {
|
|
2615
2630
|
let switchbot;
|
|
2616
2631
|
try {
|
|
2617
2632
|
const SwitchBot = (await import('node-switchbot')).SwitchBot;
|
|
2618
2633
|
queueScheduler.schedule(() => (switchbot = new SwitchBot()));
|
|
2634
|
+
await this.debugLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${switchbot}`);
|
|
2619
2635
|
}
|
|
2620
2636
|
catch (e) {
|
|
2621
2637
|
switchbot = false;
|
|
2622
|
-
this.errorLog(
|
|
2638
|
+
await this.errorLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${switchbot}, Error: ${e}`);
|
|
2623
2639
|
}
|
|
2624
2640
|
return switchbot;
|
|
2625
2641
|
}
|
|
2626
2642
|
async getVersion() {
|
|
2627
2643
|
const json = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
|
|
2628
|
-
this.debugLog(`Plugin Version: ${json.version}`);
|
|
2644
|
+
await this.debugLog(`Plugin Version: ${json.version}`);
|
|
2629
2645
|
this.version = json.version;
|
|
2630
2646
|
}
|
|
2631
2647
|
async getPlatformConfigSettings() {
|
|
@@ -2662,7 +2678,7 @@ export class SwitchBotPlatform {
|
|
|
2662
2678
|
platformConfig.delayBetweenRetries = this.delayBetweenRetries / 1000;
|
|
2663
2679
|
}
|
|
2664
2680
|
if (Object.entries(platformConfig).length !== 0) {
|
|
2665
|
-
this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
2681
|
+
await this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
2666
2682
|
}
|
|
2667
2683
|
this.platformConfig = platformConfig;
|
|
2668
2684
|
}
|
|
@@ -2671,64 +2687,64 @@ export class SwitchBotPlatform {
|
|
|
2671
2687
|
this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
|
|
2672
2688
|
if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
|
|
2673
2689
|
this.platformLogging = this.config.options.logging;
|
|
2674
|
-
this.debugWarnLog(`Using Config Logging: ${this.platformLogging}`);
|
|
2690
|
+
await this.debugWarnLog(`Using Config Logging: ${this.platformLogging}`);
|
|
2675
2691
|
}
|
|
2676
2692
|
else if (this.debugMode) {
|
|
2677
2693
|
this.platformLogging = 'debugMode';
|
|
2678
|
-
this.debugWarnLog(`Using ${this.platformLogging} Logging`);
|
|
2694
|
+
await this.debugWarnLog(`Using ${this.platformLogging} Logging`);
|
|
2679
2695
|
}
|
|
2680
2696
|
else {
|
|
2681
2697
|
this.platformLogging = 'standard';
|
|
2682
|
-
this.debugWarnLog(`Using ${this.platformLogging} Logging`);
|
|
2698
|
+
await this.debugWarnLog(`Using ${this.platformLogging} Logging`);
|
|
2683
2699
|
}
|
|
2684
2700
|
}
|
|
2685
2701
|
/**
|
|
2686
2702
|
* If device level logging is turned on, log to log.warn
|
|
2687
2703
|
* Otherwise send debug logs to log.debug
|
|
2688
2704
|
*/
|
|
2689
|
-
infoLog(...log) {
|
|
2690
|
-
if (this.enablingPlatformLogging()) {
|
|
2705
|
+
async infoLog(...log) {
|
|
2706
|
+
if (await this.enablingPlatformLogging()) {
|
|
2691
2707
|
this.log.info(String(...log));
|
|
2692
2708
|
}
|
|
2693
2709
|
}
|
|
2694
|
-
successLog(...log) {
|
|
2695
|
-
if (this.enablingPlatformLogging()) {
|
|
2710
|
+
async successLog(...log) {
|
|
2711
|
+
if (await this.enablingPlatformLogging()) {
|
|
2696
2712
|
this.log.success(String(...log));
|
|
2697
2713
|
}
|
|
2698
2714
|
}
|
|
2699
|
-
debugSuccessLog(...log) {
|
|
2700
|
-
if (this.enablingPlatformLogging()) {
|
|
2715
|
+
async debugSuccessLog(...log) {
|
|
2716
|
+
if (await this.enablingPlatformLogging()) {
|
|
2701
2717
|
if (this.platformLogging?.includes('debug')) {
|
|
2702
2718
|
this.log.success('[DEBUG]', String(...log));
|
|
2703
2719
|
}
|
|
2704
2720
|
}
|
|
2705
2721
|
}
|
|
2706
|
-
warnLog(...log) {
|
|
2707
|
-
if (this.enablingPlatformLogging()) {
|
|
2722
|
+
async warnLog(...log) {
|
|
2723
|
+
if (await this.enablingPlatformLogging()) {
|
|
2708
2724
|
this.log.warn(String(...log));
|
|
2709
2725
|
}
|
|
2710
2726
|
}
|
|
2711
|
-
debugWarnLog(...log) {
|
|
2712
|
-
if (this.enablingPlatformLogging()) {
|
|
2727
|
+
async debugWarnLog(...log) {
|
|
2728
|
+
if (await this.enablingPlatformLogging()) {
|
|
2713
2729
|
if (this.platformLogging?.includes('debug')) {
|
|
2714
2730
|
this.log.warn('[DEBUG]', String(...log));
|
|
2715
2731
|
}
|
|
2716
2732
|
}
|
|
2717
2733
|
}
|
|
2718
|
-
errorLog(...log) {
|
|
2719
|
-
if (this.enablingPlatformLogging()) {
|
|
2734
|
+
async errorLog(...log) {
|
|
2735
|
+
if (await this.enablingPlatformLogging()) {
|
|
2720
2736
|
this.log.error(String(...log));
|
|
2721
2737
|
}
|
|
2722
2738
|
}
|
|
2723
|
-
debugErrorLog(...log) {
|
|
2724
|
-
if (this.enablingPlatformLogging()) {
|
|
2739
|
+
async debugErrorLog(...log) {
|
|
2740
|
+
if (await this.enablingPlatformLogging()) {
|
|
2725
2741
|
if (this.platformLogging?.includes('debug')) {
|
|
2726
2742
|
this.log.error('[DEBUG]', String(...log));
|
|
2727
2743
|
}
|
|
2728
2744
|
}
|
|
2729
2745
|
}
|
|
2730
|
-
debugLog(...log) {
|
|
2731
|
-
if (this.enablingPlatformLogging()) {
|
|
2746
|
+
async debugLog(...log) {
|
|
2747
|
+
if (await this.enablingPlatformLogging()) {
|
|
2732
2748
|
if (this.platformLogging === 'debugMode') {
|
|
2733
2749
|
this.log.debug(String(...log));
|
|
2734
2750
|
}
|
|
@@ -2737,7 +2753,7 @@ export class SwitchBotPlatform {
|
|
|
2737
2753
|
}
|
|
2738
2754
|
}
|
|
2739
2755
|
}
|
|
2740
|
-
enablingPlatformLogging() {
|
|
2756
|
+
async enablingPlatformLogging() {
|
|
2741
2757
|
return this.platformLogging?.includes('debug') || this.platformLogging === 'standard';
|
|
2742
2758
|
}
|
|
2743
2759
|
}
|