@switchbot/homebridge-switchbot 3.5.1-beta.0 → 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 +224 -370
- 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 +197 -221
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +10 -5
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +214 -292
- 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 +335 -421
- 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 +121 -200
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +20 -7
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +229 -403
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +41 -22
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +212 -181
- 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 +204 -249
- 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 +107 -233
- 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 +193 -235
- 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 +92 -159
- 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 +288 -370
- 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 +172 -219
- 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 +94 -160
- 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 +95 -157
- 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 +85 -144
- 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 +100 -127
- 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 +172 -259
- 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 +106 -131
- 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 +2 -3
- 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 +2 -3
- 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 +2 -3
- 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 +2 -3
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +3 -1
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +5 -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 +2 -3
- 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 +2 -3
- 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 +2 -3
- 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 +2 -3
- 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 +2 -3
- 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 -190
- 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 +11 -11
- package/src/device/blindtilt.ts +254 -376
- package/src/device/bot.ts +209 -224
- package/src/device/ceilinglight.ts +227 -297
- package/src/device/colorbulb.ts +345 -435
- package/src/device/contact.ts +139 -200
- package/src/device/curtain.ts +254 -414
- package/src/device/device.ts +221 -190
- package/src/device/fan.ts +222 -253
- package/src/device/hub.ts +127 -248
- package/src/device/humidifier.ts +217 -246
- package/src/device/iosensor.ts +115 -168
- package/src/device/lightstrip.ts +303 -380
- package/src/device/lock.ts +188 -224
- package/src/device/meter.ts +117 -179
- package/src/device/meterplus.ts +118 -176
- package/src/device/motion.ts +100 -146
- package/src/device/plug.ts +111 -131
- package/src/device/robotvacuumcleaner.ts +191 -258
- package/src/device/waterdetector.ts +124 -141
- package/src/irdevice/airconditioner.ts +4 -4
- package/src/irdevice/airpurifier.ts +4 -4
- package/src/irdevice/camera.ts +4 -4
- package/src/irdevice/fan.ts +4 -4
- package/src/irdevice/irdevice.ts +8 -2
- package/src/irdevice/light.ts +4 -4
- package/src/irdevice/other.ts +4 -4
- package/src/irdevice/tv.ts +4 -4
- package/src/irdevice/vacuumcleaner.ts +4 -4
- package/src/irdevice/waterheater.ts +4 -4
- package/src/platform.ts +104 -87
- package/src/settings.ts +30 -238
- 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/src/platform.ts
CHANGED
|
@@ -34,21 +34,23 @@ import { AirConditioner } from './irdevice/airconditioner.js';
|
|
|
34
34
|
import { Buffer } from 'buffer';
|
|
35
35
|
import { request } from 'undici';
|
|
36
36
|
import asyncmqtt from 'async-mqtt';
|
|
37
|
-
import { sleep } from './utils.js';
|
|
38
37
|
import { createServer } from 'http';
|
|
39
38
|
import { queueScheduler } from 'rxjs';
|
|
40
39
|
import fakegato from 'fakegato-history';
|
|
41
40
|
import crypto, { randomUUID } from 'crypto';
|
|
42
41
|
import { readFileSync, writeFileSync } from 'fs';
|
|
43
42
|
import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes';
|
|
43
|
+
import { isBlindTiltDevice, isCurtainDevice, sleep } from './utils.js';
|
|
44
44
|
import { PLATFORM_NAME, PLUGIN_NAME, Devices, setupWebhook, updateWebhook, deleteWebhook, queryWebhook } from './settings.js';
|
|
45
45
|
|
|
46
46
|
import type { UrlObject } from 'url';
|
|
47
47
|
import type { MqttClient } from 'mqtt';
|
|
48
48
|
import type { Dispatcher } from 'undici';
|
|
49
|
+
import type { irdevice } from './types/irdevicelist.js';
|
|
49
50
|
import type { Server, IncomingMessage, ServerResponse } from 'http';
|
|
51
|
+
import type { blindTilt, curtain, curtain3, device } from './types/devicelist.js';
|
|
50
52
|
import type { API, DynamicPlatformPlugin, Logging, PlatformAccessory } from 'homebridge';
|
|
51
|
-
import type {
|
|
53
|
+
import type { SwitchBotPlatformConfig, devicesConfig, irDevicesConfig } from './settings.js';
|
|
52
54
|
|
|
53
55
|
/**
|
|
54
56
|
* HomebridgePlatform
|
|
@@ -74,7 +76,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
74
76
|
|
|
75
77
|
public readonly fakegatoAPI: any;
|
|
76
78
|
public readonly eve: any;
|
|
77
|
-
public readonly webhookEventHandler: { [x: string]: (context:
|
|
79
|
+
public readonly webhookEventHandler: { [x: string]: (context: any) => void } = {};
|
|
78
80
|
|
|
79
81
|
constructor(
|
|
80
82
|
log: Logging,
|
|
@@ -152,27 +154,27 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
152
154
|
try {
|
|
153
155
|
const { connectAsync } = asyncmqtt;
|
|
154
156
|
this.mqttClient = await connectAsync(this.config.options?.mqttURL, this.config.options.mqttOptions || {});
|
|
155
|
-
this.debugLog('MQTT connection has been established successfully.');
|
|
156
|
-
this.mqttClient.on('error', (e: Error) => {
|
|
157
|
-
this.errorLog(`Failed to publish MQTT messages. ${e}`);
|
|
157
|
+
await this.debugLog('MQTT connection has been established successfully.');
|
|
158
|
+
this.mqttClient.on('error', async (e: Error) => {
|
|
159
|
+
await this.errorLog(`Failed to publish MQTT messages. ${e}`);
|
|
158
160
|
});
|
|
159
161
|
if (!this.config.options?.webhookURL) {
|
|
160
162
|
// receive webhook events via MQTT
|
|
161
|
-
this.infoLog(`Webhook is configured to be received through ${this.config.options.mqttURL}/homebridge-switchbot/webhook.`);
|
|
163
|
+
await this.infoLog(`Webhook is configured to be received through ${this.config.options.mqttURL}/homebridge-switchbot/webhook.`);
|
|
162
164
|
this.mqttClient.subscribe('homebridge-switchbot/webhook/+');
|
|
163
165
|
this.mqttClient.on('message', async (topic: string, message) => {
|
|
164
166
|
try {
|
|
165
|
-
this.debugLog(`Received Webhook via MQTT: ${topic}=${message}`);
|
|
167
|
+
await this.debugLog(`Received Webhook via MQTT: ${topic}=${message}`);
|
|
166
168
|
const context = JSON.parse(message.toString());
|
|
167
|
-
|
|
169
|
+
this.webhookEventHandler[context.deviceMac]?.(context);
|
|
168
170
|
} catch (e: any) {
|
|
169
|
-
this.errorLog(`Failed to handle webhook event. Error:${e}`);
|
|
171
|
+
await this.errorLog(`Failed to handle webhook event. Error:${e}`);
|
|
170
172
|
}
|
|
171
173
|
});
|
|
172
174
|
}
|
|
173
175
|
} catch (e) {
|
|
174
176
|
this.mqttClient = null;
|
|
175
|
-
this.errorLog(`Failed to establish MQTT connection. ${e}`);
|
|
177
|
+
await this.errorLog(`Failed to establish MQTT connection. ${e}`);
|
|
176
178
|
}
|
|
177
179
|
}
|
|
178
180
|
}
|
|
@@ -201,7 +203,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
201
203
|
const options = this.config.options?.mqttPubOptions || {};
|
|
202
204
|
this.mqttClient?.publish(`homebridge-switchbot/webhook/${mac}`, `${JSON.stringify(body.context)}`, options);
|
|
203
205
|
}
|
|
204
|
-
|
|
206
|
+
this.webhookEventHandler[body.context.deviceMac]?.(body.context);
|
|
205
207
|
} catch (e: any) {
|
|
206
208
|
this.errorLog(`Failed to handle webhook event. Error:${e}`);
|
|
207
209
|
}
|
|
@@ -296,9 +298,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
296
298
|
}),
|
|
297
299
|
});
|
|
298
300
|
const response: any = await body.json();
|
|
299
|
-
this.debugLog(`deleteWebhook: url:${url}`);
|
|
300
|
-
this.debugLog(`deleteWebhook: body:${JSON.stringify(response)}`);
|
|
301
|
-
this.debugLog(`deleteWebhook: statusCode:${statusCode}`);
|
|
301
|
+
this.debugLog(`deleteWebhook: url:${url}, body:${JSON.stringify(response)}, statusCode:${statusCode}`);
|
|
302
302
|
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
303
303
|
this.errorLog(`Failed to delete webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
|
|
304
304
|
} else {
|
|
@@ -1402,15 +1402,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1402
1402
|
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1403
1403
|
}
|
|
1404
1404
|
|
|
1405
|
-
if (device
|
|
1406
|
-
|
|
1407
|
-
|
|
1405
|
+
if (isBlindTiltDevice(device)) {
|
|
1406
|
+
if (device.group && !device.curtain?.disable_group) {
|
|
1407
|
+
this.debugLog(
|
|
1408
|
+
'Your Curtains are grouped, ' +
|
|
1408
1409
|
`, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1409
|
-
} else {
|
|
1410
|
-
if (device.master) {
|
|
1411
|
-
this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1412
1410
|
} else {
|
|
1413
|
-
|
|
1411
|
+
if (device.master) {
|
|
1412
|
+
this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1413
|
+
} else {
|
|
1414
|
+
this.errorLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1415
|
+
}
|
|
1414
1416
|
}
|
|
1415
1417
|
}
|
|
1416
1418
|
|
|
@@ -1474,15 +1476,18 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1474
1476
|
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1475
1477
|
}
|
|
1476
1478
|
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1479
|
+
|
|
1480
|
+
if (isCurtainDevice(device)) {
|
|
1481
|
+
if (device.group && !device.curtain?.disable_group) {
|
|
1482
|
+
this.debugLog(
|
|
1483
|
+
'Your Curtains are grouped, ' +
|
|
1480
1484
|
`, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1481
|
-
} else {
|
|
1482
|
-
if (device.master) {
|
|
1483
|
-
this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1484
1485
|
} else {
|
|
1485
|
-
|
|
1486
|
+
if (device.master) {
|
|
1487
|
+
this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1488
|
+
} else {
|
|
1489
|
+
this.errorLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1490
|
+
}
|
|
1486
1491
|
}
|
|
1487
1492
|
}
|
|
1488
1493
|
|
|
@@ -1944,9 +1949,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1944
1949
|
existingAccessory.context.model = device.remoteType;
|
|
1945
1950
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1946
1951
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1947
|
-
if (device.version && !device.firmware) {
|
|
1948
|
-
existingAccessory.context.version = device.version;
|
|
1949
|
-
}
|
|
1950
1952
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1951
1953
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1952
1954
|
existingAccessory.context.connectionType = device.connectionType;
|
|
@@ -2466,18 +2468,32 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2466
2468
|
}
|
|
2467
2469
|
}
|
|
2468
2470
|
|
|
2469
|
-
async registerCurtains(device: device & devicesConfig) {
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2471
|
+
async registerCurtains(device: device & devicesConfig): Promise<boolean> {
|
|
2472
|
+
/*function isCurtainDevice(device: device & devicesConfig): device is (curtain | curtain3) & devicesConfig {
|
|
2473
|
+
return device.deviceType === 'Curtain' || device.deviceType === 'Curtain3';
|
|
2474
|
+
}
|
|
2475
|
+
|
|
2476
|
+
function isBlindTiltDevice(device: device & devicesConfig): device is blindTilt & devicesConfig {
|
|
2477
|
+
return device.deviceType === 'Blind Tilt';
|
|
2478
|
+
}*/
|
|
2479
|
+
let registerWindowCovering: boolean;
|
|
2480
|
+
if (isCurtainDevice(device)) {
|
|
2481
|
+
this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds}, master: `
|
|
2482
|
+
+ `${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}, connectionType: ${device.connectionType}`);
|
|
2483
|
+
registerWindowCovering = await this.registerWindowCovering(device);
|
|
2484
|
+
} else if (isBlindTiltDevice(device)) {
|
|
2485
|
+
this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, blindTiltDevicesIds: ${device.blindTiltDevicesIds},`
|
|
2486
|
+
+ ` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group},`
|
|
2487
|
+
+ ` connectionType: ${device.connectionType}`);
|
|
2488
|
+
registerWindowCovering =await this.registerWindowCovering(device);
|
|
2489
|
+
} else {
|
|
2490
|
+
registerWindowCovering = false;
|
|
2479
2491
|
}
|
|
2492
|
+
return registerWindowCovering;
|
|
2493
|
+
}
|
|
2480
2494
|
|
|
2495
|
+
async registerWindowCovering(device: ((curtain | curtain3) & devicesConfig) | (blindTilt & devicesConfig)) {
|
|
2496
|
+
this.debugLog(device.master);
|
|
2481
2497
|
let registerCurtain: boolean;
|
|
2482
2498
|
if (device.master && device.group) {
|
|
2483
2499
|
// OpenAPI: Master Curtains/Blind Tilt in Group
|
|
@@ -2642,67 +2658,67 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2642
2658
|
async statusCode(statusCode: number): Promise<void> {
|
|
2643
2659
|
switch (statusCode) {
|
|
2644
2660
|
case 151:
|
|
2645
|
-
this.errorLog(`Command not supported by this device type, statusCode: ${statusCode}, Submit Feature Request Here: ` +
|
|
2661
|
+
await this.errorLog(`Command not supported by this device type, statusCode: ${statusCode}, Submit Feature Request Here: ` +
|
|
2646
2662
|
'https://tinyurl.com/SwitchBotFeatureRequest');
|
|
2647
2663
|
break;
|
|
2648
2664
|
case 152:
|
|
2649
|
-
this.errorLog(`Device not found, statusCode: ${statusCode}`);
|
|
2665
|
+
await this.errorLog(`Device not found, statusCode: ${statusCode}`);
|
|
2650
2666
|
break;
|
|
2651
2667
|
case 160:
|
|
2652
|
-
this.errorLog(`Command is not supported, statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`);
|
|
2668
|
+
await this.errorLog(`Command is not supported, statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`);
|
|
2653
2669
|
break;
|
|
2654
2670
|
case 161:
|
|
2655
|
-
this.errorLog(`Device is offline, statusCode: ${statusCode}`);
|
|
2671
|
+
await this.errorLog(`Device is offline, statusCode: ${statusCode}`);
|
|
2656
2672
|
break;
|
|
2657
2673
|
case 171:
|
|
2658
|
-
this.errorLog(`is offline, statusCode: ${statusCode}`);
|
|
2674
|
+
await this.errorLog(`is offline, statusCode: ${statusCode}`);
|
|
2659
2675
|
break;
|
|
2660
2676
|
case 190:
|
|
2661
|
-
this.errorLog(`Requests reached the daily limit, statusCode: ${statusCode}`);
|
|
2677
|
+
await this.errorLog(`Requests reached the daily limit, statusCode: ${statusCode}`);
|
|
2662
2678
|
break;
|
|
2663
2679
|
case 100:
|
|
2664
|
-
this.debugLog(`Command successfully sent, statusCode: ${statusCode}`);
|
|
2680
|
+
await this.debugLog(`Command successfully sent, statusCode: ${statusCode}`);
|
|
2665
2681
|
break;
|
|
2666
2682
|
case 200:
|
|
2667
|
-
this.debugLog(`Request successful, statusCode: ${statusCode}`);
|
|
2683
|
+
await this.debugLog(`Request successful, statusCode: ${statusCode}`);
|
|
2668
2684
|
break;
|
|
2669
2685
|
case 400:
|
|
2670
|
-
this.errorLog('Bad Request, The client has issued an invalid request. This is commonly used to specify validation errors in a request '
|
|
2686
|
+
await this.errorLog('Bad Request, The client has issued an invalid request. This is commonly used to specify validation errors in a request '
|
|
2671
2687
|
+ `payload, statusCode: ${statusCode}`);
|
|
2672
2688
|
break;
|
|
2673
2689
|
case 401:
|
|
2674
|
-
this.errorLog('Unauthorized, Authorization for the API is required, but the request has not been authenticated, '
|
|
2690
|
+
await this.errorLog('Unauthorized, Authorization for the API is required, but the request has not been authenticated, '
|
|
2675
2691
|
+ `statusCode: ${statusCode}`);
|
|
2676
2692
|
break;
|
|
2677
2693
|
case 403:
|
|
2678
|
-
this.errorLog('Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not '
|
|
2694
|
+
await this.errorLog('Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not '
|
|
2679
2695
|
+ `found, statusCode: ${statusCode}`);
|
|
2680
2696
|
break;
|
|
2681
2697
|
case 404:
|
|
2682
|
-
this.errorLog(`Not Found, Specifies the requested path does not exist, statusCode: ${statusCode}`);
|
|
2698
|
+
await this.errorLog(`Not Found, Specifies the requested path does not exist, statusCode: ${statusCode}`);
|
|
2683
2699
|
break;
|
|
2684
2700
|
case 406:
|
|
2685
|
-
this.errorLog('Not Acceptable, The client has requested a MIME type via the Accept header for a value not supported by the server, '
|
|
2701
|
+
await this.errorLog('Not Acceptable, The client has requested a MIME type via the Accept header for a value not supported by the server, '
|
|
2686
2702
|
+ `statusCode: ${statusCode}`);
|
|
2687
2703
|
break;
|
|
2688
2704
|
case 415:
|
|
2689
|
-
this.errorLog('Unsupported Media Type, The client has defined a contentType header that is not supported by the server, '
|
|
2705
|
+
await this.errorLog('Unsupported Media Type, The client has defined a contentType header that is not supported by the server, '
|
|
2690
2706
|
+ `statusCode: ${statusCode}`);
|
|
2691
2707
|
break;
|
|
2692
2708
|
case 422:
|
|
2693
|
-
this.errorLog('Unprocessable Entity, The client has made a valid request, but the server cannot process it. This is often used for '
|
|
2709
|
+
await this.errorLog('Unprocessable Entity, The client has made a valid request, but the server cannot process it. This is often used for '
|
|
2694
2710
|
+ `APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
2695
2711
|
break;
|
|
2696
2712
|
case 429:
|
|
2697
|
-
this.errorLog('Too Many Requests, The client has exceeded the number of requests allowed for a given time window, '
|
|
2713
|
+
await this.errorLog('Too Many Requests, The client has exceeded the number of requests allowed for a given time window, '
|
|
2698
2714
|
+ `statusCode: ${statusCode}`);
|
|
2699
2715
|
break;
|
|
2700
2716
|
case 500:
|
|
2701
|
-
this.errorLog('Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, '
|
|
2717
|
+
await this.errorLog('Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, '
|
|
2702
2718
|
+ `statusCode: ${statusCode}`);
|
|
2703
2719
|
break;
|
|
2704
2720
|
default:
|
|
2705
|
-
this.errorLog(`Unknown statusCode, statusCode: ${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
2721
|
+
await this.errorLog(`Unknown statusCode, statusCode: ${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
2706
2722
|
}
|
|
2707
2723
|
}
|
|
2708
2724
|
|
|
@@ -2718,27 +2734,28 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2718
2734
|
if (statusCode === 200 || statusCode === 100) {
|
|
2719
2735
|
return { body, statusCode };
|
|
2720
2736
|
} else {
|
|
2721
|
-
this.debugLog(`Received status code: ${statusCode}`);
|
|
2737
|
+
await this.debugLog(`Received status code: ${statusCode}`);
|
|
2722
2738
|
}
|
|
2723
2739
|
} catch (error: any) {
|
|
2724
|
-
this.errorLog(`Error making request: ${error.message}`);
|
|
2740
|
+
await this.errorLog(`Error making request: ${error.message}`);
|
|
2725
2741
|
}
|
|
2726
2742
|
retryCount++;
|
|
2727
|
-
this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`);
|
|
2743
|
+
await this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`);
|
|
2728
2744
|
await sleep(delayBetweenRetries);
|
|
2729
2745
|
}
|
|
2730
2746
|
return { body: null, statusCode: -1 };
|
|
2731
2747
|
}
|
|
2732
2748
|
|
|
2733
2749
|
// BLE Connection
|
|
2734
|
-
async connectBLE() {
|
|
2750
|
+
async connectBLE(accessory: PlatformAccessory, device: device & devicesConfig) {
|
|
2735
2751
|
let switchbot: any;
|
|
2736
2752
|
try {
|
|
2737
2753
|
const SwitchBot = (await import('node-switchbot')).SwitchBot;
|
|
2738
2754
|
queueScheduler.schedule(() => (switchbot = new SwitchBot()));
|
|
2755
|
+
await this.debugLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${switchbot}`);
|
|
2739
2756
|
} catch (e: any) {
|
|
2740
2757
|
switchbot = false;
|
|
2741
|
-
this.errorLog(
|
|
2758
|
+
await this.errorLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${switchbot}, Error: ${e}`);
|
|
2742
2759
|
}
|
|
2743
2760
|
return switchbot;
|
|
2744
2761
|
}
|
|
@@ -2750,7 +2767,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2750
2767
|
'utf-8',
|
|
2751
2768
|
),
|
|
2752
2769
|
);
|
|
2753
|
-
this.debugLog(`Plugin Version: ${json.version}`);
|
|
2770
|
+
await this.debugLog(`Plugin Version: ${json.version}`);
|
|
2754
2771
|
this.version = json.version;
|
|
2755
2772
|
}
|
|
2756
2773
|
|
|
@@ -2786,7 +2803,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2786
2803
|
platformConfig.delayBetweenRetries = this.delayBetweenRetries / 1000;
|
|
2787
2804
|
}
|
|
2788
2805
|
if (Object.entries(platformConfig).length !== 0) {
|
|
2789
|
-
this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
2806
|
+
await this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
2790
2807
|
}
|
|
2791
2808
|
this.platformConfig = platformConfig;
|
|
2792
2809
|
}
|
|
@@ -2796,13 +2813,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2796
2813
|
this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
|
|
2797
2814
|
if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
|
|
2798
2815
|
this.platformLogging = this.config.options.logging;
|
|
2799
|
-
this.debugWarnLog(`Using Config Logging: ${this.platformLogging}`);
|
|
2816
|
+
await this.debugWarnLog(`Using Config Logging: ${this.platformLogging}`);
|
|
2800
2817
|
} else if (this.debugMode) {
|
|
2801
2818
|
this.platformLogging = 'debugMode';
|
|
2802
|
-
this.debugWarnLog(`Using ${this.platformLogging} Logging`);
|
|
2819
|
+
await this.debugWarnLog(`Using ${this.platformLogging} Logging`);
|
|
2803
2820
|
} else {
|
|
2804
2821
|
this.platformLogging = 'standard';
|
|
2805
|
-
this.debugWarnLog(`Using ${this.platformLogging} Logging`);
|
|
2822
|
+
await this.debugWarnLog(`Using ${this.platformLogging} Logging`);
|
|
2806
2823
|
}
|
|
2807
2824
|
}
|
|
2808
2825
|
|
|
@@ -2810,56 +2827,56 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2810
2827
|
* If device level logging is turned on, log to log.warn
|
|
2811
2828
|
* Otherwise send debug logs to log.debug
|
|
2812
2829
|
*/
|
|
2813
|
-
infoLog(...log: any[]): void {
|
|
2814
|
-
if (this.enablingPlatformLogging()) {
|
|
2830
|
+
async infoLog(...log: any[]): Promise<void> {
|
|
2831
|
+
if (await this.enablingPlatformLogging()) {
|
|
2815
2832
|
this.log.info(String(...log));
|
|
2816
2833
|
}
|
|
2817
2834
|
}
|
|
2818
2835
|
|
|
2819
|
-
successLog(...log: any[]): void {
|
|
2820
|
-
if (this.enablingPlatformLogging()) {
|
|
2836
|
+
async successLog(...log: any[]): Promise<void> {
|
|
2837
|
+
if (await this.enablingPlatformLogging()) {
|
|
2821
2838
|
this.log.success(String(...log));
|
|
2822
2839
|
}
|
|
2823
2840
|
}
|
|
2824
2841
|
|
|
2825
|
-
debugSuccessLog(...log: any[]): void {
|
|
2826
|
-
if (this.enablingPlatformLogging()) {
|
|
2842
|
+
async debugSuccessLog(...log: any[]): Promise<void> {
|
|
2843
|
+
if (await this.enablingPlatformLogging()) {
|
|
2827
2844
|
if (this.platformLogging?.includes('debug')) {
|
|
2828
2845
|
this.log.success('[DEBUG]', String(...log));
|
|
2829
2846
|
}
|
|
2830
2847
|
}
|
|
2831
2848
|
}
|
|
2832
2849
|
|
|
2833
|
-
warnLog(...log: any[]): void {
|
|
2834
|
-
if (this.enablingPlatformLogging()) {
|
|
2850
|
+
async warnLog(...log: any[]): Promise<void> {
|
|
2851
|
+
if (await this.enablingPlatformLogging()) {
|
|
2835
2852
|
this.log.warn(String(...log));
|
|
2836
2853
|
}
|
|
2837
2854
|
}
|
|
2838
2855
|
|
|
2839
|
-
debugWarnLog(...log: any[]): void {
|
|
2840
|
-
if (this.enablingPlatformLogging()) {
|
|
2856
|
+
async debugWarnLog(...log: any[]): Promise<void> {
|
|
2857
|
+
if (await this.enablingPlatformLogging()) {
|
|
2841
2858
|
if (this.platformLogging?.includes('debug')) {
|
|
2842
2859
|
this.log.warn('[DEBUG]', String(...log));
|
|
2843
2860
|
}
|
|
2844
2861
|
}
|
|
2845
2862
|
}
|
|
2846
2863
|
|
|
2847
|
-
errorLog(...log: any[]): void {
|
|
2848
|
-
if (this.enablingPlatformLogging()) {
|
|
2864
|
+
async errorLog(...log: any[]): Promise<void> {
|
|
2865
|
+
if (await this.enablingPlatformLogging()) {
|
|
2849
2866
|
this.log.error(String(...log));
|
|
2850
2867
|
}
|
|
2851
2868
|
}
|
|
2852
2869
|
|
|
2853
|
-
debugErrorLog(...log: any[]): void {
|
|
2854
|
-
if (this.enablingPlatformLogging()) {
|
|
2870
|
+
async debugErrorLog(...log: any[]): Promise<void> {
|
|
2871
|
+
if (await this.enablingPlatformLogging()) {
|
|
2855
2872
|
if (this.platformLogging?.includes('debug')) {
|
|
2856
2873
|
this.log.error('[DEBUG]', String(...log));
|
|
2857
2874
|
}
|
|
2858
2875
|
}
|
|
2859
2876
|
}
|
|
2860
2877
|
|
|
2861
|
-
debugLog(...log: any[]): void {
|
|
2862
|
-
if (this.enablingPlatformLogging()) {
|
|
2878
|
+
async debugLog(...log: any[]): Promise<void> {
|
|
2879
|
+
if (await this.enablingPlatformLogging()) {
|
|
2863
2880
|
if (this.platformLogging === 'debugMode') {
|
|
2864
2881
|
this.log.debug(String(...log));
|
|
2865
2882
|
} else if (this.platformLogging === 'debug') {
|
|
@@ -2868,7 +2885,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2868
2885
|
}
|
|
2869
2886
|
}
|
|
2870
2887
|
|
|
2871
|
-
enablingPlatformLogging(): boolean {
|
|
2888
|
+
async enablingPlatformLogging(): Promise<boolean> {
|
|
2872
2889
|
return this.platformLogging?.includes('debug') || this.platformLogging === 'standard';
|
|
2873
2890
|
}
|
|
2874
2891
|
}
|