@switchbot/homebridge-switchbot 3.8.3-beta.3 → 3.8.3-beta.31
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/.github/workflows/beta-release.yml +7 -4
- package/.github/workflows/release.yml +7 -6
- package/CHANGELOG.md +2 -1
- package/config.schema.json +24 -0
- package/dist/device/blindtilt.d.ts +1 -4
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +33 -34
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +1 -4
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +30 -31
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +1 -4
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +50 -54
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +1 -4
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +62 -66
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +1 -4
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +18 -18
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +1 -4
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +31 -32
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +6 -6
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +33 -17
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +1 -4
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +47 -49
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +1 -4
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +18 -18
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +1 -4
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +43 -46
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +1 -4
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +18 -18
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +1 -4
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +51 -54
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +1 -4
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +31 -32
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +1 -4
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +18 -18
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +1 -4
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +18 -18
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +1 -4
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +18 -18
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +1 -4
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +29 -30
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +1 -4
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +36 -38
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +1 -4
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +18 -18
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +11 -12
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +11 -12
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +9 -10
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +15 -16
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +6 -6
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +7 -13
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +9 -10
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +9 -10
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +27 -28
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +9 -10
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +9 -10
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +6 -14
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +127 -188
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +4 -3
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js.map +1 -1
- package/docs/assets/highlight.css +42 -0
- package/docs/assets/main.js +1 -1
- package/docs/functions/default.html +1 -1
- package/docs/index.html +61 -50
- package/docs/media/security-privacy-bluetooth.png +0 -0
- package/package.json +14 -15
- package/src/device/blindtilt.ts +35 -39
- package/src/device/bot.ts +31 -35
- package/src/device/ceilinglight.ts +51 -58
- package/src/device/colorbulb.ts +63 -70
- package/src/device/contact.ts +19 -22
- package/src/device/curtain.ts +33 -37
- package/src/device/device.ts +32 -21
- package/src/device/fan.ts +48 -53
- package/src/device/hub.ts +19 -22
- package/src/device/humidifier.ts +44 -50
- package/src/device/iosensor.ts +19 -22
- package/src/device/lightstrip.ts +52 -58
- package/src/device/lock.ts +32 -36
- package/src/device/meter.ts +19 -22
- package/src/device/meterplus.ts +19 -22
- package/src/device/motion.ts +19 -22
- package/src/device/plug.ts +30 -34
- package/src/device/robotvacuumcleaner.ts +37 -46
- package/src/device/waterdetector.ts +19 -22
- package/src/irdevice/airconditioner.ts +12 -14
- package/src/irdevice/airpurifier.ts +12 -13
- package/src/irdevice/camera.ts +10 -11
- package/src/irdevice/fan.ts +16 -17
- package/src/irdevice/irdevice.ts +9 -17
- package/src/irdevice/light.ts +10 -11
- package/src/irdevice/other.ts +10 -11
- package/src/irdevice/tv.ts +28 -29
- package/src/irdevice/vacuumcleaner.ts +10 -11
- package/src/irdevice/waterheater.ts +10 -11
- package/src/platform.ts +131 -188
- package/src/settings.ts +8 -4
- package/src/utils.ts +2 -1
- package/dist/types/bledevicestatus.d.ts +0 -281
- package/dist/types/bledevicestatus.d.ts.map +0 -1
- package/dist/types/bledevicestatus.js +0 -2
- package/dist/types/bledevicestatus.js.map +0 -1
- package/dist/types/devicelist.d.ts +0 -89
- package/dist/types/devicelist.d.ts.map +0 -1
- package/dist/types/devicelist.js +0 -6
- package/dist/types/devicelist.js.map +0 -1
- package/dist/types/deviceresponse.d.ts +0 -13
- package/dist/types/deviceresponse.d.ts.map +0 -1
- package/dist/types/deviceresponse.js +0 -2
- package/dist/types/deviceresponse.js.map +0 -1
- package/dist/types/devicestatus.d.ts +0 -149
- package/dist/types/devicestatus.d.ts.map +0 -1
- package/dist/types/devicestatus.js +0 -3
- package/dist/types/devicestatus.js.map +0 -1
- package/dist/types/devicewebhookstatus.d.ts +0 -156
- package/dist/types/devicewebhookstatus.d.ts.map +0 -1
- package/dist/types/devicewebhookstatus.js +0 -2
- package/dist/types/devicewebhookstatus.js.map +0 -1
- package/dist/types/irdevicelist.d.ts +0 -10
- package/dist/types/irdevicelist.d.ts.map +0 -1
- package/dist/types/irdevicelist.js +0 -2
- package/dist/types/irdevicelist.js.map +0 -1
- package/dist/types/pushbody.d.ts +0 -6
- package/dist/types/pushbody.d.ts.map +0 -1
- package/dist/types/pushbody.js +0 -2
- package/dist/types/pushbody.js.map +0 -1
- package/src/types/bledevicestatus.ts +0 -303
- package/src/types/devicelist.ts +0 -124
- package/src/types/deviceresponse.ts +0 -14
- package/src/types/devicestatus.ts +0 -178
- package/src/types/devicewebhookstatus.ts +0 -191
- package/src/types/irdevicelist.ts +0 -15
- package/src/types/pushbody.ts +0 -9
package/dist/platform.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { Server } from 'node:http';
|
|
2
|
-
import type { UrlObject } from 'node:url';
|
|
3
2
|
import type { API, DynamicPlatformPlugin, Logging, PlatformAccessory } from 'homebridge';
|
|
4
3
|
import type { MqttClient } from 'mqtt';
|
|
5
|
-
import type { Dispatcher } from 'undici';
|
|
6
4
|
import type { devicesConfig, irDevicesConfig, SwitchBotPlatformConfig } from './settings.js';
|
|
7
|
-
import type { blindTilt, curtain, curtain3, device } from '
|
|
5
|
+
import type { blindTilt, curtain, curtain3, device } from 'node-switchbot';
|
|
6
|
+
import { SwitchBotBLE, SwitchBotOpenAPI } from 'node-switchbot';
|
|
8
7
|
/**
|
|
9
8
|
* HomebridgePlatform
|
|
10
9
|
* This class is the main constructor for your plugin, this is where you should
|
|
@@ -24,6 +23,8 @@ export declare class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
24
23
|
config: SwitchBotPlatformConfig;
|
|
25
24
|
mqttClient: MqttClient | null;
|
|
26
25
|
webhookEventListener: Server | null;
|
|
26
|
+
switchBotAPI: SwitchBotOpenAPI;
|
|
27
|
+
switchBotBLE: SwitchBotBLE;
|
|
27
28
|
readonly eve: any;
|
|
28
29
|
readonly fakegatoAPI: any;
|
|
29
30
|
readonly webhookEventHandler: {
|
|
@@ -50,13 +51,6 @@ export declare class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
50
51
|
* This method saves the openToken as the token in the config.json file
|
|
51
52
|
*/
|
|
52
53
|
updateToken(): Promise<void>;
|
|
53
|
-
generateHeaders: () => {
|
|
54
|
-
Authorization: any;
|
|
55
|
-
sign: string;
|
|
56
|
-
nonce: `${string}-${string}-${string}-${string}-${string}`;
|
|
57
|
-
t: string;
|
|
58
|
-
'Content-Type': string;
|
|
59
|
-
};
|
|
60
54
|
discoverDevices(): Promise<void>;
|
|
61
55
|
private handleManualConfig;
|
|
62
56
|
private isSuccessfulResponse;
|
|
@@ -107,10 +101,8 @@ export declare class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
107
101
|
* @returns A promise that resolves when the logging is complete.
|
|
108
102
|
*/
|
|
109
103
|
statusCode(statusCode: number): Promise<void>;
|
|
110
|
-
retryRequest(deviceMaxRetries: number, deviceDelayBetweenRetries: number
|
|
111
|
-
|
|
112
|
-
} & Omit<Dispatcher.RequestOptions, 'origin' | 'path' | 'method'> & Partial<Pick<Dispatcher.RequestOptions, 'method'>>): Promise<{
|
|
113
|
-
body: any;
|
|
104
|
+
retryRequest(deviceId: string, deviceMaxRetries: number, deviceDelayBetweenRetries: number): Promise<{
|
|
105
|
+
response: any;
|
|
114
106
|
statusCode: number;
|
|
115
107
|
}>;
|
|
116
108
|
connectBLE(accessory: PlatformAccessory, device: device & devicesConfig): Promise<any>;
|
package/dist/platform.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"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"}
|
package/dist/platform.js
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import { Buffer } from 'node:buffer';
|
|
2
|
-
import crypto, { randomUUID } from 'node:crypto';
|
|
3
1
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
4
|
-
import { createServer } from 'node:http';
|
|
5
2
|
import process from 'node:process';
|
|
6
3
|
import asyncmqtt from 'async-mqtt';
|
|
7
4
|
import fakegato from 'fakegato-history';
|
|
8
5
|
import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes';
|
|
9
|
-
|
|
10
|
-
* For Testing Locally:
|
|
11
|
-
* import { SwitchBotModel } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
12
|
-
*/
|
|
13
|
-
import { SwitchBot, SwitchBotModel } from 'node-switchbot';
|
|
6
|
+
import { LogLevel, SwitchBotBLE, SwitchBotModel, SwitchBotOpenAPI } from 'node-switchbot';
|
|
14
7
|
import { queueScheduler } from 'rxjs';
|
|
15
|
-
import { request } from 'undici';
|
|
16
8
|
import { BlindTilt } from './device/blindtilt.js';
|
|
17
9
|
import { Bot } from './device/bot.js';
|
|
18
10
|
import { CeilingLight } from './device/ceilinglight.js';
|
|
@@ -40,7 +32,7 @@ import { Others } from './irdevice/other.js';
|
|
|
40
32
|
import { TV } from './irdevice/tv.js';
|
|
41
33
|
import { VacuumCleaner } from './irdevice/vacuumcleaner.js';
|
|
42
34
|
import { WaterHeater } from './irdevice/waterheater.js';
|
|
43
|
-
import {
|
|
35
|
+
import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js';
|
|
44
36
|
import { formatDeviceIdAsMac, isBlindTiltDevice, isCurtainDevice, sleep } from './utils.js';
|
|
45
37
|
/**
|
|
46
38
|
* HomebridgePlatform
|
|
@@ -64,6 +56,9 @@ export class SwitchBotPlatform {
|
|
|
64
56
|
// MQTT and Webhook properties
|
|
65
57
|
mqttClient = null;
|
|
66
58
|
webhookEventListener = null;
|
|
59
|
+
// SwitchBot APIs
|
|
60
|
+
switchBotAPI;
|
|
61
|
+
switchBotBLE;
|
|
67
62
|
// External APIs
|
|
68
63
|
eve;
|
|
69
64
|
fakegatoAPI;
|
|
@@ -96,10 +91,43 @@ export class SwitchBotPlatform {
|
|
|
96
91
|
this.debugLog('Config OK');
|
|
97
92
|
}
|
|
98
93
|
catch (e) {
|
|
99
|
-
this.errorLog(`Verify Config, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
100
|
-
this.debugErrorLog(`Verify Config, Error: ${e}`);
|
|
94
|
+
this.errorLog(`Verify Config, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
95
|
+
this.debugErrorLog(`Verify Config, Error: ${e.message ?? e}`);
|
|
101
96
|
return;
|
|
102
97
|
}
|
|
98
|
+
// SwitchBot OpenAPI
|
|
99
|
+
this.switchBotAPI = new SwitchBotOpenAPI(this.config.credentials?.token, this.config.credentials?.secret);
|
|
100
|
+
// Listen for log events
|
|
101
|
+
if (!this.config.options?.disableLogsforOpenAPI) {
|
|
102
|
+
this.switchBotAPI.on('log', (log) => {
|
|
103
|
+
switch (log.level) {
|
|
104
|
+
case LogLevel.SUCCESS:
|
|
105
|
+
this.successLog(log.message);
|
|
106
|
+
break;
|
|
107
|
+
case LogLevel.DEBUGSUCCESS:
|
|
108
|
+
this.debugSuccessLog(log.message);
|
|
109
|
+
break;
|
|
110
|
+
case LogLevel.WARN:
|
|
111
|
+
this.warnLog(log.message);
|
|
112
|
+
break;
|
|
113
|
+
case LogLevel.DEBUGWARN:
|
|
114
|
+
this.debugWarnLog(log.message);
|
|
115
|
+
break;
|
|
116
|
+
case LogLevel.ERROR:
|
|
117
|
+
this.errorLog(log.message);
|
|
118
|
+
break;
|
|
119
|
+
case LogLevel.DEBUGERROR:
|
|
120
|
+
this.debugErrorLog(log.message);
|
|
121
|
+
break;
|
|
122
|
+
case LogLevel.DEBUG:
|
|
123
|
+
this.debugLog(log.message);
|
|
124
|
+
break;
|
|
125
|
+
case LogLevel.INFO:
|
|
126
|
+
default:
|
|
127
|
+
this.infoLog(log.message);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
103
131
|
// import fakegato-history module and EVE characteristics
|
|
104
132
|
this.fakegatoAPI = fakegato(api);
|
|
105
133
|
this.eve = new EveHomeKitTypes(api);
|
|
@@ -122,27 +150,27 @@ export class SwitchBotPlatform {
|
|
|
122
150
|
}
|
|
123
151
|
}
|
|
124
152
|
catch (e) {
|
|
125
|
-
await this.errorLog(`Failed to Discover, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
126
|
-
await this.debugErrorLog(`Failed to Discover, Error: ${e}`);
|
|
153
|
+
await this.errorLog(`Failed to Discover, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
154
|
+
await this.debugErrorLog(`Failed to Discover, Error: ${e.message ?? e}`);
|
|
127
155
|
}
|
|
128
156
|
});
|
|
129
157
|
try {
|
|
130
158
|
this.setupMqtt();
|
|
131
159
|
}
|
|
132
160
|
catch (e) {
|
|
133
|
-
this.errorLog(`Setup MQTT, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
161
|
+
this.errorLog(`Setup MQTT, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
134
162
|
}
|
|
135
163
|
try {
|
|
136
164
|
this.setupwebhook();
|
|
137
165
|
}
|
|
138
166
|
catch (e) {
|
|
139
|
-
this.errorLog(`Setup Webhook, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
167
|
+
this.errorLog(`Setup Webhook, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
140
168
|
}
|
|
141
169
|
try {
|
|
142
170
|
this.setupBlE();
|
|
143
171
|
}
|
|
144
172
|
catch (e) {
|
|
145
|
-
this.errorLog(`Setup Platform BLE, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
173
|
+
this.errorLog(`Setup Platform BLE, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
146
174
|
}
|
|
147
175
|
}
|
|
148
176
|
async setupMqtt() {
|
|
@@ -152,7 +180,7 @@ export class SwitchBotPlatform {
|
|
|
152
180
|
this.mqttClient = await connectAsync(this.config.options?.mqttURL, this.config.options.mqttOptions || {});
|
|
153
181
|
await this.debugLog('MQTT connection has been established successfully.');
|
|
154
182
|
this.mqttClient.on('error', async (e) => {
|
|
155
|
-
await this.errorLog(`Failed to publish MQTT messages. ${e}`);
|
|
183
|
+
await this.errorLog(`Failed to publish MQTT messages. ${e.message ?? e}`);
|
|
156
184
|
});
|
|
157
185
|
if (!this.config.options?.webhookURL) {
|
|
158
186
|
// receive webhook events via MQTT
|
|
@@ -165,14 +193,14 @@ export class SwitchBotPlatform {
|
|
|
165
193
|
this.webhookEventHandler[context.deviceMac]?.(context);
|
|
166
194
|
}
|
|
167
195
|
catch (e) {
|
|
168
|
-
await this.errorLog(`Failed to handle webhook event. Error:${e}`);
|
|
196
|
+
await this.errorLog(`Failed to handle webhook event. Error:${e.message ?? e}`);
|
|
169
197
|
}
|
|
170
198
|
});
|
|
171
199
|
}
|
|
172
200
|
}
|
|
173
201
|
catch (e) {
|
|
174
202
|
this.mqttClient = null;
|
|
175
|
-
await this.errorLog(`Failed to establish MQTT connection. ${e}`);
|
|
203
|
+
await this.errorLog(`Failed to establish MQTT connection. ${e.message ?? e}`);
|
|
176
204
|
}
|
|
177
205
|
}
|
|
178
206
|
}
|
|
@@ -181,160 +209,96 @@ export class SwitchBotPlatform {
|
|
|
181
209
|
if (this.config.options?.webhookURL) {
|
|
182
210
|
const url = this.config.options?.webhookURL;
|
|
183
211
|
try {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
try {
|
|
192
|
-
const body = JSON.parse(data);
|
|
193
|
-
await this.debugLog(`Received Webhook: ${JSON.stringify(body)}`);
|
|
194
|
-
if (this.config.options?.mqttURL) {
|
|
195
|
-
const mac = body.context.deviceMac?.toLowerCase().match(/[\s\S]{1,2}/g)?.join(':');
|
|
196
|
-
const options = this.config.options?.mqttPubOptions || {};
|
|
197
|
-
this.mqttClient?.publish(`homebridge-switchbot/webhook/${mac}`, `${JSON.stringify(body.context)}`, options);
|
|
198
|
-
}
|
|
199
|
-
this.webhookEventHandler[body.context.deviceMac]?.(body.context);
|
|
200
|
-
}
|
|
201
|
-
catch (e) {
|
|
202
|
-
await this.errorLog(`Failed to handle webhook event. Error:${e}`);
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
response.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
206
|
-
response.end('OK');
|
|
207
|
-
}
|
|
208
|
-
// else {
|
|
209
|
-
// response.writeHead(403, {'Content-Type': 'text/plain'});
|
|
210
|
-
// response.end(`NG`);
|
|
211
|
-
// }
|
|
212
|
+
this.switchBotAPI.setupWebhook(url);
|
|
213
|
+
// Listen for webhook events
|
|
214
|
+
this.switchBotAPI.on('webhookEvent', (body) => {
|
|
215
|
+
if (this.config.options?.mqttURL) {
|
|
216
|
+
const mac = body.context.deviceMac?.toLowerCase().match(/[\s\S]{1,2}/g)?.join(':');
|
|
217
|
+
const options = this.config.options?.mqttPubOptions || {};
|
|
218
|
+
this.mqttClient?.publish(`homebridge-switchbot/webhook/${mac}`, `${JSON.stringify(body.context)}`, options);
|
|
212
219
|
}
|
|
213
|
-
|
|
214
|
-
this.errorLog(`Failed to handle webhook event. Error:${e}`);
|
|
215
|
-
}
|
|
216
|
-
}).listen(port || 80);
|
|
217
|
-
}
|
|
218
|
-
catch (e) {
|
|
219
|
-
await this.errorLog(`Failed to create webhook listener. Error:${e.message}`);
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
try {
|
|
223
|
-
const { body, statusCode } = await request(setupWebhook, {
|
|
224
|
-
method: 'POST',
|
|
225
|
-
headers: this.generateHeaders(),
|
|
226
|
-
body: JSON.stringify({
|
|
227
|
-
action: 'setupWebhook',
|
|
228
|
-
url,
|
|
229
|
-
deviceList: 'ALL',
|
|
230
|
-
}),
|
|
220
|
+
this.webhookEventHandler[body.context.deviceMac]?.(body.context);
|
|
231
221
|
});
|
|
232
|
-
const response = await body.json();
|
|
233
|
-
await this.debugLog(`setupWebhook: url:${url}, body:${JSON.stringify(response)}, statusCode:${statusCode}`);
|
|
234
|
-
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
235
|
-
await this.errorLog(`Failed to configure webhook. Existing webhook well be overridden. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
|
|
236
|
-
}
|
|
237
222
|
}
|
|
238
223
|
catch (e) {
|
|
239
|
-
await this.errorLog(`Failed to
|
|
240
|
-
}
|
|
241
|
-
try {
|
|
242
|
-
const { body, statusCode } = await request(updateWebhook, {
|
|
243
|
-
method: 'POST',
|
|
244
|
-
headers: this.generateHeaders(),
|
|
245
|
-
body: JSON.stringify({
|
|
246
|
-
action: 'updateWebhook',
|
|
247
|
-
config: {
|
|
248
|
-
url,
|
|
249
|
-
enable: true,
|
|
250
|
-
},
|
|
251
|
-
}),
|
|
252
|
-
});
|
|
253
|
-
const response = await body.json();
|
|
254
|
-
await this.debugLog(`updateWebhook: url:${url}, body:${JSON.stringify(response)}, statusCode:${statusCode}`);
|
|
255
|
-
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
256
|
-
await this.errorLog(`Failed to update webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
catch (e) {
|
|
260
|
-
await this.errorLog(`Failed to update webhook. Error:${e.message}`);
|
|
261
|
-
}
|
|
262
|
-
try {
|
|
263
|
-
const { body, statusCode } = await request(queryWebhook, {
|
|
264
|
-
method: 'POST',
|
|
265
|
-
headers: this.generateHeaders(),
|
|
266
|
-
body: JSON.stringify({
|
|
267
|
-
action: 'queryUrl',
|
|
268
|
-
}),
|
|
269
|
-
});
|
|
270
|
-
const response = await body.json();
|
|
271
|
-
await this.debugLog(`queryWebhook: body:${JSON.stringify(response)}`);
|
|
272
|
-
await this.debugLog(`queryWebhook: statusCode:${statusCode}`);
|
|
273
|
-
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
274
|
-
await this.errorLog(`Failed to query webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
await this.infoLog(`Listening webhook on ${response?.body?.urls[0]}`);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
catch (e) {
|
|
281
|
-
await this.errorLog(`Failed to query webhook. Error:${e}`);
|
|
224
|
+
await this.errorLog(`Failed to setup webhook. Error:${e.message ?? e}`);
|
|
282
225
|
}
|
|
283
226
|
this.api.on('shutdown', async () => {
|
|
284
227
|
try {
|
|
285
|
-
|
|
286
|
-
method: 'POST',
|
|
287
|
-
headers: this.generateHeaders(),
|
|
288
|
-
body: JSON.stringify({
|
|
289
|
-
action: 'deleteWebhook',
|
|
290
|
-
url,
|
|
291
|
-
}),
|
|
292
|
-
});
|
|
293
|
-
const response = await body.json();
|
|
294
|
-
await this.debugLog(`deleteWebhook: url:${url}, body:${JSON.stringify(response)}, statusCode:${statusCode}`);
|
|
295
|
-
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
296
|
-
await this.errorLog(`Failed to delete webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
await this.infoLog('Unregistered webhook to close listening.');
|
|
300
|
-
}
|
|
228
|
+
this.switchBotAPI.deleteWebhook(url);
|
|
301
229
|
}
|
|
302
230
|
catch (e) {
|
|
303
|
-
await this.errorLog(`Failed to delete webhook. Error:${e.message}`);
|
|
231
|
+
await this.errorLog(`Failed to delete webhook. Error:${e.message ?? e}`);
|
|
304
232
|
}
|
|
305
233
|
});
|
|
306
234
|
}
|
|
307
235
|
}
|
|
308
236
|
async setupBlE() {
|
|
237
|
+
this.switchBotBLE = new SwitchBotBLE();
|
|
238
|
+
// Listen for log events
|
|
239
|
+
if (!this.config.options?.disableLogsforBLE) {
|
|
240
|
+
this.switchBotBLE.on('log', (log) => {
|
|
241
|
+
switch (log.level) {
|
|
242
|
+
case LogLevel.SUCCESS:
|
|
243
|
+
this.successLog(log.message);
|
|
244
|
+
break;
|
|
245
|
+
case LogLevel.DEBUGSUCCESS:
|
|
246
|
+
this.debugSuccessLog(log.message);
|
|
247
|
+
break;
|
|
248
|
+
case LogLevel.WARN:
|
|
249
|
+
this.warnLog(log.message);
|
|
250
|
+
break;
|
|
251
|
+
case LogLevel.DEBUGWARN:
|
|
252
|
+
this.debugWarnLog(log.message);
|
|
253
|
+
break;
|
|
254
|
+
case LogLevel.ERROR:
|
|
255
|
+
this.errorLog(log.message);
|
|
256
|
+
break;
|
|
257
|
+
case LogLevel.DEBUGERROR:
|
|
258
|
+
this.debugErrorLog(log.message);
|
|
259
|
+
break;
|
|
260
|
+
case LogLevel.DEBUG:
|
|
261
|
+
this.debugLog(log.message);
|
|
262
|
+
break;
|
|
263
|
+
case LogLevel.INFO:
|
|
264
|
+
default:
|
|
265
|
+
this.infoLog(log.message);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
}
|
|
309
269
|
if (this.config.options?.BLE) {
|
|
310
270
|
await this.debugLog('setupBLE');
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
271
|
+
if (this.switchBotBLE === undefined) {
|
|
272
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(this.switchBotBLE)}`);
|
|
314
273
|
}
|
|
315
274
|
else {
|
|
316
275
|
// Start to monitor advertisement packets
|
|
317
276
|
(async () => {
|
|
318
277
|
// Start to monitor advertisement packets
|
|
319
278
|
await this.debugLog('Scanning for BLE SwitchBot devices...');
|
|
320
|
-
|
|
279
|
+
try {
|
|
280
|
+
await this.switchBotBLE.startScan();
|
|
281
|
+
}
|
|
282
|
+
catch (e) {
|
|
283
|
+
await this.errorLog(`Failed to start BLE scanning. Error:${e.message ?? e}`);
|
|
284
|
+
}
|
|
321
285
|
// Set an event handler to monitor advertisement packets
|
|
322
|
-
|
|
286
|
+
this.switchBotBLE.onadvertisement = async (ad) => {
|
|
323
287
|
try {
|
|
324
288
|
this.bleEventHandler[ad.address]?.(ad.serviceData);
|
|
325
289
|
}
|
|
326
290
|
catch (e) {
|
|
327
|
-
await this.errorLog(`Failed to handle BLE event. Error:${e}`);
|
|
291
|
+
await this.errorLog(`Failed to handle BLE event. Error:${e.message ?? e}`);
|
|
328
292
|
}
|
|
329
293
|
};
|
|
330
294
|
})();
|
|
331
295
|
this.api.on('shutdown', async () => {
|
|
332
296
|
try {
|
|
333
|
-
|
|
297
|
+
// this.switchBotBLE.stopScan()
|
|
334
298
|
await this.infoLog('Stopped BLE scanning to close listening.');
|
|
335
299
|
}
|
|
336
300
|
catch (e) {
|
|
337
|
-
await this.errorLog(`Failed to stop Platform BLE scanning. Error:${e.message}`);
|
|
301
|
+
await this.errorLog(`Failed to stop Platform BLE scanning. Error:${e.message ?? e}`);
|
|
338
302
|
}
|
|
339
303
|
});
|
|
340
304
|
}
|
|
@@ -489,26 +453,9 @@ export class SwitchBotPlatform {
|
|
|
489
453
|
await this.verifyConfig();
|
|
490
454
|
}
|
|
491
455
|
catch (e) {
|
|
492
|
-
await this.errorLog(`Update Token: ${e}`);
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
generateHeaders = () => {
|
|
496
|
-
const t = `${Date.now()}`;
|
|
497
|
-
const nonce = randomUUID();
|
|
498
|
-
const data = this.config.credentials?.token + t + nonce;
|
|
499
|
-
const signTerm = crypto
|
|
500
|
-
.createHmac('sha256', this.config.credentials?.secret)
|
|
501
|
-
.update(Buffer.from(data, 'utf-8'))
|
|
502
|
-
.digest();
|
|
503
|
-
const sign = signTerm.toString('base64');
|
|
504
|
-
return {
|
|
505
|
-
'Authorization': this.config.credentials?.token,
|
|
506
|
-
'sign': sign,
|
|
507
|
-
'nonce': nonce,
|
|
508
|
-
't': t,
|
|
509
|
-
'Content-Type': 'application/json',
|
|
510
|
-
};
|
|
511
|
-
};
|
|
456
|
+
await this.errorLog(`Update Token: ${e.message ?? e}`);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
512
459
|
async discoverDevices() {
|
|
513
460
|
if (!this.config.credentials?.token) {
|
|
514
461
|
return this.handleManualConfig();
|
|
@@ -521,24 +468,22 @@ export class SwitchBotPlatform {
|
|
|
521
468
|
await this.debugWarnLog(`Delay Between Retries: ${delayBetweenRetries}`);
|
|
522
469
|
while (retryCount < maxRetries) {
|
|
523
470
|
try {
|
|
524
|
-
const {
|
|
525
|
-
await this.
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
await this.handleDevices(devicesAPI.body.deviceList);
|
|
530
|
-
await this.handleIRDevices(devicesAPI.body.infraredRemoteList);
|
|
471
|
+
const { response, statusCode } = await this.switchBotAPI.getDevices();
|
|
472
|
+
await this.debugLog(`response: ${JSON.stringify(response)}`);
|
|
473
|
+
if (this.isSuccessfulResponse(statusCode)) {
|
|
474
|
+
await this.handleDevices(Array.isArray(response.body.deviceList) ? response.body.deviceList : []);
|
|
475
|
+
await this.handleIRDevices(Array.isArray(response.body.infraredRemoteList) ? response.body.infraredRemoteList : []);
|
|
531
476
|
break;
|
|
532
477
|
}
|
|
533
478
|
else {
|
|
534
|
-
await this.handleErrorResponse(statusCode,
|
|
479
|
+
await this.handleErrorResponse(statusCode, retryCount, maxRetries, delayBetweenRetries);
|
|
535
480
|
retryCount++;
|
|
536
481
|
}
|
|
537
482
|
}
|
|
538
483
|
catch (e) {
|
|
539
484
|
retryCount++;
|
|
540
485
|
await this.debugErrorLog(`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`);
|
|
541
|
-
await this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
|
|
486
|
+
await this.debugErrorLog(`Failed to Discover Devices, Error: ${e.message ?? e}`);
|
|
542
487
|
}
|
|
543
488
|
}
|
|
544
489
|
}
|
|
@@ -565,8 +510,8 @@ export class SwitchBotPlatform {
|
|
|
565
510
|
await this.errorLog('Neither SwitchBot Token or Device Config are set.');
|
|
566
511
|
}
|
|
567
512
|
}
|
|
568
|
-
isSuccessfulResponse(
|
|
569
|
-
return (
|
|
513
|
+
isSuccessfulResponse(apiStatusCode) {
|
|
514
|
+
return (apiStatusCode === 200 || apiStatusCode === 100);
|
|
570
515
|
}
|
|
571
516
|
async handleDevices(deviceLists) {
|
|
572
517
|
if (!this.config.options?.devices) {
|
|
@@ -631,11 +576,10 @@ export class SwitchBotPlatform {
|
|
|
631
576
|
return { ...matchingItem, ...itm };
|
|
632
577
|
});
|
|
633
578
|
}
|
|
634
|
-
async handleErrorResponse(
|
|
635
|
-
await this.statusCode(statusCode);
|
|
579
|
+
async handleErrorResponse(apiStatusCode, retryCount, maxRetries, delayBetweenRetries) {
|
|
636
580
|
await this.statusCode(apiStatusCode);
|
|
637
|
-
if (
|
|
638
|
-
this.infoLog(`statusCode: ${
|
|
581
|
+
if (apiStatusCode === 500) {
|
|
582
|
+
this.infoLog(`statusCode: ${apiStatusCode} Attempt ${retryCount + 1} of ${maxRetries}`);
|
|
639
583
|
await sleep(delayBetweenRetries);
|
|
640
584
|
}
|
|
641
585
|
}
|
|
@@ -2531,19 +2475,15 @@ export class SwitchBotPlatform {
|
|
|
2531
2475
|
await this.errorLog(message);
|
|
2532
2476
|
}
|
|
2533
2477
|
}
|
|
2534
|
-
async retryRequest(deviceMaxRetries, deviceDelayBetweenRetries
|
|
2478
|
+
async retryRequest(deviceId, deviceMaxRetries, deviceDelayBetweenRetries) {
|
|
2535
2479
|
let retryCount = 0;
|
|
2536
2480
|
const maxRetries = deviceMaxRetries;
|
|
2537
2481
|
const delayBetweenRetries = deviceDelayBetweenRetries;
|
|
2538
2482
|
while (retryCount < maxRetries) {
|
|
2539
2483
|
try {
|
|
2540
|
-
const {
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
}
|
|
2544
|
-
else {
|
|
2545
|
-
await this.debugLog(`Received status code: ${statusCode}`);
|
|
2546
|
-
}
|
|
2484
|
+
const { response, statusCode } = await this.switchBotAPI.getDeviceStatus(deviceId);
|
|
2485
|
+
await this.debugLog(`response: ${JSON.stringify(response)}`);
|
|
2486
|
+
return { response, statusCode };
|
|
2547
2487
|
}
|
|
2548
2488
|
catch (error) {
|
|
2549
2489
|
await this.errorLog(`Error making request: ${error.message}`);
|
|
@@ -2552,18 +2492,17 @@ export class SwitchBotPlatform {
|
|
|
2552
2492
|
await this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`);
|
|
2553
2493
|
await sleep(delayBetweenRetries);
|
|
2554
2494
|
}
|
|
2555
|
-
return {
|
|
2495
|
+
return { response: null, statusCode: 500 };
|
|
2556
2496
|
}
|
|
2557
2497
|
// BLE Connection
|
|
2558
2498
|
async connectBLE(accessory, device) {
|
|
2559
2499
|
try {
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
return switchbot;
|
|
2500
|
+
queueScheduler.schedule(async () => this.switchBotBLE);
|
|
2501
|
+
await this.debugLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${this.switchBotBLE}`);
|
|
2502
|
+
return this.switchBotBLE;
|
|
2564
2503
|
}
|
|
2565
2504
|
catch (e) {
|
|
2566
|
-
await this.errorLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' not found, Error: ${e}`);
|
|
2505
|
+
await this.errorLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' not found, Error: ${e.message ?? e}`);
|
|
2567
2506
|
return false;
|
|
2568
2507
|
}
|
|
2569
2508
|
}
|