@switchbot/homebridge-switchbot 3.5.1-beta.9 → 3.5.1
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/CHANGELOG.md +7 -0
- package/config.schema.json +19 -3
- package/dist/device/blindtilt.d.ts +6 -4
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +60 -46
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +6 -3
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +59 -25
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +6 -3
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +47 -29
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +6 -3
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +53 -36
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +6 -3
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +45 -31
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +6 -4
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +41 -27
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +6 -3
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +59 -152
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +6 -3
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +53 -32
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +6 -3
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +49 -30
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +6 -3
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +47 -28
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +6 -3
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +44 -27
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +6 -3
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +46 -28
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +6 -3
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +38 -25
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +6 -3
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +43 -27
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +6 -3
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +42 -27
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +6 -3
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +37 -24
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +6 -3
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +30 -17
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +6 -3
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +37 -22
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +6 -3
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +43 -26
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +2 -2
- package/dist/irdevice/airconditioner.d.ts +1 -3
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +67 -177
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +0 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +24 -53
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +12 -17
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +22 -38
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +22 -10
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +94 -100
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +20 -38
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +79 -77
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +38 -53
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +11 -16
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +11 -16
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +4 -6
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +564 -665
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +10 -8
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +2 -1
- package/dist/types/bledevicestatus.d.ts.map +1 -1
- package/dist/types/devicestatus.d.ts +1 -1
- package/dist/types/devicestatus.d.ts.map +1 -1
- package/package.json +11 -11
- package/src/device/blindtilt.ts +64 -48
- package/src/device/bot.ts +79 -26
- package/src/device/ceilinglight.ts +57 -31
- package/src/device/colorbulb.ts +57 -43
- package/src/device/contact.ts +49 -31
- package/src/device/curtain.ts +51 -28
- package/src/device/device.ts +61 -135
- package/src/device/fan.ts +67 -33
- package/src/device/hub.ts +62 -33
- package/src/device/humidifier.ts +60 -33
- package/src/device/iosensor.ts +51 -30
- package/src/device/lightstrip.ts +52 -29
- package/src/device/lock.ts +55 -26
- package/src/device/meter.ts +60 -29
- package/src/device/meterplus.ts +56 -29
- package/src/device/motion.ts +50 -26
- package/src/device/plug.ts +38 -18
- package/src/device/robotvacuumcleaner.ts +53 -24
- package/src/device/waterdetector.ts +62 -28
- package/src/homebridge-ui/public/index.html +2 -2
- package/src/irdevice/airconditioner.ts +76 -165
- package/src/irdevice/airpurifier.ts +29 -49
- package/src/irdevice/camera.ts +13 -16
- package/src/irdevice/fan.ts +25 -35
- package/src/irdevice/irdevice.ts +97 -96
- package/src/irdevice/light.ts +21 -35
- package/src/irdevice/other.ts +79 -77
- package/src/irdevice/tv.ts +40 -51
- package/src/irdevice/vacuumcleaner.ts +12 -15
- package/src/irdevice/waterheater.ts +12 -15
- package/src/platform.ts +566 -696
- package/src/settings.ts +11 -8
- package/src/types/bledevicestatus.ts +4 -2
- package/src/types/devicestatus.ts +1 -1
- package/.github/npm-version-script.cjs +0 -81
package/dist/platform.js
CHANGED
|
@@ -38,8 +38,9 @@ import fakegato from 'fakegato-history';
|
|
|
38
38
|
import crypto, { randomUUID } from 'crypto';
|
|
39
39
|
import { readFileSync, writeFileSync } from 'fs';
|
|
40
40
|
import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes';
|
|
41
|
+
import { PLATFORM_NAME, PLUGIN_NAME, Devices, deleteWebhook, queryWebhook, setupWebhook, updateWebhook } from './settings.js';
|
|
41
42
|
import { isBlindTiltDevice, isCurtainDevice, sleep } from './utils.js';
|
|
42
|
-
import {
|
|
43
|
+
import { SwitchBotModel } from 'node-switchbot';
|
|
43
44
|
/**
|
|
44
45
|
* HomebridgePlatform
|
|
45
46
|
* This class is the main constructor for your plugin, this is where you should
|
|
@@ -57,10 +58,10 @@ export class SwitchBotPlatform {
|
|
|
57
58
|
platformConfig;
|
|
58
59
|
platformLogging;
|
|
59
60
|
config;
|
|
60
|
-
webhookEventListener = null;
|
|
61
61
|
mqttClient = null;
|
|
62
|
-
|
|
62
|
+
webhookEventListener = null;
|
|
63
63
|
eve;
|
|
64
|
+
fakegatoAPI;
|
|
64
65
|
webhookEventHandler = {};
|
|
65
66
|
constructor(log, config, api) {
|
|
66
67
|
// initialize
|
|
@@ -117,7 +118,7 @@ export class SwitchBotPlatform {
|
|
|
117
118
|
}
|
|
118
119
|
catch (e) {
|
|
119
120
|
this.errorLog(`Failed to Discover, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
120
|
-
this.debugErrorLog(`Failed to Discover, Error: ${e}`);
|
|
121
|
+
await this.debugErrorLog(`Failed to Discover, Error: ${e}`);
|
|
121
122
|
}
|
|
122
123
|
});
|
|
123
124
|
this.setupMqtt();
|
|
@@ -138,7 +139,7 @@ export class SwitchBotPlatform {
|
|
|
138
139
|
this.mqttClient.subscribe('homebridge-switchbot/webhook/+');
|
|
139
140
|
this.mqttClient.on('message', async (topic, message) => {
|
|
140
141
|
try {
|
|
141
|
-
await this.debugLog(`Received Webhook via MQTT: ${topic}=${message}`);
|
|
142
|
+
await await this.debugLog(`Received Webhook via MQTT: ${topic}=${message}`);
|
|
142
143
|
const context = JSON.parse(message.toString());
|
|
143
144
|
this.webhookEventHandler[context.deviceMac]?.(context);
|
|
144
145
|
}
|
|
@@ -168,7 +169,7 @@ export class SwitchBotPlatform {
|
|
|
168
169
|
request.on('data', async (data) => {
|
|
169
170
|
try {
|
|
170
171
|
const body = JSON.parse(data);
|
|
171
|
-
this.debugLog(`Received Webhook: ${JSON.stringify(body)}`);
|
|
172
|
+
await this.debugLog(`Received Webhook: ${JSON.stringify(body)}`);
|
|
172
173
|
if (this.config.options?.mqttURL) {
|
|
173
174
|
const mac = body.context.deviceMac
|
|
174
175
|
?.toLowerCase()
|
|
@@ -211,9 +212,9 @@ export class SwitchBotPlatform {
|
|
|
211
212
|
}),
|
|
212
213
|
});
|
|
213
214
|
const response = await body.json();
|
|
214
|
-
this.debugLog(`setupWebhook: url:${url}`);
|
|
215
|
-
this.debugLog(`setupWebhook: body:${JSON.stringify(response)}`);
|
|
216
|
-
this.debugLog(`setupWebhook: statusCode:${statusCode}`);
|
|
215
|
+
await this.debugLog(`setupWebhook: url:${url}`);
|
|
216
|
+
await this.debugLog(`setupWebhook: body:${JSON.stringify(response)}`);
|
|
217
|
+
await this.debugLog(`setupWebhook: statusCode:${statusCode}`);
|
|
217
218
|
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
218
219
|
this.errorLog(`Failed to configure webhook. Existing webhook well be overridden. HTTP:${statusCode} API:${response?.statusCode} `
|
|
219
220
|
+ `message:${response?.message}`);
|
|
@@ -233,9 +234,9 @@ export class SwitchBotPlatform {
|
|
|
233
234
|
}),
|
|
234
235
|
});
|
|
235
236
|
const response = await body.json();
|
|
236
|
-
this.debugLog(`updateWebhook: url:${url}`);
|
|
237
|
-
this.debugLog(`updateWebhook: body:${JSON.stringify(response)}`);
|
|
238
|
-
this.debugLog(`updateWebhook: statusCode:${statusCode}`);
|
|
237
|
+
await this.debugLog(`updateWebhook: url:${url}`);
|
|
238
|
+
await this.debugLog(`updateWebhook: body:${JSON.stringify(response)}`);
|
|
239
|
+
await this.debugLog(`updateWebhook: statusCode:${statusCode}`);
|
|
239
240
|
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
240
241
|
this.errorLog(`Failed to update webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
|
|
241
242
|
}
|
|
@@ -252,8 +253,8 @@ export class SwitchBotPlatform {
|
|
|
252
253
|
}),
|
|
253
254
|
});
|
|
254
255
|
const response = await body.json();
|
|
255
|
-
this.debugLog(`queryWebhook: body:${JSON.stringify(response)}`);
|
|
256
|
-
this.debugLog(`queryWebhook: statusCode:${statusCode}`);
|
|
256
|
+
await this.debugLog(`queryWebhook: body:${JSON.stringify(response)}`);
|
|
257
|
+
await this.debugLog(`queryWebhook: statusCode:${statusCode}`);
|
|
257
258
|
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
258
259
|
this.errorLog(`Failed to query webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
|
|
259
260
|
}
|
|
@@ -275,7 +276,7 @@ export class SwitchBotPlatform {
|
|
|
275
276
|
}),
|
|
276
277
|
});
|
|
277
278
|
const response = await body.json();
|
|
278
|
-
this.debugLog(`deleteWebhook: url:${url}, body:${JSON.stringify(response)}, statusCode:${statusCode}`);
|
|
279
|
+
await this.debugLog(`deleteWebhook: url:${url}, body:${JSON.stringify(response)}, statusCode:${statusCode}`);
|
|
279
280
|
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
280
281
|
this.errorLog(`Failed to delete webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
|
|
281
282
|
}
|
|
@@ -293,8 +294,8 @@ export class SwitchBotPlatform {
|
|
|
293
294
|
* This function is invoked when homebridge restores cached accessories from disk at startup.
|
|
294
295
|
* It should be used to setup event handlers for characteristics and update respective values.
|
|
295
296
|
*/
|
|
296
|
-
configureAccessory(accessory) {
|
|
297
|
-
this.debugLog(`Loading accessory from cache: ${accessory.displayName}`);
|
|
297
|
+
async configureAccessory(accessory) {
|
|
298
|
+
await this.debugLog(`Loading accessory from cache: ${accessory.displayName}`);
|
|
298
299
|
// add the restored accessory to the accessories cache so we can track if it has already been registered
|
|
299
300
|
this.accessories.push(accessory);
|
|
300
301
|
}
|
|
@@ -316,7 +317,7 @@ export class SwitchBotPlatform {
|
|
|
316
317
|
platformConfig['pushRate'] = this.config.options.pushRate;
|
|
317
318
|
}
|
|
318
319
|
if (Object.entries(platformConfig).length !== 0) {
|
|
319
|
-
this.debugWarnLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
320
|
+
await this.debugWarnLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
320
321
|
}
|
|
321
322
|
if (this.config.options) {
|
|
322
323
|
// Device Config
|
|
@@ -431,7 +432,7 @@ export class SwitchBotPlatform {
|
|
|
431
432
|
if (pluginConfig.credentials.token) {
|
|
432
433
|
pluginConfig.credentials.openToken = undefined;
|
|
433
434
|
}
|
|
434
|
-
this.debugWarnLog(`token: ${pluginConfig.credentials.token}`);
|
|
435
|
+
await this.debugWarnLog(`token: ${pluginConfig.credentials.token}`);
|
|
435
436
|
// save the config, ensuring we maintain pretty json
|
|
436
437
|
writeFileSync(this.api.user.configPath(), JSON.stringify(currentConfig, null, 4));
|
|
437
438
|
this.verifyConfig();
|
|
@@ -471,29 +472,29 @@ export class SwitchBotPlatform {
|
|
|
471
472
|
let retryCount = 0;
|
|
472
473
|
const maxRetries = this.maxRetries; // Maximum number of retries
|
|
473
474
|
const delayBetweenRetries = this.delayBetweenRetries; // Delay between retries in milliseconds
|
|
474
|
-
this.debugWarnLog(`Retry Count: ${retryCount}`);
|
|
475
|
-
this.debugWarnLog(`Max Retries: ${maxRetries}`);
|
|
476
|
-
this.debugWarnLog(`Delay Between Retries: ${delayBetweenRetries}`);
|
|
475
|
+
await this.debugWarnLog(`Retry Count: ${retryCount}`);
|
|
476
|
+
await this.debugWarnLog(`Max Retries: ${maxRetries}`);
|
|
477
|
+
await this.debugWarnLog(`Delay Between Retries: ${delayBetweenRetries}`);
|
|
477
478
|
while (retryCount < maxRetries) {
|
|
478
479
|
try {
|
|
479
480
|
const { body, statusCode } = await request(Devices, {
|
|
480
481
|
headers: this.generateHeaders(),
|
|
481
482
|
});
|
|
482
|
-
this.debugWarnLog(`statusCode: ${statusCode}`);
|
|
483
|
+
await this.debugWarnLog(`statusCode: ${statusCode}`);
|
|
483
484
|
const devicesAPI = await body.json();
|
|
484
|
-
this.debugWarnLog(`devicesAPI: ${JSON.stringify(devicesAPI)}`);
|
|
485
|
-
this.debugWarnLog(`devicesAPI Body: ${JSON.stringify(devicesAPI.body)}`);
|
|
486
|
-
this.debugWarnLog(`devicesAPI StatusCode: ${devicesAPI.statusCode}`);
|
|
485
|
+
await this.debugWarnLog(`devicesAPI: ${JSON.stringify(devicesAPI)}`);
|
|
486
|
+
await this.debugWarnLog(`devicesAPI Body: ${JSON.stringify(devicesAPI.body)}`);
|
|
487
|
+
await this.debugWarnLog(`devicesAPI StatusCode: ${devicesAPI.statusCode}`);
|
|
487
488
|
if ((statusCode === 200 || statusCode === 100) && (devicesAPI.statusCode === 200 || devicesAPI.statusCode === 100)) {
|
|
488
|
-
this.debugErrorLog(`statusCode: ${statusCode} & devicesAPI StatusCode: ${devicesAPI.statusCode}`);
|
|
489
|
+
await this.debugErrorLog(`statusCode: ${statusCode} & devicesAPI StatusCode: ${devicesAPI.statusCode}`);
|
|
489
490
|
// SwitchBot Devices
|
|
490
491
|
const deviceLists = devicesAPI.body.deviceList;
|
|
491
|
-
this.debugWarnLog(`DeviceLists: ${JSON.stringify(deviceLists)}`);
|
|
492
|
-
this.debugWarnLog(`DeviceLists Length: ${deviceLists.length}`);
|
|
492
|
+
await this.debugWarnLog(`DeviceLists: ${JSON.stringify(deviceLists)}`);
|
|
493
|
+
await this.debugWarnLog(`DeviceLists Length: ${deviceLists.length}`);
|
|
493
494
|
if (!this.config.options?.devices) {
|
|
494
|
-
this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
495
|
+
await this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
495
496
|
if (deviceLists.length === 0) {
|
|
496
|
-
this.debugLog(`SwitchBot API
|
|
497
|
+
await this.debugLog(`SwitchBot API Has No Devices With Cloud Services Enabled: ${JSON.stringify(devicesAPI.body)}`);
|
|
497
498
|
}
|
|
498
499
|
else {
|
|
499
500
|
const devices = deviceLists.map((v) => v);
|
|
@@ -508,9 +509,9 @@ export class SwitchBotPlatform {
|
|
|
508
509
|
}
|
|
509
510
|
}
|
|
510
511
|
else if (this.config.credentials?.token && this.config.options.devices) {
|
|
511
|
-
this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
512
|
+
await this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
512
513
|
if (deviceLists.length === 0) {
|
|
513
|
-
this.debugLog(`SwitchBot API
|
|
514
|
+
await this.debugLog(`SwitchBot API Has No Devices With Cloud Services Enabled: ${JSON.stringify(devicesAPI.body)}`);
|
|
514
515
|
}
|
|
515
516
|
else {
|
|
516
517
|
const deviceConfigs = this.config.options?.devices;
|
|
@@ -519,7 +520,7 @@ export class SwitchBotPlatform {
|
|
|
519
520
|
...itm,
|
|
520
521
|
}));
|
|
521
522
|
const devices = mergeBydeviceId(deviceLists, deviceConfigs);
|
|
522
|
-
this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
|
|
523
|
+
await this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
|
|
523
524
|
for (const device of devices) {
|
|
524
525
|
if (!device.deviceType) {
|
|
525
526
|
device.deviceType = device.configDeviceType;
|
|
@@ -541,12 +542,12 @@ export class SwitchBotPlatform {
|
|
|
541
542
|
this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
542
543
|
}
|
|
543
544
|
else {
|
|
544
|
-
this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
545
|
+
await this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
545
546
|
}
|
|
546
547
|
// IR Devices
|
|
547
548
|
const irDeviceLists = devicesAPI.body.infraredRemoteList;
|
|
548
549
|
if (!this.config.options?.irdevices) {
|
|
549
|
-
this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
550
|
+
await this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
550
551
|
const devices = irDeviceLists.map((v) => v);
|
|
551
552
|
for (const device of devices) {
|
|
552
553
|
if (device.remoteType) {
|
|
@@ -555,14 +556,14 @@ export class SwitchBotPlatform {
|
|
|
555
556
|
}
|
|
556
557
|
}
|
|
557
558
|
else {
|
|
558
|
-
this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
559
|
+
await this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
559
560
|
const irDeviceConfig = this.config.options?.irdevices;
|
|
560
561
|
const mergeIRBydeviceId = (a1, a2) => a1.map((itm) => ({
|
|
561
562
|
...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
|
|
562
563
|
...itm,
|
|
563
564
|
}));
|
|
564
565
|
const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
|
|
565
|
-
this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
|
|
566
|
+
await this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
|
|
566
567
|
for (const device of devices) {
|
|
567
568
|
this.createIRDevice(device);
|
|
568
569
|
}
|
|
@@ -571,7 +572,7 @@ export class SwitchBotPlatform {
|
|
|
571
572
|
this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
572
573
|
}
|
|
573
574
|
else {
|
|
574
|
-
this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
575
|
+
await this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
575
576
|
}
|
|
576
577
|
break;
|
|
577
578
|
}
|
|
@@ -588,12 +589,12 @@ export class SwitchBotPlatform {
|
|
|
588
589
|
catch (e) {
|
|
589
590
|
retryCount++;
|
|
590
591
|
this.debugErrorLog(`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
591
|
-
this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
|
|
592
|
+
await this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
|
|
592
593
|
}
|
|
593
594
|
}
|
|
594
595
|
}
|
|
595
596
|
else if (!this.config.credentials?.token && this.config.options?.devices) {
|
|
596
|
-
this.debugLog(`SwitchBot Device Manual Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
597
|
+
await this.debugLog(`SwitchBot Device Manual Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
597
598
|
const deviceConfigs = this.config.options?.devices;
|
|
598
599
|
const devices = deviceConfigs.map((v) => v);
|
|
599
600
|
for (const device of devices) {
|
|
@@ -608,73 +609,73 @@ export class SwitchBotPlatform {
|
|
|
608
609
|
this.errorLog('Neither SwitchBot Token or Device Config are not set.');
|
|
609
610
|
}
|
|
610
611
|
}
|
|
611
|
-
createDevice(device) {
|
|
612
|
+
async createDevice(device) {
|
|
612
613
|
switch (device.deviceType) {
|
|
613
614
|
case 'Humidifier':
|
|
614
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
615
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
615
616
|
this.createHumidifier(device);
|
|
616
617
|
break;
|
|
617
618
|
case 'Hub Mini':
|
|
618
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
619
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
619
620
|
break;
|
|
620
621
|
case 'Hub Plus':
|
|
621
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
622
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
622
623
|
break;
|
|
623
624
|
case 'Hub 2':
|
|
624
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
625
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
625
626
|
this.createHub2(device);
|
|
626
627
|
break;
|
|
627
628
|
case 'Bot':
|
|
628
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
629
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
629
630
|
this.createBot(device);
|
|
630
631
|
break;
|
|
631
632
|
case 'Meter':
|
|
632
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
633
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
633
634
|
this.createMeter(device);
|
|
634
635
|
break;
|
|
635
636
|
case 'MeterPlus':
|
|
636
637
|
case 'Meter Plus (JP)':
|
|
637
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
638
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
638
639
|
this.createMeterPlus(device);
|
|
639
640
|
break;
|
|
640
641
|
case 'WoIOSensor':
|
|
641
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
642
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
642
643
|
this.createIOSensor(device);
|
|
643
644
|
break;
|
|
644
645
|
case 'Water Detector':
|
|
645
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
646
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
646
647
|
this.createWaterDetector(device);
|
|
647
648
|
break;
|
|
648
649
|
case 'Motion Sensor':
|
|
649
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
650
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
650
651
|
this.createMotion(device);
|
|
651
652
|
break;
|
|
652
653
|
case 'Contact Sensor':
|
|
653
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
654
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
654
655
|
this.createContact(device);
|
|
655
656
|
break;
|
|
656
657
|
case 'Curtain':
|
|
657
658
|
case 'Curtain3':
|
|
658
|
-
this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
|
|
659
|
+
await this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
|
|
659
660
|
this.createCurtain(device);
|
|
660
661
|
break;
|
|
661
662
|
case 'Blind Tilt':
|
|
662
|
-
this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
|
|
663
|
+
await this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
|
|
663
664
|
this.createBlindTilt(device);
|
|
664
665
|
break;
|
|
665
666
|
case 'Plug':
|
|
666
667
|
case 'Plug Mini (US)':
|
|
667
668
|
case 'Plug Mini (JP)':
|
|
668
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
669
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
669
670
|
this.createPlug(device);
|
|
670
671
|
break;
|
|
671
672
|
case 'Smart Lock':
|
|
672
673
|
case 'Smart Lock Pro':
|
|
673
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
674
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
674
675
|
this.createLock(device);
|
|
675
676
|
break;
|
|
676
677
|
case 'Color Bulb':
|
|
677
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
678
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
678
679
|
this.createColorBulb(device);
|
|
679
680
|
break;
|
|
680
681
|
case 'K10+':
|
|
@@ -683,32 +684,32 @@ export class SwitchBotPlatform {
|
|
|
683
684
|
case 'Robot Vacuum Cleaner S1':
|
|
684
685
|
case 'Robot Vacuum Cleaner S1 Plus':
|
|
685
686
|
case 'Robot Vacuum Cleaner S10':
|
|
686
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
687
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
687
688
|
this.createRobotVacuumCleaner(device);
|
|
688
689
|
break;
|
|
689
690
|
case 'Ceiling Light':
|
|
690
691
|
case 'Ceiling Light Pro':
|
|
691
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
692
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
692
693
|
this.createCeilingLight(device);
|
|
693
694
|
break;
|
|
694
695
|
case 'Strip Light':
|
|
695
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
696
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
696
697
|
this.createStripLight(device);
|
|
697
698
|
break;
|
|
698
699
|
case 'Battery Circulator Fan':
|
|
699
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
700
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
700
701
|
this.createFan(device);
|
|
701
702
|
break;
|
|
702
703
|
case 'Remote':
|
|
703
704
|
case 'Indoor Cam':
|
|
704
705
|
case 'remote with screen+':
|
|
705
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}, is currently not supported, device: ${JSON.stringify(device)}`);
|
|
706
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}, is currently not supported, device: ${JSON.stringify(device)}`);
|
|
706
707
|
break;
|
|
707
708
|
default:
|
|
708
709
|
this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`, +`Submit Feature Requests Here: https://tinyurl.com/SwitchBotFeatureRequest, device: ${JSON.stringify(device)}`);
|
|
709
710
|
}
|
|
710
711
|
}
|
|
711
|
-
createIRDevice(device) {
|
|
712
|
+
async createIRDevice(device) {
|
|
712
713
|
if (device.connectionType === undefined) {
|
|
713
714
|
device.connectionType = 'OpenAPI';
|
|
714
715
|
}
|
|
@@ -725,7 +726,7 @@ export class SwitchBotPlatform {
|
|
|
725
726
|
case 'DIY DVD':
|
|
726
727
|
case 'Speaker':
|
|
727
728
|
case 'DIY Speaker':
|
|
728
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
729
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
729
730
|
if (device.external === undefined) {
|
|
730
731
|
device.external = true;
|
|
731
732
|
this.createTV(device);
|
|
@@ -736,45 +737,45 @@ export class SwitchBotPlatform {
|
|
|
736
737
|
break;
|
|
737
738
|
case 'Fan':
|
|
738
739
|
case 'DIY Fan':
|
|
739
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
740
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
740
741
|
this.createIRFan(device);
|
|
741
742
|
break;
|
|
742
743
|
case 'Air Conditioner':
|
|
743
744
|
case 'DIY Air Conditioner':
|
|
744
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
745
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
745
746
|
this.createAirConditioner(device);
|
|
746
747
|
break;
|
|
747
748
|
case 'Light':
|
|
748
749
|
case 'DIY Light':
|
|
749
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
750
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
750
751
|
this.createLight(device);
|
|
751
752
|
break;
|
|
752
753
|
case 'Air Purifier':
|
|
753
754
|
case 'DIY Air Purifier':
|
|
754
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
755
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
755
756
|
this.createAirPurifier(device);
|
|
756
757
|
break;
|
|
757
758
|
case 'Water Heater':
|
|
758
759
|
case 'DIY Water Heater':
|
|
759
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
760
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
760
761
|
this.createWaterHeater(device);
|
|
761
762
|
break;
|
|
762
763
|
case 'Vacuum Cleaner':
|
|
763
764
|
case 'DIY Vacuum Cleaner':
|
|
764
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
765
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
765
766
|
this.createVacuumCleaner(device);
|
|
766
767
|
break;
|
|
767
768
|
case 'Camera':
|
|
768
769
|
case 'DIY Camera':
|
|
769
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
770
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
770
771
|
this.createCamera(device);
|
|
771
772
|
break;
|
|
772
773
|
case 'Others':
|
|
773
|
-
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
774
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
774
775
|
this.createOthers(device);
|
|
775
776
|
break;
|
|
776
777
|
default:
|
|
777
|
-
this.debugLog(`Unsupported Device: ${JSON.stringify(device)}`);
|
|
778
|
+
await this.debugLog(`Unsupported Device: ${JSON.stringify(device)}`);
|
|
778
779
|
this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.remoteType}, is currently not supported.`);
|
|
779
780
|
this.warnLog('Submit Feature Requests Here: ' + 'https://tinyurl.com/SwitchBotFeatureRequest');
|
|
780
781
|
}
|
|
@@ -788,52 +789,48 @@ export class SwitchBotPlatform {
|
|
|
788
789
|
// the accessory already exists
|
|
789
790
|
if (await this.registerDevice(device)) {
|
|
790
791
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
791
|
-
existingAccessory.context.
|
|
792
|
-
existingAccessory.context.
|
|
793
|
-
existingAccessory.
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
}
|
|
797
|
-
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
798
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
792
|
+
existingAccessory.context.device = device;
|
|
793
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
794
|
+
existingAccessory.context.deviceType = device.deviceType;
|
|
795
|
+
existingAccessory.context.model = SwitchBotModel.Humidifier;
|
|
796
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
799
797
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
798
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
799
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
800
800
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
801
801
|
// create the accessory handler for the restored accessory
|
|
802
802
|
// this is imported from `platformAccessory.ts`
|
|
803
803
|
new Humidifier(this, existingAccessory, device);
|
|
804
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
804
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
805
805
|
}
|
|
806
806
|
else {
|
|
807
807
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
808
808
|
}
|
|
809
809
|
}
|
|
810
810
|
else if (await this.registerDevice(device)) {
|
|
811
|
-
// the accessory does not yet exist, so we need to create it
|
|
812
|
-
if (!device.external) {
|
|
813
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
814
|
-
}
|
|
815
811
|
// create a new accessory
|
|
816
812
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
817
813
|
// store a copy of the device object in the `accessory.context`
|
|
818
814
|
// the `context` property can be used to store any data about the accessory you may need
|
|
819
815
|
accessory.context.device = device;
|
|
820
|
-
accessory.context.
|
|
821
|
-
accessory.context.
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
}
|
|
825
|
-
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
816
|
+
accessory.context.deviceId = device.deviceId;
|
|
817
|
+
accessory.context.deviceType = device.deviceType;
|
|
818
|
+
accessory.context.model = SwitchBotModel.Humidifier;
|
|
819
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
826
820
|
accessory.context.connectionType = await this.connectionType(device);
|
|
821
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
822
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
823
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
827
824
|
// create the accessory handler for the newly create accessory
|
|
828
825
|
// this is imported from `platformAccessory.ts`
|
|
829
826
|
new Humidifier(this, accessory, device);
|
|
830
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
827
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
831
828
|
// publish device externally or link the accessory to your platform
|
|
832
829
|
this.externalOrPlatform(device, accessory);
|
|
833
830
|
this.accessories.push(accessory);
|
|
834
831
|
}
|
|
835
832
|
else {
|
|
836
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType}
|
|
833
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
|
|
837
834
|
}
|
|
838
835
|
}
|
|
839
836
|
async createBot(device) {
|
|
@@ -845,53 +842,49 @@ export class SwitchBotPlatform {
|
|
|
845
842
|
// the accessory already exists
|
|
846
843
|
if (await this.registerDevice(device)) {
|
|
847
844
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
848
|
-
existingAccessory.context.
|
|
849
|
-
existingAccessory.context.
|
|
850
|
-
existingAccessory.
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
}
|
|
854
|
-
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
855
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
845
|
+
existingAccessory.context.device = device;
|
|
846
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
847
|
+
existingAccessory.context.deviceType = device.deviceType;
|
|
848
|
+
existingAccessory.context.model = SwitchBotModel.Bot;
|
|
849
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
856
850
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
851
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
852
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
857
853
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
858
854
|
// create the accessory handler for the restored accessory
|
|
859
855
|
// this is imported from `platformAccessory.ts`
|
|
860
856
|
new Bot(this, existingAccessory, device);
|
|
861
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
857
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
862
858
|
}
|
|
863
859
|
else {
|
|
864
860
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
865
861
|
}
|
|
866
862
|
}
|
|
867
863
|
else if (await this.registerDevice(device)) {
|
|
868
|
-
// the accessory does not yet exist, so we need to create it
|
|
869
|
-
if (!device.external) {
|
|
870
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
871
|
-
}
|
|
872
864
|
// create a new accessory
|
|
873
865
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
874
866
|
// store a copy of the device object in the `accessory.context`
|
|
875
867
|
// the `context` property can be used to store any data about the accessory you may need
|
|
876
868
|
accessory.context.device = device;
|
|
877
|
-
accessory.context.
|
|
878
|
-
accessory.context.
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
}
|
|
882
|
-
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
869
|
+
accessory.context.deviceId = device.deviceId;
|
|
870
|
+
accessory.context.deviceType = device.deviceType;
|
|
871
|
+
accessory.context.model = SwitchBotModel.Bot;
|
|
872
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
883
873
|
accessory.context.connectionType = await this.connectionType(device);
|
|
874
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
875
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
876
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
884
877
|
// accessory.context.version = findaccessories.accessoryAttribute.softwareRevision;
|
|
885
878
|
// create the accessory handler for the newly create accessory
|
|
886
879
|
// this is imported from `platformAccessory.ts`
|
|
887
880
|
new Bot(this, accessory, device);
|
|
888
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
881
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
889
882
|
// publish device externally or link the accessory to your platform
|
|
890
883
|
this.externalOrPlatform(device, accessory);
|
|
891
884
|
this.accessories.push(accessory);
|
|
892
885
|
}
|
|
893
886
|
else {
|
|
894
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType}
|
|
887
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
|
|
895
888
|
}
|
|
896
889
|
}
|
|
897
890
|
async createMeter(device) {
|
|
@@ -903,52 +896,48 @@ export class SwitchBotPlatform {
|
|
|
903
896
|
// the accessory already exists
|
|
904
897
|
if (await this.registerDevice(device)) {
|
|
905
898
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
906
|
-
existingAccessory.context.
|
|
907
|
-
existingAccessory.context.
|
|
908
|
-
existingAccessory.
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
}
|
|
912
|
-
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
913
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
899
|
+
existingAccessory.context.device = device;
|
|
900
|
+
existingAccessory.context.model = SwitchBotModel.Meter;
|
|
901
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
902
|
+
existingAccessory.context.deviceType = device.deviceType;
|
|
903
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
914
904
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
905
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
906
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
915
907
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
916
908
|
// create the accessory handler for the restored accessory
|
|
917
909
|
// this is imported from `platformAccessory.ts`
|
|
918
910
|
new Meter(this, existingAccessory, device);
|
|
919
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
911
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
920
912
|
}
|
|
921
913
|
else {
|
|
922
914
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
923
915
|
}
|
|
924
916
|
}
|
|
925
917
|
else if (await this.registerDevice(device)) {
|
|
926
|
-
// the accessory does not yet exist, so we need to create it
|
|
927
|
-
if (!device.external) {
|
|
928
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
929
|
-
}
|
|
930
918
|
// create a new accessory
|
|
931
919
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
932
920
|
// store a copy of the device object in the `accessory.context`
|
|
933
921
|
// the `context` property can be used to store any data about the accessory you may need
|
|
934
922
|
accessory.context.device = device;
|
|
935
|
-
accessory.context.model =
|
|
936
|
-
accessory.context.
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
}
|
|
940
|
-
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
923
|
+
accessory.context.model = SwitchBotModel.Meter;
|
|
924
|
+
accessory.context.deviceId = device.deviceId;
|
|
925
|
+
accessory.context.deviceType = device.deviceType;
|
|
926
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
941
927
|
accessory.context.connectionType = await this.connectionType(device);
|
|
928
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
929
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
930
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
942
931
|
// create the accessory handler for the newly create accessory
|
|
943
932
|
// this is imported from `platformAccessory.ts`
|
|
944
933
|
new Meter(this, accessory, device);
|
|
945
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
934
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
946
935
|
// publish device externally or link the accessory to your platform
|
|
947
936
|
this.externalOrPlatform(device, accessory);
|
|
948
937
|
this.accessories.push(accessory);
|
|
949
938
|
}
|
|
950
939
|
else {
|
|
951
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType}
|
|
940
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
|
|
952
941
|
}
|
|
953
942
|
}
|
|
954
943
|
async createMeterPlus(device) {
|
|
@@ -961,52 +950,48 @@ export class SwitchBotPlatform {
|
|
|
961
950
|
if (await this.registerDevice(device)) {
|
|
962
951
|
// console.log("existingAccessory", existingAccessory);
|
|
963
952
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
964
|
-
existingAccessory.context.
|
|
965
|
-
existingAccessory.context.
|
|
966
|
-
existingAccessory.
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
}
|
|
970
|
-
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
971
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
953
|
+
existingAccessory.context.device = device;
|
|
954
|
+
existingAccessory.context.model = SwitchBotModel.MeterPlusUS ?? SwitchBotModel.MeterPlusJP;
|
|
955
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
956
|
+
existingAccessory.context.deviceType = device.deviceType;
|
|
957
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
972
958
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
959
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
960
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
973
961
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
974
962
|
// create the accessory handler for the restored accessory
|
|
975
963
|
// this is imported from `platformAccessory.ts`
|
|
976
964
|
new MeterPlus(this, existingAccessory, device);
|
|
977
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
965
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
978
966
|
}
|
|
979
967
|
else {
|
|
980
968
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
981
969
|
}
|
|
982
970
|
}
|
|
983
971
|
else if (await this.registerDevice(device)) {
|
|
984
|
-
// the accessory does not yet exist, so we need to create it
|
|
985
|
-
if (!device.external) {
|
|
986
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
987
|
-
}
|
|
988
972
|
// create a new accessory
|
|
989
973
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
990
974
|
// store a copy of the device object in the `accessory.context`
|
|
991
975
|
// the `context` property can be used to store any data about the accessory you may need
|
|
992
976
|
accessory.context.device = device;
|
|
993
|
-
accessory.context.model =
|
|
994
|
-
accessory.context.
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
}
|
|
998
|
-
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
977
|
+
accessory.context.model = SwitchBotModel.MeterPlusUS ?? SwitchBotModel.MeterPlusJP;
|
|
978
|
+
accessory.context.deviceId = device.deviceId;
|
|
979
|
+
accessory.context.deviceType = device.deviceType;
|
|
980
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
999
981
|
accessory.context.connectionType = await this.connectionType(device);
|
|
982
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
983
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
984
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
1000
985
|
// create the accessory handler for the newly create accessory
|
|
1001
986
|
// this is imported from `platformAccessory.ts`
|
|
1002
987
|
new MeterPlus(this, accessory, device);
|
|
1003
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
988
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1004
989
|
// publish device externally or link the accessory to your platform
|
|
1005
990
|
this.externalOrPlatform(device, accessory);
|
|
1006
991
|
this.accessories.push(accessory);
|
|
1007
992
|
}
|
|
1008
993
|
else {
|
|
1009
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType}
|
|
994
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
|
|
1010
995
|
}
|
|
1011
996
|
}
|
|
1012
997
|
async createHub2(device) {
|
|
@@ -1019,52 +1004,48 @@ export class SwitchBotPlatform {
|
|
|
1019
1004
|
if (await this.registerDevice(device)) {
|
|
1020
1005
|
// console.log("existingAccessory", existingAccessory);
|
|
1021
1006
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1022
|
-
existingAccessory.context.
|
|
1023
|
-
existingAccessory.context.
|
|
1024
|
-
existingAccessory.
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
}
|
|
1028
|
-
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1029
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1007
|
+
existingAccessory.context.device = device;
|
|
1008
|
+
existingAccessory.context.model = SwitchBotModel.Hub2;
|
|
1009
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
1010
|
+
existingAccessory.context.deviceType = device.deviceType;
|
|
1011
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1030
1012
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1013
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1014
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1031
1015
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1032
1016
|
// create the accessory handler for the restored accessory
|
|
1033
1017
|
// this is imported from `platformAccessory.ts`
|
|
1034
1018
|
new Hub(this, existingAccessory, device);
|
|
1035
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1019
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1036
1020
|
}
|
|
1037
1021
|
else {
|
|
1038
1022
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1039
1023
|
}
|
|
1040
1024
|
}
|
|
1041
1025
|
else if (await this.registerDevice(device)) {
|
|
1042
|
-
// the accessory does not yet exist, so we need to create it
|
|
1043
|
-
if (!device.external) {
|
|
1044
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1045
|
-
}
|
|
1046
1026
|
// create a new accessory
|
|
1047
1027
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
1048
1028
|
// store a copy of the device object in the `accessory.context`
|
|
1049
1029
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1050
1030
|
accessory.context.device = device;
|
|
1051
|
-
accessory.context.model =
|
|
1052
|
-
accessory.context.
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
}
|
|
1056
|
-
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1031
|
+
accessory.context.model = SwitchBotModel.Hub2;
|
|
1032
|
+
accessory.context.deviceId = device.deviceId;
|
|
1033
|
+
accessory.context.deviceType = device.deviceType;
|
|
1034
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1057
1035
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1036
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1037
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
1038
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
1058
1039
|
// create the accessory handler for the newly create accessory
|
|
1059
1040
|
// this is imported from `platformAccessory.ts`
|
|
1060
1041
|
new Hub(this, accessory, device);
|
|
1061
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1042
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1062
1043
|
// publish device externally or link the accessory to your platform
|
|
1063
1044
|
this.externalOrPlatform(device, accessory);
|
|
1064
1045
|
this.accessories.push(accessory);
|
|
1065
1046
|
}
|
|
1066
1047
|
else {
|
|
1067
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType}
|
|
1048
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
|
|
1068
1049
|
}
|
|
1069
1050
|
}
|
|
1070
1051
|
async createIOSensor(device) {
|
|
@@ -1076,52 +1057,48 @@ export class SwitchBotPlatform {
|
|
|
1076
1057
|
// the accessory already exists
|
|
1077
1058
|
if (await this.registerDevice(device)) {
|
|
1078
1059
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1079
|
-
existingAccessory.context.
|
|
1080
|
-
existingAccessory.context.
|
|
1081
|
-
existingAccessory.
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
}
|
|
1085
|
-
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1086
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1060
|
+
existingAccessory.context.device = device;
|
|
1061
|
+
existingAccessory.context.model = SwitchBotModel.OutdoorMeter;
|
|
1062
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
1063
|
+
existingAccessory.context.deviceType = device.deviceType;
|
|
1064
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1087
1065
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1066
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1067
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1088
1068
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1089
1069
|
// create the accessory handler for the restored accessory
|
|
1090
1070
|
// this is imported from `platformAccessory.ts`
|
|
1091
1071
|
new IOSensor(this, existingAccessory, device);
|
|
1092
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1072
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1093
1073
|
}
|
|
1094
1074
|
else {
|
|
1095
1075
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1096
1076
|
}
|
|
1097
1077
|
}
|
|
1098
1078
|
else if (await this.registerDevice(device)) {
|
|
1099
|
-
// the accessory does not yet exist, so we need to create it
|
|
1100
|
-
if (!device.external) {
|
|
1101
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1102
|
-
}
|
|
1103
1079
|
// create a new accessory
|
|
1104
1080
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
1105
1081
|
// store a copy of the device object in the `accessory.context`
|
|
1106
1082
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1107
1083
|
accessory.context.device = device;
|
|
1108
|
-
accessory.context.model =
|
|
1109
|
-
accessory.context.
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
}
|
|
1113
|
-
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1084
|
+
accessory.context.model = SwitchBotModel.OutdoorMeter;
|
|
1085
|
+
accessory.context.deviceId = device.deviceId;
|
|
1086
|
+
accessory.context.deviceType = device.deviceType;
|
|
1087
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1114
1088
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1089
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1090
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
1091
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
1115
1092
|
// create the accessory handler for the newly create accessory
|
|
1116
1093
|
// this is imported from `platformAccessory.ts`
|
|
1117
1094
|
new IOSensor(this, accessory, device);
|
|
1118
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1095
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1119
1096
|
// publish device externally or link the accessory to your platform
|
|
1120
1097
|
this.externalOrPlatform(device, accessory);
|
|
1121
1098
|
this.accessories.push(accessory);
|
|
1122
1099
|
}
|
|
1123
1100
|
else {
|
|
1124
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType}
|
|
1101
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
|
|
1125
1102
|
}
|
|
1126
1103
|
}
|
|
1127
1104
|
async createWaterDetector(device) {
|
|
@@ -1133,52 +1110,48 @@ export class SwitchBotPlatform {
|
|
|
1133
1110
|
// the accessory already exists
|
|
1134
1111
|
if (await this.registerDevice(device)) {
|
|
1135
1112
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1136
|
-
existingAccessory.context.
|
|
1137
|
-
existingAccessory.context.
|
|
1138
|
-
existingAccessory.
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
}
|
|
1142
|
-
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1143
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1113
|
+
existingAccessory.context.device = device;
|
|
1114
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
1115
|
+
existingAccessory.context.deviceType = device.deviceType;
|
|
1116
|
+
existingAccessory.context.model = SwitchBotModel.WaterDetector;
|
|
1117
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1144
1118
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1119
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1120
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1145
1121
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1146
1122
|
// create the accessory handler for the restored accessory
|
|
1147
1123
|
// this is imported from `platformAccessory.ts`
|
|
1148
1124
|
new WaterDetector(this, existingAccessory, device);
|
|
1149
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1125
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1150
1126
|
}
|
|
1151
1127
|
else {
|
|
1152
1128
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1153
1129
|
}
|
|
1154
1130
|
}
|
|
1155
1131
|
else if (await this.registerDevice(device)) {
|
|
1156
|
-
// the accessory does not yet exist, so we need to create it
|
|
1157
|
-
if (!device.external) {
|
|
1158
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1159
|
-
}
|
|
1160
1132
|
// create a new accessory
|
|
1161
1133
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
1162
1134
|
// store a copy of the device object in the `accessory.context`
|
|
1163
1135
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1164
1136
|
accessory.context.device = device;
|
|
1165
|
-
accessory.context.
|
|
1166
|
-
accessory.context.
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1137
|
+
accessory.context.deviceId = device.deviceId;
|
|
1138
|
+
accessory.context.deviceType = device.deviceType;
|
|
1139
|
+
accessory.context.model = SwitchBotModel.WaterDetector;
|
|
1140
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1141
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1171
1142
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1143
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
1144
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
1172
1145
|
// create the accessory handler for the newly create accessory
|
|
1173
1146
|
// this is imported from `platformAccessory.ts`
|
|
1174
1147
|
new WaterDetector(this, accessory, device);
|
|
1175
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1148
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1176
1149
|
// publish device externally or link the accessory to your platform
|
|
1177
1150
|
this.externalOrPlatform(device, accessory);
|
|
1178
1151
|
this.accessories.push(accessory);
|
|
1179
1152
|
}
|
|
1180
1153
|
else {
|
|
1181
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType}
|
|
1154
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
|
|
1182
1155
|
}
|
|
1183
1156
|
}
|
|
1184
1157
|
async createMotion(device) {
|
|
@@ -1190,52 +1163,48 @@ export class SwitchBotPlatform {
|
|
|
1190
1163
|
// the accessory already exists
|
|
1191
1164
|
if (await this.registerDevice(device)) {
|
|
1192
1165
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1193
|
-
existingAccessory.context.
|
|
1194
|
-
existingAccessory.context.
|
|
1195
|
-
existingAccessory.
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
}
|
|
1199
|
-
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1200
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1166
|
+
existingAccessory.context.device = device;
|
|
1167
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
1168
|
+
existingAccessory.context.deviceType = device.deviceType;
|
|
1169
|
+
existingAccessory.context.model = SwitchBotModel.MotionSensor;
|
|
1170
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1201
1171
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1172
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1173
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1202
1174
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1203
1175
|
// create the accessory handler for the restored accessory
|
|
1204
1176
|
// this is imported from `platformAccessory.ts`
|
|
1205
1177
|
new Motion(this, existingAccessory, device);
|
|
1206
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1178
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1207
1179
|
}
|
|
1208
1180
|
else {
|
|
1209
1181
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1210
1182
|
}
|
|
1211
1183
|
}
|
|
1212
1184
|
else if (await this.registerDevice(device)) {
|
|
1213
|
-
// the accessory does not yet exist, so we need to create it
|
|
1214
|
-
if (!device.external) {
|
|
1215
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1216
|
-
}
|
|
1217
1185
|
// create a new accessory
|
|
1218
1186
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
1219
1187
|
// store a copy of the device object in the `accessory.context`
|
|
1220
1188
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1221
1189
|
accessory.context.device = device;
|
|
1222
|
-
accessory.context.
|
|
1223
|
-
accessory.context.
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
}
|
|
1227
|
-
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1190
|
+
accessory.context.deviceId = device.deviceId;
|
|
1191
|
+
accessory.context.deviceType = device.deviceType;
|
|
1192
|
+
accessory.context.model = SwitchBotModel.MotionSensor;
|
|
1193
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1228
1194
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1195
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1196
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
1197
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
1229
1198
|
// create the accessory handler for the newly create accessory
|
|
1230
1199
|
// this is imported from `platformAccessory.ts`
|
|
1231
1200
|
new Motion(this, accessory, device);
|
|
1232
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1201
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1233
1202
|
// publish device externally or link the accessory to your platform
|
|
1234
1203
|
this.externalOrPlatform(device, accessory);
|
|
1235
1204
|
this.accessories.push(accessory);
|
|
1236
1205
|
}
|
|
1237
1206
|
else {
|
|
1238
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType}
|
|
1207
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
|
|
1239
1208
|
}
|
|
1240
1209
|
}
|
|
1241
1210
|
async createContact(device) {
|
|
@@ -1247,52 +1216,48 @@ export class SwitchBotPlatform {
|
|
|
1247
1216
|
// the accessory already exists
|
|
1248
1217
|
if (await this.registerDevice(device)) {
|
|
1249
1218
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1250
|
-
existingAccessory.context.
|
|
1251
|
-
existingAccessory.context.
|
|
1252
|
-
existingAccessory.
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
}
|
|
1256
|
-
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1257
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1219
|
+
existingAccessory.context.device = device;
|
|
1220
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
1221
|
+
existingAccessory.context.deviceType = device.deviceType;
|
|
1222
|
+
existingAccessory.context.model = SwitchBotModel.ContactSensor;
|
|
1223
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1258
1224
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1225
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1226
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1259
1227
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1260
1228
|
// create the accessory handler for the restored accessory
|
|
1261
1229
|
// this is imported from `platformAccessory.ts`
|
|
1262
1230
|
new Contact(this, existingAccessory, device);
|
|
1263
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1231
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1264
1232
|
}
|
|
1265
1233
|
else {
|
|
1266
1234
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1267
1235
|
}
|
|
1268
1236
|
}
|
|
1269
1237
|
else if (await this.registerDevice(device)) {
|
|
1270
|
-
// the accessory does not yet exist, so we need to create it
|
|
1271
|
-
if (!device.external) {
|
|
1272
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1273
|
-
}
|
|
1274
1238
|
// create a new accessory
|
|
1275
1239
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
1276
1240
|
// store a copy of the device object in the `accessory.context`
|
|
1277
1241
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1278
1242
|
accessory.context.device = device;
|
|
1279
|
-
accessory.context.
|
|
1280
|
-
accessory.context.
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
}
|
|
1284
|
-
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1243
|
+
accessory.context.deviceId = device.deviceId;
|
|
1244
|
+
accessory.context.deviceType = device.deviceType;
|
|
1245
|
+
accessory.context.model = SwitchBotModel.ContactSensor;
|
|
1246
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1285
1247
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1248
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1249
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
1250
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
1286
1251
|
// create the accessory handler for the newly create accessory
|
|
1287
1252
|
// this is imported from `platformAccessory.ts`
|
|
1288
1253
|
new Contact(this, accessory, device);
|
|
1289
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1254
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1290
1255
|
// publish device externally or link the accessory to your platform
|
|
1291
1256
|
this.externalOrPlatform(device, accessory);
|
|
1292
1257
|
this.accessories.push(accessory);
|
|
1293
1258
|
}
|
|
1294
1259
|
else {
|
|
1295
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType}
|
|
1260
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
|
|
1296
1261
|
}
|
|
1297
1262
|
}
|
|
1298
1263
|
async createBlindTilt(device) {
|
|
@@ -1304,41 +1269,36 @@ export class SwitchBotPlatform {
|
|
|
1304
1269
|
// the accessory already exists
|
|
1305
1270
|
if (await this.registerDevice(device)) {
|
|
1306
1271
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1307
|
-
existingAccessory.context.
|
|
1308
|
-
existingAccessory.context.
|
|
1309
|
-
existingAccessory.
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
}
|
|
1313
|
-
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1314
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1272
|
+
existingAccessory.context.device = device;
|
|
1273
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
1274
|
+
existingAccessory.context.deviceType = device.deviceType;
|
|
1275
|
+
existingAccessory.context.model = SwitchBotModel.BlindTilt;
|
|
1276
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1315
1277
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1278
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1279
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1316
1280
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1317
1281
|
// create the accessory handler for the restored accessory
|
|
1318
1282
|
// this is imported from `platformAccessory.ts`
|
|
1319
1283
|
new BlindTilt(this, existingAccessory, device);
|
|
1320
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1284
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1321
1285
|
}
|
|
1322
1286
|
else {
|
|
1323
1287
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1324
1288
|
}
|
|
1325
1289
|
}
|
|
1326
1290
|
else if (await this.registerDevice(device)) {
|
|
1327
|
-
// the accessory does not yet exist, so we need to create it
|
|
1328
|
-
if (!device.external) {
|
|
1329
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1330
|
-
}
|
|
1331
1291
|
if (isBlindTiltDevice(device)) {
|
|
1332
1292
|
if (device.group && !device.curtain?.disable_group) {
|
|
1333
1293
|
this.debugLog('Your Curtains are grouped, ' +
|
|
1334
|
-
`, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName},
|
|
1294
|
+
`, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
|
|
1335
1295
|
}
|
|
1336
1296
|
else {
|
|
1337
1297
|
if (device.master) {
|
|
1338
|
-
this.warnLog(`Main Curtain: ${device.deviceName},
|
|
1298
|
+
this.warnLog(`Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
|
|
1339
1299
|
}
|
|
1340
1300
|
else {
|
|
1341
|
-
this.errorLog(`Secondary Curtain: ${device.deviceName},
|
|
1301
|
+
this.errorLog(`Secondary Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
|
|
1342
1302
|
}
|
|
1343
1303
|
}
|
|
1344
1304
|
}
|
|
@@ -1347,23 +1307,25 @@ export class SwitchBotPlatform {
|
|
|
1347
1307
|
// store a copy of the device object in the `accessory.context`
|
|
1348
1308
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1349
1309
|
accessory.context.device = device;
|
|
1350
|
-
|
|
1351
|
-
accessory.context.
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1310
|
+
;
|
|
1311
|
+
accessory.context.deviceId = device.deviceId;
|
|
1312
|
+
accessory.context.deviceType = device.deviceType;
|
|
1313
|
+
accessory.context.model = SwitchBotModel.BlindTilt;
|
|
1314
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1356
1315
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1316
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1317
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
1318
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
1357
1319
|
// create the accessory handler for the newly create accessory
|
|
1358
1320
|
// this is imported from `platformAccessory.ts`
|
|
1359
1321
|
new BlindTilt(this, accessory, device);
|
|
1360
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1322
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1361
1323
|
// publish device externally or link the accessory to your platform
|
|
1362
1324
|
this.externalOrPlatform(device, accessory);
|
|
1363
1325
|
this.accessories.push(accessory);
|
|
1364
1326
|
}
|
|
1365
1327
|
else {
|
|
1366
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType}
|
|
1328
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
|
|
1367
1329
|
}
|
|
1368
1330
|
}
|
|
1369
1331
|
async createCurtain(device) {
|
|
@@ -1375,41 +1337,36 @@ export class SwitchBotPlatform {
|
|
|
1375
1337
|
// the accessory already exists
|
|
1376
1338
|
if (await this.registerDevice(device)) {
|
|
1377
1339
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1378
|
-
existingAccessory.context.
|
|
1379
|
-
existingAccessory.context.
|
|
1380
|
-
existingAccessory.
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
}
|
|
1384
|
-
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1385
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1340
|
+
existingAccessory.context.device = device;
|
|
1341
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
1342
|
+
existingAccessory.context.deviceType = device.deviceType;
|
|
1343
|
+
existingAccessory.context.model = device.deviceType === 'Curtain3' ? SwitchBotModel.Curtain3 : SwitchBotModel.Curtain;
|
|
1344
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1386
1345
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1346
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1347
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1387
1348
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1388
1349
|
// create the accessory handler for the restored accessory
|
|
1389
1350
|
// this is imported from `platformAccessory.ts`
|
|
1390
1351
|
new Curtain(this, existingAccessory, device);
|
|
1391
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1352
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1392
1353
|
}
|
|
1393
1354
|
else {
|
|
1394
1355
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1395
1356
|
}
|
|
1396
1357
|
}
|
|
1397
1358
|
else if (await this.registerDevice(device)) {
|
|
1398
|
-
// the accessory does not yet exist, so we need to create it
|
|
1399
|
-
if (!device.external) {
|
|
1400
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1401
|
-
}
|
|
1402
1359
|
if (isCurtainDevice(device)) {
|
|
1403
1360
|
if (device.group && !device.curtain?.disable_group) {
|
|
1404
1361
|
this.debugLog('Your Curtains are grouped, ' +
|
|
1405
|
-
`, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName},
|
|
1362
|
+
`, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
|
|
1406
1363
|
}
|
|
1407
1364
|
else {
|
|
1408
1365
|
if (device.master) {
|
|
1409
|
-
this.warnLog(`Main Curtain: ${device.deviceName},
|
|
1366
|
+
this.warnLog(`Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
|
|
1410
1367
|
}
|
|
1411
1368
|
else {
|
|
1412
|
-
this.errorLog(`Secondary Curtain: ${device.deviceName},
|
|
1369
|
+
this.errorLog(`Secondary Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
|
|
1413
1370
|
}
|
|
1414
1371
|
}
|
|
1415
1372
|
}
|
|
@@ -1418,23 +1375,24 @@ export class SwitchBotPlatform {
|
|
|
1418
1375
|
// store a copy of the device object in the `accessory.context`
|
|
1419
1376
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1420
1377
|
accessory.context.device = device;
|
|
1421
|
-
accessory.context.
|
|
1422
|
-
accessory.context.
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
}
|
|
1426
|
-
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1378
|
+
accessory.context.deviceId = device.deviceId;
|
|
1379
|
+
accessory.context.deviceType = device.deviceType;
|
|
1380
|
+
accessory.context.model = device.deviceType === 'Curtain3' ? SwitchBotModel.Curtain3 : SwitchBotModel.Curtain;
|
|
1381
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1427
1382
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1383
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1384
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
1385
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
1428
1386
|
// create the accessory handler for the newly create accessory
|
|
1429
1387
|
// this is imported from `platformAccessory.ts`
|
|
1430
1388
|
new Curtain(this, accessory, device);
|
|
1431
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1389
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1432
1390
|
// publish device externally or link the accessory to your platform
|
|
1433
1391
|
this.externalOrPlatform(device, accessory);
|
|
1434
1392
|
this.accessories.push(accessory);
|
|
1435
1393
|
}
|
|
1436
1394
|
else {
|
|
1437
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType}
|
|
1395
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
|
|
1438
1396
|
}
|
|
1439
1397
|
}
|
|
1440
1398
|
async createPlug(device) {
|
|
@@ -1446,52 +1404,50 @@ export class SwitchBotPlatform {
|
|
|
1446
1404
|
// the accessory already exists
|
|
1447
1405
|
if (await this.registerDevice(device)) {
|
|
1448
1406
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1449
|
-
existingAccessory.context.
|
|
1450
|
-
existingAccessory.context.
|
|
1451
|
-
existingAccessory.
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1456
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1407
|
+
existingAccessory.context.device = device;
|
|
1408
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
1409
|
+
existingAccessory.context.deviceType = device.deviceType;
|
|
1410
|
+
existingAccessory.context.model = device.deviceType === 'Plug Mini (US)' ? SwitchBotModel.PlugMiniUS : device.deviceType === 'Plug Mini (JP)'
|
|
1411
|
+
? SwitchBotModel.PlugMiniJP : SwitchBotModel.Plug;
|
|
1412
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1457
1413
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1414
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1415
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1458
1416
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1459
1417
|
// create the accessory handler for the restored accessory
|
|
1460
1418
|
// this is imported from `platformAccessory.ts`
|
|
1461
1419
|
new Plug(this, existingAccessory, device);
|
|
1462
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1420
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1463
1421
|
}
|
|
1464
1422
|
else {
|
|
1465
1423
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1466
1424
|
}
|
|
1467
1425
|
}
|
|
1468
1426
|
else if (await this.registerDevice(device)) {
|
|
1469
|
-
// the accessory does not yet exist, so we need to create it
|
|
1470
|
-
if (!device.external) {
|
|
1471
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1472
|
-
}
|
|
1473
1427
|
// create a new accessory
|
|
1474
1428
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
1475
1429
|
// store a copy of the device object in the `accessory.context`
|
|
1476
1430
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1477
1431
|
accessory.context.device = device;
|
|
1478
|
-
accessory.context.
|
|
1479
|
-
accessory.context.
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1432
|
+
accessory.context.deviceId = device.deviceId;
|
|
1433
|
+
accessory.context.deviceType = device.deviceType;
|
|
1434
|
+
accessory.context.model = device.deviceType === 'Plug Mini (US)' ? SwitchBotModel.PlugMiniUS : device.deviceType === 'Plug Mini (JP)'
|
|
1435
|
+
? SwitchBotModel.PlugMiniJP : SwitchBotModel.Plug;
|
|
1436
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1484
1437
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1438
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1439
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
1440
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
1485
1441
|
// create the accessory handler for the newly create accessory
|
|
1486
1442
|
// this is imported from `platformAccessory.ts`
|
|
1487
1443
|
new Plug(this, accessory, device);
|
|
1488
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1444
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1489
1445
|
// publish device externally or link the accessory to your platform
|
|
1490
1446
|
this.externalOrPlatform(device, accessory);
|
|
1491
1447
|
this.accessories.push(accessory);
|
|
1492
1448
|
}
|
|
1493
1449
|
else {
|
|
1494
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType}
|
|
1450
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
|
|
1495
1451
|
}
|
|
1496
1452
|
}
|
|
1497
1453
|
async createLock(device) {
|
|
@@ -1503,52 +1459,48 @@ export class SwitchBotPlatform {
|
|
|
1503
1459
|
// the accessory already exists
|
|
1504
1460
|
if (await this.registerDevice(device)) {
|
|
1505
1461
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1506
|
-
existingAccessory.context.
|
|
1507
|
-
existingAccessory.context.
|
|
1508
|
-
existingAccessory.
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
}
|
|
1512
|
-
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1513
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1462
|
+
existingAccessory.context.device = device;
|
|
1463
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
1464
|
+
existingAccessory.context.deviceType = device.deviceType;
|
|
1465
|
+
existingAccessory.context.model = device.deviceType === 'Smart Lock Pro' ? SwitchBotModel.LockPro : SwitchBotModel.Lock;
|
|
1466
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1514
1467
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1468
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1469
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1515
1470
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1516
1471
|
// create the accessory handler for the restored accessory
|
|
1517
1472
|
// this is imported from `platformAccessory.ts`
|
|
1518
1473
|
new Lock(this, existingAccessory, device);
|
|
1519
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1474
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1520
1475
|
}
|
|
1521
1476
|
else {
|
|
1522
1477
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1523
1478
|
}
|
|
1524
1479
|
}
|
|
1525
1480
|
else if (await this.registerDevice(device)) {
|
|
1526
|
-
// the accessory does not yet exist, so we need to create it
|
|
1527
|
-
if (!device.external) {
|
|
1528
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1529
|
-
}
|
|
1530
1481
|
// create a new accessory
|
|
1531
1482
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
1532
1483
|
// store a copy of the device object in the `accessory.context`
|
|
1533
1484
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1534
1485
|
accessory.context.device = device;
|
|
1535
|
-
accessory.context.
|
|
1536
|
-
accessory.context.
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
}
|
|
1540
|
-
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1486
|
+
accessory.context.deviceId = device.deviceId;
|
|
1487
|
+
accessory.context.deviceType = device.deviceType;
|
|
1488
|
+
accessory.context.model = device.deviceType === 'Smart Lock Pro' ? SwitchBotModel.LockPro : SwitchBotModel.Lock;
|
|
1489
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1541
1490
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1491
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1492
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
1493
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
1542
1494
|
// create the accessory handler for the newly create accessory
|
|
1543
1495
|
// this is imported from `platformAccessory.ts`
|
|
1544
1496
|
new Lock(this, accessory, device);
|
|
1545
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1497
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1546
1498
|
// publish device externally or link the accessory to your platform
|
|
1547
1499
|
this.externalOrPlatform(device, accessory);
|
|
1548
1500
|
this.accessories.push(accessory);
|
|
1549
1501
|
}
|
|
1550
1502
|
else {
|
|
1551
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType}
|
|
1503
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
|
|
1552
1504
|
}
|
|
1553
1505
|
}
|
|
1554
1506
|
async createColorBulb(device) {
|
|
@@ -1560,52 +1512,48 @@ export class SwitchBotPlatform {
|
|
|
1560
1512
|
// the accessory already exists
|
|
1561
1513
|
if (await this.registerDevice(device)) {
|
|
1562
1514
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1563
|
-
existingAccessory.context.
|
|
1564
|
-
existingAccessory.context.
|
|
1565
|
-
existingAccessory.
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
}
|
|
1569
|
-
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1570
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1515
|
+
existingAccessory.context.device = device;
|
|
1516
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
1517
|
+
existingAccessory.context.deviceType = device.deviceType;
|
|
1518
|
+
existingAccessory.context.model = SwitchBotModel.ColorBulb;
|
|
1519
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1571
1520
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1521
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1522
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1572
1523
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1573
1524
|
// create the accessory handler for the restored accessory
|
|
1574
1525
|
// this is imported from `platformAccessory.ts`
|
|
1575
1526
|
new ColorBulb(this, existingAccessory, device);
|
|
1576
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1527
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1577
1528
|
}
|
|
1578
1529
|
else {
|
|
1579
1530
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1580
1531
|
}
|
|
1581
1532
|
}
|
|
1582
1533
|
else if (await this.registerDevice(device)) {
|
|
1583
|
-
// the accessory does not yet exist, so we need to create it
|
|
1584
|
-
if (!device.external) {
|
|
1585
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1586
|
-
}
|
|
1587
1534
|
// create a new accessory
|
|
1588
1535
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
1589
1536
|
// store a copy of the device object in the `accessory.context`
|
|
1590
1537
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1591
1538
|
accessory.context.device = device;
|
|
1592
|
-
accessory.context.
|
|
1593
|
-
accessory.context.
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
}
|
|
1597
|
-
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1539
|
+
accessory.context.deviceId = device.deviceId;
|
|
1540
|
+
accessory.context.deviceType = device.deviceType;
|
|
1541
|
+
accessory.context.model = SwitchBotModel.ColorBulb;
|
|
1542
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1598
1543
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1544
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1545
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
1546
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
1599
1547
|
// create the accessory handler for the newly create accessory
|
|
1600
1548
|
// this is imported from `platformAccessory.ts`
|
|
1601
1549
|
new ColorBulb(this, accessory, device);
|
|
1602
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1550
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1603
1551
|
// publish device externally or link the accessory to your platform
|
|
1604
1552
|
this.externalOrPlatform(device, accessory);
|
|
1605
1553
|
this.accessories.push(accessory);
|
|
1606
1554
|
}
|
|
1607
1555
|
else {
|
|
1608
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType}
|
|
1556
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
|
|
1609
1557
|
}
|
|
1610
1558
|
}
|
|
1611
1559
|
async createCeilingLight(device) {
|
|
@@ -1617,52 +1565,48 @@ export class SwitchBotPlatform {
|
|
|
1617
1565
|
// the accessory already exists
|
|
1618
1566
|
if (await this.registerDevice(device)) {
|
|
1619
1567
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1620
|
-
existingAccessory.context.
|
|
1621
|
-
existingAccessory.context.
|
|
1622
|
-
existingAccessory.
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
}
|
|
1626
|
-
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1627
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1568
|
+
existingAccessory.context.device = device;
|
|
1569
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
1570
|
+
existingAccessory.context.deviceType = device.deviceType;
|
|
1571
|
+
existingAccessory.context.model = device.deviceType === 'Ceiling Light Pro' ? SwitchBotModel.CeilingLightPro : SwitchBotModel.CeilingLight;
|
|
1572
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1628
1573
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1574
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1575
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1629
1576
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1630
1577
|
// create the accessory handler for the restored accessory
|
|
1631
1578
|
// this is imported from `platformAccessory.ts`
|
|
1632
1579
|
new CeilingLight(this, existingAccessory, device);
|
|
1633
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1580
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1634
1581
|
}
|
|
1635
1582
|
else {
|
|
1636
1583
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1637
1584
|
}
|
|
1638
1585
|
}
|
|
1639
1586
|
else if (await this.registerDevice(device)) {
|
|
1640
|
-
// the accessory does not yet exist, so we need to create it
|
|
1641
|
-
if (!device.external) {
|
|
1642
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1643
|
-
}
|
|
1644
1587
|
// create a new accessory
|
|
1645
1588
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
1646
1589
|
// store a copy of the device object in the `accessory.context`
|
|
1647
1590
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1648
1591
|
accessory.context.device = device;
|
|
1649
|
-
accessory.context.
|
|
1650
|
-
accessory.context.
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
}
|
|
1654
|
-
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1592
|
+
accessory.context.deviceId = device.deviceId;
|
|
1593
|
+
accessory.context.deviceType = device.deviceType;
|
|
1594
|
+
accessory.context.model = device.deviceType === 'Ceiling Light Pro' ? SwitchBotModel.CeilingLightPro : SwitchBotModel.CeilingLight;
|
|
1595
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1655
1596
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1597
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1598
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
1599
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
1656
1600
|
// create the accessory handler for the newly create accessory
|
|
1657
1601
|
// this is imported from `platformAccessory.ts`
|
|
1658
1602
|
new CeilingLight(this, accessory, device);
|
|
1659
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1603
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1660
1604
|
// publish device externally or link the accessory to your platform
|
|
1661
1605
|
this.externalOrPlatform(device, accessory);
|
|
1662
1606
|
this.accessories.push(accessory);
|
|
1663
1607
|
}
|
|
1664
1608
|
else {
|
|
1665
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType}
|
|
1609
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
|
|
1666
1610
|
}
|
|
1667
1611
|
}
|
|
1668
1612
|
async createStripLight(device) {
|
|
@@ -1674,52 +1618,48 @@ export class SwitchBotPlatform {
|
|
|
1674
1618
|
// the accessory already exists
|
|
1675
1619
|
if (await this.registerDevice(device)) {
|
|
1676
1620
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1677
|
-
existingAccessory.context.
|
|
1678
|
-
existingAccessory.context.
|
|
1679
|
-
existingAccessory.
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
}
|
|
1683
|
-
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1684
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1621
|
+
existingAccessory.context.device = device;
|
|
1622
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
1623
|
+
existingAccessory.context.deviceType = device.deviceType;
|
|
1624
|
+
existingAccessory.context.model = SwitchBotModel.StripLight;
|
|
1625
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1685
1626
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1627
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1628
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1686
1629
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1687
1630
|
// create the accessory handler for the restored accessory
|
|
1688
1631
|
// this is imported from `platformAccessory.ts`
|
|
1689
1632
|
new StripLight(this, existingAccessory, device);
|
|
1690
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1633
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1691
1634
|
}
|
|
1692
1635
|
else {
|
|
1693
1636
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1694
1637
|
}
|
|
1695
1638
|
}
|
|
1696
1639
|
else if (await this.registerDevice(device)) {
|
|
1697
|
-
// the accessory does not yet exist, so we need to create it
|
|
1698
|
-
if (!device.external) {
|
|
1699
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1700
|
-
}
|
|
1701
1640
|
// create a new accessory
|
|
1702
1641
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
1703
1642
|
// store a copy of the device object in the `accessory.context`
|
|
1704
1643
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1705
1644
|
accessory.context.device = device;
|
|
1706
|
-
accessory.context.
|
|
1707
|
-
accessory.context.
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
}
|
|
1711
|
-
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1645
|
+
accessory.context.deviceId = device.deviceId;
|
|
1646
|
+
accessory.context.deviceType = device.deviceType;
|
|
1647
|
+
accessory.context.model = SwitchBotModel.StripLight;
|
|
1648
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1712
1649
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1650
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1651
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
1652
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
1713
1653
|
// create the accessory handler for the newly create accessory
|
|
1714
1654
|
// this is imported from `platformAccessory.ts`
|
|
1715
1655
|
new StripLight(this, accessory, device);
|
|
1716
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1656
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1717
1657
|
// publish device externally or link the accessory to your platform
|
|
1718
1658
|
this.externalOrPlatform(device, accessory);
|
|
1719
1659
|
this.accessories.push(accessory);
|
|
1720
1660
|
}
|
|
1721
1661
|
else {
|
|
1722
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType}
|
|
1662
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
|
|
1723
1663
|
}
|
|
1724
1664
|
}
|
|
1725
1665
|
async createFan(device) {
|
|
@@ -1731,52 +1671,48 @@ export class SwitchBotPlatform {
|
|
|
1731
1671
|
// the accessory already exists
|
|
1732
1672
|
if (await this.registerDevice(device)) {
|
|
1733
1673
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1734
|
-
existingAccessory.context.
|
|
1735
|
-
existingAccessory.context.
|
|
1736
|
-
existingAccessory.
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
}
|
|
1740
|
-
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1741
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1674
|
+
existingAccessory.context.device = device;
|
|
1675
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
1676
|
+
existingAccessory.context.deviceType = device.deviceType;
|
|
1677
|
+
existingAccessory.context.model = SwitchBotModel.BatteryCirculatorFan;
|
|
1678
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1742
1679
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1680
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1681
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1743
1682
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1744
1683
|
// create the accessory handler for the restored accessory
|
|
1745
1684
|
// this is imported from `platformAccessory.ts`
|
|
1746
1685
|
new Fan(this, existingAccessory, device);
|
|
1747
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1686
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1748
1687
|
}
|
|
1749
1688
|
else {
|
|
1750
1689
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1751
1690
|
}
|
|
1752
1691
|
}
|
|
1753
1692
|
else if (await this.registerDevice(device)) {
|
|
1754
|
-
// the accessory does not yet exist, so we need to create it
|
|
1755
|
-
if (!device.external) {
|
|
1756
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1757
|
-
}
|
|
1758
1693
|
// create a new accessory
|
|
1759
1694
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
1760
1695
|
// store a copy of the device object in the `accessory.context`
|
|
1761
1696
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1762
1697
|
accessory.context.device = device;
|
|
1763
|
-
accessory.context.
|
|
1764
|
-
accessory.context.
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
}
|
|
1768
|
-
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1698
|
+
accessory.context.deviceId = device.deviceId;
|
|
1699
|
+
accessory.context.deviceType = device.deviceType;
|
|
1700
|
+
accessory.context.model = SwitchBotModel.BatteryCirculatorFan;
|
|
1701
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1769
1702
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1703
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1704
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
1705
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
1770
1706
|
// create the accessory handler for the newly create accessory
|
|
1771
1707
|
// this is imported from `platformAccessory.ts`
|
|
1772
1708
|
new Fan(this, accessory, device);
|
|
1773
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1709
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1774
1710
|
// publish device externally or link the accessory to your platform
|
|
1775
1711
|
this.externalOrPlatform(device, accessory);
|
|
1776
1712
|
this.accessories.push(accessory);
|
|
1777
1713
|
}
|
|
1778
1714
|
else {
|
|
1779
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType}
|
|
1715
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
|
|
1780
1716
|
}
|
|
1781
1717
|
}
|
|
1782
1718
|
async createRobotVacuumCleaner(device) {
|
|
@@ -1788,52 +1724,56 @@ export class SwitchBotPlatform {
|
|
|
1788
1724
|
// the accessory already exists
|
|
1789
1725
|
if (await this.registerDevice(device)) {
|
|
1790
1726
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1791
|
-
existingAccessory.context.
|
|
1792
|
-
existingAccessory.context.
|
|
1793
|
-
existingAccessory.
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1727
|
+
existingAccessory.context.device = device;
|
|
1728
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
1729
|
+
existingAccessory.context.deviceType = device.deviceType;
|
|
1730
|
+
existingAccessory.context.model = device.deviceType === 'Robot Vacuum Cleaner S1' ? SwitchBotModel.RobotVacuumCleanerS1
|
|
1731
|
+
: device.deviceType === 'Robot Vacuum Cleaner S1 Plus' ? SwitchBotModel.RobotVacuumCleanerS1Plus
|
|
1732
|
+
: device.deviceType === 'Robot Vacuum Cleaner S10' ? SwitchBotModel.RobotVacuumCleanerS10
|
|
1733
|
+
: device.deviceType === 'WoSweeper' ? SwitchBotModel.WoSweeper : device.deviceType === 'WoSweeperMini' ? SwitchBotModel.WoSweeperMini
|
|
1734
|
+
: SwitchBotModel.Unknown;
|
|
1735
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1799
1736
|
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1737
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1738
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1800
1739
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1801
1740
|
// create the accessory handler for the restored accessory
|
|
1802
1741
|
// this is imported from `platformAccessory.ts`
|
|
1803
1742
|
new RobotVacuumCleaner(this, existingAccessory, device);
|
|
1804
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1743
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1805
1744
|
}
|
|
1806
1745
|
else {
|
|
1807
1746
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1808
1747
|
}
|
|
1809
1748
|
}
|
|
1810
1749
|
else if (await this.registerDevice(device)) {
|
|
1811
|
-
// the accessory does not yet exist, so we need to create it
|
|
1812
|
-
if (!device.external) {
|
|
1813
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1814
|
-
}
|
|
1815
1750
|
// create a new accessory
|
|
1816
1751
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
1817
1752
|
// store a copy of the device object in the `accessory.context`
|
|
1818
1753
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1819
1754
|
accessory.context.device = device;
|
|
1820
|
-
accessory.context.
|
|
1821
|
-
accessory.context.
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1755
|
+
accessory.context.deviceId = device.deviceId;
|
|
1756
|
+
accessory.context.deviceType = device.deviceType;
|
|
1757
|
+
accessory.context.model = device.deviceType === 'Robot Vacuum Cleaner S1' ? SwitchBotModel.RobotVacuumCleanerS1
|
|
1758
|
+
: device.deviceType === 'Robot Vacuum Cleaner S1 Plus' ? SwitchBotModel.RobotVacuumCleanerS1Plus
|
|
1759
|
+
: device.deviceType === 'Robot Vacuum Cleaner S10' ? SwitchBotModel.RobotVacuumCleanerS10
|
|
1760
|
+
: device.deviceType === 'WoSweeper' ? SwitchBotModel.WoSweeper : device.deviceType === 'WoSweeperMini' ? SwitchBotModel.WoSweeperMini
|
|
1761
|
+
: SwitchBotModel.Unknown;
|
|
1762
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1826
1763
|
accessory.context.connectionType = await this.connectionType(device);
|
|
1764
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1765
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
1766
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
1827
1767
|
// create the accessory handler for the newly create accessory
|
|
1828
1768
|
// this is imported from `platformAccessory.ts`
|
|
1829
1769
|
new RobotVacuumCleaner(this, accessory, device);
|
|
1830
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1770
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1831
1771
|
// publish device externally or link the accessory to your platform
|
|
1832
1772
|
this.externalOrPlatform(device, accessory);
|
|
1833
1773
|
this.accessories.push(accessory);
|
|
1834
1774
|
}
|
|
1835
1775
|
else {
|
|
1836
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType}
|
|
1776
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
|
|
1837
1777
|
}
|
|
1838
1778
|
}
|
|
1839
1779
|
async createTV(device) {
|
|
@@ -1843,44 +1783,42 @@ export class SwitchBotPlatform {
|
|
|
1843
1783
|
const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
|
|
1844
1784
|
if (!device.hide_device && existingAccessory) {
|
|
1845
1785
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1846
|
-
existingAccessory.context.
|
|
1847
|
-
existingAccessory.context.
|
|
1848
|
-
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1786
|
+
existingAccessory.context.device = device;
|
|
1787
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
1849
1788
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1850
|
-
|
|
1789
|
+
existingAccessory.context.model = device.remoteType;
|
|
1790
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1791
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1851
1792
|
existingAccessory.context.connectionType = device.connectionType;
|
|
1852
1793
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1853
1794
|
// create the accessory handler for the restored accessory
|
|
1854
1795
|
// this is imported from `platformAccessory.ts`
|
|
1855
1796
|
new TV(this, existingAccessory, device);
|
|
1856
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1797
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1857
1798
|
}
|
|
1858
1799
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
1859
|
-
// the accessory does not yet exist, so we need to create it
|
|
1860
|
-
if (!device.external) {
|
|
1861
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1862
|
-
}
|
|
1863
1800
|
// create a new accessory
|
|
1864
1801
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
1865
1802
|
// store a copy of the device object in the `accessory.context`
|
|
1866
1803
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1867
1804
|
accessory.context.device = device;
|
|
1868
|
-
accessory.context.
|
|
1869
|
-
accessory.context.deviceID = device.deviceId;
|
|
1870
|
-
if (device.firmware) {
|
|
1871
|
-
accessory.context.version = device.firmware;
|
|
1872
|
-
}
|
|
1805
|
+
accessory.context.deviceId = device.deviceId;
|
|
1873
1806
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1807
|
+
accessory.context.model = device.remoteType;
|
|
1808
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1874
1809
|
accessory.context.connectionType = device.connectionType;
|
|
1810
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1811
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
1812
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
1875
1813
|
// create the accessory handler for the newly create accessory
|
|
1876
1814
|
// this is imported from `platformAccessory.ts`
|
|
1877
1815
|
new TV(this, accessory, device);
|
|
1878
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1816
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1879
1817
|
this.externalOrPlatformIR(device, accessory);
|
|
1880
1818
|
this.accessories.push(accessory);
|
|
1881
1819
|
}
|
|
1882
1820
|
else {
|
|
1883
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType}
|
|
1821
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
|
|
1884
1822
|
}
|
|
1885
1823
|
}
|
|
1886
1824
|
async createIRFan(device) {
|
|
@@ -1892,52 +1830,47 @@ export class SwitchBotPlatform {
|
|
|
1892
1830
|
// the accessory already exists
|
|
1893
1831
|
if (!device.hide_device && device.hubDeviceId) {
|
|
1894
1832
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1895
|
-
existingAccessory.context.
|
|
1896
|
-
existingAccessory.context.
|
|
1897
|
-
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1898
|
-
if (device.firmware) {
|
|
1899
|
-
existingAccessory.context.version = device.firmware;
|
|
1900
|
-
}
|
|
1833
|
+
existingAccessory.context.device = device;
|
|
1834
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
1901
1835
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1902
|
-
|
|
1836
|
+
existingAccessory.context.model = device.remoteType;
|
|
1837
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1838
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1903
1839
|
existingAccessory.context.connectionType = device.connectionType;
|
|
1904
1840
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1905
1841
|
// create the accessory handler for the restored accessory
|
|
1906
1842
|
// this is imported from `platformAccessory.ts`
|
|
1907
1843
|
new IRFan(this, existingAccessory, device);
|
|
1908
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1844
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1909
1845
|
}
|
|
1910
1846
|
else {
|
|
1911
1847
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1912
1848
|
}
|
|
1913
1849
|
}
|
|
1914
1850
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
1915
|
-
// the accessory does not yet exist, so we need to create it
|
|
1916
|
-
if (!device.external) {
|
|
1917
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1918
|
-
}
|
|
1919
1851
|
// create a new accessory
|
|
1920
1852
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
1921
1853
|
// store a copy of the device object in the `accessory.context`
|
|
1922
1854
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1923
1855
|
accessory.context.device = device;
|
|
1924
|
-
accessory.context.
|
|
1925
|
-
accessory.context.deviceID = device.deviceId;
|
|
1926
|
-
if (device.firmware) {
|
|
1927
|
-
accessory.context.version = device.firmware;
|
|
1928
|
-
}
|
|
1856
|
+
accessory.context.deviceId = device.deviceId;
|
|
1929
1857
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1858
|
+
accessory.context.model = device.remoteType;
|
|
1859
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1930
1860
|
accessory.context.connectionType = device.connectionType;
|
|
1861
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1862
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
1863
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
1931
1864
|
// create the accessory handler for the newly create accessory
|
|
1932
1865
|
// this is imported from `platformAccessory.ts`
|
|
1933
1866
|
new IRFan(this, accessory, device);
|
|
1934
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1867
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1935
1868
|
// publish device externally or link the accessory to your platform
|
|
1936
1869
|
this.externalOrPlatformIR(device, accessory);
|
|
1937
1870
|
this.accessories.push(accessory);
|
|
1938
1871
|
}
|
|
1939
1872
|
else {
|
|
1940
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType}
|
|
1873
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
|
|
1941
1874
|
}
|
|
1942
1875
|
}
|
|
1943
1876
|
async createLight(device) {
|
|
@@ -1949,52 +1882,47 @@ export class SwitchBotPlatform {
|
|
|
1949
1882
|
// the accessory already exists
|
|
1950
1883
|
if (!device.hide_device && device.hubDeviceId) {
|
|
1951
1884
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1952
|
-
existingAccessory.context.
|
|
1953
|
-
existingAccessory.context.
|
|
1954
|
-
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1955
|
-
if (device.firmware) {
|
|
1956
|
-
existingAccessory.context.version = device.firmware;
|
|
1957
|
-
}
|
|
1885
|
+
existingAccessory.context.device = device;
|
|
1886
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
1958
1887
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1959
|
-
|
|
1888
|
+
existingAccessory.context.model = device.remoteType;
|
|
1889
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1890
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1960
1891
|
existingAccessory.context.connectionType = device.connectionType;
|
|
1961
1892
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1962
1893
|
// create the accessory handler for the restored accessory
|
|
1963
1894
|
// this is imported from `platformAccessory.ts`
|
|
1964
1895
|
new Light(this, existingAccessory, device);
|
|
1965
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1896
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1966
1897
|
}
|
|
1967
1898
|
else {
|
|
1968
1899
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1969
1900
|
}
|
|
1970
1901
|
}
|
|
1971
1902
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
1972
|
-
// the accessory does not yet exist, so we need to create it
|
|
1973
|
-
if (!device.external) {
|
|
1974
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1975
|
-
}
|
|
1976
1903
|
// create a new accessory
|
|
1977
1904
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
1978
1905
|
// store a copy of the device object in the `accessory.context`
|
|
1979
1906
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1980
1907
|
accessory.context.device = device;
|
|
1981
|
-
accessory.context.
|
|
1982
|
-
accessory.context.deviceID = device.deviceId;
|
|
1983
|
-
if (device.firmware) {
|
|
1984
|
-
accessory.context.version = device.firmware;
|
|
1985
|
-
}
|
|
1908
|
+
accessory.context.deviceId = device.deviceId;
|
|
1986
1909
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1910
|
+
accessory.context.model = device.remoteType;
|
|
1911
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1987
1912
|
accessory.context.connectionType = device.connectionType;
|
|
1913
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1914
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
1915
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
1988
1916
|
// create the accessory handler for the newly create accessory
|
|
1989
1917
|
// this is imported from `platformAccessory.ts`
|
|
1990
1918
|
new Light(this, accessory, device);
|
|
1991
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1919
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1992
1920
|
// publish device externally or link the accessory to your platform
|
|
1993
1921
|
this.externalOrPlatformIR(device, accessory);
|
|
1994
1922
|
this.accessories.push(accessory);
|
|
1995
1923
|
}
|
|
1996
1924
|
else {
|
|
1997
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType}
|
|
1925
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
|
|
1998
1926
|
}
|
|
1999
1927
|
}
|
|
2000
1928
|
async createAirConditioner(device) {
|
|
@@ -2006,52 +1934,47 @@ export class SwitchBotPlatform {
|
|
|
2006
1934
|
// the accessory already exists
|
|
2007
1935
|
if (!device.hide_device && device.hubDeviceId) {
|
|
2008
1936
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
2009
|
-
existingAccessory.context.
|
|
2010
|
-
existingAccessory.context.
|
|
2011
|
-
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
2012
|
-
if (device.firmware) {
|
|
2013
|
-
existingAccessory.context.version = device.firmware;
|
|
2014
|
-
}
|
|
1937
|
+
existingAccessory.context.device = device;
|
|
1938
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
2015
1939
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2016
|
-
|
|
1940
|
+
existingAccessory.context.model = device.remoteType;
|
|
1941
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1942
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
2017
1943
|
existingAccessory.context.connectionType = device.connectionType;
|
|
2018
1944
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
2019
1945
|
// create the accessory handler for the restored accessory
|
|
2020
1946
|
// this is imported from `platformAccessory.ts`
|
|
2021
1947
|
new AirConditioner(this, existingAccessory, device);
|
|
2022
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1948
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2023
1949
|
}
|
|
2024
1950
|
else {
|
|
2025
1951
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
2026
1952
|
}
|
|
2027
1953
|
}
|
|
2028
1954
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
2029
|
-
// the accessory does not yet exist, so we need to create it
|
|
2030
|
-
if (!device.external) {
|
|
2031
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2032
|
-
}
|
|
2033
1955
|
// create a new accessory
|
|
2034
1956
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
2035
1957
|
// store a copy of the device object in the `accessory.context`
|
|
2036
1958
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2037
1959
|
accessory.context.device = device;
|
|
2038
|
-
accessory.context.
|
|
2039
|
-
accessory.context.deviceID = device.deviceId;
|
|
2040
|
-
if (device.firmware) {
|
|
2041
|
-
accessory.context.version = device.firmware;
|
|
2042
|
-
}
|
|
1960
|
+
accessory.context.deviceId = device.deviceId;
|
|
2043
1961
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1962
|
+
accessory.context.model = device.remoteType;
|
|
1963
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
2044
1964
|
accessory.context.connectionType = device.connectionType;
|
|
1965
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1966
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
1967
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
2045
1968
|
// create the accessory handler for the newly create accessory
|
|
2046
1969
|
// this is imported from `platformAccessory.ts`
|
|
2047
1970
|
new AirConditioner(this, accessory, device);
|
|
2048
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1971
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2049
1972
|
// publish device externally or link the accessory to your platform
|
|
2050
1973
|
this.externalOrPlatformIR(device, accessory);
|
|
2051
1974
|
this.accessories.push(accessory);
|
|
2052
1975
|
}
|
|
2053
1976
|
else {
|
|
2054
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType}
|
|
1977
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
|
|
2055
1978
|
}
|
|
2056
1979
|
}
|
|
2057
1980
|
async createAirPurifier(device) {
|
|
@@ -2063,52 +1986,47 @@ export class SwitchBotPlatform {
|
|
|
2063
1986
|
// the accessory already exists
|
|
2064
1987
|
if (!device.hide_device && device.hubDeviceId) {
|
|
2065
1988
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
2066
|
-
existingAccessory.context.
|
|
2067
|
-
existingAccessory.context.
|
|
2068
|
-
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
2069
|
-
if (device.firmware) {
|
|
2070
|
-
existingAccessory.context.version = device.firmware;
|
|
2071
|
-
}
|
|
1989
|
+
existingAccessory.context.device = device;
|
|
1990
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
2072
1991
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2073
|
-
|
|
1992
|
+
existingAccessory.context.model = device.remoteType;
|
|
1993
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
1994
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
2074
1995
|
existingAccessory.context.connectionType = device.connectionType;
|
|
2075
1996
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
2076
1997
|
// create the accessory handler for the restored accessory
|
|
2077
1998
|
// this is imported from `platformAccessory.ts`
|
|
2078
1999
|
new AirPurifier(this, existingAccessory, device);
|
|
2079
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2000
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2080
2001
|
}
|
|
2081
2002
|
else {
|
|
2082
2003
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
2083
2004
|
}
|
|
2084
2005
|
}
|
|
2085
2006
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
2086
|
-
// the accessory does not yet exist, so we need to create it
|
|
2087
|
-
if (!device.external) {
|
|
2088
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2089
|
-
}
|
|
2090
2007
|
// create a new accessory
|
|
2091
2008
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
2092
2009
|
// store a copy of the device object in the `accessory.context`
|
|
2093
2010
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2094
2011
|
accessory.context.device = device;
|
|
2095
|
-
accessory.context.
|
|
2096
|
-
accessory.context.deviceID = device.deviceId;
|
|
2097
|
-
if (device.firmware) {
|
|
2098
|
-
accessory.context.version = device.firmware;
|
|
2099
|
-
}
|
|
2012
|
+
accessory.context.deviceId = device.deviceId;
|
|
2100
2013
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2014
|
+
accessory.context.model = device.remoteType;
|
|
2015
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
2101
2016
|
accessory.context.connectionType = device.connectionType;
|
|
2017
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
2018
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
2019
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
2102
2020
|
// create the accessory handler for the newly create accessory
|
|
2103
2021
|
// this is imported from `platformAccessory.ts`
|
|
2104
2022
|
new AirPurifier(this, accessory, device);
|
|
2105
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2023
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2106
2024
|
// publish device externally or link the accessory to your platform
|
|
2107
2025
|
this.externalOrPlatformIR(device, accessory);
|
|
2108
2026
|
this.accessories.push(accessory);
|
|
2109
2027
|
}
|
|
2110
2028
|
else {
|
|
2111
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType}
|
|
2029
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
|
|
2112
2030
|
}
|
|
2113
2031
|
}
|
|
2114
2032
|
async createWaterHeater(device) {
|
|
@@ -2120,52 +2038,47 @@ export class SwitchBotPlatform {
|
|
|
2120
2038
|
// the accessory already exists
|
|
2121
2039
|
if (!device.hide_device && device.hubDeviceId) {
|
|
2122
2040
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
2123
|
-
existingAccessory.context.
|
|
2124
|
-
existingAccessory.context.
|
|
2125
|
-
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
2126
|
-
if (device.firmware) {
|
|
2127
|
-
existingAccessory.context.version = device.firmware;
|
|
2128
|
-
}
|
|
2041
|
+
existingAccessory.context.device = device;
|
|
2042
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
2129
2043
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2130
|
-
|
|
2044
|
+
existingAccessory.context.model = device.remoteType;
|
|
2045
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
2046
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
2131
2047
|
existingAccessory.context.connectionType = device.connectionType;
|
|
2132
2048
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
2133
2049
|
// create the accessory handler for the restored accessory
|
|
2134
2050
|
// this is imported from `platformAccessory.ts`
|
|
2135
2051
|
new WaterHeater(this, existingAccessory, device);
|
|
2136
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2052
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2137
2053
|
}
|
|
2138
2054
|
else {
|
|
2139
2055
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
2140
2056
|
}
|
|
2141
2057
|
}
|
|
2142
2058
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
2143
|
-
// the accessory does not yet exist, so we need to create it
|
|
2144
|
-
if (!device.external) {
|
|
2145
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2146
|
-
}
|
|
2147
2059
|
// create a new accessory
|
|
2148
2060
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
2149
2061
|
// store a copy of the device object in the `accessory.context`
|
|
2150
2062
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2151
2063
|
accessory.context.device = device;
|
|
2152
|
-
accessory.context.
|
|
2153
|
-
accessory.context.deviceID = device.deviceId;
|
|
2154
|
-
if (device.firmware) {
|
|
2155
|
-
accessory.context.version = device.firmware;
|
|
2156
|
-
}
|
|
2064
|
+
accessory.context.deviceId = device.deviceId;
|
|
2157
2065
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2066
|
+
accessory.context.model = device.remoteType;
|
|
2067
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
2158
2068
|
accessory.context.connectionType = device.connectionType;
|
|
2069
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
2070
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
2071
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
2159
2072
|
// create the accessory handler for the newly create accessory
|
|
2160
2073
|
// this is imported from `platformAccessory.ts`
|
|
2161
2074
|
new WaterHeater(this, accessory, device);
|
|
2162
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2075
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2163
2076
|
// publish device externally or link the accessory to your platform
|
|
2164
2077
|
this.externalOrPlatformIR(device, accessory);
|
|
2165
2078
|
this.accessories.push(accessory);
|
|
2166
2079
|
}
|
|
2167
2080
|
else {
|
|
2168
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType}
|
|
2081
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
|
|
2169
2082
|
}
|
|
2170
2083
|
}
|
|
2171
2084
|
async createVacuumCleaner(device) {
|
|
@@ -2177,52 +2090,47 @@ export class SwitchBotPlatform {
|
|
|
2177
2090
|
// the accessory already exists
|
|
2178
2091
|
if (!device.hide_device && device.hubDeviceId) {
|
|
2179
2092
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
2180
|
-
existingAccessory.context.
|
|
2181
|
-
existingAccessory.context.
|
|
2182
|
-
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
2183
|
-
if (device.firmware) {
|
|
2184
|
-
existingAccessory.context.version = device.firmware;
|
|
2185
|
-
}
|
|
2093
|
+
existingAccessory.context.device = device;
|
|
2094
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
2186
2095
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2187
|
-
|
|
2096
|
+
existingAccessory.context.model = device.remoteType;
|
|
2097
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
2098
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
2188
2099
|
existingAccessory.context.connectionType = device.connectionType;
|
|
2189
2100
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
2190
2101
|
// create the accessory handler for the restored accessory
|
|
2191
2102
|
// this is imported from `platformAccessory.ts`
|
|
2192
2103
|
new VacuumCleaner(this, existingAccessory, device);
|
|
2193
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2104
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2194
2105
|
}
|
|
2195
2106
|
else {
|
|
2196
2107
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
2197
2108
|
}
|
|
2198
2109
|
}
|
|
2199
2110
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
2200
|
-
// the accessory does not yet exist, so we need to create it
|
|
2201
|
-
if (!device.external) {
|
|
2202
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2203
|
-
}
|
|
2204
2111
|
// create a new accessory
|
|
2205
2112
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
2206
2113
|
// store a copy of the device object in the `accessory.context`
|
|
2207
2114
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2208
2115
|
accessory.context.device = device;
|
|
2209
|
-
accessory.context.
|
|
2210
|
-
accessory.context.deviceID = device.deviceId;
|
|
2211
|
-
if (device.firmware) {
|
|
2212
|
-
accessory.context.version = device.firmware;
|
|
2213
|
-
}
|
|
2116
|
+
accessory.context.deviceId = device.deviceId;
|
|
2214
2117
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2118
|
+
accessory.context.model = device.remoteType;
|
|
2119
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
2215
2120
|
accessory.context.connectionType = device.connectionType;
|
|
2121
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
2122
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
2123
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
2216
2124
|
// create the accessory handler for the newly create accessory
|
|
2217
2125
|
// this is imported from `platformAccessory.ts`
|
|
2218
2126
|
new VacuumCleaner(this, accessory, device);
|
|
2219
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2127
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2220
2128
|
// publish device externally or link the accessory to your platform
|
|
2221
2129
|
this.externalOrPlatformIR(device, accessory);
|
|
2222
2130
|
this.accessories.push(accessory);
|
|
2223
2131
|
}
|
|
2224
2132
|
else {
|
|
2225
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType}
|
|
2133
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
|
|
2226
2134
|
}
|
|
2227
2135
|
}
|
|
2228
2136
|
async createCamera(device) {
|
|
@@ -2234,52 +2142,47 @@ export class SwitchBotPlatform {
|
|
|
2234
2142
|
// the accessory already exists
|
|
2235
2143
|
if (!device.hide_device && device.hubDeviceId) {
|
|
2236
2144
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
2237
|
-
existingAccessory.context.
|
|
2238
|
-
existingAccessory.context.
|
|
2239
|
-
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
2240
|
-
if (device.firmware) {
|
|
2241
|
-
existingAccessory.context.version = device.firmware;
|
|
2242
|
-
}
|
|
2145
|
+
existingAccessory.context.device = device;
|
|
2146
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
2243
2147
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2244
|
-
|
|
2148
|
+
existingAccessory.context.model = device.remoteType;
|
|
2149
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
2150
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
2245
2151
|
existingAccessory.context.connectionType = device.connectionType;
|
|
2246
2152
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
2247
2153
|
// create the accessory handler for the restored accessory
|
|
2248
2154
|
// this is imported from `platformAccessory.ts`
|
|
2249
2155
|
new Camera(this, existingAccessory, device);
|
|
2250
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2156
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2251
2157
|
}
|
|
2252
2158
|
else {
|
|
2253
2159
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
2254
2160
|
}
|
|
2255
2161
|
}
|
|
2256
2162
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
2257
|
-
// the accessory does not yet exist, so we need to create it
|
|
2258
|
-
if (!device.external) {
|
|
2259
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2260
|
-
}
|
|
2261
2163
|
// create a new accessory
|
|
2262
2164
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
2263
2165
|
// store a copy of the device object in the `accessory.context`
|
|
2264
2166
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2265
2167
|
accessory.context.device = device;
|
|
2266
|
-
accessory.context.
|
|
2267
|
-
accessory.context.deviceID = device.deviceId;
|
|
2268
|
-
if (device.firmware) {
|
|
2269
|
-
accessory.context.version = device.firmware;
|
|
2270
|
-
}
|
|
2168
|
+
accessory.context.deviceId = device.deviceId;
|
|
2271
2169
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2170
|
+
accessory.context.model = device.remoteType;
|
|
2171
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
2272
2172
|
accessory.context.connectionType = device.connectionType;
|
|
2173
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
2174
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
2175
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
2273
2176
|
// create the accessory handler for the newly create accessory
|
|
2274
2177
|
// this is imported from `platformAccessory.ts`
|
|
2275
2178
|
new Camera(this, accessory, device);
|
|
2276
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2179
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2277
2180
|
// publish device externally or link the accessory to your platform
|
|
2278
2181
|
this.externalOrPlatformIR(device, accessory);
|
|
2279
2182
|
this.accessories.push(accessory);
|
|
2280
2183
|
}
|
|
2281
2184
|
else {
|
|
2282
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType}
|
|
2185
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
|
|
2283
2186
|
}
|
|
2284
2187
|
}
|
|
2285
2188
|
async createOthers(device) {
|
|
@@ -2291,52 +2194,47 @@ export class SwitchBotPlatform {
|
|
|
2291
2194
|
// the accessory already exists
|
|
2292
2195
|
if (!device.hide_device && device.hubDeviceId) {
|
|
2293
2196
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
2294
|
-
existingAccessory.context.
|
|
2295
|
-
existingAccessory.context.
|
|
2296
|
-
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
2297
|
-
if (device.firmware) {
|
|
2298
|
-
existingAccessory.context.version = device.firmware;
|
|
2299
|
-
}
|
|
2197
|
+
existingAccessory.context.device = device;
|
|
2198
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
2300
2199
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2301
|
-
|
|
2200
|
+
existingAccessory.context.model = device.remoteType;
|
|
2201
|
+
existingAccessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
2202
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
2302
2203
|
existingAccessory.context.connectionType = device.connectionType;
|
|
2303
2204
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
2304
2205
|
// create the accessory handler for the restored accessory
|
|
2305
2206
|
// this is imported from `platformAccessory.ts`
|
|
2306
2207
|
new Others(this, existingAccessory, device);
|
|
2307
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2208
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2308
2209
|
}
|
|
2309
2210
|
else {
|
|
2310
2211
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
2311
2212
|
}
|
|
2312
2213
|
}
|
|
2313
2214
|
else if (!device.hide_device && device.hubDeviceId) {
|
|
2314
|
-
// the accessory does not yet exist, so we need to create it
|
|
2315
|
-
if (!device.external) {
|
|
2316
|
-
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
2317
|
-
}
|
|
2318
2215
|
// create a new accessory
|
|
2319
2216
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
2320
2217
|
// store a copy of the device object in the `accessory.context`
|
|
2321
2218
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2322
2219
|
accessory.context.device = device;
|
|
2323
|
-
accessory.context.
|
|
2324
|
-
accessory.context.deviceID = device.deviceId;
|
|
2325
|
-
if (device.firmware) {
|
|
2326
|
-
accessory.context.version = device.firmware;
|
|
2327
|
-
}
|
|
2220
|
+
accessory.context.deviceId = device.deviceId;
|
|
2328
2221
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2222
|
+
accessory.context.model = device.remoteType;
|
|
2223
|
+
accessory.displayName = device.configDeviceName ?? device.deviceName;
|
|
2329
2224
|
accessory.context.connectionType = device.connectionType;
|
|
2225
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
2226
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
2227
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
2330
2228
|
// create the accessory handler for the newly create accessory
|
|
2331
2229
|
// this is imported from `platformAccessory.ts`
|
|
2332
2230
|
new Others(this, accessory, device);
|
|
2333
|
-
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2231
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2334
2232
|
// publish device externally or link the accessory to your platform
|
|
2335
2233
|
this.externalOrPlatformIR(device, accessory);
|
|
2336
2234
|
this.accessories.push(accessory);
|
|
2337
2235
|
}
|
|
2338
2236
|
else {
|
|
2339
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType}
|
|
2237
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
|
|
2340
2238
|
}
|
|
2341
2239
|
}
|
|
2342
2240
|
async registerCurtains(device) {
|
|
@@ -2349,12 +2247,13 @@ export class SwitchBotPlatform {
|
|
|
2349
2247
|
}*/
|
|
2350
2248
|
let registerWindowCovering;
|
|
2351
2249
|
if (isCurtainDevice(device)) {
|
|
2352
|
-
this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds}
|
|
2353
|
-
+
|
|
2250
|
+
await this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds},`
|
|
2251
|
+
+ ` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group},`
|
|
2252
|
+
+ ` connectionType: ${device.connectionType}`);
|
|
2354
2253
|
registerWindowCovering = await this.registerWindowCovering(device);
|
|
2355
2254
|
}
|
|
2356
2255
|
else if (isBlindTiltDevice(device)) {
|
|
2357
|
-
this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, blindTiltDevicesIds: ${device.blindTiltDevicesIds},`
|
|
2256
|
+
await this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, blindTiltDevicesIds: ${device.blindTiltDevicesIds},`
|
|
2358
2257
|
+ ` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group},`
|
|
2359
2258
|
+ ` connectionType: ${device.connectionType}`);
|
|
2360
2259
|
registerWindowCovering = await this.registerWindowCovering(device);
|
|
@@ -2365,42 +2264,42 @@ export class SwitchBotPlatform {
|
|
|
2365
2264
|
return registerWindowCovering;
|
|
2366
2265
|
}
|
|
2367
2266
|
async registerWindowCovering(device) {
|
|
2368
|
-
this.debugLog(device.master);
|
|
2267
|
+
await this.debugLog(`master: ${device.master}`);
|
|
2369
2268
|
let registerCurtain;
|
|
2370
2269
|
if (device.master && device.group) {
|
|
2371
2270
|
// OpenAPI: Master Curtains/Blind Tilt in Group
|
|
2372
2271
|
registerCurtain = true;
|
|
2373
|
-
this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}
|
|
2374
|
-
+ ` connectionType; ${device.connectionType}`);
|
|
2375
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2272
|
+
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master},`
|
|
2273
|
+
+ ` device.group: ${device.group} connectionType; ${device.connectionType}`);
|
|
2274
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2376
2275
|
}
|
|
2377
2276
|
else if (!device.master && device.curtain?.disable_group) {
|
|
2378
2277
|
//!device.group && device.connectionType === 'BLE'
|
|
2379
2278
|
// OpenAPI: Non-Master Curtains/Blind Tilts that has Disable Grouping Checked
|
|
2380
2279
|
registerCurtain = true;
|
|
2381
|
-
this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, disable_group: `
|
|
2280
|
+
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, disable_group: `
|
|
2382
2281
|
+ `${device.curtain?.disable_group}, connectionType; ${device.connectionType}`);
|
|
2383
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2282
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2384
2283
|
}
|
|
2385
2284
|
else if (device.master && !device.group) {
|
|
2386
2285
|
// OpenAPI: Master Curtains/Blind Tilts not in Group
|
|
2387
2286
|
registerCurtain = true;
|
|
2388
|
-
this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}
|
|
2389
|
-
+ ` connectionType; ${device.connectionType}`);
|
|
2390
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2287
|
+
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master},`
|
|
2288
|
+
+ ` device.group: ${device.group} connectionType; ${device.connectionType}`);
|
|
2289
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2391
2290
|
}
|
|
2392
2291
|
else if (device.connectionType === 'BLE') {
|
|
2393
2292
|
// BLE: Curtains/Blind Tilt
|
|
2394
2293
|
registerCurtain = true;
|
|
2395
|
-
this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] connectionType: ${device.connectionType}, `
|
|
2294
|
+
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] connectionType: ${device.connectionType}, `
|
|
2396
2295
|
+ ` group: ${device.group}`);
|
|
2397
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2296
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2398
2297
|
}
|
|
2399
2298
|
else {
|
|
2400
2299
|
registerCurtain = false;
|
|
2401
|
-
this.debugErrorLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] disable_group: ${device.curtain?.disable_group},`
|
|
2300
|
+
await this.debugErrorLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] disable_group: ${device.curtain?.disable_group},`
|
|
2402
2301
|
+ ` device.master: ${device.master}, device.group: ${device.group}`);
|
|
2403
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}, device.connectionType: ${device.connectionType}`);
|
|
2302
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}, device.connectionType: ${device.connectionType}`);
|
|
2404
2303
|
}
|
|
2405
2304
|
return registerCurtain;
|
|
2406
2305
|
}
|
|
@@ -2423,17 +2322,17 @@ export class SwitchBotPlatform {
|
|
|
2423
2322
|
case 'Curtain3':
|
|
2424
2323
|
case 'Blind Tilt':
|
|
2425
2324
|
registerDevice = await this.registerCurtains(device);
|
|
2426
|
-
this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2325
|
+
await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2427
2326
|
break;
|
|
2428
2327
|
default:
|
|
2429
2328
|
registerDevice = true;
|
|
2430
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2329
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2431
2330
|
}
|
|
2432
2331
|
if (registerDevice === true) {
|
|
2433
|
-
this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
2332
|
+
await this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
2434
2333
|
}
|
|
2435
2334
|
else {
|
|
2436
|
-
this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2335
|
+
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2437
2336
|
}
|
|
2438
2337
|
}
|
|
2439
2338
|
else if (!device.hide_device && device.deviceId && device.configDeviceType && device.configDeviceName && device.connectionType === 'BLE') {
|
|
@@ -2442,17 +2341,17 @@ export class SwitchBotPlatform {
|
|
|
2442
2341
|
case 'Curtain3':
|
|
2443
2342
|
case 'Blind Tilt':
|
|
2444
2343
|
registerDevice = await this.registerCurtains(device);
|
|
2445
|
-
this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2344
|
+
await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2446
2345
|
break;
|
|
2447
2346
|
default:
|
|
2448
2347
|
registerDevice = true;
|
|
2449
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2348
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2450
2349
|
}
|
|
2451
2350
|
if (registerDevice === true) {
|
|
2452
|
-
this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
2351
|
+
await this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
2453
2352
|
}
|
|
2454
2353
|
else {
|
|
2455
|
-
this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2354
|
+
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2456
2355
|
}
|
|
2457
2356
|
}
|
|
2458
2357
|
else if (!device.hide_device && device.connectionType === 'OpenAPI') {
|
|
@@ -2461,17 +2360,17 @@ export class SwitchBotPlatform {
|
|
|
2461
2360
|
case 'Curtain3':
|
|
2462
2361
|
case 'Blind Tilt':
|
|
2463
2362
|
registerDevice = await this.registerCurtains(device);
|
|
2464
|
-
this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2363
|
+
await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2465
2364
|
break;
|
|
2466
2365
|
default:
|
|
2467
2366
|
registerDevice = true;
|
|
2468
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2367
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2469
2368
|
}
|
|
2470
2369
|
if (registerDevice === true) {
|
|
2471
|
-
this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
2370
|
+
await this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
2472
2371
|
}
|
|
2473
2372
|
else {
|
|
2474
|
-
this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2373
|
+
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2475
2374
|
}
|
|
2476
2375
|
}
|
|
2477
2376
|
else if (!device.hide_device && device.connectionType === 'Disabled') {
|
|
@@ -2480,25 +2379,25 @@ export class SwitchBotPlatform {
|
|
|
2480
2379
|
case 'Curtain3':
|
|
2481
2380
|
case 'Blind Tilt':
|
|
2482
2381
|
registerDevice = await this.registerCurtains(device);
|
|
2483
|
-
this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2382
|
+
await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2484
2383
|
break;
|
|
2485
2384
|
default:
|
|
2486
2385
|
registerDevice = true;
|
|
2487
|
-
this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2386
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2488
2387
|
}
|
|
2489
|
-
this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will continue to display in HomeKit`);
|
|
2388
|
+
await this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will continue to display in HomeKit`);
|
|
2490
2389
|
}
|
|
2491
2390
|
else if (!device.connectionType && !device.hide_device) {
|
|
2492
2391
|
registerDevice = false;
|
|
2493
|
-
this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2392
|
+
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2494
2393
|
}
|
|
2495
2394
|
else if (device.hide_device) {
|
|
2496
2395
|
registerDevice = false;
|
|
2497
|
-
this.debugErrorLog(`Device: ${device.deviceName} hide_device: ${device.hide_device}, will not display in HomeKit`);
|
|
2396
|
+
await this.debugErrorLog(`Device: ${device.deviceName} hide_device: ${device.hide_device}, will not display in HomeKit`);
|
|
2498
2397
|
}
|
|
2499
2398
|
else {
|
|
2500
2399
|
registerDevice = false;
|
|
2501
|
-
this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, hide_device: `
|
|
2400
|
+
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, hide_device: `
|
|
2502
2401
|
+ `${device.hide_device}, will not display in HomeKit`);
|
|
2503
2402
|
}
|
|
2504
2403
|
return registerDevice;
|
|
@@ -2510,21 +2409,21 @@ export class SwitchBotPlatform {
|
|
|
2510
2409
|
* publish your TV as an external accessory.
|
|
2511
2410
|
*/
|
|
2512
2411
|
if (device.external) {
|
|
2513
|
-
this.debugWarnLog(`${accessory.displayName} External Accessory Mode`);
|
|
2412
|
+
await this.debugWarnLog(`${accessory.displayName} External Accessory Mode`);
|
|
2514
2413
|
this.externalAccessory(accessory);
|
|
2515
2414
|
}
|
|
2516
2415
|
else {
|
|
2517
|
-
this.debugLog(`${accessory.displayName} External Accessory Mode: ${device.external}`);
|
|
2416
|
+
await this.debugLog(`${accessory.displayName} External Accessory Mode: ${device.external}`);
|
|
2518
2417
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
2519
2418
|
}
|
|
2520
2419
|
}
|
|
2521
2420
|
async externalOrPlatform(device, accessory) {
|
|
2522
2421
|
if (device.external) {
|
|
2523
|
-
this.debugWarnLog(`${accessory.displayName} External Accessory Mode`);
|
|
2524
|
-
this.externalAccessory(accessory);
|
|
2422
|
+
await this.debugWarnLog(`${accessory.displayName} External Accessory Mode`);
|
|
2423
|
+
await this.externalAccessory(accessory);
|
|
2525
2424
|
}
|
|
2526
2425
|
else {
|
|
2527
|
-
this.debugLog(`${accessory.displayName} External Accessory Mode: ${device.external}`);
|
|
2426
|
+
await this.debugLog(`${accessory.displayName} External Accessory Mode: ${device.external}`);
|
|
2528
2427
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
2529
2428
|
}
|
|
2530
2429
|
}
|