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