@switchbot/homebridge-switchbot 3.8.3-beta.11 → 3.8.3-beta.13
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/dist/device/blindtilt.d.ts +1 -4
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +6 -6
- 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 +3 -3
- 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 +8 -8
- 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 +8 -8
- 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.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 +4 -4
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +3 -3
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +2 -8
- 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 +6 -6
- 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.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 +6 -6
- 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.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 +6 -6
- 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 +3 -3
- 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.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.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.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 +2 -2
- 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 +4 -4
- 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.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 +6 -6
- 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 +6 -6
- 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 +4 -4
- 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 +10 -10
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +2 -2
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +1 -7
- 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 +4 -4
- 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 +4 -4
- 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 +22 -22
- 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 +4 -4
- 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 +4 -4
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +4 -13
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +20 -132
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -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/package.json +3 -4
- package/src/device/blindtilt.ts +8 -11
- package/src/device/bot.ts +4 -7
- package/src/device/ceilinglight.ts +9 -12
- package/src/device/colorbulb.ts +9 -12
- package/src/device/contact.ts +1 -4
- package/src/device/curtain.ts +6 -9
- package/src/device/device.ts +4 -11
- package/src/device/fan.ts +7 -10
- package/src/device/hub.ts +1 -4
- package/src/device/humidifier.ts +7 -10
- package/src/device/iosensor.ts +1 -4
- package/src/device/lightstrip.ts +7 -10
- package/src/device/lock.ts +4 -7
- package/src/device/meter.ts +1 -4
- package/src/device/meterplus.ts +1 -4
- package/src/device/motion.ts +1 -4
- package/src/device/plug.ts +3 -6
- package/src/device/robotvacuumcleaner.ts +5 -12
- package/src/device/waterdetector.ts +1 -4
- package/src/irdevice/airconditioner.ts +7 -8
- package/src/irdevice/airpurifier.ts +7 -7
- package/src/irdevice/camera.ts +5 -5
- package/src/irdevice/fan.ts +11 -11
- package/src/irdevice/irdevice.ts +3 -11
- package/src/irdevice/light.ts +5 -5
- package/src/irdevice/other.ts +5 -5
- package/src/irdevice/tv.ts +23 -23
- package/src/irdevice/vacuumcleaner.ts +5 -5
- package/src/irdevice/waterheater.ts +5 -5
- package/src/platform.ts +23 -132
- package/src/settings.ts +1 -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 { 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
|
|
@@ -32,6 +31,7 @@ export declare class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
32
31
|
readonly bleEventHandler: {
|
|
33
32
|
[x: string]: (context: any) => void;
|
|
34
33
|
};
|
|
34
|
+
switchBotAPI: SwitchBotOpenAPI;
|
|
35
35
|
constructor(log: Logging, config: SwitchBotPlatformConfig, api: API);
|
|
36
36
|
setupMqtt(): Promise<void>;
|
|
37
37
|
setupwebhook(): Promise<void>;
|
|
@@ -50,13 +50,6 @@ export declare class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
50
50
|
* This method saves the openToken as the token in the config.json file
|
|
51
51
|
*/
|
|
52
52
|
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
53
|
discoverDevices(): Promise<void>;
|
|
61
54
|
private handleManualConfig;
|
|
62
55
|
private isSuccessfulResponse;
|
|
@@ -107,9 +100,7 @@ export declare class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
107
100
|
* @returns A promise that resolves when the logging is complete.
|
|
108
101
|
*/
|
|
109
102
|
statusCode(statusCode: number): Promise<void>;
|
|
110
|
-
retryRequest(deviceMaxRetries: number, deviceDelayBetweenRetries: number
|
|
111
|
-
dispatcher?: Dispatcher;
|
|
112
|
-
} & Omit<Dispatcher.RequestOptions, 'origin' | 'path' | 'method'> & Partial<Pick<Dispatcher.RequestOptions, 'method'>>): Promise<{
|
|
103
|
+
retryRequest(deviceId: string, deviceMaxRetries: number, deviceDelayBetweenRetries: number): Promise<{
|
|
113
104
|
body: any;
|
|
114
105
|
statusCode: number;
|
|
115
106
|
}>;
|
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":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAEvC,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAqB,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AACxF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAEtC,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAW,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAYrG,OAAO,KAAK,EAAE,SAAS,EAAE,O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C,OAAO,CAAC;CAGlD"}
|
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, SwitchBot, 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
|
|
@@ -70,6 +62,7 @@ export class SwitchBotPlatform {
|
|
|
70
62
|
// Event Handlers
|
|
71
63
|
webhookEventHandler = {};
|
|
72
64
|
bleEventHandler = {};
|
|
65
|
+
switchBotAPI;
|
|
73
66
|
constructor(log, config, api) {
|
|
74
67
|
this.api = api;
|
|
75
68
|
this.log = log;
|
|
@@ -100,6 +93,10 @@ export class SwitchBotPlatform {
|
|
|
100
93
|
this.debugErrorLog(`Verify Config, Error: ${e}`);
|
|
101
94
|
return;
|
|
102
95
|
}
|
|
96
|
+
// SwitchBot OpenAPI
|
|
97
|
+
this.switchBotAPI = new SwitchBotOpenAPI(this.config.credentials?.token, this.config.credentials?.secret);
|
|
98
|
+
// Set the log level
|
|
99
|
+
this.switchBotAPI.setLogLevel(LogLevel.DEBUG);
|
|
103
100
|
// import fakegato-history module and EVE characteristics
|
|
104
101
|
this.fakegatoAPI = fakegato(api);
|
|
105
102
|
this.eve = new EveHomeKitTypes(api);
|
|
@@ -181,123 +178,31 @@ export class SwitchBotPlatform {
|
|
|
181
178
|
if (this.config.options?.webhookURL) {
|
|
182
179
|
const url = this.config.options?.webhookURL;
|
|
183
180
|
try {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (request.url === path && request.method === 'POST') {
|
|
190
|
-
request.on('data', async (data) => {
|
|
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
|
-
}
|
|
213
|
-
catch (e) {
|
|
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
|
-
}),
|
|
181
|
+
this.switchBotAPI.setupWebhook(url);
|
|
182
|
+
// Listen for webhook events
|
|
183
|
+
this.switchBotAPI.on('webhookEvent', (body) => {
|
|
184
|
+
this.debugLog('Received webhook event:', body);
|
|
185
|
+
this.webhookEventHandler[body.context.deviceMac]?.(body.context);
|
|
231
186
|
});
|
|
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
187
|
}
|
|
238
188
|
catch (e) {
|
|
239
|
-
await this.errorLog(`Failed to
|
|
189
|
+
await this.errorLog(`Failed to setup webhook. Error:${e.message}`);
|
|
240
190
|
}
|
|
241
191
|
try {
|
|
242
|
-
|
|
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
|
-
}
|
|
192
|
+
this.switchBotAPI.updateWebhook(url);
|
|
258
193
|
}
|
|
259
194
|
catch (e) {
|
|
260
195
|
await this.errorLog(`Failed to update webhook. Error:${e.message}`);
|
|
261
196
|
}
|
|
262
197
|
try {
|
|
263
|
-
|
|
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
|
-
}
|
|
198
|
+
this.switchBotAPI.queryWebhook();
|
|
279
199
|
}
|
|
280
200
|
catch (e) {
|
|
281
|
-
await this.errorLog(`Failed to query webhook. Error:${e}`);
|
|
201
|
+
await this.errorLog(`Failed to query webhook. Error:${e.message}`);
|
|
282
202
|
}
|
|
283
203
|
this.api.on('shutdown', async () => {
|
|
284
204
|
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
|
-
}
|
|
205
|
+
this.switchBotAPI.deleteWebhook(url);
|
|
301
206
|
}
|
|
302
207
|
catch (e) {
|
|
303
208
|
await this.errorLog(`Failed to delete webhook. Error:${e.message}`);
|
|
@@ -497,23 +402,6 @@ export class SwitchBotPlatform {
|
|
|
497
402
|
await this.errorLog(`Update Token: ${e}`);
|
|
498
403
|
}
|
|
499
404
|
}
|
|
500
|
-
generateHeaders = () => {
|
|
501
|
-
const t = `${Date.now()}`;
|
|
502
|
-
const nonce = randomUUID();
|
|
503
|
-
const data = this.config.credentials?.token + t + nonce;
|
|
504
|
-
const signTerm = crypto
|
|
505
|
-
.createHmac('sha256', this.config.credentials?.secret)
|
|
506
|
-
.update(Buffer.from(data, 'utf-8'))
|
|
507
|
-
.digest();
|
|
508
|
-
const sign = signTerm.toString('base64');
|
|
509
|
-
return {
|
|
510
|
-
'Authorization': this.config.credentials?.token,
|
|
511
|
-
'sign': sign,
|
|
512
|
-
'nonce': nonce,
|
|
513
|
-
't': t,
|
|
514
|
-
'Content-Type': 'application/json',
|
|
515
|
-
};
|
|
516
|
-
};
|
|
517
405
|
async discoverDevices() {
|
|
518
406
|
if (!this.config.credentials?.token) {
|
|
519
407
|
return this.handleManualConfig();
|
|
@@ -526,7 +414,7 @@ export class SwitchBotPlatform {
|
|
|
526
414
|
await this.debugWarnLog(`Delay Between Retries: ${delayBetweenRetries}`);
|
|
527
415
|
while (retryCount < maxRetries) {
|
|
528
416
|
try {
|
|
529
|
-
const { body, statusCode } = await
|
|
417
|
+
const { body, statusCode } = await this.switchBotAPI.getDevices();
|
|
530
418
|
await this.debugWarnLog(`statusCode: ${statusCode}`);
|
|
531
419
|
const devicesAPI = await body.json();
|
|
532
420
|
await this.debugWarnLog(`devicesAPI: ${JSON.stringify(devicesAPI)}`);
|
|
@@ -2536,13 +2424,13 @@ export class SwitchBotPlatform {
|
|
|
2536
2424
|
await this.errorLog(message);
|
|
2537
2425
|
}
|
|
2538
2426
|
}
|
|
2539
|
-
async retryRequest(deviceMaxRetries, deviceDelayBetweenRetries
|
|
2427
|
+
async retryRequest(deviceId, deviceMaxRetries, deviceDelayBetweenRetries) {
|
|
2540
2428
|
let retryCount = 0;
|
|
2541
2429
|
const maxRetries = deviceMaxRetries;
|
|
2542
2430
|
const delayBetweenRetries = deviceDelayBetweenRetries;
|
|
2543
2431
|
while (retryCount < maxRetries) {
|
|
2544
2432
|
try {
|
|
2545
|
-
const { body, statusCode } = await
|
|
2433
|
+
const { body, statusCode } = await this.switchBotAPI.getDeviceStatus(deviceId);
|
|
2546
2434
|
if (statusCode === 200 || statusCode === 100) {
|
|
2547
2435
|
return { body, statusCode };
|
|
2548
2436
|
}
|