@switchbot/homebridge-switchbot 3.5.1-beta.1 → 3.5.1-beta.11
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 +203 -249
- 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 +45 -51
- 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 +17 -17
- 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 +9 -9
- 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 +19 -19
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +24 -11
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +90 -68
- 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 +15 -17
- 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 +76 -76
- 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 +35 -35
- 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 +9 -9
- 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 +9 -9
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +15 -15
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +288 -271
- 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 +211 -261
- 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 +47 -52
- package/src/irdevice/airpurifier.ts +19 -18
- package/src/irdevice/camera.ts +11 -10
- package/src/irdevice/fan.ts +21 -20
- package/src/irdevice/irdevice.ts +95 -70
- package/src/irdevice/light.ts +17 -18
- package/src/irdevice/other.ts +78 -77
- package/src/irdevice/tv.ts +37 -36
- package/src/irdevice/vacuumcleaner.ts +11 -10
- package/src/irdevice/waterheater.ts +11 -10
- package/src/platform.ts +290 -272
- 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
|
|
@@ -117,7 +117,7 @@ export class SwitchBotPlatform {
|
|
|
117
117
|
}
|
|
118
118
|
catch (e) {
|
|
119
119
|
this.errorLog(`Failed to Discover, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
120
|
-
this.debugErrorLog(`Failed to Discover, Error: ${e}`);
|
|
120
|
+
await this.debugErrorLog(`Failed to Discover, Error: ${e}`);
|
|
121
121
|
}
|
|
122
122
|
});
|
|
123
123
|
this.setupMqtt();
|
|
@@ -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 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
|
}
|
|
@@ -168,7 +168,7 @@ export class SwitchBotPlatform {
|
|
|
168
168
|
request.on('data', async (data) => {
|
|
169
169
|
try {
|
|
170
170
|
const body = JSON.parse(data);
|
|
171
|
-
this.debugLog(`Received Webhook: ${JSON.stringify(body)}`);
|
|
171
|
+
await this.debugLog(`Received Webhook: ${JSON.stringify(body)}`);
|
|
172
172
|
if (this.config.options?.mqttURL) {
|
|
173
173
|
const mac = body.context.deviceMac
|
|
174
174
|
?.toLowerCase()
|
|
@@ -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}`);
|
|
@@ -211,9 +211,9 @@ export class SwitchBotPlatform {
|
|
|
211
211
|
}),
|
|
212
212
|
});
|
|
213
213
|
const response = await body.json();
|
|
214
|
-
this.debugLog(`setupWebhook: url:${url}`);
|
|
215
|
-
this.debugLog(`setupWebhook: body:${JSON.stringify(response)}`);
|
|
216
|
-
this.debugLog(`setupWebhook: statusCode:${statusCode}`);
|
|
214
|
+
await this.debugLog(`setupWebhook: url:${url}`);
|
|
215
|
+
await this.debugLog(`setupWebhook: body:${JSON.stringify(response)}`);
|
|
216
|
+
await this.debugLog(`setupWebhook: statusCode:${statusCode}`);
|
|
217
217
|
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
218
218
|
this.errorLog(`Failed to configure webhook. Existing webhook well be overridden. HTTP:${statusCode} API:${response?.statusCode} `
|
|
219
219
|
+ `message:${response?.message}`);
|
|
@@ -233,9 +233,9 @@ export class SwitchBotPlatform {
|
|
|
233
233
|
}),
|
|
234
234
|
});
|
|
235
235
|
const response = await body.json();
|
|
236
|
-
this.debugLog(`updateWebhook: url:${url}`);
|
|
237
|
-
this.debugLog(`updateWebhook: body:${JSON.stringify(response)}`);
|
|
238
|
-
this.debugLog(`updateWebhook: statusCode:${statusCode}`);
|
|
236
|
+
await this.debugLog(`updateWebhook: url:${url}`);
|
|
237
|
+
await this.debugLog(`updateWebhook: body:${JSON.stringify(response)}`);
|
|
238
|
+
await this.debugLog(`updateWebhook: statusCode:${statusCode}`);
|
|
239
239
|
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
240
240
|
this.errorLog(`Failed to update webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
|
|
241
241
|
}
|
|
@@ -252,8 +252,8 @@ export class SwitchBotPlatform {
|
|
|
252
252
|
}),
|
|
253
253
|
});
|
|
254
254
|
const response = await body.json();
|
|
255
|
-
this.debugLog(`queryWebhook: body:${JSON.stringify(response)}`);
|
|
256
|
-
this.debugLog(`queryWebhook: statusCode:${statusCode}`);
|
|
255
|
+
await this.debugLog(`queryWebhook: body:${JSON.stringify(response)}`);
|
|
256
|
+
await this.debugLog(`queryWebhook: statusCode:${statusCode}`);
|
|
257
257
|
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
258
258
|
this.errorLog(`Failed to query webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
|
|
259
259
|
}
|
|
@@ -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
|
+
await 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
|
}
|
|
@@ -295,8 +293,8 @@ export class SwitchBotPlatform {
|
|
|
295
293
|
* This function is invoked when homebridge restores cached accessories from disk at startup.
|
|
296
294
|
* It should be used to setup event handlers for characteristics and update respective values.
|
|
297
295
|
*/
|
|
298
|
-
configureAccessory(accessory) {
|
|
299
|
-
this.debugLog(`Loading accessory from cache: ${accessory.displayName}`);
|
|
296
|
+
async configureAccessory(accessory) {
|
|
297
|
+
await this.debugLog(`Loading accessory from cache: ${accessory.displayName}`);
|
|
300
298
|
// add the restored accessory to the accessories cache so we can track if it has already been registered
|
|
301
299
|
this.accessories.push(accessory);
|
|
302
300
|
}
|
|
@@ -318,7 +316,7 @@ export class SwitchBotPlatform {
|
|
|
318
316
|
platformConfig['pushRate'] = this.config.options.pushRate;
|
|
319
317
|
}
|
|
320
318
|
if (Object.entries(platformConfig).length !== 0) {
|
|
321
|
-
this.debugWarnLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
319
|
+
await this.debugWarnLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
322
320
|
}
|
|
323
321
|
if (this.config.options) {
|
|
324
322
|
// Device Config
|
|
@@ -433,7 +431,7 @@ export class SwitchBotPlatform {
|
|
|
433
431
|
if (pluginConfig.credentials.token) {
|
|
434
432
|
pluginConfig.credentials.openToken = undefined;
|
|
435
433
|
}
|
|
436
|
-
this.debugWarnLog(`token: ${pluginConfig.credentials.token}`);
|
|
434
|
+
await this.debugWarnLog(`token: ${pluginConfig.credentials.token}`);
|
|
437
435
|
// save the config, ensuring we maintain pretty json
|
|
438
436
|
writeFileSync(this.api.user.configPath(), JSON.stringify(currentConfig, null, 4));
|
|
439
437
|
this.verifyConfig();
|
|
@@ -473,29 +471,29 @@ export class SwitchBotPlatform {
|
|
|
473
471
|
let retryCount = 0;
|
|
474
472
|
const maxRetries = this.maxRetries; // Maximum number of retries
|
|
475
473
|
const delayBetweenRetries = this.delayBetweenRetries; // Delay between retries in milliseconds
|
|
476
|
-
this.debugWarnLog(`Retry Count: ${retryCount}`);
|
|
477
|
-
this.debugWarnLog(`Max Retries: ${maxRetries}`);
|
|
478
|
-
this.debugWarnLog(`Delay Between Retries: ${delayBetweenRetries}`);
|
|
474
|
+
await this.debugWarnLog(`Retry Count: ${retryCount}`);
|
|
475
|
+
await this.debugWarnLog(`Max Retries: ${maxRetries}`);
|
|
476
|
+
await this.debugWarnLog(`Delay Between Retries: ${delayBetweenRetries}`);
|
|
479
477
|
while (retryCount < maxRetries) {
|
|
480
478
|
try {
|
|
481
479
|
const { body, statusCode } = await request(Devices, {
|
|
482
480
|
headers: this.generateHeaders(),
|
|
483
481
|
});
|
|
484
|
-
this.debugWarnLog(`statusCode: ${statusCode}`);
|
|
482
|
+
await this.debugWarnLog(`statusCode: ${statusCode}`);
|
|
485
483
|
const devicesAPI = await body.json();
|
|
486
|
-
this.debugWarnLog(`devicesAPI: ${JSON.stringify(devicesAPI)}`);
|
|
487
|
-
this.debugWarnLog(`devicesAPI Body: ${JSON.stringify(devicesAPI.body)}`);
|
|
488
|
-
this.debugWarnLog(`devicesAPI StatusCode: ${devicesAPI.statusCode}`);
|
|
484
|
+
await this.debugWarnLog(`devicesAPI: ${JSON.stringify(devicesAPI)}`);
|
|
485
|
+
await this.debugWarnLog(`devicesAPI Body: ${JSON.stringify(devicesAPI.body)}`);
|
|
486
|
+
await this.debugWarnLog(`devicesAPI StatusCode: ${devicesAPI.statusCode}`);
|
|
489
487
|
if ((statusCode === 200 || statusCode === 100) && (devicesAPI.statusCode === 200 || devicesAPI.statusCode === 100)) {
|
|
490
|
-
this.debugErrorLog(`statusCode: ${statusCode} & devicesAPI StatusCode: ${devicesAPI.statusCode}`);
|
|
488
|
+
await this.debugErrorLog(`statusCode: ${statusCode} & devicesAPI StatusCode: ${devicesAPI.statusCode}`);
|
|
491
489
|
// SwitchBot Devices
|
|
492
490
|
const deviceLists = devicesAPI.body.deviceList;
|
|
493
|
-
this.debugWarnLog(`DeviceLists: ${JSON.stringify(deviceLists)}`);
|
|
494
|
-
this.debugWarnLog(`DeviceLists Length: ${deviceLists.length}`);
|
|
491
|
+
await this.debugWarnLog(`DeviceLists: ${JSON.stringify(deviceLists)}`);
|
|
492
|
+
await this.debugWarnLog(`DeviceLists Length: ${deviceLists.length}`);
|
|
495
493
|
if (!this.config.options?.devices) {
|
|
496
|
-
this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
494
|
+
await this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
497
495
|
if (deviceLists.length === 0) {
|
|
498
|
-
this.debugLog(`SwitchBot API
|
|
496
|
+
await this.debugLog(`SwitchBot API Has No Devices With Cloud Services Enabled: ${JSON.stringify(devicesAPI.body)}`);
|
|
499
497
|
}
|
|
500
498
|
else {
|
|
501
499
|
const devices = deviceLists.map((v) => v);
|
|
@@ -510,9 +508,9 @@ export class SwitchBotPlatform {
|
|
|
510
508
|
}
|
|
511
509
|
}
|
|
512
510
|
else if (this.config.credentials?.token && this.config.options.devices) {
|
|
513
|
-
this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
511
|
+
await this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
514
512
|
if (deviceLists.length === 0) {
|
|
515
|
-
this.debugLog(`SwitchBot API
|
|
513
|
+
await this.debugLog(`SwitchBot API Has No Devices With Cloud Services Enabled: ${JSON.stringify(devicesAPI.body)}`);
|
|
516
514
|
}
|
|
517
515
|
else {
|
|
518
516
|
const deviceConfigs = this.config.options?.devices;
|
|
@@ -521,7 +519,7 @@ export class SwitchBotPlatform {
|
|
|
521
519
|
...itm,
|
|
522
520
|
}));
|
|
523
521
|
const devices = mergeBydeviceId(deviceLists, deviceConfigs);
|
|
524
|
-
this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
|
|
522
|
+
await this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
|
|
525
523
|
for (const device of devices) {
|
|
526
524
|
if (!device.deviceType) {
|
|
527
525
|
device.deviceType = device.configDeviceType;
|
|
@@ -543,12 +541,12 @@ export class SwitchBotPlatform {
|
|
|
543
541
|
this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
544
542
|
}
|
|
545
543
|
else {
|
|
546
|
-
this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
544
|
+
await this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
547
545
|
}
|
|
548
546
|
// IR Devices
|
|
549
547
|
const irDeviceLists = devicesAPI.body.infraredRemoteList;
|
|
550
548
|
if (!this.config.options?.irdevices) {
|
|
551
|
-
this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
549
|
+
await this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
552
550
|
const devices = irDeviceLists.map((v) => v);
|
|
553
551
|
for (const device of devices) {
|
|
554
552
|
if (device.remoteType) {
|
|
@@ -557,14 +555,14 @@ export class SwitchBotPlatform {
|
|
|
557
555
|
}
|
|
558
556
|
}
|
|
559
557
|
else {
|
|
560
|
-
this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
558
|
+
await this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
561
559
|
const irDeviceConfig = this.config.options?.irdevices;
|
|
562
560
|
const mergeIRBydeviceId = (a1, a2) => a1.map((itm) => ({
|
|
563
561
|
...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
|
|
564
562
|
...itm,
|
|
565
563
|
}));
|
|
566
564
|
const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
|
|
567
|
-
this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
|
|
565
|
+
await this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
|
|
568
566
|
for (const device of devices) {
|
|
569
567
|
this.createIRDevice(device);
|
|
570
568
|
}
|
|
@@ -573,7 +571,7 @@ export class SwitchBotPlatform {
|
|
|
573
571
|
this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
574
572
|
}
|
|
575
573
|
else {
|
|
576
|
-
this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
574
|
+
await this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
577
575
|
}
|
|
578
576
|
break;
|
|
579
577
|
}
|
|
@@ -590,12 +588,12 @@ export class SwitchBotPlatform {
|
|
|
590
588
|
catch (e) {
|
|
591
589
|
retryCount++;
|
|
592
590
|
this.debugErrorLog(`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
593
|
-
this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
|
|
591
|
+
await this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
|
|
594
592
|
}
|
|
595
593
|
}
|
|
596
594
|
}
|
|
597
595
|
else if (!this.config.credentials?.token && this.config.options?.devices) {
|
|
598
|
-
this.debugLog(`SwitchBot Device Manual Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
596
|
+
await this.debugLog(`SwitchBot Device Manual Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
599
597
|
const deviceConfigs = this.config.options?.devices;
|
|
600
598
|
const devices = deviceConfigs.map((v) => v);
|
|
601
599
|
for (const device of devices) {
|
|
@@ -610,73 +608,73 @@ export class SwitchBotPlatform {
|
|
|
610
608
|
this.errorLog('Neither SwitchBot Token or Device Config are not set.');
|
|
611
609
|
}
|
|
612
610
|
}
|
|
613
|
-
createDevice(device) {
|
|
611
|
+
async createDevice(device) {
|
|
614
612
|
switch (device.deviceType) {
|
|
615
613
|
case 'Humidifier':
|
|
616
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
614
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
617
615
|
this.createHumidifier(device);
|
|
618
616
|
break;
|
|
619
617
|
case 'Hub Mini':
|
|
620
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
618
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
621
619
|
break;
|
|
622
620
|
case 'Hub Plus':
|
|
623
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
621
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
624
622
|
break;
|
|
625
623
|
case 'Hub 2':
|
|
626
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
624
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
627
625
|
this.createHub2(device);
|
|
628
626
|
break;
|
|
629
627
|
case 'Bot':
|
|
630
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
628
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
631
629
|
this.createBot(device);
|
|
632
630
|
break;
|
|
633
631
|
case 'Meter':
|
|
634
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
632
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
635
633
|
this.createMeter(device);
|
|
636
634
|
break;
|
|
637
635
|
case 'MeterPlus':
|
|
638
636
|
case 'Meter Plus (JP)':
|
|
639
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
637
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
640
638
|
this.createMeterPlus(device);
|
|
641
639
|
break;
|
|
642
640
|
case 'WoIOSensor':
|
|
643
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
641
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
644
642
|
this.createIOSensor(device);
|
|
645
643
|
break;
|
|
646
644
|
case 'Water Detector':
|
|
647
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
645
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
648
646
|
this.createWaterDetector(device);
|
|
649
647
|
break;
|
|
650
648
|
case 'Motion Sensor':
|
|
651
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
649
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
652
650
|
this.createMotion(device);
|
|
653
651
|
break;
|
|
654
652
|
case 'Contact Sensor':
|
|
655
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
653
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
656
654
|
this.createContact(device);
|
|
657
655
|
break;
|
|
658
656
|
case 'Curtain':
|
|
659
657
|
case 'Curtain3':
|
|
660
|
-
this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
|
|
658
|
+
await this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
|
|
661
659
|
this.createCurtain(device);
|
|
662
660
|
break;
|
|
663
661
|
case 'Blind Tilt':
|
|
664
|
-
this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
|
|
662
|
+
await this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
|
|
665
663
|
this.createBlindTilt(device);
|
|
666
664
|
break;
|
|
667
665
|
case 'Plug':
|
|
668
666
|
case 'Plug Mini (US)':
|
|
669
667
|
case 'Plug Mini (JP)':
|
|
670
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
668
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
671
669
|
this.createPlug(device);
|
|
672
670
|
break;
|
|
673
671
|
case 'Smart Lock':
|
|
674
672
|
case 'Smart Lock Pro':
|
|
675
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
673
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
676
674
|
this.createLock(device);
|
|
677
675
|
break;
|
|
678
676
|
case 'Color Bulb':
|
|
679
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
677
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
680
678
|
this.createColorBulb(device);
|
|
681
679
|
break;
|
|
682
680
|
case 'K10+':
|
|
@@ -685,32 +683,32 @@ export class SwitchBotPlatform {
|
|
|
685
683
|
case 'Robot Vacuum Cleaner S1':
|
|
686
684
|
case 'Robot Vacuum Cleaner S1 Plus':
|
|
687
685
|
case 'Robot Vacuum Cleaner S10':
|
|
688
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
686
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
689
687
|
this.createRobotVacuumCleaner(device);
|
|
690
688
|
break;
|
|
691
689
|
case 'Ceiling Light':
|
|
692
690
|
case 'Ceiling Light Pro':
|
|
693
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
691
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
694
692
|
this.createCeilingLight(device);
|
|
695
693
|
break;
|
|
696
694
|
case 'Strip Light':
|
|
697
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
695
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
698
696
|
this.createStripLight(device);
|
|
699
697
|
break;
|
|
700
698
|
case 'Battery Circulator Fan':
|
|
701
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
699
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
702
700
|
this.createFan(device);
|
|
703
701
|
break;
|
|
704
702
|
case 'Remote':
|
|
705
703
|
case 'Indoor Cam':
|
|
706
704
|
case 'remote with screen+':
|
|
707
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}, is currently not supported, device: ${JSON.stringify(device)}`);
|
|
705
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}, is currently not supported, device: ${JSON.stringify(device)}`);
|
|
708
706
|
break;
|
|
709
707
|
default:
|
|
710
708
|
this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`, +`Submit Feature Requests Here: https://tinyurl.com/SwitchBotFeatureRequest, device: ${JSON.stringify(device)}`);
|
|
711
709
|
}
|
|
712
710
|
}
|
|
713
|
-
createIRDevice(device) {
|
|
711
|
+
async createIRDevice(device) {
|
|
714
712
|
if (device.connectionType === undefined) {
|
|
715
713
|
device.connectionType = 'OpenAPI';
|
|
716
714
|
}
|
|
@@ -727,7 +725,7 @@ export class SwitchBotPlatform {
|
|
|
727
725
|
case 'DIY DVD':
|
|
728
726
|
case 'Speaker':
|
|
729
727
|
case 'DIY Speaker':
|
|
730
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
728
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
731
729
|
if (device.external === undefined) {
|
|
732
730
|
device.external = true;
|
|
733
731
|
this.createTV(device);
|
|
@@ -738,45 +736,45 @@ export class SwitchBotPlatform {
|
|
|
738
736
|
break;
|
|
739
737
|
case 'Fan':
|
|
740
738
|
case 'DIY Fan':
|
|
741
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
739
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
742
740
|
this.createIRFan(device);
|
|
743
741
|
break;
|
|
744
742
|
case 'Air Conditioner':
|
|
745
743
|
case 'DIY Air Conditioner':
|
|
746
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
744
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
747
745
|
this.createAirConditioner(device);
|
|
748
746
|
break;
|
|
749
747
|
case 'Light':
|
|
750
748
|
case 'DIY Light':
|
|
751
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
749
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
752
750
|
this.createLight(device);
|
|
753
751
|
break;
|
|
754
752
|
case 'Air Purifier':
|
|
755
753
|
case 'DIY Air Purifier':
|
|
756
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
754
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
757
755
|
this.createAirPurifier(device);
|
|
758
756
|
break;
|
|
759
757
|
case 'Water Heater':
|
|
760
758
|
case 'DIY Water Heater':
|
|
761
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
759
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
762
760
|
this.createWaterHeater(device);
|
|
763
761
|
break;
|
|
764
762
|
case 'Vacuum Cleaner':
|
|
765
763
|
case 'DIY Vacuum Cleaner':
|
|
766
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
764
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
767
765
|
this.createVacuumCleaner(device);
|
|
768
766
|
break;
|
|
769
767
|
case 'Camera':
|
|
770
768
|
case 'DIY Camera':
|
|
771
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
769
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
772
770
|
this.createCamera(device);
|
|
773
771
|
break;
|
|
774
772
|
case 'Others':
|
|
775
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
773
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
776
774
|
this.createOthers(device);
|
|
777
775
|
break;
|
|
778
776
|
default:
|
|
779
|
-
this.debugLog(`Unsupported Device: ${JSON.stringify(device)}`);
|
|
777
|
+
await this.debugLog(`Unsupported Device: ${JSON.stringify(device)}`);
|
|
780
778
|
this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.remoteType}, is currently not supported.`);
|
|
781
779
|
this.warnLog('Submit Feature Requests Here: ' + 'https://tinyurl.com/SwitchBotFeatureRequest');
|
|
782
780
|
}
|
|
@@ -803,7 +801,7 @@ export class SwitchBotPlatform {
|
|
|
803
801
|
// create the accessory handler for the restored accessory
|
|
804
802
|
// this is imported from `platformAccessory.ts`
|
|
805
803
|
new Humidifier(this, existingAccessory, device);
|
|
806
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
804
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
807
805
|
}
|
|
808
806
|
else {
|
|
809
807
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -829,13 +827,13 @@ export class SwitchBotPlatform {
|
|
|
829
827
|
// create the accessory handler for the newly create accessory
|
|
830
828
|
// this is imported from `platformAccessory.ts`
|
|
831
829
|
new Humidifier(this, accessory, device);
|
|
832
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
830
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
833
831
|
// publish device externally or link the accessory to your platform
|
|
834
832
|
this.externalOrPlatform(device, accessory);
|
|
835
833
|
this.accessories.push(accessory);
|
|
836
834
|
}
|
|
837
835
|
else {
|
|
838
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
836
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
839
837
|
}
|
|
840
838
|
}
|
|
841
839
|
async createBot(device) {
|
|
@@ -860,7 +858,7 @@ export class SwitchBotPlatform {
|
|
|
860
858
|
// create the accessory handler for the restored accessory
|
|
861
859
|
// this is imported from `platformAccessory.ts`
|
|
862
860
|
new Bot(this, existingAccessory, device);
|
|
863
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
861
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
864
862
|
}
|
|
865
863
|
else {
|
|
866
864
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -887,13 +885,13 @@ export class SwitchBotPlatform {
|
|
|
887
885
|
// create the accessory handler for the newly create accessory
|
|
888
886
|
// this is imported from `platformAccessory.ts`
|
|
889
887
|
new Bot(this, accessory, device);
|
|
890
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
888
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
891
889
|
// publish device externally or link the accessory to your platform
|
|
892
890
|
this.externalOrPlatform(device, accessory);
|
|
893
891
|
this.accessories.push(accessory);
|
|
894
892
|
}
|
|
895
893
|
else {
|
|
896
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
894
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
897
895
|
}
|
|
898
896
|
}
|
|
899
897
|
async createMeter(device) {
|
|
@@ -918,7 +916,7 @@ export class SwitchBotPlatform {
|
|
|
918
916
|
// create the accessory handler for the restored accessory
|
|
919
917
|
// this is imported from `platformAccessory.ts`
|
|
920
918
|
new Meter(this, existingAccessory, device);
|
|
921
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
919
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
922
920
|
}
|
|
923
921
|
else {
|
|
924
922
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -944,13 +942,13 @@ export class SwitchBotPlatform {
|
|
|
944
942
|
// create the accessory handler for the newly create accessory
|
|
945
943
|
// this is imported from `platformAccessory.ts`
|
|
946
944
|
new Meter(this, accessory, device);
|
|
947
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
945
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
948
946
|
// publish device externally or link the accessory to your platform
|
|
949
947
|
this.externalOrPlatform(device, accessory);
|
|
950
948
|
this.accessories.push(accessory);
|
|
951
949
|
}
|
|
952
950
|
else {
|
|
953
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
951
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
954
952
|
}
|
|
955
953
|
}
|
|
956
954
|
async createMeterPlus(device) {
|
|
@@ -976,7 +974,7 @@ export class SwitchBotPlatform {
|
|
|
976
974
|
// create the accessory handler for the restored accessory
|
|
977
975
|
// this is imported from `platformAccessory.ts`
|
|
978
976
|
new MeterPlus(this, existingAccessory, device);
|
|
979
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
977
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
980
978
|
}
|
|
981
979
|
else {
|
|
982
980
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -1002,13 +1000,13 @@ export class SwitchBotPlatform {
|
|
|
1002
1000
|
// create the accessory handler for the newly create accessory
|
|
1003
1001
|
// this is imported from `platformAccessory.ts`
|
|
1004
1002
|
new MeterPlus(this, accessory, device);
|
|
1005
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1003
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1006
1004
|
// publish device externally or link the accessory to your platform
|
|
1007
1005
|
this.externalOrPlatform(device, accessory);
|
|
1008
1006
|
this.accessories.push(accessory);
|
|
1009
1007
|
}
|
|
1010
1008
|
else {
|
|
1011
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1009
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1012
1010
|
}
|
|
1013
1011
|
}
|
|
1014
1012
|
async createHub2(device) {
|
|
@@ -1034,7 +1032,7 @@ export class SwitchBotPlatform {
|
|
|
1034
1032
|
// create the accessory handler for the restored accessory
|
|
1035
1033
|
// this is imported from `platformAccessory.ts`
|
|
1036
1034
|
new Hub(this, existingAccessory, device);
|
|
1037
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1035
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1038
1036
|
}
|
|
1039
1037
|
else {
|
|
1040
1038
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -1060,13 +1058,13 @@ export class SwitchBotPlatform {
|
|
|
1060
1058
|
// create the accessory handler for the newly create accessory
|
|
1061
1059
|
// this is imported from `platformAccessory.ts`
|
|
1062
1060
|
new Hub(this, accessory, device);
|
|
1063
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1061
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1064
1062
|
// publish device externally or link the accessory to your platform
|
|
1065
1063
|
this.externalOrPlatform(device, accessory);
|
|
1066
1064
|
this.accessories.push(accessory);
|
|
1067
1065
|
}
|
|
1068
1066
|
else {
|
|
1069
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1067
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1070
1068
|
}
|
|
1071
1069
|
}
|
|
1072
1070
|
async createIOSensor(device) {
|
|
@@ -1091,7 +1089,7 @@ export class SwitchBotPlatform {
|
|
|
1091
1089
|
// create the accessory handler for the restored accessory
|
|
1092
1090
|
// this is imported from `platformAccessory.ts`
|
|
1093
1091
|
new IOSensor(this, existingAccessory, device);
|
|
1094
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1092
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1095
1093
|
}
|
|
1096
1094
|
else {
|
|
1097
1095
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -1117,13 +1115,13 @@ export class SwitchBotPlatform {
|
|
|
1117
1115
|
// create the accessory handler for the newly create accessory
|
|
1118
1116
|
// this is imported from `platformAccessory.ts`
|
|
1119
1117
|
new IOSensor(this, accessory, device);
|
|
1120
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1118
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1121
1119
|
// publish device externally or link the accessory to your platform
|
|
1122
1120
|
this.externalOrPlatform(device, accessory);
|
|
1123
1121
|
this.accessories.push(accessory);
|
|
1124
1122
|
}
|
|
1125
1123
|
else {
|
|
1126
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1124
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1127
1125
|
}
|
|
1128
1126
|
}
|
|
1129
1127
|
async createWaterDetector(device) {
|
|
@@ -1148,7 +1146,7 @@ export class SwitchBotPlatform {
|
|
|
1148
1146
|
// create the accessory handler for the restored accessory
|
|
1149
1147
|
// this is imported from `platformAccessory.ts`
|
|
1150
1148
|
new WaterDetector(this, existingAccessory, device);
|
|
1151
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1149
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1152
1150
|
}
|
|
1153
1151
|
else {
|
|
1154
1152
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -1174,13 +1172,13 @@ export class SwitchBotPlatform {
|
|
|
1174
1172
|
// create the accessory handler for the newly create accessory
|
|
1175
1173
|
// this is imported from `platformAccessory.ts`
|
|
1176
1174
|
new WaterDetector(this, accessory, device);
|
|
1177
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1175
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1178
1176
|
// publish device externally or link the accessory to your platform
|
|
1179
1177
|
this.externalOrPlatform(device, accessory);
|
|
1180
1178
|
this.accessories.push(accessory);
|
|
1181
1179
|
}
|
|
1182
1180
|
else {
|
|
1183
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1181
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1184
1182
|
}
|
|
1185
1183
|
}
|
|
1186
1184
|
async createMotion(device) {
|
|
@@ -1205,7 +1203,7 @@ export class SwitchBotPlatform {
|
|
|
1205
1203
|
// create the accessory handler for the restored accessory
|
|
1206
1204
|
// this is imported from `platformAccessory.ts`
|
|
1207
1205
|
new Motion(this, existingAccessory, device);
|
|
1208
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1206
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1209
1207
|
}
|
|
1210
1208
|
else {
|
|
1211
1209
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -1231,13 +1229,13 @@ export class SwitchBotPlatform {
|
|
|
1231
1229
|
// create the accessory handler for the newly create accessory
|
|
1232
1230
|
// this is imported from `platformAccessory.ts`
|
|
1233
1231
|
new Motion(this, accessory, device);
|
|
1234
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1232
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1235
1233
|
// publish device externally or link the accessory to your platform
|
|
1236
1234
|
this.externalOrPlatform(device, accessory);
|
|
1237
1235
|
this.accessories.push(accessory);
|
|
1238
1236
|
}
|
|
1239
1237
|
else {
|
|
1240
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1238
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1241
1239
|
}
|
|
1242
1240
|
}
|
|
1243
1241
|
async createContact(device) {
|
|
@@ -1262,7 +1260,7 @@ export class SwitchBotPlatform {
|
|
|
1262
1260
|
// create the accessory handler for the restored accessory
|
|
1263
1261
|
// this is imported from `platformAccessory.ts`
|
|
1264
1262
|
new Contact(this, existingAccessory, device);
|
|
1265
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1263
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1266
1264
|
}
|
|
1267
1265
|
else {
|
|
1268
1266
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -1288,13 +1286,13 @@ export class SwitchBotPlatform {
|
|
|
1288
1286
|
// create the accessory handler for the newly create accessory
|
|
1289
1287
|
// this is imported from `platformAccessory.ts`
|
|
1290
1288
|
new Contact(this, accessory, device);
|
|
1291
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1289
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1292
1290
|
// publish device externally or link the accessory to your platform
|
|
1293
1291
|
this.externalOrPlatform(device, accessory);
|
|
1294
1292
|
this.accessories.push(accessory);
|
|
1295
1293
|
}
|
|
1296
1294
|
else {
|
|
1297
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1295
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1298
1296
|
}
|
|
1299
1297
|
}
|
|
1300
1298
|
async createBlindTilt(device) {
|
|
@@ -1319,7 +1317,7 @@ export class SwitchBotPlatform {
|
|
|
1319
1317
|
// create the accessory handler for the restored accessory
|
|
1320
1318
|
// this is imported from `platformAccessory.ts`
|
|
1321
1319
|
new BlindTilt(this, existingAccessory, device);
|
|
1322
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1320
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1323
1321
|
}
|
|
1324
1322
|
else {
|
|
1325
1323
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -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
|
|
@@ -1357,13 +1357,13 @@ export class SwitchBotPlatform {
|
|
|
1357
1357
|
// create the accessory handler for the newly create accessory
|
|
1358
1358
|
// this is imported from `platformAccessory.ts`
|
|
1359
1359
|
new BlindTilt(this, accessory, device);
|
|
1360
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1360
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1361
1361
|
// publish device externally or link the accessory to your platform
|
|
1362
1362
|
this.externalOrPlatform(device, accessory);
|
|
1363
1363
|
this.accessories.push(accessory);
|
|
1364
1364
|
}
|
|
1365
1365
|
else {
|
|
1366
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1366
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1367
1367
|
}
|
|
1368
1368
|
}
|
|
1369
1369
|
async createCurtain(device) {
|
|
@@ -1388,7 +1388,7 @@ export class SwitchBotPlatform {
|
|
|
1388
1388
|
// create the accessory handler for the restored accessory
|
|
1389
1389
|
// this is imported from `platformAccessory.ts`
|
|
1390
1390
|
new Curtain(this, existingAccessory, device);
|
|
1391
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1391
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1392
1392
|
}
|
|
1393
1393
|
else {
|
|
1394
1394
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -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
|
|
@@ -1426,13 +1428,13 @@ export class SwitchBotPlatform {
|
|
|
1426
1428
|
// create the accessory handler for the newly create accessory
|
|
1427
1429
|
// this is imported from `platformAccessory.ts`
|
|
1428
1430
|
new Curtain(this, accessory, device);
|
|
1429
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1431
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1430
1432
|
// publish device externally or link the accessory to your platform
|
|
1431
1433
|
this.externalOrPlatform(device, accessory);
|
|
1432
1434
|
this.accessories.push(accessory);
|
|
1433
1435
|
}
|
|
1434
1436
|
else {
|
|
1435
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1437
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1436
1438
|
}
|
|
1437
1439
|
}
|
|
1438
1440
|
async createPlug(device) {
|
|
@@ -1457,7 +1459,7 @@ export class SwitchBotPlatform {
|
|
|
1457
1459
|
// create the accessory handler for the restored accessory
|
|
1458
1460
|
// this is imported from `platformAccessory.ts`
|
|
1459
1461
|
new Plug(this, existingAccessory, device);
|
|
1460
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1462
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1461
1463
|
}
|
|
1462
1464
|
else {
|
|
1463
1465
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -1483,13 +1485,13 @@ export class SwitchBotPlatform {
|
|
|
1483
1485
|
// create the accessory handler for the newly create accessory
|
|
1484
1486
|
// this is imported from `platformAccessory.ts`
|
|
1485
1487
|
new Plug(this, accessory, device);
|
|
1486
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1488
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1487
1489
|
// publish device externally or link the accessory to your platform
|
|
1488
1490
|
this.externalOrPlatform(device, accessory);
|
|
1489
1491
|
this.accessories.push(accessory);
|
|
1490
1492
|
}
|
|
1491
1493
|
else {
|
|
1492
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1494
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1493
1495
|
}
|
|
1494
1496
|
}
|
|
1495
1497
|
async createLock(device) {
|
|
@@ -1514,7 +1516,7 @@ export class SwitchBotPlatform {
|
|
|
1514
1516
|
// create the accessory handler for the restored accessory
|
|
1515
1517
|
// this is imported from `platformAccessory.ts`
|
|
1516
1518
|
new Lock(this, existingAccessory, device);
|
|
1517
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1519
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1518
1520
|
}
|
|
1519
1521
|
else {
|
|
1520
1522
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -1540,13 +1542,13 @@ export class SwitchBotPlatform {
|
|
|
1540
1542
|
// create the accessory handler for the newly create accessory
|
|
1541
1543
|
// this is imported from `platformAccessory.ts`
|
|
1542
1544
|
new Lock(this, accessory, device);
|
|
1543
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1545
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1544
1546
|
// publish device externally or link the accessory to your platform
|
|
1545
1547
|
this.externalOrPlatform(device, accessory);
|
|
1546
1548
|
this.accessories.push(accessory);
|
|
1547
1549
|
}
|
|
1548
1550
|
else {
|
|
1549
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1551
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1550
1552
|
}
|
|
1551
1553
|
}
|
|
1552
1554
|
async createColorBulb(device) {
|
|
@@ -1571,7 +1573,7 @@ export class SwitchBotPlatform {
|
|
|
1571
1573
|
// create the accessory handler for the restored accessory
|
|
1572
1574
|
// this is imported from `platformAccessory.ts`
|
|
1573
1575
|
new ColorBulb(this, existingAccessory, device);
|
|
1574
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1576
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1575
1577
|
}
|
|
1576
1578
|
else {
|
|
1577
1579
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -1597,13 +1599,13 @@ export class SwitchBotPlatform {
|
|
|
1597
1599
|
// create the accessory handler for the newly create accessory
|
|
1598
1600
|
// this is imported from `platformAccessory.ts`
|
|
1599
1601
|
new ColorBulb(this, accessory, device);
|
|
1600
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1602
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1601
1603
|
// publish device externally or link the accessory to your platform
|
|
1602
1604
|
this.externalOrPlatform(device, accessory);
|
|
1603
1605
|
this.accessories.push(accessory);
|
|
1604
1606
|
}
|
|
1605
1607
|
else {
|
|
1606
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1608
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1607
1609
|
}
|
|
1608
1610
|
}
|
|
1609
1611
|
async createCeilingLight(device) {
|
|
@@ -1628,7 +1630,7 @@ export class SwitchBotPlatform {
|
|
|
1628
1630
|
// create the accessory handler for the restored accessory
|
|
1629
1631
|
// this is imported from `platformAccessory.ts`
|
|
1630
1632
|
new CeilingLight(this, existingAccessory, device);
|
|
1631
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1633
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1632
1634
|
}
|
|
1633
1635
|
else {
|
|
1634
1636
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -1654,13 +1656,13 @@ export class SwitchBotPlatform {
|
|
|
1654
1656
|
// create the accessory handler for the newly create accessory
|
|
1655
1657
|
// this is imported from `platformAccessory.ts`
|
|
1656
1658
|
new CeilingLight(this, accessory, device);
|
|
1657
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1659
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1658
1660
|
// publish device externally or link the accessory to your platform
|
|
1659
1661
|
this.externalOrPlatform(device, accessory);
|
|
1660
1662
|
this.accessories.push(accessory);
|
|
1661
1663
|
}
|
|
1662
1664
|
else {
|
|
1663
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1665
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1664
1666
|
}
|
|
1665
1667
|
}
|
|
1666
1668
|
async createStripLight(device) {
|
|
@@ -1685,7 +1687,7 @@ export class SwitchBotPlatform {
|
|
|
1685
1687
|
// create the accessory handler for the restored accessory
|
|
1686
1688
|
// this is imported from `platformAccessory.ts`
|
|
1687
1689
|
new StripLight(this, existingAccessory, device);
|
|
1688
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1690
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1689
1691
|
}
|
|
1690
1692
|
else {
|
|
1691
1693
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -1711,13 +1713,13 @@ export class SwitchBotPlatform {
|
|
|
1711
1713
|
// create the accessory handler for the newly create accessory
|
|
1712
1714
|
// this is imported from `platformAccessory.ts`
|
|
1713
1715
|
new StripLight(this, accessory, device);
|
|
1714
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1716
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1715
1717
|
// publish device externally or link the accessory to your platform
|
|
1716
1718
|
this.externalOrPlatform(device, accessory);
|
|
1717
1719
|
this.accessories.push(accessory);
|
|
1718
1720
|
}
|
|
1719
1721
|
else {
|
|
1720
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1722
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1721
1723
|
}
|
|
1722
1724
|
}
|
|
1723
1725
|
async createFan(device) {
|
|
@@ -1742,7 +1744,7 @@ export class SwitchBotPlatform {
|
|
|
1742
1744
|
// create the accessory handler for the restored accessory
|
|
1743
1745
|
// this is imported from `platformAccessory.ts`
|
|
1744
1746
|
new Fan(this, existingAccessory, device);
|
|
1745
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1747
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1746
1748
|
}
|
|
1747
1749
|
else {
|
|
1748
1750
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -1768,13 +1770,13 @@ export class SwitchBotPlatform {
|
|
|
1768
1770
|
// create the accessory handler for the newly create accessory
|
|
1769
1771
|
// this is imported from `platformAccessory.ts`
|
|
1770
1772
|
new Fan(this, accessory, device);
|
|
1771
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1773
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1772
1774
|
// publish device externally or link the accessory to your platform
|
|
1773
1775
|
this.externalOrPlatform(device, accessory);
|
|
1774
1776
|
this.accessories.push(accessory);
|
|
1775
1777
|
}
|
|
1776
1778
|
else {
|
|
1777
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1779
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1778
1780
|
}
|
|
1779
1781
|
}
|
|
1780
1782
|
async createRobotVacuumCleaner(device) {
|
|
@@ -1799,7 +1801,7 @@ export class SwitchBotPlatform {
|
|
|
1799
1801
|
// create the accessory handler for the restored accessory
|
|
1800
1802
|
// this is imported from `platformAccessory.ts`
|
|
1801
1803
|
new RobotVacuumCleaner(this, existingAccessory, device);
|
|
1802
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1804
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1803
1805
|
}
|
|
1804
1806
|
else {
|
|
1805
1807
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -1825,13 +1827,13 @@ export class SwitchBotPlatform {
|
|
|
1825
1827
|
// create the accessory handler for the newly create accessory
|
|
1826
1828
|
// this is imported from `platformAccessory.ts`
|
|
1827
1829
|
new RobotVacuumCleaner(this, accessory, device);
|
|
1828
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1830
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1829
1831
|
// publish device externally or link the accessory to your platform
|
|
1830
1832
|
this.externalOrPlatform(device, accessory);
|
|
1831
1833
|
this.accessories.push(accessory);
|
|
1832
1834
|
}
|
|
1833
1835
|
else {
|
|
1834
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1836
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1835
1837
|
}
|
|
1836
1838
|
}
|
|
1837
1839
|
async createTV(device) {
|
|
@@ -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;
|
|
@@ -1854,7 +1853,7 @@ export class SwitchBotPlatform {
|
|
|
1854
1853
|
// create the accessory handler for the restored accessory
|
|
1855
1854
|
// this is imported from `platformAccessory.ts`
|
|
1856
1855
|
new TV(this, existingAccessory, device);
|
|
1857
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1856
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1858
1857
|
}
|
|
1859
1858
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
1860
1859
|
// the accessory does not yet exist, so we need to create it
|
|
@@ -1876,12 +1875,12 @@ export class SwitchBotPlatform {
|
|
|
1876
1875
|
// create the accessory handler for the newly create accessory
|
|
1877
1876
|
// this is imported from `platformAccessory.ts`
|
|
1878
1877
|
new TV(this, accessory, device);
|
|
1879
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1878
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1880
1879
|
this.externalOrPlatformIR(device, accessory);
|
|
1881
1880
|
this.accessories.push(accessory);
|
|
1882
1881
|
}
|
|
1883
1882
|
else {
|
|
1884
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1883
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1885
1884
|
}
|
|
1886
1885
|
}
|
|
1887
1886
|
async createIRFan(device) {
|
|
@@ -1906,7 +1905,7 @@ export class SwitchBotPlatform {
|
|
|
1906
1905
|
// create the accessory handler for the restored accessory
|
|
1907
1906
|
// this is imported from `platformAccessory.ts`
|
|
1908
1907
|
new IRFan(this, existingAccessory, device);
|
|
1909
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1908
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1910
1909
|
}
|
|
1911
1910
|
else {
|
|
1912
1911
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -1932,13 +1931,13 @@ export class SwitchBotPlatform {
|
|
|
1932
1931
|
// create the accessory handler for the newly create accessory
|
|
1933
1932
|
// this is imported from `platformAccessory.ts`
|
|
1934
1933
|
new IRFan(this, accessory, device);
|
|
1935
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1934
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1936
1935
|
// publish device externally or link the accessory to your platform
|
|
1937
1936
|
this.externalOrPlatformIR(device, accessory);
|
|
1938
1937
|
this.accessories.push(accessory);
|
|
1939
1938
|
}
|
|
1940
1939
|
else {
|
|
1941
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1940
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1942
1941
|
}
|
|
1943
1942
|
}
|
|
1944
1943
|
async createLight(device) {
|
|
@@ -1963,7 +1962,7 @@ export class SwitchBotPlatform {
|
|
|
1963
1962
|
// create the accessory handler for the restored accessory
|
|
1964
1963
|
// this is imported from `platformAccessory.ts`
|
|
1965
1964
|
new Light(this, existingAccessory, device);
|
|
1966
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1965
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1967
1966
|
}
|
|
1968
1967
|
else {
|
|
1969
1968
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -1989,13 +1988,13 @@ export class SwitchBotPlatform {
|
|
|
1989
1988
|
// create the accessory handler for the newly create accessory
|
|
1990
1989
|
// this is imported from `platformAccessory.ts`
|
|
1991
1990
|
new Light(this, accessory, device);
|
|
1992
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1991
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1993
1992
|
// publish device externally or link the accessory to your platform
|
|
1994
1993
|
this.externalOrPlatformIR(device, accessory);
|
|
1995
1994
|
this.accessories.push(accessory);
|
|
1996
1995
|
}
|
|
1997
1996
|
else {
|
|
1998
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1997
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1999
1998
|
}
|
|
2000
1999
|
}
|
|
2001
2000
|
async createAirConditioner(device) {
|
|
@@ -2020,7 +2019,7 @@ export class SwitchBotPlatform {
|
|
|
2020
2019
|
// create the accessory handler for the restored accessory
|
|
2021
2020
|
// this is imported from `platformAccessory.ts`
|
|
2022
2021
|
new AirConditioner(this, existingAccessory, device);
|
|
2023
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2022
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2024
2023
|
}
|
|
2025
2024
|
else {
|
|
2026
2025
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -2046,13 +2045,13 @@ export class SwitchBotPlatform {
|
|
|
2046
2045
|
// create the accessory handler for the newly create accessory
|
|
2047
2046
|
// this is imported from `platformAccessory.ts`
|
|
2048
2047
|
new AirConditioner(this, accessory, device);
|
|
2049
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2048
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2050
2049
|
// publish device externally or link the accessory to your platform
|
|
2051
2050
|
this.externalOrPlatformIR(device, accessory);
|
|
2052
2051
|
this.accessories.push(accessory);
|
|
2053
2052
|
}
|
|
2054
2053
|
else {
|
|
2055
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2054
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2056
2055
|
}
|
|
2057
2056
|
}
|
|
2058
2057
|
async createAirPurifier(device) {
|
|
@@ -2077,7 +2076,7 @@ export class SwitchBotPlatform {
|
|
|
2077
2076
|
// create the accessory handler for the restored accessory
|
|
2078
2077
|
// this is imported from `platformAccessory.ts`
|
|
2079
2078
|
new AirPurifier(this, existingAccessory, device);
|
|
2080
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2079
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2081
2080
|
}
|
|
2082
2081
|
else {
|
|
2083
2082
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -2103,13 +2102,13 @@ export class SwitchBotPlatform {
|
|
|
2103
2102
|
// create the accessory handler for the newly create accessory
|
|
2104
2103
|
// this is imported from `platformAccessory.ts`
|
|
2105
2104
|
new AirPurifier(this, accessory, device);
|
|
2106
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2105
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2107
2106
|
// publish device externally or link the accessory to your platform
|
|
2108
2107
|
this.externalOrPlatformIR(device, accessory);
|
|
2109
2108
|
this.accessories.push(accessory);
|
|
2110
2109
|
}
|
|
2111
2110
|
else {
|
|
2112
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2111
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2113
2112
|
}
|
|
2114
2113
|
}
|
|
2115
2114
|
async createWaterHeater(device) {
|
|
@@ -2134,7 +2133,7 @@ export class SwitchBotPlatform {
|
|
|
2134
2133
|
// create the accessory handler for the restored accessory
|
|
2135
2134
|
// this is imported from `platformAccessory.ts`
|
|
2136
2135
|
new WaterHeater(this, existingAccessory, device);
|
|
2137
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2136
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2138
2137
|
}
|
|
2139
2138
|
else {
|
|
2140
2139
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -2160,13 +2159,13 @@ export class SwitchBotPlatform {
|
|
|
2160
2159
|
// create the accessory handler for the newly create accessory
|
|
2161
2160
|
// this is imported from `platformAccessory.ts`
|
|
2162
2161
|
new WaterHeater(this, accessory, device);
|
|
2163
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2162
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2164
2163
|
// publish device externally or link the accessory to your platform
|
|
2165
2164
|
this.externalOrPlatformIR(device, accessory);
|
|
2166
2165
|
this.accessories.push(accessory);
|
|
2167
2166
|
}
|
|
2168
2167
|
else {
|
|
2169
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2168
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2170
2169
|
}
|
|
2171
2170
|
}
|
|
2172
2171
|
async createVacuumCleaner(device) {
|
|
@@ -2191,7 +2190,7 @@ export class SwitchBotPlatform {
|
|
|
2191
2190
|
// create the accessory handler for the restored accessory
|
|
2192
2191
|
// this is imported from `platformAccessory.ts`
|
|
2193
2192
|
new VacuumCleaner(this, existingAccessory, device);
|
|
2194
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2193
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2195
2194
|
}
|
|
2196
2195
|
else {
|
|
2197
2196
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -2217,13 +2216,13 @@ export class SwitchBotPlatform {
|
|
|
2217
2216
|
// create the accessory handler for the newly create accessory
|
|
2218
2217
|
// this is imported from `platformAccessory.ts`
|
|
2219
2218
|
new VacuumCleaner(this, accessory, device);
|
|
2220
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2219
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2221
2220
|
// publish device externally or link the accessory to your platform
|
|
2222
2221
|
this.externalOrPlatformIR(device, accessory);
|
|
2223
2222
|
this.accessories.push(accessory);
|
|
2224
2223
|
}
|
|
2225
2224
|
else {
|
|
2226
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2225
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2227
2226
|
}
|
|
2228
2227
|
}
|
|
2229
2228
|
async createCamera(device) {
|
|
@@ -2248,7 +2247,7 @@ export class SwitchBotPlatform {
|
|
|
2248
2247
|
// create the accessory handler for the restored accessory
|
|
2249
2248
|
// this is imported from `platformAccessory.ts`
|
|
2250
2249
|
new Camera(this, existingAccessory, device);
|
|
2251
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2250
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2252
2251
|
}
|
|
2253
2252
|
else {
|
|
2254
2253
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -2274,13 +2273,13 @@ export class SwitchBotPlatform {
|
|
|
2274
2273
|
// create the accessory handler for the newly create accessory
|
|
2275
2274
|
// this is imported from `platformAccessory.ts`
|
|
2276
2275
|
new Camera(this, accessory, device);
|
|
2277
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2276
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2278
2277
|
// publish device externally or link the accessory to your platform
|
|
2279
2278
|
this.externalOrPlatformIR(device, accessory);
|
|
2280
2279
|
this.accessories.push(accessory);
|
|
2281
2280
|
}
|
|
2282
2281
|
else {
|
|
2283
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2282
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2284
2283
|
}
|
|
2285
2284
|
}
|
|
2286
2285
|
async createOthers(device) {
|
|
@@ -2305,7 +2304,7 @@ export class SwitchBotPlatform {
|
|
|
2305
2304
|
// create the accessory handler for the restored accessory
|
|
2306
2305
|
// this is imported from `platformAccessory.ts`
|
|
2307
2306
|
new Others(this, existingAccessory, device);
|
|
2308
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2307
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2309
2308
|
}
|
|
2310
2309
|
else {
|
|
2311
2310
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -2331,61 +2330,78 @@ export class SwitchBotPlatform {
|
|
|
2331
2330
|
// create the accessory handler for the newly create accessory
|
|
2332
2331
|
// this is imported from `platformAccessory.ts`
|
|
2333
2332
|
new Others(this, accessory, device);
|
|
2334
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2333
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2335
2334
|
// publish device externally or link the accessory to your platform
|
|
2336
2335
|
this.externalOrPlatformIR(device, accessory);
|
|
2337
2336
|
this.accessories.push(accessory);
|
|
2338
2337
|
}
|
|
2339
2338
|
else {
|
|
2340
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2339
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
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
|
+
await this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds},`
|
|
2353
|
+
+ ` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group},`
|
|
2354
|
+
+ ` connectionType: ${device.connectionType}`);
|
|
2355
|
+
registerWindowCovering = await this.registerWindowCovering(device);
|
|
2356
|
+
}
|
|
2357
|
+
else if (isBlindTiltDevice(device)) {
|
|
2358
|
+
await this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, blindTiltDevicesIds: ${device.blindTiltDevicesIds},`
|
|
2359
|
+
+ ` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group},`
|
|
2360
|
+
+ ` connectionType: ${device.connectionType}`);
|
|
2361
|
+
registerWindowCovering = await this.registerWindowCovering(device);
|
|
2362
|
+
}
|
|
2363
|
+
else {
|
|
2364
|
+
registerWindowCovering = false;
|
|
2353
2365
|
}
|
|
2366
|
+
return registerWindowCovering;
|
|
2367
|
+
}
|
|
2368
|
+
async registerWindowCovering(device) {
|
|
2369
|
+
await this.debugLog(`master: ${device.master}`);
|
|
2354
2370
|
let registerCurtain;
|
|
2355
2371
|
if (device.master && device.group) {
|
|
2356
2372
|
// OpenAPI: Master Curtains/Blind Tilt in Group
|
|
2357
2373
|
registerCurtain = true;
|
|
2358
|
-
this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}
|
|
2359
|
-
+ ` connectionType; ${device.connectionType}`);
|
|
2360
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2374
|
+
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master},`
|
|
2375
|
+
+ ` device.group: ${device.group} connectionType; ${device.connectionType}`);
|
|
2376
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2361
2377
|
}
|
|
2362
2378
|
else if (!device.master && device.curtain?.disable_group) {
|
|
2363
2379
|
//!device.group && device.connectionType === 'BLE'
|
|
2364
2380
|
// OpenAPI: Non-Master Curtains/Blind Tilts that has Disable Grouping Checked
|
|
2365
2381
|
registerCurtain = true;
|
|
2366
|
-
this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, disable_group: `
|
|
2382
|
+
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, disable_group: `
|
|
2367
2383
|
+ `${device.curtain?.disable_group}, connectionType; ${device.connectionType}`);
|
|
2368
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2384
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2369
2385
|
}
|
|
2370
2386
|
else if (device.master && !device.group) {
|
|
2371
2387
|
// OpenAPI: Master Curtains/Blind Tilts not in Group
|
|
2372
2388
|
registerCurtain = true;
|
|
2373
|
-
this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}
|
|
2374
|
-
+ ` connectionType; ${device.connectionType}`);
|
|
2375
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2389
|
+
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master},`
|
|
2390
|
+
+ ` device.group: ${device.group} connectionType; ${device.connectionType}`);
|
|
2391
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2376
2392
|
}
|
|
2377
2393
|
else if (device.connectionType === 'BLE') {
|
|
2378
2394
|
// BLE: Curtains/Blind Tilt
|
|
2379
2395
|
registerCurtain = true;
|
|
2380
|
-
this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] connectionType: ${device.connectionType}, `
|
|
2396
|
+
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] connectionType: ${device.connectionType}, `
|
|
2381
2397
|
+ ` group: ${device.group}`);
|
|
2382
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2398
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2383
2399
|
}
|
|
2384
2400
|
else {
|
|
2385
2401
|
registerCurtain = false;
|
|
2386
|
-
this.debugErrorLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] disable_group: ${device.curtain?.disable_group},`
|
|
2402
|
+
await this.debugErrorLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] disable_group: ${device.curtain?.disable_group},`
|
|
2387
2403
|
+ ` device.master: ${device.master}, device.group: ${device.group}`);
|
|
2388
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}, device.connectionType: ${device.connectionType}`);
|
|
2404
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}, device.connectionType: ${device.connectionType}`);
|
|
2389
2405
|
}
|
|
2390
2406
|
return registerCurtain;
|
|
2391
2407
|
}
|
|
@@ -2408,17 +2424,17 @@ export class SwitchBotPlatform {
|
|
|
2408
2424
|
case 'Curtain3':
|
|
2409
2425
|
case 'Blind Tilt':
|
|
2410
2426
|
registerDevice = await this.registerCurtains(device);
|
|
2411
|
-
this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2427
|
+
await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2412
2428
|
break;
|
|
2413
2429
|
default:
|
|
2414
2430
|
registerDevice = true;
|
|
2415
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2431
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2416
2432
|
}
|
|
2417
2433
|
if (registerDevice === true) {
|
|
2418
|
-
this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
2434
|
+
await this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
2419
2435
|
}
|
|
2420
2436
|
else {
|
|
2421
|
-
this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2437
|
+
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2422
2438
|
}
|
|
2423
2439
|
}
|
|
2424
2440
|
else if (!device.hide_device && device.deviceId && device.configDeviceType && device.configDeviceName && device.connectionType === 'BLE') {
|
|
@@ -2427,17 +2443,17 @@ export class SwitchBotPlatform {
|
|
|
2427
2443
|
case 'Curtain3':
|
|
2428
2444
|
case 'Blind Tilt':
|
|
2429
2445
|
registerDevice = await this.registerCurtains(device);
|
|
2430
|
-
this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2446
|
+
await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2431
2447
|
break;
|
|
2432
2448
|
default:
|
|
2433
2449
|
registerDevice = true;
|
|
2434
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2450
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2435
2451
|
}
|
|
2436
2452
|
if (registerDevice === true) {
|
|
2437
|
-
this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
2453
|
+
await this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
2438
2454
|
}
|
|
2439
2455
|
else {
|
|
2440
|
-
this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2456
|
+
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2441
2457
|
}
|
|
2442
2458
|
}
|
|
2443
2459
|
else if (!device.hide_device && device.connectionType === 'OpenAPI') {
|
|
@@ -2446,17 +2462,17 @@ export class SwitchBotPlatform {
|
|
|
2446
2462
|
case 'Curtain3':
|
|
2447
2463
|
case 'Blind Tilt':
|
|
2448
2464
|
registerDevice = await this.registerCurtains(device);
|
|
2449
|
-
this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2465
|
+
await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2450
2466
|
break;
|
|
2451
2467
|
default:
|
|
2452
2468
|
registerDevice = true;
|
|
2453
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2469
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2454
2470
|
}
|
|
2455
2471
|
if (registerDevice === true) {
|
|
2456
|
-
this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
2472
|
+
await this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
2457
2473
|
}
|
|
2458
2474
|
else {
|
|
2459
|
-
this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2475
|
+
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2460
2476
|
}
|
|
2461
2477
|
}
|
|
2462
2478
|
else if (!device.hide_device && device.connectionType === 'Disabled') {
|
|
@@ -2465,25 +2481,25 @@ export class SwitchBotPlatform {
|
|
|
2465
2481
|
case 'Curtain3':
|
|
2466
2482
|
case 'Blind Tilt':
|
|
2467
2483
|
registerDevice = await this.registerCurtains(device);
|
|
2468
|
-
this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2484
|
+
await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2469
2485
|
break;
|
|
2470
2486
|
default:
|
|
2471
2487
|
registerDevice = true;
|
|
2472
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2488
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2473
2489
|
}
|
|
2474
|
-
this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will continue to display in HomeKit`);
|
|
2490
|
+
await this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will continue to display in HomeKit`);
|
|
2475
2491
|
}
|
|
2476
2492
|
else if (!device.connectionType && !device.hide_device) {
|
|
2477
2493
|
registerDevice = false;
|
|
2478
|
-
this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2494
|
+
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2479
2495
|
}
|
|
2480
2496
|
else if (device.hide_device) {
|
|
2481
2497
|
registerDevice = false;
|
|
2482
|
-
this.debugErrorLog(`Device: ${device.deviceName} hide_device: ${device.hide_device}, will not display in HomeKit`);
|
|
2498
|
+
await this.debugErrorLog(`Device: ${device.deviceName} hide_device: ${device.hide_device}, will not display in HomeKit`);
|
|
2483
2499
|
}
|
|
2484
2500
|
else {
|
|
2485
2501
|
registerDevice = false;
|
|
2486
|
-
this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, hide_device: `
|
|
2502
|
+
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, hide_device: `
|
|
2487
2503
|
+ `${device.hide_device}, will not display in HomeKit`);
|
|
2488
2504
|
}
|
|
2489
2505
|
return registerDevice;
|
|
@@ -2495,21 +2511,21 @@ export class SwitchBotPlatform {
|
|
|
2495
2511
|
* publish your TV as an external accessory.
|
|
2496
2512
|
*/
|
|
2497
2513
|
if (device.external) {
|
|
2498
|
-
this.debugWarnLog(`${accessory.displayName} External Accessory Mode`);
|
|
2514
|
+
await this.debugWarnLog(`${accessory.displayName} External Accessory Mode`);
|
|
2499
2515
|
this.externalAccessory(accessory);
|
|
2500
2516
|
}
|
|
2501
2517
|
else {
|
|
2502
|
-
this.debugLog(`${accessory.displayName} External Accessory Mode: ${device.external}`);
|
|
2518
|
+
await this.debugLog(`${accessory.displayName} External Accessory Mode: ${device.external}`);
|
|
2503
2519
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
2504
2520
|
}
|
|
2505
2521
|
}
|
|
2506
2522
|
async externalOrPlatform(device, accessory) {
|
|
2507
2523
|
if (device.external) {
|
|
2508
|
-
this.debugWarnLog(`${accessory.displayName} External Accessory Mode`);
|
|
2509
|
-
this.externalAccessory(accessory);
|
|
2524
|
+
await this.debugWarnLog(`${accessory.displayName} External Accessory Mode`);
|
|
2525
|
+
await this.externalAccessory(accessory);
|
|
2510
2526
|
}
|
|
2511
2527
|
else {
|
|
2512
|
-
this.debugLog(`${accessory.displayName} External Accessory Mode: ${device.external}`);
|
|
2528
|
+
await this.debugLog(`${accessory.displayName} External Accessory Mode: ${device.external}`);
|
|
2513
2529
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
2514
2530
|
}
|
|
2515
2531
|
}
|
|
@@ -2524,67 +2540,67 @@ export class SwitchBotPlatform {
|
|
|
2524
2540
|
async statusCode(statusCode) {
|
|
2525
2541
|
switch (statusCode) {
|
|
2526
2542
|
case 151:
|
|
2527
|
-
this.errorLog(`Command not supported by this device type, statusCode: ${statusCode}, Submit Feature Request Here: ` +
|
|
2543
|
+
await this.errorLog(`Command not supported by this device type, statusCode: ${statusCode}, Submit Feature Request Here: ` +
|
|
2528
2544
|
'https://tinyurl.com/SwitchBotFeatureRequest');
|
|
2529
2545
|
break;
|
|
2530
2546
|
case 152:
|
|
2531
|
-
this.errorLog(`Device not found, statusCode: ${statusCode}`);
|
|
2547
|
+
await this.errorLog(`Device not found, statusCode: ${statusCode}`);
|
|
2532
2548
|
break;
|
|
2533
2549
|
case 160:
|
|
2534
|
-
this.errorLog(`Command is not supported, statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`);
|
|
2550
|
+
await this.errorLog(`Command is not supported, statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`);
|
|
2535
2551
|
break;
|
|
2536
2552
|
case 161:
|
|
2537
|
-
this.errorLog(`Device is offline, statusCode: ${statusCode}`);
|
|
2553
|
+
await this.errorLog(`Device is offline, statusCode: ${statusCode}`);
|
|
2538
2554
|
break;
|
|
2539
2555
|
case 171:
|
|
2540
|
-
this.errorLog(`is offline, statusCode: ${statusCode}`);
|
|
2556
|
+
await this.errorLog(`is offline, statusCode: ${statusCode}`);
|
|
2541
2557
|
break;
|
|
2542
2558
|
case 190:
|
|
2543
|
-
this.errorLog(`Requests reached the daily limit, statusCode: ${statusCode}`);
|
|
2559
|
+
await this.errorLog(`Requests reached the daily limit, statusCode: ${statusCode}`);
|
|
2544
2560
|
break;
|
|
2545
2561
|
case 100:
|
|
2546
|
-
this.debugLog(`Command successfully sent, statusCode: ${statusCode}`);
|
|
2562
|
+
await await this.debugLog(`Command successfully sent, statusCode: ${statusCode}`);
|
|
2547
2563
|
break;
|
|
2548
2564
|
case 200:
|
|
2549
|
-
this.debugLog(`Request successful, statusCode: ${statusCode}`);
|
|
2565
|
+
await await this.debugLog(`Request successful, statusCode: ${statusCode}`);
|
|
2550
2566
|
break;
|
|
2551
2567
|
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 '
|
|
2568
|
+
await this.errorLog('Bad Request, The client has issued an invalid request. This is commonly used to specify validation errors in a request '
|
|
2553
2569
|
+ `payload, statusCode: ${statusCode}`);
|
|
2554
2570
|
break;
|
|
2555
2571
|
case 401:
|
|
2556
|
-
this.errorLog('Unauthorized, Authorization for the API is required, but the request has not been authenticated, '
|
|
2572
|
+
await this.errorLog('Unauthorized, Authorization for the API is required, but the request has not been authenticated, '
|
|
2557
2573
|
+ `statusCode: ${statusCode}`);
|
|
2558
2574
|
break;
|
|
2559
2575
|
case 403:
|
|
2560
|
-
this.errorLog('Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not '
|
|
2576
|
+
await this.errorLog('Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not '
|
|
2561
2577
|
+ `found, statusCode: ${statusCode}`);
|
|
2562
2578
|
break;
|
|
2563
2579
|
case 404:
|
|
2564
|
-
this.errorLog(`Not Found, Specifies the requested path does not exist, statusCode: ${statusCode}`);
|
|
2580
|
+
await this.errorLog(`Not Found, Specifies the requested path does not exist, statusCode: ${statusCode}`);
|
|
2565
2581
|
break;
|
|
2566
2582
|
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, '
|
|
2583
|
+
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
2584
|
+ `statusCode: ${statusCode}`);
|
|
2569
2585
|
break;
|
|
2570
2586
|
case 415:
|
|
2571
|
-
this.errorLog('Unsupported Media Type, The client has defined a contentType header that is not supported by the server, '
|
|
2587
|
+
await this.errorLog('Unsupported Media Type, The client has defined a contentType header that is not supported by the server, '
|
|
2572
2588
|
+ `statusCode: ${statusCode}`);
|
|
2573
2589
|
break;
|
|
2574
2590
|
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 '
|
|
2591
|
+
await this.errorLog('Unprocessable Entity, The client has made a valid request, but the server cannot process it. This is often used for '
|
|
2576
2592
|
+ `APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
2577
2593
|
break;
|
|
2578
2594
|
case 429:
|
|
2579
|
-
this.errorLog('Too Many Requests, The client has exceeded the number of requests allowed for a given time window, '
|
|
2595
|
+
await this.errorLog('Too Many Requests, The client has exceeded the number of requests allowed for a given time window, '
|
|
2580
2596
|
+ `statusCode: ${statusCode}`);
|
|
2581
2597
|
break;
|
|
2582
2598
|
case 500:
|
|
2583
|
-
this.errorLog('Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, '
|
|
2599
|
+
await this.errorLog('Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, '
|
|
2584
2600
|
+ `statusCode: ${statusCode}`);
|
|
2585
2601
|
break;
|
|
2586
2602
|
default:
|
|
2587
|
-
this.errorLog(`Unknown statusCode, statusCode: ${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
2603
|
+
await this.errorLog(`Unknown statusCode, statusCode: ${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
2588
2604
|
}
|
|
2589
2605
|
}
|
|
2590
2606
|
async retryRequest(deviceMaxRetries, deviceDelayBetweenRetries, url, options) {
|
|
@@ -2598,34 +2614,35 @@ export class SwitchBotPlatform {
|
|
|
2598
2614
|
return { body, statusCode };
|
|
2599
2615
|
}
|
|
2600
2616
|
else {
|
|
2601
|
-
this.debugLog(`Received status code: ${statusCode}`);
|
|
2617
|
+
await await this.debugLog(`Received status code: ${statusCode}`);
|
|
2602
2618
|
}
|
|
2603
2619
|
}
|
|
2604
2620
|
catch (error) {
|
|
2605
|
-
this.errorLog(`Error making request: ${error.message}`);
|
|
2621
|
+
await this.errorLog(`Error making request: ${error.message}`);
|
|
2606
2622
|
}
|
|
2607
2623
|
retryCount++;
|
|
2608
|
-
this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`);
|
|
2624
|
+
await await this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`);
|
|
2609
2625
|
await sleep(delayBetweenRetries);
|
|
2610
2626
|
}
|
|
2611
2627
|
return { body: null, statusCode: -1 };
|
|
2612
2628
|
}
|
|
2613
2629
|
// BLE Connection
|
|
2614
|
-
async connectBLE() {
|
|
2630
|
+
async connectBLE(accessory, device) {
|
|
2615
2631
|
let switchbot;
|
|
2616
2632
|
try {
|
|
2617
2633
|
const SwitchBot = (await import('node-switchbot')).SwitchBot;
|
|
2618
2634
|
queueScheduler.schedule(() => (switchbot = new SwitchBot()));
|
|
2635
|
+
await await this.debugLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${switchbot}`);
|
|
2619
2636
|
}
|
|
2620
2637
|
catch (e) {
|
|
2621
2638
|
switchbot = false;
|
|
2622
|
-
this.errorLog(
|
|
2639
|
+
await this.errorLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${switchbot}, Error: ${e}`);
|
|
2623
2640
|
}
|
|
2624
2641
|
return switchbot;
|
|
2625
2642
|
}
|
|
2626
2643
|
async getVersion() {
|
|
2627
2644
|
const json = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
|
|
2628
|
-
this.debugLog(`Plugin Version: ${json.version}`);
|
|
2645
|
+
await await this.debugLog(`Plugin Version: ${json.version}`);
|
|
2629
2646
|
this.version = json.version;
|
|
2630
2647
|
}
|
|
2631
2648
|
async getPlatformConfigSettings() {
|
|
@@ -2662,7 +2679,7 @@ export class SwitchBotPlatform {
|
|
|
2662
2679
|
platformConfig.delayBetweenRetries = this.delayBetweenRetries / 1000;
|
|
2663
2680
|
}
|
|
2664
2681
|
if (Object.entries(platformConfig).length !== 0) {
|
|
2665
|
-
this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
2682
|
+
await await this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
2666
2683
|
}
|
|
2667
2684
|
this.platformConfig = platformConfig;
|
|
2668
2685
|
}
|
|
@@ -2671,64 +2688,64 @@ export class SwitchBotPlatform {
|
|
|
2671
2688
|
this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
|
|
2672
2689
|
if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
|
|
2673
2690
|
this.platformLogging = this.config.options.logging;
|
|
2674
|
-
this.debugWarnLog(`Using Config Logging: ${this.platformLogging}`);
|
|
2691
|
+
await await this.debugWarnLog(`Using Config Logging: ${this.platformLogging}`);
|
|
2675
2692
|
}
|
|
2676
2693
|
else if (this.debugMode) {
|
|
2677
2694
|
this.platformLogging = 'debugMode';
|
|
2678
|
-
this.debugWarnLog(`Using ${this.platformLogging} Logging`);
|
|
2695
|
+
await await this.debugWarnLog(`Using ${this.platformLogging} Logging`);
|
|
2679
2696
|
}
|
|
2680
2697
|
else {
|
|
2681
2698
|
this.platformLogging = 'standard';
|
|
2682
|
-
this.debugWarnLog(`Using ${this.platformLogging} Logging`);
|
|
2699
|
+
await await this.debugWarnLog(`Using ${this.platformLogging} Logging`);
|
|
2683
2700
|
}
|
|
2684
2701
|
}
|
|
2685
2702
|
/**
|
|
2686
2703
|
* If device level logging is turned on, log to log.warn
|
|
2687
2704
|
* Otherwise send debug logs to log.debug
|
|
2688
2705
|
*/
|
|
2689
|
-
infoLog(...log) {
|
|
2690
|
-
if (this.enablingPlatformLogging()) {
|
|
2706
|
+
async infoLog(...log) {
|
|
2707
|
+
if (await this.enablingPlatformLogging()) {
|
|
2691
2708
|
this.log.info(String(...log));
|
|
2692
2709
|
}
|
|
2693
2710
|
}
|
|
2694
|
-
successLog(...log) {
|
|
2695
|
-
if (this.enablingPlatformLogging()) {
|
|
2711
|
+
async successLog(...log) {
|
|
2712
|
+
if (await this.enablingPlatformLogging()) {
|
|
2696
2713
|
this.log.success(String(...log));
|
|
2697
2714
|
}
|
|
2698
2715
|
}
|
|
2699
|
-
debugSuccessLog(...log) {
|
|
2700
|
-
if (this.enablingPlatformLogging()) {
|
|
2716
|
+
async debugSuccessLog(...log) {
|
|
2717
|
+
if (await this.enablingPlatformLogging()) {
|
|
2701
2718
|
if (this.platformLogging?.includes('debug')) {
|
|
2702
2719
|
this.log.success('[DEBUG]', String(...log));
|
|
2703
2720
|
}
|
|
2704
2721
|
}
|
|
2705
2722
|
}
|
|
2706
|
-
warnLog(...log) {
|
|
2707
|
-
if (this.enablingPlatformLogging()) {
|
|
2723
|
+
async warnLog(...log) {
|
|
2724
|
+
if (await this.enablingPlatformLogging()) {
|
|
2708
2725
|
this.log.warn(String(...log));
|
|
2709
2726
|
}
|
|
2710
2727
|
}
|
|
2711
|
-
debugWarnLog(...log) {
|
|
2712
|
-
if (this.enablingPlatformLogging()) {
|
|
2728
|
+
async debugWarnLog(...log) {
|
|
2729
|
+
if (await this.enablingPlatformLogging()) {
|
|
2713
2730
|
if (this.platformLogging?.includes('debug')) {
|
|
2714
2731
|
this.log.warn('[DEBUG]', String(...log));
|
|
2715
2732
|
}
|
|
2716
2733
|
}
|
|
2717
2734
|
}
|
|
2718
|
-
errorLog(...log) {
|
|
2719
|
-
if (this.enablingPlatformLogging()) {
|
|
2735
|
+
async errorLog(...log) {
|
|
2736
|
+
if (await this.enablingPlatformLogging()) {
|
|
2720
2737
|
this.log.error(String(...log));
|
|
2721
2738
|
}
|
|
2722
2739
|
}
|
|
2723
|
-
debugErrorLog(...log) {
|
|
2724
|
-
if (this.enablingPlatformLogging()) {
|
|
2740
|
+
async debugErrorLog(...log) {
|
|
2741
|
+
if (await this.enablingPlatformLogging()) {
|
|
2725
2742
|
if (this.platformLogging?.includes('debug')) {
|
|
2726
2743
|
this.log.error('[DEBUG]', String(...log));
|
|
2727
2744
|
}
|
|
2728
2745
|
}
|
|
2729
2746
|
}
|
|
2730
|
-
debugLog(...log) {
|
|
2731
|
-
if (this.enablingPlatformLogging()) {
|
|
2747
|
+
async debugLog(...log) {
|
|
2748
|
+
if (await this.enablingPlatformLogging()) {
|
|
2732
2749
|
if (this.platformLogging === 'debugMode') {
|
|
2733
2750
|
this.log.debug(String(...log));
|
|
2734
2751
|
}
|
|
@@ -2737,7 +2754,7 @@ export class SwitchBotPlatform {
|
|
|
2737
2754
|
}
|
|
2738
2755
|
}
|
|
2739
2756
|
}
|
|
2740
|
-
enablingPlatformLogging() {
|
|
2757
|
+
async enablingPlatformLogging() {
|
|
2741
2758
|
return this.platformLogging?.includes('debug') || this.platformLogging === 'standard';
|
|
2742
2759
|
}
|
|
2743
2760
|
}
|