@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/src/platform.ts
CHANGED
|
@@ -34,21 +34,23 @@ import { AirConditioner } from './irdevice/airconditioner.js';
|
|
|
34
34
|
import { Buffer } from 'buffer';
|
|
35
35
|
import { request } from 'undici';
|
|
36
36
|
import asyncmqtt from 'async-mqtt';
|
|
37
|
-
import { sleep } from './utils.js';
|
|
38
37
|
import { createServer } from 'http';
|
|
39
38
|
import { queueScheduler } from 'rxjs';
|
|
40
39
|
import fakegato from 'fakegato-history';
|
|
41
40
|
import crypto, { randomUUID } from 'crypto';
|
|
42
41
|
import { readFileSync, writeFileSync } from 'fs';
|
|
43
42
|
import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes';
|
|
43
|
+
import { isBlindTiltDevice, isCurtainDevice, sleep } from './utils.js';
|
|
44
44
|
import { PLATFORM_NAME, PLUGIN_NAME, Devices, setupWebhook, updateWebhook, deleteWebhook, queryWebhook } from './settings.js';
|
|
45
45
|
|
|
46
46
|
import type { UrlObject } from 'url';
|
|
47
47
|
import type { MqttClient } from 'mqtt';
|
|
48
48
|
import type { Dispatcher } from 'undici';
|
|
49
|
+
import type { irdevice } from './types/irdevicelist.js';
|
|
49
50
|
import type { Server, IncomingMessage, ServerResponse } from 'http';
|
|
51
|
+
import type { blindTilt, curtain, curtain3, device } from './types/devicelist.js';
|
|
50
52
|
import type { API, DynamicPlatformPlugin, Logging, PlatformAccessory } from 'homebridge';
|
|
51
|
-
import type {
|
|
53
|
+
import type { SwitchBotPlatformConfig, devicesConfig, irDevicesConfig } from './settings.js';
|
|
52
54
|
|
|
53
55
|
/**
|
|
54
56
|
* HomebridgePlatform
|
|
@@ -74,7 +76,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
74
76
|
|
|
75
77
|
public readonly fakegatoAPI: any;
|
|
76
78
|
public readonly eve: any;
|
|
77
|
-
public readonly webhookEventHandler: { [x: string]: (context:
|
|
79
|
+
public readonly webhookEventHandler: { [x: string]: (context: any) => void } = {};
|
|
78
80
|
|
|
79
81
|
constructor(
|
|
80
82
|
log: Logging,
|
|
@@ -139,7 +141,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
139
141
|
}
|
|
140
142
|
} catch (e: any) {
|
|
141
143
|
this.errorLog(`Failed to Discover, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
142
|
-
this.debugErrorLog(`Failed to Discover, Error: ${e}`);
|
|
144
|
+
await this.debugErrorLog(`Failed to Discover, Error: ${e}`);
|
|
143
145
|
}
|
|
144
146
|
});
|
|
145
147
|
|
|
@@ -152,27 +154,27 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
152
154
|
try {
|
|
153
155
|
const { connectAsync } = asyncmqtt;
|
|
154
156
|
this.mqttClient = await connectAsync(this.config.options?.mqttURL, this.config.options.mqttOptions || {});
|
|
155
|
-
this.debugLog('MQTT connection has been established successfully.');
|
|
156
|
-
this.mqttClient.on('error', (e: Error) => {
|
|
157
|
-
this.errorLog(`Failed to publish MQTT messages. ${e}`);
|
|
157
|
+
await this.debugLog('MQTT connection has been established successfully.');
|
|
158
|
+
this.mqttClient.on('error', async (e: Error) => {
|
|
159
|
+
await this.errorLog(`Failed to publish MQTT messages. ${e}`);
|
|
158
160
|
});
|
|
159
161
|
if (!this.config.options?.webhookURL) {
|
|
160
162
|
// receive webhook events via MQTT
|
|
161
|
-
this.infoLog(`Webhook is configured to be received through ${this.config.options.mqttURL}/homebridge-switchbot/webhook.`);
|
|
163
|
+
await this.infoLog(`Webhook is configured to be received through ${this.config.options.mqttURL}/homebridge-switchbot/webhook.`);
|
|
162
164
|
this.mqttClient.subscribe('homebridge-switchbot/webhook/+');
|
|
163
165
|
this.mqttClient.on('message', async (topic: string, message) => {
|
|
164
166
|
try {
|
|
165
|
-
this.debugLog(`Received Webhook via MQTT: ${topic}=${message}`);
|
|
167
|
+
await await this.debugLog(`Received Webhook via MQTT: ${topic}=${message}`);
|
|
166
168
|
const context = JSON.parse(message.toString());
|
|
167
|
-
|
|
169
|
+
this.webhookEventHandler[context.deviceMac]?.(context);
|
|
168
170
|
} catch (e: any) {
|
|
169
|
-
this.errorLog(`Failed to handle webhook event. Error:${e}`);
|
|
171
|
+
await this.errorLog(`Failed to handle webhook event. Error:${e}`);
|
|
170
172
|
}
|
|
171
173
|
});
|
|
172
174
|
}
|
|
173
175
|
} catch (e) {
|
|
174
176
|
this.mqttClient = null;
|
|
175
|
-
this.errorLog(`Failed to establish MQTT connection. ${e}`);
|
|
177
|
+
await this.errorLog(`Failed to establish MQTT connection. ${e}`);
|
|
176
178
|
}
|
|
177
179
|
}
|
|
178
180
|
}
|
|
@@ -192,7 +194,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
192
194
|
request.on('data', async (data) => {
|
|
193
195
|
try {
|
|
194
196
|
const body = JSON.parse(data);
|
|
195
|
-
this.debugLog(`Received Webhook: ${JSON.stringify(body)}`);
|
|
197
|
+
await this.debugLog(`Received Webhook: ${JSON.stringify(body)}`);
|
|
196
198
|
if (this.config.options?.mqttURL) {
|
|
197
199
|
const mac = body.context.deviceMac
|
|
198
200
|
?.toLowerCase()
|
|
@@ -201,7 +203,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
201
203
|
const options = this.config.options?.mqttPubOptions || {};
|
|
202
204
|
this.mqttClient?.publish(`homebridge-switchbot/webhook/${mac}`, `${JSON.stringify(body.context)}`, options);
|
|
203
205
|
}
|
|
204
|
-
|
|
206
|
+
this.webhookEventHandler[body.context.deviceMac]?.(body.context);
|
|
205
207
|
} catch (e: any) {
|
|
206
208
|
this.errorLog(`Failed to handle webhook event. Error:${e}`);
|
|
207
209
|
}
|
|
@@ -233,9 +235,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
233
235
|
}),
|
|
234
236
|
});
|
|
235
237
|
const response: any = await body.json();
|
|
236
|
-
this.debugLog(`setupWebhook: url:${url}`);
|
|
237
|
-
this.debugLog(`setupWebhook: body:${JSON.stringify(response)}`);
|
|
238
|
-
this.debugLog(`setupWebhook: statusCode:${statusCode}`);
|
|
238
|
+
await this.debugLog(`setupWebhook: url:${url}`);
|
|
239
|
+
await this.debugLog(`setupWebhook: body:${JSON.stringify(response)}`);
|
|
240
|
+
await this.debugLog(`setupWebhook: statusCode:${statusCode}`);
|
|
239
241
|
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
240
242
|
this.errorLog(`Failed to configure webhook. Existing webhook well be overridden. HTTP:${statusCode} API:${response?.statusCode} `
|
|
241
243
|
+ `message:${response?.message}`);
|
|
@@ -255,9 +257,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
255
257
|
}),
|
|
256
258
|
});
|
|
257
259
|
const response: any = await body.json();
|
|
258
|
-
this.debugLog(`updateWebhook: url:${url}`);
|
|
259
|
-
this.debugLog(`updateWebhook: body:${JSON.stringify(response)}`);
|
|
260
|
-
this.debugLog(`updateWebhook: statusCode:${statusCode}`);
|
|
260
|
+
await this.debugLog(`updateWebhook: url:${url}`);
|
|
261
|
+
await this.debugLog(`updateWebhook: body:${JSON.stringify(response)}`);
|
|
262
|
+
await this.debugLog(`updateWebhook: statusCode:${statusCode}`);
|
|
261
263
|
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
262
264
|
this.errorLog(`Failed to update webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
|
|
263
265
|
}
|
|
@@ -274,8 +276,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
274
276
|
}),
|
|
275
277
|
});
|
|
276
278
|
const response: any = await body.json();
|
|
277
|
-
this.debugLog(`queryWebhook: body:${JSON.stringify(response)}`);
|
|
278
|
-
this.debugLog(`queryWebhook: statusCode:${statusCode}`);
|
|
279
|
+
await this.debugLog(`queryWebhook: body:${JSON.stringify(response)}`);
|
|
280
|
+
await this.debugLog(`queryWebhook: statusCode:${statusCode}`);
|
|
279
281
|
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
280
282
|
this.errorLog(`Failed to query webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
|
|
281
283
|
} else {
|
|
@@ -296,9 +298,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
296
298
|
}),
|
|
297
299
|
});
|
|
298
300
|
const response: any = await body.json();
|
|
299
|
-
this.debugLog(`deleteWebhook: url:${url}`);
|
|
300
|
-
this.debugLog(`deleteWebhook: body:${JSON.stringify(response)}`);
|
|
301
|
-
this.debugLog(`deleteWebhook: statusCode:${statusCode}`);
|
|
301
|
+
await this.debugLog(`deleteWebhook: url:${url}, body:${JSON.stringify(response)}, statusCode:${statusCode}`);
|
|
302
302
|
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
303
303
|
this.errorLog(`Failed to delete webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
|
|
304
304
|
} else {
|
|
@@ -315,8 +315,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
315
315
|
* This function is invoked when homebridge restores cached accessories from disk at startup.
|
|
316
316
|
* It should be used to setup event handlers for characteristics and update respective values.
|
|
317
317
|
*/
|
|
318
|
-
configureAccessory(accessory: PlatformAccessory) {
|
|
319
|
-
this.debugLog(`Loading accessory from cache: ${accessory.displayName}`);
|
|
318
|
+
async configureAccessory(accessory: PlatformAccessory) {
|
|
319
|
+
await this.debugLog(`Loading accessory from cache: ${accessory.displayName}`);
|
|
320
320
|
|
|
321
321
|
// add the restored accessory to the accessories cache so we can track if it has already been registered
|
|
322
322
|
this.accessories.push(accessory);
|
|
@@ -341,7 +341,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
341
341
|
platformConfig['pushRate'] = this.config.options.pushRate;
|
|
342
342
|
}
|
|
343
343
|
if (Object.entries(platformConfig).length !== 0) {
|
|
344
|
-
this.debugWarnLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
344
|
+
await this.debugWarnLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
345
345
|
}
|
|
346
346
|
|
|
347
347
|
if (this.config.options) {
|
|
@@ -468,7 +468,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
468
468
|
pluginConfig.credentials.openToken = undefined;
|
|
469
469
|
}
|
|
470
470
|
|
|
471
|
-
this.debugWarnLog(`token: ${pluginConfig.credentials.token}`);
|
|
471
|
+
await this.debugWarnLog(`token: ${pluginConfig.credentials.token}`);
|
|
472
472
|
|
|
473
473
|
// save the config, ensuring we maintain pretty json
|
|
474
474
|
writeFileSync(this.api.user.configPath(), JSON.stringify(currentConfig, null, 4));
|
|
@@ -511,29 +511,29 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
511
511
|
let retryCount = 0;
|
|
512
512
|
const maxRetries = this.maxRetries; // Maximum number of retries
|
|
513
513
|
const delayBetweenRetries = this.delayBetweenRetries; // Delay between retries in milliseconds
|
|
514
|
-
this.debugWarnLog(`Retry Count: ${retryCount}`);
|
|
515
|
-
this.debugWarnLog(`Max Retries: ${maxRetries}`);
|
|
516
|
-
this.debugWarnLog(`Delay Between Retries: ${delayBetweenRetries}`);
|
|
514
|
+
await this.debugWarnLog(`Retry Count: ${retryCount}`);
|
|
515
|
+
await this.debugWarnLog(`Max Retries: ${maxRetries}`);
|
|
516
|
+
await this.debugWarnLog(`Delay Between Retries: ${delayBetweenRetries}`);
|
|
517
517
|
while (retryCount < maxRetries) {
|
|
518
518
|
try {
|
|
519
519
|
const { body, statusCode } = await request(Devices, {
|
|
520
520
|
headers: this.generateHeaders(),
|
|
521
521
|
});
|
|
522
|
-
this.debugWarnLog(`statusCode: ${statusCode}`);
|
|
522
|
+
await this.debugWarnLog(`statusCode: ${statusCode}`);
|
|
523
523
|
const devicesAPI: any = await body.json();
|
|
524
|
-
this.debugWarnLog(`devicesAPI: ${JSON.stringify(devicesAPI)}`);
|
|
525
|
-
this.debugWarnLog(`devicesAPI Body: ${JSON.stringify(devicesAPI.body)}`);
|
|
526
|
-
this.debugWarnLog(`devicesAPI StatusCode: ${devicesAPI.statusCode}`);
|
|
524
|
+
await this.debugWarnLog(`devicesAPI: ${JSON.stringify(devicesAPI)}`);
|
|
525
|
+
await this.debugWarnLog(`devicesAPI Body: ${JSON.stringify(devicesAPI.body)}`);
|
|
526
|
+
await this.debugWarnLog(`devicesAPI StatusCode: ${devicesAPI.statusCode}`);
|
|
527
527
|
if ((statusCode === 200 || statusCode === 100) && (devicesAPI.statusCode === 200 || devicesAPI.statusCode === 100)) {
|
|
528
|
-
this.debugErrorLog(`statusCode: ${statusCode} & devicesAPI StatusCode: ${devicesAPI.statusCode}`);
|
|
528
|
+
await this.debugErrorLog(`statusCode: ${statusCode} & devicesAPI StatusCode: ${devicesAPI.statusCode}`);
|
|
529
529
|
// SwitchBot Devices
|
|
530
530
|
const deviceLists = devicesAPI.body.deviceList;
|
|
531
|
-
this.debugWarnLog(`DeviceLists: ${JSON.stringify(deviceLists)}`);
|
|
532
|
-
this.debugWarnLog(`DeviceLists Length: ${deviceLists.length}`);
|
|
531
|
+
await this.debugWarnLog(`DeviceLists: ${JSON.stringify(deviceLists)}`);
|
|
532
|
+
await this.debugWarnLog(`DeviceLists Length: ${deviceLists.length}`);
|
|
533
533
|
if (!this.config.options?.devices) {
|
|
534
|
-
this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
534
|
+
await this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
535
535
|
if (deviceLists.length === 0) {
|
|
536
|
-
this.debugLog(`SwitchBot API
|
|
536
|
+
await this.debugLog(`SwitchBot API Has No Devices With Cloud Services Enabled: ${JSON.stringify(devicesAPI.body)}`);
|
|
537
537
|
} else {
|
|
538
538
|
const devices = deviceLists.map((v: any) => v);
|
|
539
539
|
for (const device of devices) {
|
|
@@ -546,9 +546,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
546
546
|
}
|
|
547
547
|
}
|
|
548
548
|
} else if (this.config.credentials?.token && this.config.options.devices) {
|
|
549
|
-
this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
549
|
+
await this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
550
550
|
if (deviceLists.length === 0) {
|
|
551
|
-
this.debugLog(`SwitchBot API
|
|
551
|
+
await this.debugLog(`SwitchBot API Has No Devices With Cloud Services Enabled: ${JSON.stringify(devicesAPI.body)}`);
|
|
552
552
|
} else {
|
|
553
553
|
const deviceConfigs = this.config.options?.devices;
|
|
554
554
|
|
|
@@ -562,7 +562,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
562
562
|
}));
|
|
563
563
|
|
|
564
564
|
const devices = mergeBydeviceId(deviceLists, deviceConfigs);
|
|
565
|
-
this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
|
|
565
|
+
await this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
|
|
566
566
|
for (const device of devices) {
|
|
567
567
|
if (!device.deviceType) {
|
|
568
568
|
device.deviceType = device.configDeviceType;
|
|
@@ -582,13 +582,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
582
582
|
if (devicesAPI.body.deviceList.length !== 0) {
|
|
583
583
|
this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
584
584
|
} else {
|
|
585
|
-
this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
585
|
+
await this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
586
586
|
}
|
|
587
587
|
|
|
588
588
|
// IR Devices
|
|
589
589
|
const irDeviceLists = devicesAPI.body.infraredRemoteList;
|
|
590
590
|
if (!this.config.options?.irdevices) {
|
|
591
|
-
this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
591
|
+
await this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
592
592
|
const devices = irDeviceLists.map((v: any) => v);
|
|
593
593
|
for (const device of devices) {
|
|
594
594
|
if (device.remoteType) {
|
|
@@ -596,7 +596,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
596
596
|
}
|
|
597
597
|
}
|
|
598
598
|
} else {
|
|
599
|
-
this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
599
|
+
await this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
600
600
|
const irDeviceConfig = this.config.options?.irdevices;
|
|
601
601
|
|
|
602
602
|
const mergeIRBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
|
|
@@ -609,7 +609,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
609
609
|
}));
|
|
610
610
|
|
|
611
611
|
const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
|
|
612
|
-
this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
|
|
612
|
+
await this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
|
|
613
613
|
for (const device of devices) {
|
|
614
614
|
this.createIRDevice(device);
|
|
615
615
|
}
|
|
@@ -617,7 +617,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
617
617
|
if (devicesAPI.body.infraredRemoteList.length !== 0) {
|
|
618
618
|
this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
619
619
|
} else {
|
|
620
|
-
this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
620
|
+
await this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
621
621
|
}
|
|
622
622
|
break;
|
|
623
623
|
} else {
|
|
@@ -633,11 +633,11 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
633
633
|
retryCount++;
|
|
634
634
|
this.debugErrorLog(
|
|
635
635
|
`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
636
|
-
this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
|
|
636
|
+
await this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
|
|
637
637
|
}
|
|
638
638
|
}
|
|
639
639
|
} else if (!this.config.credentials?.token && this.config.options?.devices) {
|
|
640
|
-
this.debugLog(`SwitchBot Device Manual Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
640
|
+
await this.debugLog(`SwitchBot Device Manual Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
641
641
|
const deviceConfigs = this.config.options?.devices;
|
|
642
642
|
const devices = deviceConfigs.map((v: any) => v);
|
|
643
643
|
for (const device of devices) {
|
|
@@ -652,73 +652,73 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
652
652
|
}
|
|
653
653
|
}
|
|
654
654
|
|
|
655
|
-
private createDevice(device: device & devicesConfig) {
|
|
655
|
+
private async createDevice(device: device & devicesConfig) {
|
|
656
656
|
switch (device.deviceType!) {
|
|
657
657
|
case 'Humidifier':
|
|
658
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
658
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
659
659
|
this.createHumidifier(device);
|
|
660
660
|
break;
|
|
661
661
|
case 'Hub Mini':
|
|
662
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
662
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
663
663
|
break;
|
|
664
664
|
case 'Hub Plus':
|
|
665
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
665
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
666
666
|
break;
|
|
667
667
|
case 'Hub 2':
|
|
668
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
668
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
669
669
|
this.createHub2(device);
|
|
670
670
|
break;
|
|
671
671
|
case 'Bot':
|
|
672
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
672
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
673
673
|
this.createBot(device);
|
|
674
674
|
break;
|
|
675
675
|
case 'Meter':
|
|
676
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
676
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
677
677
|
this.createMeter(device);
|
|
678
678
|
break;
|
|
679
679
|
case 'MeterPlus':
|
|
680
680
|
case 'Meter Plus (JP)':
|
|
681
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
681
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
682
682
|
this.createMeterPlus(device);
|
|
683
683
|
break;
|
|
684
684
|
case 'WoIOSensor':
|
|
685
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
685
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
686
686
|
this.createIOSensor(device);
|
|
687
687
|
break;
|
|
688
688
|
case 'Water Detector':
|
|
689
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
689
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
690
690
|
this.createWaterDetector(device);
|
|
691
691
|
break;
|
|
692
692
|
case 'Motion Sensor':
|
|
693
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
693
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
694
694
|
this.createMotion(device);
|
|
695
695
|
break;
|
|
696
696
|
case 'Contact Sensor':
|
|
697
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
697
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
698
698
|
this.createContact(device);
|
|
699
699
|
break;
|
|
700
700
|
case 'Curtain':
|
|
701
701
|
case 'Curtain3':
|
|
702
|
-
this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
|
|
702
|
+
await this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
|
|
703
703
|
this.createCurtain(device);
|
|
704
704
|
break;
|
|
705
705
|
case 'Blind Tilt':
|
|
706
|
-
this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
|
|
706
|
+
await this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
|
|
707
707
|
this.createBlindTilt(device);
|
|
708
708
|
break;
|
|
709
709
|
case 'Plug':
|
|
710
710
|
case 'Plug Mini (US)':
|
|
711
711
|
case 'Plug Mini (JP)':
|
|
712
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
712
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
713
713
|
this.createPlug(device);
|
|
714
714
|
break;
|
|
715
715
|
case 'Smart Lock':
|
|
716
716
|
case 'Smart Lock Pro':
|
|
717
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
717
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
718
718
|
this.createLock(device);
|
|
719
719
|
break;
|
|
720
720
|
case 'Color Bulb':
|
|
721
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
721
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
722
722
|
this.createColorBulb(device);
|
|
723
723
|
break;
|
|
724
724
|
case 'K10+':
|
|
@@ -727,26 +727,26 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
727
727
|
case 'Robot Vacuum Cleaner S1':
|
|
728
728
|
case 'Robot Vacuum Cleaner S1 Plus':
|
|
729
729
|
case 'Robot Vacuum Cleaner S10':
|
|
730
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
730
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
731
731
|
this.createRobotVacuumCleaner(device);
|
|
732
732
|
break;
|
|
733
733
|
case 'Ceiling Light':
|
|
734
734
|
case 'Ceiling Light Pro':
|
|
735
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
735
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
736
736
|
this.createCeilingLight(device);
|
|
737
737
|
break;
|
|
738
738
|
case 'Strip Light':
|
|
739
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
739
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
740
740
|
this.createStripLight(device);
|
|
741
741
|
break;
|
|
742
742
|
case 'Battery Circulator Fan':
|
|
743
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
743
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
744
744
|
this.createFan(device);
|
|
745
745
|
break;
|
|
746
746
|
case 'Remote':
|
|
747
747
|
case 'Indoor Cam':
|
|
748
748
|
case 'remote with screen+':
|
|
749
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}, is currently not supported, device: ${JSON.stringify(device)}`);
|
|
749
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}, is currently not supported, device: ${JSON.stringify(device)}`);
|
|
750
750
|
break;
|
|
751
751
|
default:
|
|
752
752
|
this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`,
|
|
@@ -754,7 +754,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
754
754
|
}
|
|
755
755
|
}
|
|
756
756
|
|
|
757
|
-
private createIRDevice(device: irdevice & devicesConfig) {
|
|
757
|
+
private async createIRDevice(device: irdevice & devicesConfig) {
|
|
758
758
|
if (device.connectionType === undefined) {
|
|
759
759
|
device.connectionType = 'OpenAPI';
|
|
760
760
|
}
|
|
@@ -771,7 +771,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
771
771
|
case 'DIY DVD':
|
|
772
772
|
case 'Speaker':
|
|
773
773
|
case 'DIY Speaker':
|
|
774
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
774
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
775
775
|
if (device.external === undefined) {
|
|
776
776
|
device.external = true;
|
|
777
777
|
this.createTV(device);
|
|
@@ -781,45 +781,45 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
781
781
|
break;
|
|
782
782
|
case 'Fan':
|
|
783
783
|
case 'DIY Fan':
|
|
784
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
784
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
785
785
|
this.createIRFan(device);
|
|
786
786
|
break;
|
|
787
787
|
case 'Air Conditioner':
|
|
788
788
|
case 'DIY Air Conditioner':
|
|
789
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
789
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
790
790
|
this.createAirConditioner(device);
|
|
791
791
|
break;
|
|
792
792
|
case 'Light':
|
|
793
793
|
case 'DIY Light':
|
|
794
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
794
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
795
795
|
this.createLight(device);
|
|
796
796
|
break;
|
|
797
797
|
case 'Air Purifier':
|
|
798
798
|
case 'DIY Air Purifier':
|
|
799
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
799
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
800
800
|
this.createAirPurifier(device);
|
|
801
801
|
break;
|
|
802
802
|
case 'Water Heater':
|
|
803
803
|
case 'DIY Water Heater':
|
|
804
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
804
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
805
805
|
this.createWaterHeater(device);
|
|
806
806
|
break;
|
|
807
807
|
case 'Vacuum Cleaner':
|
|
808
808
|
case 'DIY Vacuum Cleaner':
|
|
809
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
809
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
810
810
|
this.createVacuumCleaner(device);
|
|
811
811
|
break;
|
|
812
812
|
case 'Camera':
|
|
813
813
|
case 'DIY Camera':
|
|
814
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
814
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
815
815
|
this.createCamera(device);
|
|
816
816
|
break;
|
|
817
817
|
case 'Others':
|
|
818
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
818
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
819
819
|
this.createOthers(device);
|
|
820
820
|
break;
|
|
821
821
|
default:
|
|
822
|
-
this.debugLog(`Unsupported Device: ${JSON.stringify(device)}`);
|
|
822
|
+
await this.debugLog(`Unsupported Device: ${JSON.stringify(device)}`);
|
|
823
823
|
this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.remoteType}, is currently not supported.`);
|
|
824
824
|
this.warnLog('Submit Feature Requests Here: ' + 'https://tinyurl.com/SwitchBotFeatureRequest');
|
|
825
825
|
}
|
|
@@ -849,7 +849,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
849
849
|
// create the accessory handler for the restored accessory
|
|
850
850
|
// this is imported from `platformAccessory.ts`
|
|
851
851
|
new Humidifier(this, existingAccessory, device);
|
|
852
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
852
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
853
853
|
} else {
|
|
854
854
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
855
855
|
}
|
|
@@ -875,13 +875,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
875
875
|
// create the accessory handler for the newly create accessory
|
|
876
876
|
// this is imported from `platformAccessory.ts`
|
|
877
877
|
new Humidifier(this, accessory, device);
|
|
878
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
878
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
879
879
|
|
|
880
880
|
// publish device externally or link the accessory to your platform
|
|
881
881
|
this.externalOrPlatform(device, accessory);
|
|
882
882
|
this.accessories.push(accessory);
|
|
883
883
|
} else {
|
|
884
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
884
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
885
885
|
}
|
|
886
886
|
}
|
|
887
887
|
|
|
@@ -909,7 +909,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
909
909
|
// create the accessory handler for the restored accessory
|
|
910
910
|
// this is imported from `platformAccessory.ts`
|
|
911
911
|
new Bot(this, existingAccessory, device);
|
|
912
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
912
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
913
913
|
} else {
|
|
914
914
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
915
915
|
}
|
|
@@ -936,13 +936,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
936
936
|
// create the accessory handler for the newly create accessory
|
|
937
937
|
// this is imported from `platformAccessory.ts`
|
|
938
938
|
new Bot(this, accessory, device);
|
|
939
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
939
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
940
940
|
|
|
941
941
|
// publish device externally or link the accessory to your platform
|
|
942
942
|
this.externalOrPlatform(device, accessory);
|
|
943
943
|
this.accessories.push(accessory);
|
|
944
944
|
} else {
|
|
945
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
945
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
946
946
|
}
|
|
947
947
|
}
|
|
948
948
|
|
|
@@ -970,7 +970,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
970
970
|
// create the accessory handler for the restored accessory
|
|
971
971
|
// this is imported from `platformAccessory.ts`
|
|
972
972
|
new Meter(this, existingAccessory, device);
|
|
973
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
973
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
974
974
|
} else {
|
|
975
975
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
976
976
|
}
|
|
@@ -996,13 +996,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
996
996
|
// create the accessory handler for the newly create accessory
|
|
997
997
|
// this is imported from `platformAccessory.ts`
|
|
998
998
|
new Meter(this, accessory, device);
|
|
999
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
999
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1000
1000
|
|
|
1001
1001
|
// publish device externally or link the accessory to your platform
|
|
1002
1002
|
this.externalOrPlatform(device, accessory);
|
|
1003
1003
|
this.accessories.push(accessory);
|
|
1004
1004
|
} else {
|
|
1005
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1005
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1006
1006
|
}
|
|
1007
1007
|
}
|
|
1008
1008
|
|
|
@@ -1031,7 +1031,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1031
1031
|
// create the accessory handler for the restored accessory
|
|
1032
1032
|
// this is imported from `platformAccessory.ts`
|
|
1033
1033
|
new MeterPlus(this, existingAccessory, device);
|
|
1034
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1034
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1035
1035
|
} else {
|
|
1036
1036
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1037
1037
|
}
|
|
@@ -1057,13 +1057,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1057
1057
|
// create the accessory handler for the newly create accessory
|
|
1058
1058
|
// this is imported from `platformAccessory.ts`
|
|
1059
1059
|
new MeterPlus(this, accessory, device);
|
|
1060
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1060
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1061
1061
|
|
|
1062
1062
|
// publish device externally or link the accessory to your platform
|
|
1063
1063
|
this.externalOrPlatform(device, accessory);
|
|
1064
1064
|
this.accessories.push(accessory);
|
|
1065
1065
|
} else {
|
|
1066
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1066
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1067
1067
|
}
|
|
1068
1068
|
}
|
|
1069
1069
|
|
|
@@ -1092,7 +1092,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1092
1092
|
// create the accessory handler for the restored accessory
|
|
1093
1093
|
// this is imported from `platformAccessory.ts`
|
|
1094
1094
|
new Hub(this, existingAccessory, device);
|
|
1095
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1095
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1096
1096
|
} else {
|
|
1097
1097
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1098
1098
|
}
|
|
@@ -1118,13 +1118,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1118
1118
|
// create the accessory handler for the newly create accessory
|
|
1119
1119
|
// this is imported from `platformAccessory.ts`
|
|
1120
1120
|
new Hub(this, accessory, device);
|
|
1121
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1121
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1122
1122
|
|
|
1123
1123
|
// publish device externally or link the accessory to your platform
|
|
1124
1124
|
this.externalOrPlatform(device, accessory);
|
|
1125
1125
|
this.accessories.push(accessory);
|
|
1126
1126
|
} else {
|
|
1127
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1127
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1128
1128
|
}
|
|
1129
1129
|
}
|
|
1130
1130
|
|
|
@@ -1152,7 +1152,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1152
1152
|
// create the accessory handler for the restored accessory
|
|
1153
1153
|
// this is imported from `platformAccessory.ts`
|
|
1154
1154
|
new IOSensor(this, existingAccessory, device);
|
|
1155
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1155
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1156
1156
|
} else {
|
|
1157
1157
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1158
1158
|
}
|
|
@@ -1178,13 +1178,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1178
1178
|
// create the accessory handler for the newly create accessory
|
|
1179
1179
|
// this is imported from `platformAccessory.ts`
|
|
1180
1180
|
new IOSensor(this, accessory, device);
|
|
1181
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1181
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1182
1182
|
|
|
1183
1183
|
// publish device externally or link the accessory to your platform
|
|
1184
1184
|
this.externalOrPlatform(device, accessory);
|
|
1185
1185
|
this.accessories.push(accessory);
|
|
1186
1186
|
} else {
|
|
1187
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1187
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1188
1188
|
}
|
|
1189
1189
|
}
|
|
1190
1190
|
|
|
@@ -1212,7 +1212,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1212
1212
|
// create the accessory handler for the restored accessory
|
|
1213
1213
|
// this is imported from `platformAccessory.ts`
|
|
1214
1214
|
new WaterDetector(this, existingAccessory, device);
|
|
1215
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1215
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1216
1216
|
} else {
|
|
1217
1217
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1218
1218
|
}
|
|
@@ -1238,13 +1238,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1238
1238
|
// create the accessory handler for the newly create accessory
|
|
1239
1239
|
// this is imported from `platformAccessory.ts`
|
|
1240
1240
|
new WaterDetector(this, accessory, device);
|
|
1241
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1241
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1242
1242
|
|
|
1243
1243
|
// publish device externally or link the accessory to your platform
|
|
1244
1244
|
this.externalOrPlatform(device, accessory);
|
|
1245
1245
|
this.accessories.push(accessory);
|
|
1246
1246
|
} else {
|
|
1247
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1247
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1248
1248
|
}
|
|
1249
1249
|
}
|
|
1250
1250
|
|
|
@@ -1272,7 +1272,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1272
1272
|
// create the accessory handler for the restored accessory
|
|
1273
1273
|
// this is imported from `platformAccessory.ts`
|
|
1274
1274
|
new Motion(this, existingAccessory, device);
|
|
1275
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1275
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1276
1276
|
} else {
|
|
1277
1277
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1278
1278
|
}
|
|
@@ -1298,13 +1298,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1298
1298
|
// create the accessory handler for the newly create accessory
|
|
1299
1299
|
// this is imported from `platformAccessory.ts`
|
|
1300
1300
|
new Motion(this, accessory, device);
|
|
1301
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1301
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1302
1302
|
|
|
1303
1303
|
// publish device externally or link the accessory to your platform
|
|
1304
1304
|
this.externalOrPlatform(device, accessory);
|
|
1305
1305
|
this.accessories.push(accessory);
|
|
1306
1306
|
} else {
|
|
1307
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1307
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1308
1308
|
}
|
|
1309
1309
|
}
|
|
1310
1310
|
|
|
@@ -1332,7 +1332,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1332
1332
|
// create the accessory handler for the restored accessory
|
|
1333
1333
|
// this is imported from `platformAccessory.ts`
|
|
1334
1334
|
new Contact(this, existingAccessory, device);
|
|
1335
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1335
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1336
1336
|
} else {
|
|
1337
1337
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1338
1338
|
}
|
|
@@ -1358,13 +1358,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1358
1358
|
// create the accessory handler for the newly create accessory
|
|
1359
1359
|
// this is imported from `platformAccessory.ts`
|
|
1360
1360
|
new Contact(this, accessory, device);
|
|
1361
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1361
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1362
1362
|
|
|
1363
1363
|
// publish device externally or link the accessory to your platform
|
|
1364
1364
|
this.externalOrPlatform(device, accessory);
|
|
1365
1365
|
this.accessories.push(accessory);
|
|
1366
1366
|
} else {
|
|
1367
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1367
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1368
1368
|
}
|
|
1369
1369
|
}
|
|
1370
1370
|
|
|
@@ -1392,7 +1392,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1392
1392
|
// create the accessory handler for the restored accessory
|
|
1393
1393
|
// this is imported from `platformAccessory.ts`
|
|
1394
1394
|
new BlindTilt(this, existingAccessory, device);
|
|
1395
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1395
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1396
1396
|
} else {
|
|
1397
1397
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1398
1398
|
}
|
|
@@ -1402,15 +1402,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1402
1402
|
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1403
1403
|
}
|
|
1404
1404
|
|
|
1405
|
-
if (device
|
|
1406
|
-
|
|
1407
|
-
|
|
1405
|
+
if (isBlindTiltDevice(device)) {
|
|
1406
|
+
if (device.group && !device.curtain?.disable_group) {
|
|
1407
|
+
this.debugLog(
|
|
1408
|
+
'Your Curtains are grouped, ' +
|
|
1408
1409
|
`, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1409
|
-
} else {
|
|
1410
|
-
if (device.master) {
|
|
1411
|
-
this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1412
1410
|
} else {
|
|
1413
|
-
|
|
1411
|
+
if (device.master) {
|
|
1412
|
+
this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1413
|
+
} else {
|
|
1414
|
+
this.errorLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1415
|
+
}
|
|
1414
1416
|
}
|
|
1415
1417
|
}
|
|
1416
1418
|
|
|
@@ -1430,13 +1432,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1430
1432
|
// create the accessory handler for the newly create accessory
|
|
1431
1433
|
// this is imported from `platformAccessory.ts`
|
|
1432
1434
|
new BlindTilt(this, accessory, device);
|
|
1433
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1435
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1434
1436
|
|
|
1435
1437
|
// publish device externally or link the accessory to your platform
|
|
1436
1438
|
this.externalOrPlatform(device, accessory);
|
|
1437
1439
|
this.accessories.push(accessory);
|
|
1438
1440
|
} else {
|
|
1439
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1441
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1440
1442
|
}
|
|
1441
1443
|
}
|
|
1442
1444
|
|
|
@@ -1464,7 +1466,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1464
1466
|
// create the accessory handler for the restored accessory
|
|
1465
1467
|
// this is imported from `platformAccessory.ts`
|
|
1466
1468
|
new Curtain(this, existingAccessory, device);
|
|
1467
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1469
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1468
1470
|
} else {
|
|
1469
1471
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1470
1472
|
}
|
|
@@ -1474,15 +1476,18 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1474
1476
|
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1475
1477
|
}
|
|
1476
1478
|
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1479
|
+
|
|
1480
|
+
if (isCurtainDevice(device)) {
|
|
1481
|
+
if (device.group && !device.curtain?.disable_group) {
|
|
1482
|
+
this.debugLog(
|
|
1483
|
+
'Your Curtains are grouped, ' +
|
|
1480
1484
|
`, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1481
|
-
} else {
|
|
1482
|
-
if (device.master) {
|
|
1483
|
-
this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1484
1485
|
} else {
|
|
1485
|
-
|
|
1486
|
+
if (device.master) {
|
|
1487
|
+
this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1488
|
+
} else {
|
|
1489
|
+
this.errorLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1490
|
+
}
|
|
1486
1491
|
}
|
|
1487
1492
|
}
|
|
1488
1493
|
|
|
@@ -1502,13 +1507,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1502
1507
|
// create the accessory handler for the newly create accessory
|
|
1503
1508
|
// this is imported from `platformAccessory.ts`
|
|
1504
1509
|
new Curtain(this, accessory, device);
|
|
1505
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1510
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1506
1511
|
|
|
1507
1512
|
// publish device externally or link the accessory to your platform
|
|
1508
1513
|
this.externalOrPlatform(device, accessory);
|
|
1509
1514
|
this.accessories.push(accessory);
|
|
1510
1515
|
} else {
|
|
1511
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1516
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1512
1517
|
}
|
|
1513
1518
|
}
|
|
1514
1519
|
|
|
@@ -1536,7 +1541,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1536
1541
|
// create the accessory handler for the restored accessory
|
|
1537
1542
|
// this is imported from `platformAccessory.ts`
|
|
1538
1543
|
new Plug(this, existingAccessory, device);
|
|
1539
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1544
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1540
1545
|
} else {
|
|
1541
1546
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1542
1547
|
}
|
|
@@ -1562,13 +1567,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1562
1567
|
// create the accessory handler for the newly create accessory
|
|
1563
1568
|
// this is imported from `platformAccessory.ts`
|
|
1564
1569
|
new Plug(this, accessory, device);
|
|
1565
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1570
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1566
1571
|
|
|
1567
1572
|
// publish device externally or link the accessory to your platform
|
|
1568
1573
|
this.externalOrPlatform(device, accessory);
|
|
1569
1574
|
this.accessories.push(accessory);
|
|
1570
1575
|
} else {
|
|
1571
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1576
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1572
1577
|
}
|
|
1573
1578
|
}
|
|
1574
1579
|
|
|
@@ -1596,7 +1601,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1596
1601
|
// create the accessory handler for the restored accessory
|
|
1597
1602
|
// this is imported from `platformAccessory.ts`
|
|
1598
1603
|
new Lock(this, existingAccessory, device);
|
|
1599
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1604
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1600
1605
|
} else {
|
|
1601
1606
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1602
1607
|
}
|
|
@@ -1622,13 +1627,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1622
1627
|
// create the accessory handler for the newly create accessory
|
|
1623
1628
|
// this is imported from `platformAccessory.ts`
|
|
1624
1629
|
new Lock(this, accessory, device);
|
|
1625
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1630
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1626
1631
|
|
|
1627
1632
|
// publish device externally or link the accessory to your platform
|
|
1628
1633
|
this.externalOrPlatform(device, accessory);
|
|
1629
1634
|
this.accessories.push(accessory);
|
|
1630
1635
|
} else {
|
|
1631
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1636
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1632
1637
|
}
|
|
1633
1638
|
}
|
|
1634
1639
|
|
|
@@ -1656,7 +1661,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1656
1661
|
// create the accessory handler for the restored accessory
|
|
1657
1662
|
// this is imported from `platformAccessory.ts`
|
|
1658
1663
|
new ColorBulb(this, existingAccessory, device);
|
|
1659
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1664
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1660
1665
|
} else {
|
|
1661
1666
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1662
1667
|
}
|
|
@@ -1682,13 +1687,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1682
1687
|
// create the accessory handler for the newly create accessory
|
|
1683
1688
|
// this is imported from `platformAccessory.ts`
|
|
1684
1689
|
new ColorBulb(this, accessory, device);
|
|
1685
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1690
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1686
1691
|
|
|
1687
1692
|
// publish device externally or link the accessory to your platform
|
|
1688
1693
|
this.externalOrPlatform(device, accessory);
|
|
1689
1694
|
this.accessories.push(accessory);
|
|
1690
1695
|
} else {
|
|
1691
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1696
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1692
1697
|
}
|
|
1693
1698
|
}
|
|
1694
1699
|
|
|
@@ -1716,7 +1721,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1716
1721
|
// create the accessory handler for the restored accessory
|
|
1717
1722
|
// this is imported from `platformAccessory.ts`
|
|
1718
1723
|
new CeilingLight(this, existingAccessory, device);
|
|
1719
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1724
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1720
1725
|
} else {
|
|
1721
1726
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1722
1727
|
}
|
|
@@ -1742,13 +1747,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1742
1747
|
// create the accessory handler for the newly create accessory
|
|
1743
1748
|
// this is imported from `platformAccessory.ts`
|
|
1744
1749
|
new CeilingLight(this, accessory, device);
|
|
1745
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1750
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1746
1751
|
|
|
1747
1752
|
// publish device externally or link the accessory to your platform
|
|
1748
1753
|
this.externalOrPlatform(device, accessory);
|
|
1749
1754
|
this.accessories.push(accessory);
|
|
1750
1755
|
} else {
|
|
1751
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1756
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1752
1757
|
}
|
|
1753
1758
|
}
|
|
1754
1759
|
|
|
@@ -1776,7 +1781,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1776
1781
|
// create the accessory handler for the restored accessory
|
|
1777
1782
|
// this is imported from `platformAccessory.ts`
|
|
1778
1783
|
new StripLight(this, existingAccessory, device);
|
|
1779
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1784
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1780
1785
|
} else {
|
|
1781
1786
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1782
1787
|
}
|
|
@@ -1802,13 +1807,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1802
1807
|
// create the accessory handler for the newly create accessory
|
|
1803
1808
|
// this is imported from `platformAccessory.ts`
|
|
1804
1809
|
new StripLight(this, accessory, device);
|
|
1805
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1810
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1806
1811
|
|
|
1807
1812
|
// publish device externally or link the accessory to your platform
|
|
1808
1813
|
this.externalOrPlatform(device, accessory);
|
|
1809
1814
|
this.accessories.push(accessory);
|
|
1810
1815
|
} else {
|
|
1811
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1816
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1812
1817
|
}
|
|
1813
1818
|
}
|
|
1814
1819
|
|
|
@@ -1836,7 +1841,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1836
1841
|
// create the accessory handler for the restored accessory
|
|
1837
1842
|
// this is imported from `platformAccessory.ts`
|
|
1838
1843
|
new Fan(this, existingAccessory, device);
|
|
1839
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1844
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1840
1845
|
} else {
|
|
1841
1846
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1842
1847
|
}
|
|
@@ -1862,13 +1867,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1862
1867
|
// create the accessory handler for the newly create accessory
|
|
1863
1868
|
// this is imported from `platformAccessory.ts`
|
|
1864
1869
|
new Fan(this, accessory, device);
|
|
1865
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1870
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1866
1871
|
|
|
1867
1872
|
// publish device externally or link the accessory to your platform
|
|
1868
1873
|
this.externalOrPlatform(device, accessory);
|
|
1869
1874
|
this.accessories.push(accessory);
|
|
1870
1875
|
} else {
|
|
1871
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1876
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1872
1877
|
}
|
|
1873
1878
|
}
|
|
1874
1879
|
|
|
@@ -1896,7 +1901,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1896
1901
|
// create the accessory handler for the restored accessory
|
|
1897
1902
|
// this is imported from `platformAccessory.ts`
|
|
1898
1903
|
new RobotVacuumCleaner(this, existingAccessory, device);
|
|
1899
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1904
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1900
1905
|
} else {
|
|
1901
1906
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1902
1907
|
}
|
|
@@ -1922,13 +1927,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1922
1927
|
// create the accessory handler for the newly create accessory
|
|
1923
1928
|
// this is imported from `platformAccessory.ts`
|
|
1924
1929
|
new RobotVacuumCleaner(this, accessory, device);
|
|
1925
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1930
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1926
1931
|
|
|
1927
1932
|
// publish device externally or link the accessory to your platform
|
|
1928
1933
|
this.externalOrPlatform(device, accessory);
|
|
1929
1934
|
this.accessories.push(accessory);
|
|
1930
1935
|
} else {
|
|
1931
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1936
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1932
1937
|
}
|
|
1933
1938
|
}
|
|
1934
1939
|
|
|
@@ -1944,9 +1949,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1944
1949
|
existingAccessory.context.model = device.remoteType;
|
|
1945
1950
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1946
1951
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1947
|
-
if (device.version && !device.firmware) {
|
|
1948
|
-
existingAccessory.context.version = device.version;
|
|
1949
|
-
}
|
|
1950
1952
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1951
1953
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1952
1954
|
existingAccessory.context.connectionType = device.connectionType;
|
|
@@ -1954,7 +1956,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1954
1956
|
// create the accessory handler for the restored accessory
|
|
1955
1957
|
// this is imported from `platformAccessory.ts`
|
|
1956
1958
|
new TV(this, existingAccessory, device);
|
|
1957
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1959
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1958
1960
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
1959
1961
|
// the accessory does not yet exist, so we need to create it
|
|
1960
1962
|
if (!device.external) {
|
|
@@ -1977,12 +1979,12 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1977
1979
|
// create the accessory handler for the newly create accessory
|
|
1978
1980
|
// this is imported from `platformAccessory.ts`
|
|
1979
1981
|
new TV(this, accessory, device);
|
|
1980
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1982
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1981
1983
|
|
|
1982
1984
|
this.externalOrPlatformIR(device, accessory);
|
|
1983
1985
|
this.accessories.push(accessory);
|
|
1984
1986
|
} else {
|
|
1985
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1987
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1986
1988
|
}
|
|
1987
1989
|
}
|
|
1988
1990
|
|
|
@@ -2010,7 +2012,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2010
2012
|
// create the accessory handler for the restored accessory
|
|
2011
2013
|
// this is imported from `platformAccessory.ts`
|
|
2012
2014
|
new IRFan(this, existingAccessory, device);
|
|
2013
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2015
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2014
2016
|
} else {
|
|
2015
2017
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
2016
2018
|
}
|
|
@@ -2036,13 +2038,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2036
2038
|
// create the accessory handler for the newly create accessory
|
|
2037
2039
|
// this is imported from `platformAccessory.ts`
|
|
2038
2040
|
new IRFan(this, accessory, device);
|
|
2039
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2041
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2040
2042
|
|
|
2041
2043
|
// publish device externally or link the accessory to your platform
|
|
2042
2044
|
this.externalOrPlatformIR(device, accessory);
|
|
2043
2045
|
this.accessories.push(accessory);
|
|
2044
2046
|
} else {
|
|
2045
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2047
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2046
2048
|
}
|
|
2047
2049
|
}
|
|
2048
2050
|
|
|
@@ -2070,7 +2072,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2070
2072
|
// create the accessory handler for the restored accessory
|
|
2071
2073
|
// this is imported from `platformAccessory.ts`
|
|
2072
2074
|
new Light(this, existingAccessory, device);
|
|
2073
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2075
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2074
2076
|
} else {
|
|
2075
2077
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
2076
2078
|
}
|
|
@@ -2096,13 +2098,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2096
2098
|
// create the accessory handler for the newly create accessory
|
|
2097
2099
|
// this is imported from `platformAccessory.ts`
|
|
2098
2100
|
new Light(this, accessory, device);
|
|
2099
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2101
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2100
2102
|
|
|
2101
2103
|
// publish device externally or link the accessory to your platform
|
|
2102
2104
|
this.externalOrPlatformIR(device, accessory);
|
|
2103
2105
|
this.accessories.push(accessory);
|
|
2104
2106
|
} else {
|
|
2105
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2107
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2106
2108
|
}
|
|
2107
2109
|
}
|
|
2108
2110
|
|
|
@@ -2130,7 +2132,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2130
2132
|
// create the accessory handler for the restored accessory
|
|
2131
2133
|
// this is imported from `platformAccessory.ts`
|
|
2132
2134
|
new AirConditioner(this, existingAccessory, device);
|
|
2133
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2135
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2134
2136
|
} else {
|
|
2135
2137
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
2136
2138
|
}
|
|
@@ -2156,13 +2158,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2156
2158
|
// create the accessory handler for the newly create accessory
|
|
2157
2159
|
// this is imported from `platformAccessory.ts`
|
|
2158
2160
|
new AirConditioner(this, accessory, device);
|
|
2159
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2161
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2160
2162
|
|
|
2161
2163
|
// publish device externally or link the accessory to your platform
|
|
2162
2164
|
this.externalOrPlatformIR(device, accessory);
|
|
2163
2165
|
this.accessories.push(accessory);
|
|
2164
2166
|
} else {
|
|
2165
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2167
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2166
2168
|
}
|
|
2167
2169
|
}
|
|
2168
2170
|
|
|
@@ -2190,7 +2192,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2190
2192
|
// create the accessory handler for the restored accessory
|
|
2191
2193
|
// this is imported from `platformAccessory.ts`
|
|
2192
2194
|
new AirPurifier(this, existingAccessory, device);
|
|
2193
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2195
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2194
2196
|
} else {
|
|
2195
2197
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
2196
2198
|
}
|
|
@@ -2216,13 +2218,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2216
2218
|
// create the accessory handler for the newly create accessory
|
|
2217
2219
|
// this is imported from `platformAccessory.ts`
|
|
2218
2220
|
new AirPurifier(this, accessory, device);
|
|
2219
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2221
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2220
2222
|
|
|
2221
2223
|
// publish device externally or link the accessory to your platform
|
|
2222
2224
|
this.externalOrPlatformIR(device, accessory);
|
|
2223
2225
|
this.accessories.push(accessory);
|
|
2224
2226
|
} else {
|
|
2225
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2227
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2226
2228
|
}
|
|
2227
2229
|
}
|
|
2228
2230
|
|
|
@@ -2250,7 +2252,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2250
2252
|
// create the accessory handler for the restored accessory
|
|
2251
2253
|
// this is imported from `platformAccessory.ts`
|
|
2252
2254
|
new WaterHeater(this, existingAccessory, device);
|
|
2253
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2255
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2254
2256
|
} else {
|
|
2255
2257
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
2256
2258
|
}
|
|
@@ -2276,13 +2278,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2276
2278
|
// create the accessory handler for the newly create accessory
|
|
2277
2279
|
// this is imported from `platformAccessory.ts`
|
|
2278
2280
|
new WaterHeater(this, accessory, device);
|
|
2279
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2281
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2280
2282
|
|
|
2281
2283
|
// publish device externally or link the accessory to your platform
|
|
2282
2284
|
this.externalOrPlatformIR(device, accessory);
|
|
2283
2285
|
this.accessories.push(accessory);
|
|
2284
2286
|
} else {
|
|
2285
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2287
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2286
2288
|
}
|
|
2287
2289
|
}
|
|
2288
2290
|
|
|
@@ -2310,7 +2312,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2310
2312
|
// create the accessory handler for the restored accessory
|
|
2311
2313
|
// this is imported from `platformAccessory.ts`
|
|
2312
2314
|
new VacuumCleaner(this, existingAccessory, device);
|
|
2313
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2315
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2314
2316
|
} else {
|
|
2315
2317
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
2316
2318
|
}
|
|
@@ -2336,13 +2338,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2336
2338
|
// create the accessory handler for the newly create accessory
|
|
2337
2339
|
// this is imported from `platformAccessory.ts`
|
|
2338
2340
|
new VacuumCleaner(this, accessory, device);
|
|
2339
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2341
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2340
2342
|
|
|
2341
2343
|
// publish device externally or link the accessory to your platform
|
|
2342
2344
|
this.externalOrPlatformIR(device, accessory);
|
|
2343
2345
|
this.accessories.push(accessory);
|
|
2344
2346
|
} else {
|
|
2345
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2347
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2346
2348
|
}
|
|
2347
2349
|
}
|
|
2348
2350
|
|
|
@@ -2370,7 +2372,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2370
2372
|
// create the accessory handler for the restored accessory
|
|
2371
2373
|
// this is imported from `platformAccessory.ts`
|
|
2372
2374
|
new Camera(this, existingAccessory, device);
|
|
2373
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2375
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2374
2376
|
} else {
|
|
2375
2377
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
2376
2378
|
}
|
|
@@ -2396,13 +2398,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2396
2398
|
// create the accessory handler for the newly create accessory
|
|
2397
2399
|
// this is imported from `platformAccessory.ts`
|
|
2398
2400
|
new Camera(this, accessory, device);
|
|
2399
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2401
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2400
2402
|
|
|
2401
2403
|
// publish device externally or link the accessory to your platform
|
|
2402
2404
|
this.externalOrPlatformIR(device, accessory);
|
|
2403
2405
|
this.accessories.push(accessory);
|
|
2404
2406
|
} else {
|
|
2405
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2407
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2406
2408
|
}
|
|
2407
2409
|
}
|
|
2408
2410
|
|
|
@@ -2430,7 +2432,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2430
2432
|
// create the accessory handler for the restored accessory
|
|
2431
2433
|
// this is imported from `platformAccessory.ts`
|
|
2432
2434
|
new Others(this, existingAccessory, device);
|
|
2433
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2435
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2434
2436
|
} else {
|
|
2435
2437
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
2436
2438
|
}
|
|
@@ -2456,59 +2458,74 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2456
2458
|
// create the accessory handler for the newly create accessory
|
|
2457
2459
|
// this is imported from `platformAccessory.ts`
|
|
2458
2460
|
new Others(this, accessory, device);
|
|
2459
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2461
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2460
2462
|
|
|
2461
2463
|
// publish device externally or link the accessory to your platform
|
|
2462
2464
|
this.externalOrPlatformIR(device, accessory);
|
|
2463
2465
|
this.accessories.push(accessory);
|
|
2464
2466
|
} else {
|
|
2465
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2467
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2466
2468
|
}
|
|
2467
2469
|
}
|
|
2468
2470
|
|
|
2469
|
-
async registerCurtains(device: device & devicesConfig) {
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2471
|
+
async registerCurtains(device: device & devicesConfig): Promise<boolean> {
|
|
2472
|
+
/*function isCurtainDevice(device: device & devicesConfig): device is (curtain | curtain3) & devicesConfig {
|
|
2473
|
+
return device.deviceType === 'Curtain' || device.deviceType === 'Curtain3';
|
|
2474
|
+
}
|
|
2475
|
+
|
|
2476
|
+
function isBlindTiltDevice(device: device & devicesConfig): device is blindTilt & devicesConfig {
|
|
2477
|
+
return device.deviceType === 'Blind Tilt';
|
|
2478
|
+
}*/
|
|
2479
|
+
let registerWindowCovering: boolean;
|
|
2480
|
+
if (isCurtainDevice(device)) {
|
|
2481
|
+
await this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds},`
|
|
2482
|
+
+ ` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group},`
|
|
2483
|
+
+ ` connectionType: ${device.connectionType}`);
|
|
2484
|
+
registerWindowCovering = await this.registerWindowCovering(device);
|
|
2485
|
+
} else if (isBlindTiltDevice(device)) {
|
|
2486
|
+
await this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, blindTiltDevicesIds: ${device.blindTiltDevicesIds},`
|
|
2487
|
+
+ ` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group},`
|
|
2488
|
+
+ ` connectionType: ${device.connectionType}`);
|
|
2489
|
+
registerWindowCovering =await this.registerWindowCovering(device);
|
|
2490
|
+
} else {
|
|
2491
|
+
registerWindowCovering = false;
|
|
2479
2492
|
}
|
|
2493
|
+
return registerWindowCovering;
|
|
2494
|
+
}
|
|
2480
2495
|
|
|
2496
|
+
async registerWindowCovering(device: ((curtain | curtain3) & devicesConfig) | (blindTilt & devicesConfig)) {
|
|
2497
|
+
await this.debugLog(`master: ${device.master}`);
|
|
2481
2498
|
let registerCurtain: boolean;
|
|
2482
2499
|
if (device.master && device.group) {
|
|
2483
2500
|
// OpenAPI: Master Curtains/Blind Tilt in Group
|
|
2484
2501
|
registerCurtain = true;
|
|
2485
|
-
this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}
|
|
2486
|
-
+ ` connectionType; ${device.connectionType}`);
|
|
2487
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2502
|
+
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master},`
|
|
2503
|
+
+ ` device.group: ${device.group} connectionType; ${device.connectionType}`);
|
|
2504
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2488
2505
|
} else if (!device.master && device.curtain?.disable_group) {
|
|
2489
2506
|
//!device.group && device.connectionType === 'BLE'
|
|
2490
2507
|
// OpenAPI: Non-Master Curtains/Blind Tilts that has Disable Grouping Checked
|
|
2491
2508
|
registerCurtain = true;
|
|
2492
|
-
this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, disable_group: `
|
|
2509
|
+
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, disable_group: `
|
|
2493
2510
|
+ `${device.curtain?.disable_group}, connectionType; ${device.connectionType}`);
|
|
2494
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2511
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2495
2512
|
} else if (device.master && !device.group) {
|
|
2496
2513
|
// OpenAPI: Master Curtains/Blind Tilts not in Group
|
|
2497
2514
|
registerCurtain = true;
|
|
2498
|
-
this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}
|
|
2499
|
-
+ ` connectionType; ${device.connectionType}`);
|
|
2500
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2515
|
+
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master},`
|
|
2516
|
+
+ ` device.group: ${device.group} connectionType; ${device.connectionType}`);
|
|
2517
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2501
2518
|
} else if (device.connectionType === 'BLE') {
|
|
2502
2519
|
// BLE: Curtains/Blind Tilt
|
|
2503
2520
|
registerCurtain = true;
|
|
2504
|
-
this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] connectionType: ${device.connectionType}, `
|
|
2521
|
+
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] connectionType: ${device.connectionType}, `
|
|
2505
2522
|
+ ` group: ${device.group}`);
|
|
2506
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2523
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2507
2524
|
} else {
|
|
2508
2525
|
registerCurtain = false;
|
|
2509
|
-
this.debugErrorLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] disable_group: ${device.curtain?.disable_group},`
|
|
2526
|
+
await this.debugErrorLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] disable_group: ${device.curtain?.disable_group},`
|
|
2510
2527
|
+ ` device.master: ${device.master}, device.group: ${device.group}`);
|
|
2511
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}, device.connectionType: ${device.connectionType}`);
|
|
2528
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}, device.connectionType: ${device.connectionType}`);
|
|
2512
2529
|
}
|
|
2513
2530
|
return registerCurtain;
|
|
2514
2531
|
}
|
|
@@ -2532,16 +2549,16 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2532
2549
|
case 'Curtain3':
|
|
2533
2550
|
case 'Blind Tilt':
|
|
2534
2551
|
registerDevice = await this.registerCurtains(device);
|
|
2535
|
-
this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2552
|
+
await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2536
2553
|
break;
|
|
2537
2554
|
default:
|
|
2538
2555
|
registerDevice = true;
|
|
2539
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2556
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2540
2557
|
}
|
|
2541
2558
|
if (registerDevice === true) {
|
|
2542
|
-
this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
2559
|
+
await this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
2543
2560
|
} else {
|
|
2544
|
-
this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2561
|
+
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2545
2562
|
}
|
|
2546
2563
|
} else if (!device.hide_device && device.deviceId && device.configDeviceType && device.configDeviceName && device.connectionType === 'BLE') {
|
|
2547
2564
|
switch (device.deviceType) {
|
|
@@ -2549,16 +2566,16 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2549
2566
|
case 'Curtain3':
|
|
2550
2567
|
case 'Blind Tilt':
|
|
2551
2568
|
registerDevice = await this.registerCurtains(device);
|
|
2552
|
-
this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2569
|
+
await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2553
2570
|
break;
|
|
2554
2571
|
default:
|
|
2555
2572
|
registerDevice = true;
|
|
2556
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2573
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2557
2574
|
}
|
|
2558
2575
|
if (registerDevice === true) {
|
|
2559
|
-
this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
2576
|
+
await this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
2560
2577
|
} else {
|
|
2561
|
-
this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2578
|
+
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2562
2579
|
}
|
|
2563
2580
|
} else if (!device.hide_device && device.connectionType === 'OpenAPI') {
|
|
2564
2581
|
switch (device.deviceType) {
|
|
@@ -2566,16 +2583,16 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2566
2583
|
case 'Curtain3':
|
|
2567
2584
|
case 'Blind Tilt':
|
|
2568
2585
|
registerDevice = await this.registerCurtains(device);
|
|
2569
|
-
this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2586
|
+
await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2570
2587
|
break;
|
|
2571
2588
|
default:
|
|
2572
2589
|
registerDevice = true;
|
|
2573
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2590
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2574
2591
|
}
|
|
2575
2592
|
if (registerDevice === true) {
|
|
2576
|
-
this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
2593
|
+
await this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
2577
2594
|
} else {
|
|
2578
|
-
this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2595
|
+
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2579
2596
|
}
|
|
2580
2597
|
} else if (!device.hide_device && device.connectionType === 'Disabled') {
|
|
2581
2598
|
switch (device.deviceType) {
|
|
@@ -2583,22 +2600,22 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2583
2600
|
case 'Curtain3':
|
|
2584
2601
|
case 'Blind Tilt':
|
|
2585
2602
|
registerDevice = await this.registerCurtains(device);
|
|
2586
|
-
this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2603
|
+
await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2587
2604
|
break;
|
|
2588
2605
|
default:
|
|
2589
2606
|
registerDevice = true;
|
|
2590
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2607
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2591
2608
|
}
|
|
2592
|
-
this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will continue to display in HomeKit`);
|
|
2609
|
+
await this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will continue to display in HomeKit`);
|
|
2593
2610
|
} else if (!device.connectionType && !device.hide_device) {
|
|
2594
2611
|
registerDevice = false;
|
|
2595
|
-
this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2612
|
+
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2596
2613
|
} else if (device.hide_device) {
|
|
2597
2614
|
registerDevice = false;
|
|
2598
|
-
this.debugErrorLog(`Device: ${device.deviceName} hide_device: ${device.hide_device}, will not display in HomeKit`);
|
|
2615
|
+
await this.debugErrorLog(`Device: ${device.deviceName} hide_device: ${device.hide_device}, will not display in HomeKit`);
|
|
2599
2616
|
} else {
|
|
2600
2617
|
registerDevice = false;
|
|
2601
|
-
this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, hide_device: `
|
|
2618
|
+
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, hide_device: `
|
|
2602
2619
|
+ `${device.hide_device}, will not display in HomeKit`);
|
|
2603
2620
|
}
|
|
2604
2621
|
return registerDevice;
|
|
@@ -2611,20 +2628,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2611
2628
|
* publish your TV as an external accessory.
|
|
2612
2629
|
*/
|
|
2613
2630
|
if (device.external) {
|
|
2614
|
-
this.debugWarnLog(`${accessory.displayName} External Accessory Mode`);
|
|
2631
|
+
await this.debugWarnLog(`${accessory.displayName} External Accessory Mode`);
|
|
2615
2632
|
this.externalAccessory(accessory);
|
|
2616
2633
|
} else {
|
|
2617
|
-
this.debugLog(`${accessory.displayName} External Accessory Mode: ${device.external}`);
|
|
2634
|
+
await this.debugLog(`${accessory.displayName} External Accessory Mode: ${device.external}`);
|
|
2618
2635
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
2619
2636
|
}
|
|
2620
2637
|
}
|
|
2621
2638
|
|
|
2622
2639
|
public async externalOrPlatform(device: device & devicesConfig, accessory: PlatformAccessory) {
|
|
2623
2640
|
if (device.external) {
|
|
2624
|
-
this.debugWarnLog(`${accessory.displayName} External Accessory Mode`);
|
|
2625
|
-
this.externalAccessory(accessory);
|
|
2641
|
+
await this.debugWarnLog(`${accessory.displayName} External Accessory Mode`);
|
|
2642
|
+
await this.externalAccessory(accessory);
|
|
2626
2643
|
} else {
|
|
2627
|
-
this.debugLog(`${accessory.displayName} External Accessory Mode: ${device.external}`);
|
|
2644
|
+
await this.debugLog(`${accessory.displayName} External Accessory Mode: ${device.external}`);
|
|
2628
2645
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
2629
2646
|
}
|
|
2630
2647
|
}
|
|
@@ -2642,67 +2659,67 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2642
2659
|
async statusCode(statusCode: number): Promise<void> {
|
|
2643
2660
|
switch (statusCode) {
|
|
2644
2661
|
case 151:
|
|
2645
|
-
this.errorLog(`Command not supported by this device type, statusCode: ${statusCode}, Submit Feature Request Here: ` +
|
|
2662
|
+
await this.errorLog(`Command not supported by this device type, statusCode: ${statusCode}, Submit Feature Request Here: ` +
|
|
2646
2663
|
'https://tinyurl.com/SwitchBotFeatureRequest');
|
|
2647
2664
|
break;
|
|
2648
2665
|
case 152:
|
|
2649
|
-
this.errorLog(`Device not found, statusCode: ${statusCode}`);
|
|
2666
|
+
await this.errorLog(`Device not found, statusCode: ${statusCode}`);
|
|
2650
2667
|
break;
|
|
2651
2668
|
case 160:
|
|
2652
|
-
this.errorLog(`Command is not supported, statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`);
|
|
2669
|
+
await this.errorLog(`Command is not supported, statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`);
|
|
2653
2670
|
break;
|
|
2654
2671
|
case 161:
|
|
2655
|
-
this.errorLog(`Device is offline, statusCode: ${statusCode}`);
|
|
2672
|
+
await this.errorLog(`Device is offline, statusCode: ${statusCode}`);
|
|
2656
2673
|
break;
|
|
2657
2674
|
case 171:
|
|
2658
|
-
this.errorLog(`is offline, statusCode: ${statusCode}`);
|
|
2675
|
+
await this.errorLog(`is offline, statusCode: ${statusCode}`);
|
|
2659
2676
|
break;
|
|
2660
2677
|
case 190:
|
|
2661
|
-
this.errorLog(`Requests reached the daily limit, statusCode: ${statusCode}`);
|
|
2678
|
+
await this.errorLog(`Requests reached the daily limit, statusCode: ${statusCode}`);
|
|
2662
2679
|
break;
|
|
2663
2680
|
case 100:
|
|
2664
|
-
this.debugLog(`Command successfully sent, statusCode: ${statusCode}`);
|
|
2681
|
+
await await this.debugLog(`Command successfully sent, statusCode: ${statusCode}`);
|
|
2665
2682
|
break;
|
|
2666
2683
|
case 200:
|
|
2667
|
-
this.debugLog(`Request successful, statusCode: ${statusCode}`);
|
|
2684
|
+
await await this.debugLog(`Request successful, statusCode: ${statusCode}`);
|
|
2668
2685
|
break;
|
|
2669
2686
|
case 400:
|
|
2670
|
-
this.errorLog('Bad Request, The client has issued an invalid request. This is commonly used to specify validation errors in a request '
|
|
2687
|
+
await this.errorLog('Bad Request, The client has issued an invalid request. This is commonly used to specify validation errors in a request '
|
|
2671
2688
|
+ `payload, statusCode: ${statusCode}`);
|
|
2672
2689
|
break;
|
|
2673
2690
|
case 401:
|
|
2674
|
-
this.errorLog('Unauthorized, Authorization for the API is required, but the request has not been authenticated, '
|
|
2691
|
+
await this.errorLog('Unauthorized, Authorization for the API is required, but the request has not been authenticated, '
|
|
2675
2692
|
+ `statusCode: ${statusCode}`);
|
|
2676
2693
|
break;
|
|
2677
2694
|
case 403:
|
|
2678
|
-
this.errorLog('Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not '
|
|
2695
|
+
await this.errorLog('Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not '
|
|
2679
2696
|
+ `found, statusCode: ${statusCode}`);
|
|
2680
2697
|
break;
|
|
2681
2698
|
case 404:
|
|
2682
|
-
this.errorLog(`Not Found, Specifies the requested path does not exist, statusCode: ${statusCode}`);
|
|
2699
|
+
await this.errorLog(`Not Found, Specifies the requested path does not exist, statusCode: ${statusCode}`);
|
|
2683
2700
|
break;
|
|
2684
2701
|
case 406:
|
|
2685
|
-
this.errorLog('Not Acceptable, The client has requested a MIME type via the Accept header for a value not supported by the server, '
|
|
2702
|
+
await this.errorLog('Not Acceptable, The client has requested a MIME type via the Accept header for a value not supported by the server, '
|
|
2686
2703
|
+ `statusCode: ${statusCode}`);
|
|
2687
2704
|
break;
|
|
2688
2705
|
case 415:
|
|
2689
|
-
this.errorLog('Unsupported Media Type, The client has defined a contentType header that is not supported by the server, '
|
|
2706
|
+
await this.errorLog('Unsupported Media Type, The client has defined a contentType header that is not supported by the server, '
|
|
2690
2707
|
+ `statusCode: ${statusCode}`);
|
|
2691
2708
|
break;
|
|
2692
2709
|
case 422:
|
|
2693
|
-
this.errorLog('Unprocessable Entity, The client has made a valid request, but the server cannot process it. This is often used for '
|
|
2710
|
+
await this.errorLog('Unprocessable Entity, The client has made a valid request, but the server cannot process it. This is often used for '
|
|
2694
2711
|
+ `APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
2695
2712
|
break;
|
|
2696
2713
|
case 429:
|
|
2697
|
-
this.errorLog('Too Many Requests, The client has exceeded the number of requests allowed for a given time window, '
|
|
2714
|
+
await this.errorLog('Too Many Requests, The client has exceeded the number of requests allowed for a given time window, '
|
|
2698
2715
|
+ `statusCode: ${statusCode}`);
|
|
2699
2716
|
break;
|
|
2700
2717
|
case 500:
|
|
2701
|
-
this.errorLog('Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, '
|
|
2718
|
+
await this.errorLog('Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, '
|
|
2702
2719
|
+ `statusCode: ${statusCode}`);
|
|
2703
2720
|
break;
|
|
2704
2721
|
default:
|
|
2705
|
-
this.errorLog(`Unknown statusCode, statusCode: ${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
2722
|
+
await this.errorLog(`Unknown statusCode, statusCode: ${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
2706
2723
|
}
|
|
2707
2724
|
}
|
|
2708
2725
|
|
|
@@ -2718,27 +2735,28 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2718
2735
|
if (statusCode === 200 || statusCode === 100) {
|
|
2719
2736
|
return { body, statusCode };
|
|
2720
2737
|
} else {
|
|
2721
|
-
this.debugLog(`Received status code: ${statusCode}`);
|
|
2738
|
+
await await this.debugLog(`Received status code: ${statusCode}`);
|
|
2722
2739
|
}
|
|
2723
2740
|
} catch (error: any) {
|
|
2724
|
-
this.errorLog(`Error making request: ${error.message}`);
|
|
2741
|
+
await this.errorLog(`Error making request: ${error.message}`);
|
|
2725
2742
|
}
|
|
2726
2743
|
retryCount++;
|
|
2727
|
-
this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`);
|
|
2744
|
+
await await this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`);
|
|
2728
2745
|
await sleep(delayBetweenRetries);
|
|
2729
2746
|
}
|
|
2730
2747
|
return { body: null, statusCode: -1 };
|
|
2731
2748
|
}
|
|
2732
2749
|
|
|
2733
2750
|
// BLE Connection
|
|
2734
|
-
async connectBLE() {
|
|
2751
|
+
async connectBLE(accessory: PlatformAccessory, device: device & devicesConfig) {
|
|
2735
2752
|
let switchbot: any;
|
|
2736
2753
|
try {
|
|
2737
2754
|
const SwitchBot = (await import('node-switchbot')).SwitchBot;
|
|
2738
2755
|
queueScheduler.schedule(() => (switchbot = new SwitchBot()));
|
|
2756
|
+
await await this.debugLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${switchbot}`);
|
|
2739
2757
|
} catch (e: any) {
|
|
2740
2758
|
switchbot = false;
|
|
2741
|
-
this.errorLog(
|
|
2759
|
+
await this.errorLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${switchbot}, Error: ${e}`);
|
|
2742
2760
|
}
|
|
2743
2761
|
return switchbot;
|
|
2744
2762
|
}
|
|
@@ -2750,7 +2768,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2750
2768
|
'utf-8',
|
|
2751
2769
|
),
|
|
2752
2770
|
);
|
|
2753
|
-
this.debugLog(`Plugin Version: ${json.version}`);
|
|
2771
|
+
await await this.debugLog(`Plugin Version: ${json.version}`);
|
|
2754
2772
|
this.version = json.version;
|
|
2755
2773
|
}
|
|
2756
2774
|
|
|
@@ -2786,7 +2804,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2786
2804
|
platformConfig.delayBetweenRetries = this.delayBetweenRetries / 1000;
|
|
2787
2805
|
}
|
|
2788
2806
|
if (Object.entries(platformConfig).length !== 0) {
|
|
2789
|
-
this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
2807
|
+
await await this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
2790
2808
|
}
|
|
2791
2809
|
this.platformConfig = platformConfig;
|
|
2792
2810
|
}
|
|
@@ -2796,13 +2814,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2796
2814
|
this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
|
|
2797
2815
|
if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
|
|
2798
2816
|
this.platformLogging = this.config.options.logging;
|
|
2799
|
-
this.debugWarnLog(`Using Config Logging: ${this.platformLogging}`);
|
|
2817
|
+
await await this.debugWarnLog(`Using Config Logging: ${this.platformLogging}`);
|
|
2800
2818
|
} else if (this.debugMode) {
|
|
2801
2819
|
this.platformLogging = 'debugMode';
|
|
2802
|
-
this.debugWarnLog(`Using ${this.platformLogging} Logging`);
|
|
2820
|
+
await await this.debugWarnLog(`Using ${this.platformLogging} Logging`);
|
|
2803
2821
|
} else {
|
|
2804
2822
|
this.platformLogging = 'standard';
|
|
2805
|
-
this.debugWarnLog(`Using ${this.platformLogging} Logging`);
|
|
2823
|
+
await await this.debugWarnLog(`Using ${this.platformLogging} Logging`);
|
|
2806
2824
|
}
|
|
2807
2825
|
}
|
|
2808
2826
|
|
|
@@ -2810,56 +2828,56 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2810
2828
|
* If device level logging is turned on, log to log.warn
|
|
2811
2829
|
* Otherwise send debug logs to log.debug
|
|
2812
2830
|
*/
|
|
2813
|
-
infoLog(...log: any[]): void {
|
|
2814
|
-
if (this.enablingPlatformLogging()) {
|
|
2831
|
+
async infoLog(...log: any[]): Promise<void> {
|
|
2832
|
+
if (await this.enablingPlatformLogging()) {
|
|
2815
2833
|
this.log.info(String(...log));
|
|
2816
2834
|
}
|
|
2817
2835
|
}
|
|
2818
2836
|
|
|
2819
|
-
successLog(...log: any[]): void {
|
|
2820
|
-
if (this.enablingPlatformLogging()) {
|
|
2837
|
+
async successLog(...log: any[]): Promise<void> {
|
|
2838
|
+
if (await this.enablingPlatformLogging()) {
|
|
2821
2839
|
this.log.success(String(...log));
|
|
2822
2840
|
}
|
|
2823
2841
|
}
|
|
2824
2842
|
|
|
2825
|
-
debugSuccessLog(...log: any[]): void {
|
|
2826
|
-
if (this.enablingPlatformLogging()) {
|
|
2843
|
+
async debugSuccessLog(...log: any[]): Promise<void> {
|
|
2844
|
+
if (await this.enablingPlatformLogging()) {
|
|
2827
2845
|
if (this.platformLogging?.includes('debug')) {
|
|
2828
2846
|
this.log.success('[DEBUG]', String(...log));
|
|
2829
2847
|
}
|
|
2830
2848
|
}
|
|
2831
2849
|
}
|
|
2832
2850
|
|
|
2833
|
-
warnLog(...log: any[]): void {
|
|
2834
|
-
if (this.enablingPlatformLogging()) {
|
|
2851
|
+
async warnLog(...log: any[]): Promise<void> {
|
|
2852
|
+
if (await this.enablingPlatformLogging()) {
|
|
2835
2853
|
this.log.warn(String(...log));
|
|
2836
2854
|
}
|
|
2837
2855
|
}
|
|
2838
2856
|
|
|
2839
|
-
debugWarnLog(...log: any[]): void {
|
|
2840
|
-
if (this.enablingPlatformLogging()) {
|
|
2857
|
+
async debugWarnLog(...log: any[]): Promise<void> {
|
|
2858
|
+
if (await this.enablingPlatformLogging()) {
|
|
2841
2859
|
if (this.platformLogging?.includes('debug')) {
|
|
2842
2860
|
this.log.warn('[DEBUG]', String(...log));
|
|
2843
2861
|
}
|
|
2844
2862
|
}
|
|
2845
2863
|
}
|
|
2846
2864
|
|
|
2847
|
-
errorLog(...log: any[]): void {
|
|
2848
|
-
if (this.enablingPlatformLogging()) {
|
|
2865
|
+
async errorLog(...log: any[]): Promise<void> {
|
|
2866
|
+
if (await this.enablingPlatformLogging()) {
|
|
2849
2867
|
this.log.error(String(...log));
|
|
2850
2868
|
}
|
|
2851
2869
|
}
|
|
2852
2870
|
|
|
2853
|
-
debugErrorLog(...log: any[]): void {
|
|
2854
|
-
if (this.enablingPlatformLogging()) {
|
|
2871
|
+
async debugErrorLog(...log: any[]): Promise<void> {
|
|
2872
|
+
if (await this.enablingPlatformLogging()) {
|
|
2855
2873
|
if (this.platformLogging?.includes('debug')) {
|
|
2856
2874
|
this.log.error('[DEBUG]', String(...log));
|
|
2857
2875
|
}
|
|
2858
2876
|
}
|
|
2859
2877
|
}
|
|
2860
2878
|
|
|
2861
|
-
debugLog(...log: any[]): void {
|
|
2862
|
-
if (this.enablingPlatformLogging()) {
|
|
2879
|
+
async debugLog(...log: any[]): Promise<void> {
|
|
2880
|
+
if (await this.enablingPlatformLogging()) {
|
|
2863
2881
|
if (this.platformLogging === 'debugMode') {
|
|
2864
2882
|
this.log.debug(String(...log));
|
|
2865
2883
|
} else if (this.platformLogging === 'debug') {
|
|
@@ -2868,7 +2886,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2868
2886
|
}
|
|
2869
2887
|
}
|
|
2870
2888
|
|
|
2871
|
-
enablingPlatformLogging(): boolean {
|
|
2889
|
+
async enablingPlatformLogging(): Promise<boolean> {
|
|
2872
2890
|
return this.platformLogging?.includes('debug') || this.platformLogging === 'standard';
|
|
2873
2891
|
}
|
|
2874
2892
|
}
|