@switchbot/homebridge-switchbot 3.7.1-beta.12 → 3.7.1-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/device/blindtilt.d.ts +8 -8
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +34 -66
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -9
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +61 -97
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -13
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +38 -73
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +12 -12
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +41 -79
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +5 -5
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +20 -42
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +5 -5
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +36 -71
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +18 -18
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +33 -36
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +8 -8
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +43 -75
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +5 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +18 -39
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +5 -5
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +38 -78
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +5 -5
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +21 -40
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +6 -6
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +34 -73
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +9 -9
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +37 -52
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +5 -5
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +21 -39
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +5 -5
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +21 -38
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +5 -5
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +14 -32
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +12 -12
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +16 -25
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -11
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +42 -56
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +5 -5
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +22 -37
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/server.js +2 -2
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -8
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +64 -105
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +10 -10
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +22 -42
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +9 -9
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +15 -25
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +8 -8
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +21 -40
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +11 -11
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +14 -22
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +9 -9
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +24 -47
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +9 -9
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +40 -83
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +9 -9
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +29 -54
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +5 -5
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +11 -21
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +5 -5
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +11 -22
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +5 -6
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +141 -146
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +2 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +9 -9
- package/dist/types/bledevicestatus.d.ts.map +1 -1
- package/dist/types/devicelist.d.ts +6 -6
- package/dist/types/devicelist.d.ts.map +1 -1
- package/dist/types/deviceresponse.d.ts +4 -4
- package/dist/types/deviceresponse.d.ts.map +1 -1
- package/dist/types/devicestatus.d.ts +2 -2
- package/dist/types/devicestatus.d.ts.map +1 -1
- package/dist/types/devicewebhookstatus.d.ts +5 -5
- package/dist/types/devicewebhookstatus.d.ts.map +1 -1
- package/dist/types/irdevicelist.d.ts +4 -4
- package/dist/types/irdevicelist.d.ts.map +1 -1
- package/dist/types/pushbody.d.ts +2 -2
- package/dist/types/pushbody.d.ts.map +1 -1
- package/dist/utils.d.ts +4 -4
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +9 -13
- package/dist/utils.js.map +1 -1
- package/eslint.config.js +48 -93
- package/package.json +54 -47
- package/src/device/blindtilt.ts +419 -456
- package/src/device/bot.ts +656 -693
- package/src/device/ceilinglight.ts +331 -364
- package/src/device/colorbulb.ts +412 -448
- package/src/device/contact.ts +200 -221
- package/src/device/curtain.ts +400 -435
- package/src/device/device.ts +206 -208
- package/src/device/fan.ts +307 -340
- package/src/device/hub.ts +184 -209
- package/src/device/humidifier.ts +297 -342
- package/src/device/iosensor.ts +182 -204
- package/src/device/lightstrip.ts +362 -399
- package/src/device/lock.ts +262 -276
- package/src/device/meter.ts +183 -205
- package/src/device/meterplus.ts +183 -204
- package/src/device/motion.ts +169 -185
- package/src/device/plug.ts +174 -177
- package/src/device/robotvacuumcleaner.ts +256 -269
- package/src/device/waterdetector.ts +169 -184
- package/src/homebridge-ui/server.ts +16 -15
- package/src/index.ts +5 -6
- package/src/irdevice/airconditioner.ts +280 -326
- package/src/irdevice/airpurifier.ts +124 -143
- package/src/irdevice/camera.ts +58 -64
- package/src/irdevice/fan.ts +106 -123
- package/src/irdevice/irdevice.ts +116 -119
- package/src/irdevice/light.ts +119 -143
- package/src/irdevice/other.ts +417 -461
- package/src/irdevice/tv.ts +155 -177
- package/src/irdevice/vacuumcleaner.ts +54 -60
- package/src/irdevice/waterheater.ts +56 -63
- package/src/platform.ts +1281 -1281
- package/src/settings.ts +170 -170
- package/src/types/bledevicestatus.ts +255 -255
- package/src/types/devicelist.ts +79 -79
- package/src/types/deviceresponse.ts +12 -13
- package/src/types/devicestatus.ts +124 -124
- package/src/types/devicewebhookstatus.ts +126 -127
- package/src/types/irdevicelist.ts +10 -10
- package/src/types/pushbody.ts +5 -5
- package/src/utils.ts +64 -65
- package/tsconfig.json +10 -9
package/dist/platform.js
CHANGED
|
@@ -1,50 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import crypto, { randomUUID } from 'node:crypto';
|
|
3
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { createServer } from 'node:http';
|
|
5
|
+
import process from 'node:process';
|
|
6
|
+
import asyncmqtt from 'async-mqtt';
|
|
7
|
+
import fakegato from 'fakegato-history';
|
|
8
|
+
import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes';
|
|
9
|
+
/*
|
|
10
|
+
* For Testing Locally:
|
|
11
|
+
* import { SwitchBotModel } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
12
|
+
*/
|
|
13
|
+
import { SwitchBotModel } from 'node-switchbot';
|
|
14
|
+
import { queueScheduler } from 'rxjs';
|
|
15
|
+
import { request } from 'undici';
|
|
16
|
+
import { BlindTilt } from './device/blindtilt.js';
|
|
6
17
|
import { Bot } from './device/bot.js';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { Meter } from './device/meter.js';
|
|
10
|
-
import { Motion } from './device/motion.js';
|
|
18
|
+
import { CeilingLight } from './device/ceilinglight.js';
|
|
19
|
+
import { ColorBulb } from './device/colorbulb.js';
|
|
11
20
|
import { Contact } from './device/contact.js';
|
|
12
21
|
import { Curtain } from './device/curtain.js';
|
|
22
|
+
import { Fan } from './device/fan.js';
|
|
23
|
+
import { Hub } from './device/hub.js';
|
|
24
|
+
import { Humidifier } from './device/humidifier.js';
|
|
13
25
|
import { IOSensor } from './device/iosensor.js';
|
|
14
|
-
import { MeterPlus } from './device/meterplus.js';
|
|
15
|
-
import { ColorBulb } from './device/colorbulb.js';
|
|
16
26
|
import { StripLight } from './device/lightstrip.js';
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
27
|
+
import { Lock } from './device/lock.js';
|
|
28
|
+
import { Meter } from './device/meter.js';
|
|
29
|
+
import { MeterPlus } from './device/meterplus.js';
|
|
30
|
+
import { Motion } from './device/motion.js';
|
|
31
|
+
import { Plug } from './device/plug.js';
|
|
20
32
|
import { RobotVacuumCleaner } from './device/robotvacuumcleaner.js';
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
33
|
+
import { WaterDetector } from './device/waterdetector.js';
|
|
34
|
+
import { AirConditioner } from './irdevice/airconditioner.js';
|
|
35
|
+
import { AirPurifier } from './irdevice/airpurifier.js';
|
|
36
|
+
import { Camera } from './irdevice/camera.js';
|
|
23
37
|
import { IRFan } from './irdevice/fan.js';
|
|
24
38
|
import { Light } from './irdevice/light.js';
|
|
25
39
|
import { Others } from './irdevice/other.js';
|
|
26
|
-
import {
|
|
27
|
-
import { BlindTilt } from './device/blindtilt.js';
|
|
28
|
-
import { AirPurifier } from './irdevice/airpurifier.js';
|
|
29
|
-
import { WaterHeater } from './irdevice/waterheater.js';
|
|
40
|
+
import { TV } from './irdevice/tv.js';
|
|
30
41
|
import { VacuumCleaner } from './irdevice/vacuumcleaner.js';
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import { request } from 'undici';
|
|
34
|
-
import asyncmqtt from 'async-mqtt';
|
|
35
|
-
import { createServer } from 'http';
|
|
36
|
-
import { queueScheduler } from 'rxjs';
|
|
37
|
-
import fakegato from 'fakegato-history';
|
|
38
|
-
import crypto, { randomUUID } from 'crypto';
|
|
39
|
-
import { readFileSync, writeFileSync } from 'fs';
|
|
40
|
-
import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes';
|
|
41
|
-
import { PLATFORM_NAME, PLUGIN_NAME, Devices, deleteWebhook, queryWebhook, setupWebhook, updateWebhook } from './settings.js';
|
|
42
|
+
import { WaterHeater } from './irdevice/waterheater.js';
|
|
43
|
+
import { deleteWebhook, Devices, PLATFORM_NAME, PLUGIN_NAME, queryWebhook, setupWebhook, updateWebhook } from './settings.js';
|
|
42
44
|
import { isBlindTiltDevice, isCurtainDevice, sleep } from './utils.js';
|
|
43
|
-
/*
|
|
44
|
-
* For Testing Locally:
|
|
45
|
-
* import { SwitchBotModel } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
46
|
-
*/
|
|
47
|
-
import { SwitchBotModel } from 'node-switchbot';
|
|
48
45
|
/**
|
|
49
46
|
* HomebridgePlatform
|
|
50
47
|
* This class is the main constructor for your plugin, this is where you should
|
|
@@ -180,7 +177,7 @@ export class SwitchBotPlatform {
|
|
|
180
177
|
}
|
|
181
178
|
}
|
|
182
179
|
async setupwebhook() {
|
|
183
|
-
//webhook configuration
|
|
180
|
+
// webhook configuration
|
|
184
181
|
if (this.config.options?.webhookURL) {
|
|
185
182
|
const url = this.config.options?.webhookURL;
|
|
186
183
|
try {
|
|
@@ -216,7 +213,7 @@ export class SwitchBotPlatform {
|
|
|
216
213
|
catch (e) {
|
|
217
214
|
this.errorLog(`Failed to handle webhook event. Error:${e}`);
|
|
218
215
|
}
|
|
219
|
-
}).listen(port
|
|
216
|
+
}).listen(port || 80);
|
|
220
217
|
}
|
|
221
218
|
catch (e) {
|
|
222
219
|
await this.errorLog(`Failed to create webhook listener. Error:${e.message}`);
|
|
@@ -227,16 +224,15 @@ export class SwitchBotPlatform {
|
|
|
227
224
|
method: 'POST',
|
|
228
225
|
headers: this.generateHeaders(),
|
|
229
226
|
body: JSON.stringify({
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
227
|
+
action: 'setupWebhook',
|
|
228
|
+
url,
|
|
229
|
+
deviceList: 'ALL',
|
|
233
230
|
}),
|
|
234
231
|
});
|
|
235
232
|
const response = await body.json();
|
|
236
233
|
await this.debugLog(`setupWebhook: url:${url}, body:${JSON.stringify(response)}, statusCode:${statusCode}`);
|
|
237
234
|
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
238
|
-
await this.errorLog(`Failed to configure webhook. Existing webhook well be overridden. HTTP:${statusCode} API:${response?.statusCode} `
|
|
239
|
-
+ `message:${response?.message}`);
|
|
235
|
+
await this.errorLog(`Failed to configure webhook. Existing webhook well be overridden. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
|
|
240
236
|
}
|
|
241
237
|
}
|
|
242
238
|
catch (e) {
|
|
@@ -244,11 +240,13 @@ export class SwitchBotPlatform {
|
|
|
244
240
|
}
|
|
245
241
|
try {
|
|
246
242
|
const { body, statusCode } = await request(updateWebhook, {
|
|
247
|
-
method: 'POST',
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
243
|
+
method: 'POST',
|
|
244
|
+
headers: this.generateHeaders(),
|
|
245
|
+
body: JSON.stringify({
|
|
246
|
+
action: 'updateWebhook',
|
|
247
|
+
config: {
|
|
248
|
+
url,
|
|
249
|
+
enable: true,
|
|
252
250
|
},
|
|
253
251
|
}),
|
|
254
252
|
});
|
|
@@ -266,7 +264,7 @@ export class SwitchBotPlatform {
|
|
|
266
264
|
method: 'POST',
|
|
267
265
|
headers: this.generateHeaders(),
|
|
268
266
|
body: JSON.stringify({
|
|
269
|
-
|
|
267
|
+
action: 'queryUrl',
|
|
270
268
|
}),
|
|
271
269
|
});
|
|
272
270
|
const response = await body.json();
|
|
@@ -288,8 +286,8 @@ export class SwitchBotPlatform {
|
|
|
288
286
|
method: 'POST',
|
|
289
287
|
headers: this.generateHeaders(),
|
|
290
288
|
body: JSON.stringify({
|
|
291
|
-
|
|
292
|
-
|
|
289
|
+
action: 'deleteWebhook',
|
|
290
|
+
url,
|
|
293
291
|
}),
|
|
294
292
|
});
|
|
295
293
|
const response = await body.json();
|
|
@@ -365,13 +363,13 @@ export class SwitchBotPlatform {
|
|
|
365
363
|
this.config.options = this.config.options || {};
|
|
366
364
|
const platformConfig = {};
|
|
367
365
|
if (this.config.options.logging) {
|
|
368
|
-
platformConfig
|
|
366
|
+
platformConfig.logging = this.config.options.logging;
|
|
369
367
|
}
|
|
370
368
|
if (this.config.options.logging && this.config.options.refreshRate) {
|
|
371
|
-
platformConfig
|
|
369
|
+
platformConfig.refreshRate = this.config.options.refreshRate;
|
|
372
370
|
}
|
|
373
371
|
if (this.config.options.logging && this.config.options.pushRate) {
|
|
374
|
-
platformConfig
|
|
372
|
+
platformConfig.pushRate = this.config.options.pushRate;
|
|
375
373
|
}
|
|
376
374
|
if (Object.entries(platformConfig).length !== 0) {
|
|
377
375
|
await this.debugWarnLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
@@ -451,7 +449,6 @@ export class SwitchBotPlatform {
|
|
|
451
449
|
/**
|
|
452
450
|
* The openToken was old config.
|
|
453
451
|
* This method saves the openToken as the token in the config.json file
|
|
454
|
-
* @param this.config.credentials.openToken
|
|
455
452
|
*/
|
|
456
453
|
async updateToken() {
|
|
457
454
|
try {
|
|
@@ -463,7 +460,7 @@ export class SwitchBotPlatform {
|
|
|
463
460
|
const currentConfig = JSON.parse(readFileSync(this.api.user.configPath(), 'utf8'));
|
|
464
461
|
// check the platforms section is an array before we do array things on it
|
|
465
462
|
if (!Array.isArray(currentConfig.platforms)) {
|
|
466
|
-
throw new
|
|
463
|
+
throw new TypeError('Cannot find platforms array in config');
|
|
467
464
|
}
|
|
468
465
|
// find this plugins current config
|
|
469
466
|
const pluginConfig = currentConfig.platforms.find((x) => x.platform === PLATFORM_NAME);
|
|
@@ -472,17 +469,15 @@ export class SwitchBotPlatform {
|
|
|
472
469
|
}
|
|
473
470
|
// check the .credentials is an object before doing object things with it
|
|
474
471
|
if (typeof pluginConfig.credentials !== 'object') {
|
|
475
|
-
throw new
|
|
472
|
+
throw new TypeError('pluginConfig.credentials is not an object');
|
|
476
473
|
}
|
|
477
474
|
// Move openToken to token
|
|
478
475
|
if (!this.config.credentials.secret) {
|
|
479
|
-
await this.warnLog('This plugin has been updated to use OpenAPI v1.1, config is set with openToken,'
|
|
480
|
-
+ ' "openToken" cconfig has been moved to the "token" config');
|
|
476
|
+
await this.warnLog('This plugin has been updated to use OpenAPI v1.1, config is set with openToken, "openToken" cconfig has been moved to the "token" config');
|
|
481
477
|
this.errorLog('"secret" config is not populated, you must populate then please restart Homebridge.');
|
|
482
478
|
}
|
|
483
479
|
else {
|
|
484
|
-
await this.warnLog('This plugin has been updated to use OpenAPI v1.1, config is set with openToken, '
|
|
485
|
-
+ '"openToken" config has been moved to the "token" config, please restart Homebridge.');
|
|
480
|
+
await this.warnLog('This plugin has been updated to use OpenAPI v1.1, config is set with openToken, "openToken" config has been moved to the "token" config, please restart Homebridge.');
|
|
486
481
|
}
|
|
487
482
|
// set the refresh token
|
|
488
483
|
pluginConfig.credentials.token = this.config.credentials?.openToken;
|
|
@@ -508,10 +503,10 @@ export class SwitchBotPlatform {
|
|
|
508
503
|
.digest();
|
|
509
504
|
const sign = signTerm.toString('base64');
|
|
510
505
|
return {
|
|
511
|
-
Authorization: this.config.credentials?.token,
|
|
512
|
-
sign: sign,
|
|
513
|
-
nonce: nonce,
|
|
514
|
-
t: t,
|
|
506
|
+
'Authorization': this.config.credentials?.token,
|
|
507
|
+
'sign': sign,
|
|
508
|
+
'nonce': nonce,
|
|
509
|
+
't': t,
|
|
515
510
|
'Content-Type': 'application/json',
|
|
516
511
|
};
|
|
517
512
|
};
|
|
@@ -543,8 +538,7 @@ export class SwitchBotPlatform {
|
|
|
543
538
|
}
|
|
544
539
|
catch (e) {
|
|
545
540
|
retryCount++;
|
|
546
|
-
await this.debugErrorLog(`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}
|
|
547
|
-
+ ' Submit Bugs Here: https://tinyurl.com/SwitchBotBug');
|
|
541
|
+
await this.debugErrorLog(`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`);
|
|
548
542
|
await this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
|
|
549
543
|
}
|
|
550
544
|
}
|
|
@@ -626,7 +620,7 @@ export class SwitchBotPlatform {
|
|
|
626
620
|
}
|
|
627
621
|
mergeByDeviceId(a1, a2) {
|
|
628
622
|
const normalizeDeviceId = (deviceId) => deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '');
|
|
629
|
-
return a1.map(itm => {
|
|
623
|
+
return a1.map((itm) => {
|
|
630
624
|
const matchingItem = a2.find(item => normalizeDeviceId(item.deviceId) === normalizeDeviceId(itm.deviceId));
|
|
631
625
|
return { ...matchingItem, ...itm };
|
|
632
626
|
});
|
|
@@ -680,8 +674,7 @@ export class SwitchBotPlatform {
|
|
|
680
674
|
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}, is currently not supported, device: ${JSON.stringify(device)}`);
|
|
681
675
|
}
|
|
682
676
|
else {
|
|
683
|
-
await this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported
|
|
684
|
-
+ ` Submit Feature Requests Here: https://tinyurl.com/SwitchBotFeatureRequest, device: ${JSON.stringify(device)}`);
|
|
677
|
+
await this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported. Submit Feature Requests Here: https://tinyurl.com/SwitchBotFeatureRequest, device: ${JSON.stringify(device)}`);
|
|
685
678
|
}
|
|
686
679
|
}
|
|
687
680
|
async createIRDevice(device) {
|
|
@@ -723,15 +716,14 @@ export class SwitchBotPlatform {
|
|
|
723
716
|
await deviceTypeHandlers[device.remoteType](device);
|
|
724
717
|
}
|
|
725
718
|
else {
|
|
726
|
-
await this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.remoteType}, is currently not supported
|
|
727
|
-
+ ` Submit Feature Requests Here: https://tinyurl.com/SwitchBotFeatureRequest, device: ${JSON.stringify(device)}`);
|
|
719
|
+
await this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.remoteType}, is currently not supported. Submit Feature Requests Here: https://tinyurl.com/SwitchBotFeatureRequest, device: ${JSON.stringify(device)}`);
|
|
728
720
|
}
|
|
729
721
|
}
|
|
730
722
|
async createHumidifier(device) {
|
|
731
723
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
732
724
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
733
725
|
// the cached devices we stored in the `configureAccessory` method above
|
|
734
|
-
const existingAccessory = this.accessories.find(
|
|
726
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
735
727
|
if (existingAccessory) {
|
|
736
728
|
// the accessory already exists
|
|
737
729
|
if (await this.registerDevice(device)) {
|
|
@@ -790,7 +782,7 @@ export class SwitchBotPlatform {
|
|
|
790
782
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
791
783
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
792
784
|
// the cached devices we stored in the `configureAccessory` method above
|
|
793
|
-
const existingAccessory = this.accessories.find(
|
|
785
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
794
786
|
if (existingAccessory) {
|
|
795
787
|
// the accessory already exists
|
|
796
788
|
if (await this.registerDevice(device)) {
|
|
@@ -851,7 +843,7 @@ export class SwitchBotPlatform {
|
|
|
851
843
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
852
844
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
853
845
|
// the cached devices we stored in the `configureAccessory` method above
|
|
854
|
-
const existingAccessory = this.accessories.find(
|
|
846
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
855
847
|
if (existingAccessory) {
|
|
856
848
|
// the accessory already exists
|
|
857
849
|
if (await this.registerDevice(device)) {
|
|
@@ -911,7 +903,7 @@ export class SwitchBotPlatform {
|
|
|
911
903
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
912
904
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
913
905
|
// the cached devices we stored in the `configureAccessory` method above
|
|
914
|
-
const existingAccessory = this.accessories.find(
|
|
906
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
915
907
|
if (existingAccessory) {
|
|
916
908
|
// the accessory already exists
|
|
917
909
|
if (await this.registerDevice(device)) {
|
|
@@ -972,7 +964,7 @@ export class SwitchBotPlatform {
|
|
|
972
964
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
973
965
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
974
966
|
// the cached devices we stored in the `configureAccessory` method above
|
|
975
|
-
const existingAccessory = this.accessories.find(
|
|
967
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
976
968
|
if (existingAccessory) {
|
|
977
969
|
// the accessory already exists
|
|
978
970
|
if (await this.registerDevice(device)) {
|
|
@@ -1033,7 +1025,7 @@ export class SwitchBotPlatform {
|
|
|
1033
1025
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1034
1026
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1035
1027
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1036
|
-
const existingAccessory = this.accessories.find(
|
|
1028
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
1037
1029
|
if (existingAccessory) {
|
|
1038
1030
|
// the accessory already exists
|
|
1039
1031
|
if (await this.registerDevice(device)) {
|
|
@@ -1093,7 +1085,7 @@ export class SwitchBotPlatform {
|
|
|
1093
1085
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1094
1086
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1095
1087
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1096
|
-
const existingAccessory = this.accessories.find(
|
|
1088
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
1097
1089
|
if (existingAccessory) {
|
|
1098
1090
|
// the accessory already exists
|
|
1099
1091
|
if (await this.registerDevice(device)) {
|
|
@@ -1153,7 +1145,7 @@ export class SwitchBotPlatform {
|
|
|
1153
1145
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1154
1146
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1155
1147
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1156
|
-
const existingAccessory = this.accessories.find(
|
|
1148
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
1157
1149
|
if (existingAccessory) {
|
|
1158
1150
|
// the accessory already exists
|
|
1159
1151
|
if (await this.registerDevice(device)) {
|
|
@@ -1213,7 +1205,7 @@ export class SwitchBotPlatform {
|
|
|
1213
1205
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1214
1206
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1215
1207
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1216
|
-
const existingAccessory = this.accessories.find(
|
|
1208
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
1217
1209
|
if (existingAccessory) {
|
|
1218
1210
|
// the accessory already exists
|
|
1219
1211
|
if (await this.registerDevice(device)) {
|
|
@@ -1273,7 +1265,7 @@ export class SwitchBotPlatform {
|
|
|
1273
1265
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1274
1266
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1275
1267
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1276
|
-
const existingAccessory = this.accessories.find(
|
|
1268
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
1277
1269
|
if (existingAccessory) {
|
|
1278
1270
|
// the accessory already exists
|
|
1279
1271
|
if (await this.registerDevice(device)) {
|
|
@@ -1301,8 +1293,8 @@ export class SwitchBotPlatform {
|
|
|
1301
1293
|
else if (await this.registerDevice(device)) {
|
|
1302
1294
|
if (isBlindTiltDevice(device)) {
|
|
1303
1295
|
if (device.group && !device.curtain?.disable_group) {
|
|
1304
|
-
this.debugLog('Your Curtains are grouped, '
|
|
1305
|
-
`, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
|
|
1296
|
+
this.debugLog('Your Curtains are grouped, '
|
|
1297
|
+
+ `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
|
|
1306
1298
|
}
|
|
1307
1299
|
else {
|
|
1308
1300
|
if (device.master) {
|
|
@@ -1320,7 +1312,6 @@ export class SwitchBotPlatform {
|
|
|
1320
1312
|
// store a copy of the device object in the `accessory.context`
|
|
1321
1313
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1322
1314
|
accessory.context.device = device;
|
|
1323
|
-
;
|
|
1324
1315
|
accessory.context.deviceId = device.deviceId;
|
|
1325
1316
|
accessory.context.deviceType = device.deviceType;
|
|
1326
1317
|
accessory.context.model = SwitchBotModel.BlindTilt;
|
|
@@ -1348,7 +1339,7 @@ export class SwitchBotPlatform {
|
|
|
1348
1339
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1349
1340
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1350
1341
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1351
|
-
const existingAccessory = this.accessories.find(
|
|
1342
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
1352
1343
|
if (existingAccessory) {
|
|
1353
1344
|
// the accessory already exists
|
|
1354
1345
|
if (await this.registerDevice(device)) {
|
|
@@ -1376,8 +1367,8 @@ export class SwitchBotPlatform {
|
|
|
1376
1367
|
else if (await this.registerDevice(device)) {
|
|
1377
1368
|
if (isCurtainDevice(device)) {
|
|
1378
1369
|
if (device.group && !device.curtain?.disable_group) {
|
|
1379
|
-
this.debugLog('Your Curtains are grouped, '
|
|
1380
|
-
`, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
|
|
1370
|
+
this.debugLog('Your Curtains are grouped, '
|
|
1371
|
+
+ `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
|
|
1381
1372
|
}
|
|
1382
1373
|
else {
|
|
1383
1374
|
if (device.master) {
|
|
@@ -1422,7 +1413,7 @@ export class SwitchBotPlatform {
|
|
|
1422
1413
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1423
1414
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1424
1415
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1425
|
-
const existingAccessory = this.accessories.find(
|
|
1416
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
1426
1417
|
if (existingAccessory) {
|
|
1427
1418
|
// the accessory already exists
|
|
1428
1419
|
if (await this.registerDevice(device)) {
|
|
@@ -1430,8 +1421,11 @@ export class SwitchBotPlatform {
|
|
|
1430
1421
|
existingAccessory.context.device = device;
|
|
1431
1422
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1432
1423
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1433
|
-
existingAccessory.context.model = device.deviceType === 'Plug Mini (US)'
|
|
1434
|
-
? SwitchBotModel.
|
|
1424
|
+
existingAccessory.context.model = device.deviceType === 'Plug Mini (US)'
|
|
1425
|
+
? SwitchBotModel.PlugMiniUS
|
|
1426
|
+
: device.deviceType === 'Plug Mini (JP)'
|
|
1427
|
+
? SwitchBotModel.PlugMiniJP
|
|
1428
|
+
: SwitchBotModel.Plug;
|
|
1435
1429
|
existingAccessory.displayName = device.configDeviceName
|
|
1436
1430
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1437
1431
|
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
@@ -1458,8 +1452,11 @@ export class SwitchBotPlatform {
|
|
|
1458
1452
|
accessory.context.device = device;
|
|
1459
1453
|
accessory.context.deviceId = device.deviceId;
|
|
1460
1454
|
accessory.context.deviceType = device.deviceType;
|
|
1461
|
-
accessory.context.model = device.deviceType === 'Plug Mini (US)'
|
|
1462
|
-
? SwitchBotModel.
|
|
1455
|
+
accessory.context.model = device.deviceType === 'Plug Mini (US)'
|
|
1456
|
+
? SwitchBotModel.PlugMiniUS
|
|
1457
|
+
: device.deviceType === 'Plug Mini (JP)'
|
|
1458
|
+
? SwitchBotModel.PlugMiniJP
|
|
1459
|
+
: SwitchBotModel.Plug;
|
|
1463
1460
|
accessory.displayName = device.configDeviceName
|
|
1464
1461
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1465
1462
|
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
@@ -1484,7 +1481,7 @@ export class SwitchBotPlatform {
|
|
|
1484
1481
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1485
1482
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1486
1483
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1487
|
-
const existingAccessory = this.accessories.find(
|
|
1484
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
1488
1485
|
if (existingAccessory) {
|
|
1489
1486
|
// the accessory already exists
|
|
1490
1487
|
if (await this.registerDevice(device)) {
|
|
@@ -1544,7 +1541,7 @@ export class SwitchBotPlatform {
|
|
|
1544
1541
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1545
1542
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1546
1543
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1547
|
-
const existingAccessory = this.accessories.find(
|
|
1544
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
1548
1545
|
if (existingAccessory) {
|
|
1549
1546
|
// the accessory already exists
|
|
1550
1547
|
if (await this.registerDevice(device)) {
|
|
@@ -1604,7 +1601,7 @@ export class SwitchBotPlatform {
|
|
|
1604
1601
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1605
1602
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1606
1603
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1607
|
-
const existingAccessory = this.accessories.find(
|
|
1604
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
1608
1605
|
if (existingAccessory) {
|
|
1609
1606
|
// the accessory already exists
|
|
1610
1607
|
if (await this.registerDevice(device)) {
|
|
@@ -1664,7 +1661,7 @@ export class SwitchBotPlatform {
|
|
|
1664
1661
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1665
1662
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1666
1663
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1667
|
-
const existingAccessory = this.accessories.find(
|
|
1664
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
1668
1665
|
if (existingAccessory) {
|
|
1669
1666
|
// the accessory already exists
|
|
1670
1667
|
if (await this.registerDevice(device)) {
|
|
@@ -1724,7 +1721,7 @@ export class SwitchBotPlatform {
|
|
|
1724
1721
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1725
1722
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1726
1723
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1727
|
-
const existingAccessory = this.accessories.find(
|
|
1724
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
1728
1725
|
if (existingAccessory) {
|
|
1729
1726
|
// the accessory already exists
|
|
1730
1727
|
if (await this.registerDevice(device)) {
|
|
@@ -1784,7 +1781,7 @@ export class SwitchBotPlatform {
|
|
|
1784
1781
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1785
1782
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1786
1783
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1787
|
-
const existingAccessory = this.accessories.find(
|
|
1784
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
1788
1785
|
if (existingAccessory) {
|
|
1789
1786
|
// the accessory already exists
|
|
1790
1787
|
if (await this.registerDevice(device)) {
|
|
@@ -1792,11 +1789,17 @@ export class SwitchBotPlatform {
|
|
|
1792
1789
|
existingAccessory.context.device = device;
|
|
1793
1790
|
existingAccessory.context.deviceId = device.deviceId;
|
|
1794
1791
|
existingAccessory.context.deviceType = device.deviceType;
|
|
1795
|
-
existingAccessory.context.model = device.deviceType === 'Robot Vacuum Cleaner S1'
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1792
|
+
existingAccessory.context.model = device.deviceType === 'Robot Vacuum Cleaner S1'
|
|
1793
|
+
? SwitchBotModel.RobotVacuumCleanerS1
|
|
1794
|
+
: device.deviceType === 'Robot Vacuum Cleaner S1 Plus'
|
|
1795
|
+
? SwitchBotModel.RobotVacuumCleanerS1Plus
|
|
1796
|
+
: device.deviceType === 'Robot Vacuum Cleaner S10'
|
|
1797
|
+
? SwitchBotModel.RobotVacuumCleanerS10
|
|
1798
|
+
: device.deviceType === 'WoSweeper'
|
|
1799
|
+
? SwitchBotModel.WoSweeper
|
|
1800
|
+
: device.deviceType === 'WoSweeperMini'
|
|
1801
|
+
? SwitchBotModel.WoSweeperMini
|
|
1802
|
+
: SwitchBotModel.Unknown;
|
|
1800
1803
|
existingAccessory.displayName = device.configDeviceName
|
|
1801
1804
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1802
1805
|
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
@@ -1823,11 +1826,17 @@ export class SwitchBotPlatform {
|
|
|
1823
1826
|
accessory.context.device = device;
|
|
1824
1827
|
accessory.context.deviceId = device.deviceId;
|
|
1825
1828
|
accessory.context.deviceType = device.deviceType;
|
|
1826
|
-
accessory.context.model = device.deviceType === 'Robot Vacuum Cleaner S1'
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1829
|
+
accessory.context.model = device.deviceType === 'Robot Vacuum Cleaner S1'
|
|
1830
|
+
? SwitchBotModel.RobotVacuumCleanerS1
|
|
1831
|
+
: device.deviceType === 'Robot Vacuum Cleaner S1 Plus'
|
|
1832
|
+
? SwitchBotModel.RobotVacuumCleanerS1Plus
|
|
1833
|
+
: device.deviceType === 'Robot Vacuum Cleaner S10'
|
|
1834
|
+
? SwitchBotModel.RobotVacuumCleanerS10
|
|
1835
|
+
: device.deviceType === 'WoSweeper'
|
|
1836
|
+
? SwitchBotModel.WoSweeper
|
|
1837
|
+
: device.deviceType === 'WoSweeperMini'
|
|
1838
|
+
? SwitchBotModel.WoSweeperMini
|
|
1839
|
+
: SwitchBotModel.Unknown;
|
|
1831
1840
|
accessory.displayName = device.configDeviceName
|
|
1832
1841
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1833
1842
|
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
@@ -1852,7 +1861,7 @@ export class SwitchBotPlatform {
|
|
|
1852
1861
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
|
|
1853
1862
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1854
1863
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1855
|
-
const existingAccessory = this.accessories.find(
|
|
1864
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
1856
1865
|
if (!device.hide_device && existingAccessory) {
|
|
1857
1866
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1858
1867
|
existingAccessory.context.device = device;
|
|
@@ -1903,7 +1912,7 @@ export class SwitchBotPlatform {
|
|
|
1903
1912
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
|
|
1904
1913
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1905
1914
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1906
|
-
const existingAccessory = this.accessories.find(
|
|
1915
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
1907
1916
|
if (existingAccessory) {
|
|
1908
1917
|
// the accessory already exists
|
|
1909
1918
|
if (!device.hide_device && device.hubDeviceId) {
|
|
@@ -1961,7 +1970,7 @@ export class SwitchBotPlatform {
|
|
|
1961
1970
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
|
|
1962
1971
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1963
1972
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1964
|
-
const existingAccessory = this.accessories.find(
|
|
1973
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
1965
1974
|
if (existingAccessory) {
|
|
1966
1975
|
// the accessory already exists
|
|
1967
1976
|
if (!device.hide_device && device.hubDeviceId) {
|
|
@@ -2019,7 +2028,7 @@ export class SwitchBotPlatform {
|
|
|
2019
2028
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
|
|
2020
2029
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
2021
2030
|
// the cached devices we stored in the `configureAccessory` method above
|
|
2022
|
-
const existingAccessory = this.accessories.find(
|
|
2031
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
2023
2032
|
if (existingAccessory) {
|
|
2024
2033
|
// the accessory already exists
|
|
2025
2034
|
if (!device.hide_device && device.hubDeviceId) {
|
|
@@ -2077,7 +2086,7 @@ export class SwitchBotPlatform {
|
|
|
2077
2086
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
|
|
2078
2087
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
2079
2088
|
// the cached devices we stored in the `configureAccessory` method above
|
|
2080
|
-
const existingAccessory = this.accessories.find(
|
|
2089
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
2081
2090
|
if (existingAccessory) {
|
|
2082
2091
|
// the accessory already exists
|
|
2083
2092
|
if (!device.hide_device && device.hubDeviceId) {
|
|
@@ -2135,7 +2144,7 @@ export class SwitchBotPlatform {
|
|
|
2135
2144
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
|
|
2136
2145
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
2137
2146
|
// the cached devices we stored in the `configureAccessory` method above
|
|
2138
|
-
const existingAccessory = this.accessories.find(
|
|
2147
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
2139
2148
|
if (existingAccessory) {
|
|
2140
2149
|
// the accessory already exists
|
|
2141
2150
|
if (!device.hide_device && device.hubDeviceId) {
|
|
@@ -2193,7 +2202,7 @@ export class SwitchBotPlatform {
|
|
|
2193
2202
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
|
|
2194
2203
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
2195
2204
|
// the cached devices we stored in the `configureAccessory` method above
|
|
2196
|
-
const existingAccessory = this.accessories.find(
|
|
2205
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
2197
2206
|
if (existingAccessory) {
|
|
2198
2207
|
// the accessory already exists
|
|
2199
2208
|
if (!device.hide_device && device.hubDeviceId) {
|
|
@@ -2251,7 +2260,7 @@ export class SwitchBotPlatform {
|
|
|
2251
2260
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
|
|
2252
2261
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
2253
2262
|
// the cached devices we stored in the `configureAccessory` method above
|
|
2254
|
-
const existingAccessory = this.accessories.find(
|
|
2263
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
2255
2264
|
if (existingAccessory) {
|
|
2256
2265
|
// the accessory already exists
|
|
2257
2266
|
if (!device.hide_device && device.hubDeviceId) {
|
|
@@ -2309,7 +2318,7 @@ export class SwitchBotPlatform {
|
|
|
2309
2318
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
|
|
2310
2319
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
2311
2320
|
// the cached devices we stored in the `configureAccessory` method above
|
|
2312
|
-
const existingAccessory = this.accessories.find(
|
|
2321
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
2313
2322
|
if (existingAccessory) {
|
|
2314
2323
|
// the accessory already exists
|
|
2315
2324
|
if (!device.hide_device && device.hubDeviceId) {
|
|
@@ -2366,15 +2375,11 @@ export class SwitchBotPlatform {
|
|
|
2366
2375
|
async registerCurtains(device) {
|
|
2367
2376
|
let registerWindowCovering;
|
|
2368
2377
|
if (isCurtainDevice(device)) {
|
|
2369
|
-
await this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds}
|
|
2370
|
-
+ ` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group},`
|
|
2371
|
-
+ ` connectionType: ${device.connectionType}`);
|
|
2378
|
+
await this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds},x master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}, connectionType: ${device.connectionType}`);
|
|
2372
2379
|
registerWindowCovering = await this.registerWindowCovering(device);
|
|
2373
2380
|
}
|
|
2374
2381
|
else if (isBlindTiltDevice(device)) {
|
|
2375
|
-
await this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, blindTiltDevicesIds: ${device.blindTiltDevicesIds}
|
|
2376
|
-
+ ` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group},`
|
|
2377
|
-
+ ` connectionType: ${device.connectionType}`);
|
|
2382
|
+
await this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, blindTiltDevicesIds: ${device.blindTiltDevicesIds}, master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}, connectionType: ${device.connectionType}`);
|
|
2378
2383
|
registerWindowCovering = await this.registerWindowCovering(device);
|
|
2379
2384
|
}
|
|
2380
2385
|
else {
|
|
@@ -2388,36 +2393,31 @@ export class SwitchBotPlatform {
|
|
|
2388
2393
|
if (device.master && device.group) {
|
|
2389
2394
|
// OpenAPI: Master Curtains/Blind Tilt in Group
|
|
2390
2395
|
registerCurtain = true;
|
|
2391
|
-
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}
|
|
2392
|
-
+ ` device.group: ${device.group} connectionType; ${device.connectionType}`);
|
|
2396
|
+
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, device.group: ${device.group} connectionType; ${device.connectionType}`);
|
|
2393
2397
|
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2394
2398
|
}
|
|
2395
2399
|
else if (!device.master && device.curtain?.disable_group) {
|
|
2396
|
-
|
|
2400
|
+
// !device.group && device.connectionType === 'BLE'
|
|
2397
2401
|
// OpenAPI: Non-Master Curtains/Blind Tilts that has Disable Grouping Checked
|
|
2398
2402
|
registerCurtain = true;
|
|
2399
|
-
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, disable_group: `
|
|
2400
|
-
+ `${device.curtain?.disable_group}, connectionType; ${device.connectionType}`);
|
|
2403
|
+
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, disable_group: ${device.curtain?.disable_group}, connectionType; ${device.connectionType}`);
|
|
2401
2404
|
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2402
2405
|
}
|
|
2403
2406
|
else if (device.master && !device.group) {
|
|
2404
2407
|
// OpenAPI: Master Curtains/Blind Tilts not in Group
|
|
2405
2408
|
registerCurtain = true;
|
|
2406
|
-
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}
|
|
2407
|
-
+ ` device.group: ${device.group} connectionType; ${device.connectionType}`);
|
|
2409
|
+
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, device.group: ${device.group} connectionType; ${device.connectionType}`);
|
|
2408
2410
|
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2409
2411
|
}
|
|
2410
2412
|
else if (device.connectionType === 'BLE') {
|
|
2411
2413
|
// BLE: Curtains/Blind Tilt
|
|
2412
2414
|
registerCurtain = true;
|
|
2413
|
-
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] connectionType: ${device.connectionType}, `
|
|
2414
|
-
+ ` group: ${device.group}`);
|
|
2415
|
+
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] connectionType: ${device.connectionType}, group: ${device.group}`);
|
|
2415
2416
|
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2416
2417
|
}
|
|
2417
2418
|
else {
|
|
2418
2419
|
registerCurtain = false;
|
|
2419
|
-
await this.debugErrorLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] disable_group: ${device.curtain?.disable_group}
|
|
2420
|
-
+ ` device.master: ${device.master}, device.group: ${device.group}`);
|
|
2420
|
+
await this.debugErrorLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] disable_group: ${device.curtain?.disable_group}, device.master: ${device.master}, device.group: ${device.group}`);
|
|
2421
2421
|
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}, device.connectionType: ${device.connectionType}`);
|
|
2422
2422
|
}
|
|
2423
2423
|
return registerCurtain;
|
|
@@ -2516,8 +2516,7 @@ export class SwitchBotPlatform {
|
|
|
2516
2516
|
}
|
|
2517
2517
|
else {
|
|
2518
2518
|
registerDevice = false;
|
|
2519
|
-
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, hide_device: `
|
|
2520
|
-
+ `${device.hide_device}, will not display in HomeKit`);
|
|
2519
|
+
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, hide_device: ${device.hide_device}, will not display in HomeKit`);
|
|
2521
2520
|
}
|
|
2522
2521
|
return registerDevice;
|
|
2523
2522
|
}
|
|
@@ -2667,32 +2666,28 @@ export class SwitchBotPlatform {
|
|
|
2667
2666
|
* @param name - The name of the characteristic.
|
|
2668
2667
|
* @param value - The value to be validated and cleaned.
|
|
2669
2668
|
* @returns The cleaned string value.
|
|
2670
|
-
|
|
2669
|
+
*/
|
|
2671
2670
|
async validateAndCleanDisplayName(displayName, name, value) {
|
|
2672
2671
|
if (this.config.options?.allowInvalidCharacters) {
|
|
2673
2672
|
return value;
|
|
2674
2673
|
}
|
|
2675
2674
|
else {
|
|
2676
|
-
const validPattern =
|
|
2675
|
+
const validPattern = /^[\p{L}\p{N}][\p{L}\p{N} ']*[\p{L}\p{N}]$/u;
|
|
2677
2676
|
const invalidCharsPattern = /[^\p{L}\p{N} ']/gu;
|
|
2678
2677
|
const invalidStartEndPattern = /^[^\p{L}\p{N}]+|[^\p{L}\p{N}]+$/gu;
|
|
2679
2678
|
if (typeof value === 'string' && !validPattern.test(value)) {
|
|
2680
|
-
await this.warnLog(`WARNING: The accessory '${displayName}' has an invalid '${name}' characteristic ('${value}').`
|
|
2681
|
-
+ ' Please use only alphanumeric, space, and apostrophe characters. Ensure it starts and ends with an alphabetic or numeric character,'
|
|
2682
|
-
+ ' and avoid emojis. This may prevent the accessory from being added in the Home App or cause unresponsiveness.');
|
|
2679
|
+
await this.warnLog(`WARNING: The accessory '${displayName}' has an invalid '${name}' characteristic ('${value}'). Please use only alphanumeric, space, and apostrophe characters. Ensure it starts and ends with an alphabetic or numeric character, and avoid emojis. This may prevent the accessory from being added in the Home App or cause unresponsiveness.`);
|
|
2683
2680
|
// Remove invalid characters
|
|
2684
2681
|
if (invalidCharsPattern.test(value)) {
|
|
2685
2682
|
const before = value;
|
|
2686
|
-
await this.warnLog(`Removing invalid characters from '${name}' characteristic, if you feel this is incorrect
|
|
2687
|
-
+ ' please enable \'allowInvalidCharacter\' in the config to allow all characters');
|
|
2683
|
+
await this.warnLog(`Removing invalid characters from '${name}' characteristic, if you feel this is incorrect, please enable \'allowInvalidCharacter\' in the config to allow all characters`);
|
|
2688
2684
|
value = value.replace(invalidCharsPattern, '');
|
|
2689
2685
|
await this.warnLog(`${name} Before: '${before}' After: '${value}'`);
|
|
2690
2686
|
}
|
|
2691
2687
|
// Ensure it starts and ends with an alphanumeric character
|
|
2692
2688
|
if (invalidStartEndPattern.test(value)) {
|
|
2693
2689
|
const before = value;
|
|
2694
|
-
await this.warnLog(`Removing invalid starting or ending characters from '${name}' characteristic, if you feel this is incorrect
|
|
2695
|
-
+ ' please enable \'allowInvalidCharacter\' in the config to allow all characters');
|
|
2690
|
+
await this.warnLog(`Removing invalid starting or ending characters from '${name}' characteristic, if you feel this is incorrect, please enable \'allowInvalidCharacter\' in the config to allow all characters`);
|
|
2696
2691
|
value = value.replace(invalidStartEndPattern, '');
|
|
2697
2692
|
await this.warnLog(`${name} Before: '${before}' After: '${value}'`);
|
|
2698
2693
|
}
|