@switchbot/homebridge-switchbot 3.7.1-beta.9 → 3.8.0
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 +8 -2
- package/README.md +14 -0
- package/assets/security-privacy-bluetooth.png +0 -0
- package/config.schema.json +76 -1
- package/dist/device/blindtilt.d.ts +18 -8
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +108 -70
- 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 +133 -160
- 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 +15 -5
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +127 -81
- 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 +47 -44
- 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 +61 -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 +20 -19
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +466 -710
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +5 -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 +61 -54
- package/src/device/blindtilt.ts +509 -460
- package/src/device/bot.ts +696 -718
- 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 +506 -444
- 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 +185 -185
- package/src/homebridge-ui/server.ts +16 -15
- package/src/index.ts +5 -6
- package/src/irdevice/airconditioner.ts +277 -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 +1462 -1678
- package/src/settings.ts +173 -170
- package/src/types/bledevicestatus.ts +252 -256
- 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 -131
- 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/.github/npm-version-script.cjs +0 -81
package/src/platform.ts
CHANGED
|
@@ -2,60 +2,63 @@
|
|
|
2
2
|
*
|
|
3
3
|
* platform.ts: @switchbot/homebridge-switchbot platform class.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import
|
|
21
|
-
|
|
22
|
-
import
|
|
23
|
-
import
|
|
24
|
-
import {
|
|
25
|
-
import { Light } from './irdevice/light.js';
|
|
26
|
-
import { Others } from './irdevice/other.js';
|
|
27
|
-
import { Camera } from './irdevice/camera.js';
|
|
28
|
-
import { BlindTilt } from './device/blindtilt.js';
|
|
29
|
-
import { AirPurifier } from './irdevice/airpurifier.js';
|
|
30
|
-
import { WaterHeater } from './irdevice/waterheater.js';
|
|
31
|
-
import { VacuumCleaner } from './irdevice/vacuumcleaner.js';
|
|
32
|
-
import { AirConditioner } from './irdevice/airconditioner.js';
|
|
33
|
-
|
|
34
|
-
import { Buffer } from 'buffer';
|
|
35
|
-
import { request } from 'undici';
|
|
36
|
-
import asyncmqtt from 'async-mqtt';
|
|
37
|
-
import { createServer } from 'http';
|
|
38
|
-
import { queueScheduler } from 'rxjs';
|
|
39
|
-
import fakegato from 'fakegato-history';
|
|
40
|
-
import crypto, { randomUUID } from 'crypto';
|
|
41
|
-
import { readFileSync, writeFileSync } from 'fs';
|
|
42
|
-
import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes';
|
|
43
|
-
import { PLATFORM_NAME, PLUGIN_NAME, Devices, deleteWebhook, queryWebhook, setupWebhook, updateWebhook } from './settings.js';
|
|
44
|
-
import { isBlindTiltDevice, isCurtainDevice, sleep } from './utils.js';
|
|
45
|
-
|
|
46
|
-
import type { UrlObject } from 'url';
|
|
47
|
-
import type { MqttClient } from 'mqtt';
|
|
48
|
-
import type { Dispatcher } from 'undici';
|
|
49
|
-
import type { irdevice } from './types/irdevicelist.js';
|
|
50
|
-
import type { blindTilt, curtain, curtain3, device } from './types/devicelist.js';
|
|
51
|
-
import type { API, DynamicPlatformPlugin, Logging, PlatformAccessory } from 'homebridge';
|
|
52
|
-
import type { SwitchBotPlatformConfig, devicesConfig, irDevicesConfig } from './settings.js';
|
|
53
|
-
import type { IncomingMessage, Server, ServerResponse } from 'http';
|
|
5
|
+
import type { IncomingMessage, Server, ServerResponse } from 'node:http'
|
|
6
|
+
import type { UrlObject } from 'node:url'
|
|
7
|
+
|
|
8
|
+
import type { API, DynamicPlatformPlugin, Logging, PlatformAccessory } from 'homebridge'
|
|
9
|
+
import type { MqttClient } from 'mqtt'
|
|
10
|
+
import type { Dispatcher } from 'undici'
|
|
11
|
+
|
|
12
|
+
import type { devicesConfig, irDevicesConfig, options, SwitchBotPlatformConfig } from './settings.js'
|
|
13
|
+
import type { blindTilt, curtain, curtain3, device } from './types/devicelist.js'
|
|
14
|
+
import type { irdevice } from './types/irdevicelist.js'
|
|
15
|
+
|
|
16
|
+
import { Buffer } from 'node:buffer'
|
|
17
|
+
import crypto, { randomUUID } from 'node:crypto'
|
|
18
|
+
import { readFileSync, writeFileSync } from 'node:fs'
|
|
19
|
+
import { createServer } from 'node:http'
|
|
20
|
+
import process from 'node:process'
|
|
21
|
+
|
|
22
|
+
import asyncmqtt from 'async-mqtt'
|
|
23
|
+
import fakegato from 'fakegato-history'
|
|
24
|
+
import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes'
|
|
54
25
|
/*
|
|
55
26
|
* For Testing Locally:
|
|
56
27
|
* import { SwitchBotModel } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
57
28
|
*/
|
|
58
|
-
import { SwitchBotModel } from 'node-switchbot'
|
|
29
|
+
import { SwitchBot, SwitchBotModel } from 'node-switchbot'
|
|
30
|
+
import { queueScheduler } from 'rxjs'
|
|
31
|
+
import { request } from 'undici'
|
|
32
|
+
|
|
33
|
+
import { BlindTilt } from './device/blindtilt.js'
|
|
34
|
+
import { Bot } from './device/bot.js'
|
|
35
|
+
import { CeilingLight } from './device/ceilinglight.js'
|
|
36
|
+
import { ColorBulb } from './device/colorbulb.js'
|
|
37
|
+
import { Contact } from './device/contact.js'
|
|
38
|
+
import { Curtain } from './device/curtain.js'
|
|
39
|
+
import { Fan } from './device/fan.js'
|
|
40
|
+
import { Hub } from './device/hub.js'
|
|
41
|
+
import { Humidifier } from './device/humidifier.js'
|
|
42
|
+
import { IOSensor } from './device/iosensor.js'
|
|
43
|
+
import { StripLight } from './device/lightstrip.js'
|
|
44
|
+
import { Lock } from './device/lock.js'
|
|
45
|
+
import { Meter } from './device/meter.js'
|
|
46
|
+
import { MeterPlus } from './device/meterplus.js'
|
|
47
|
+
import { Motion } from './device/motion.js'
|
|
48
|
+
import { Plug } from './device/plug.js'
|
|
49
|
+
import { RobotVacuumCleaner } from './device/robotvacuumcleaner.js'
|
|
50
|
+
import { WaterDetector } from './device/waterdetector.js'
|
|
51
|
+
import { AirConditioner } from './irdevice/airconditioner.js'
|
|
52
|
+
import { AirPurifier } from './irdevice/airpurifier.js'
|
|
53
|
+
import { Camera } from './irdevice/camera.js'
|
|
54
|
+
import { IRFan } from './irdevice/fan.js'
|
|
55
|
+
import { Light } from './irdevice/light.js'
|
|
56
|
+
import { Others } from './irdevice/other.js'
|
|
57
|
+
import { TV } from './irdevice/tv.js'
|
|
58
|
+
import { VacuumCleaner } from './irdevice/vacuumcleaner.js'
|
|
59
|
+
import { WaterHeater } from './irdevice/waterheater.js'
|
|
60
|
+
import { deleteWebhook, Devices, PLATFORM_NAME, PLUGIN_NAME, queryWebhook, setupWebhook, updateWebhook } from './settings.js'
|
|
61
|
+
import { isBlindTiltDevice, isCurtainDevice, sleep } from './utils.js'
|
|
59
62
|
|
|
60
63
|
/**
|
|
61
64
|
* HomebridgePlatform
|
|
@@ -63,40 +66,44 @@ import { SwitchBotModel } from 'node-switchbot';
|
|
|
63
66
|
* parse the user config and discover/register accessories with Homebridge.
|
|
64
67
|
*/
|
|
65
68
|
export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
66
|
-
|
|
67
|
-
public
|
|
68
|
-
public readonly
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
69
|
+
// Platform properties
|
|
70
|
+
public accessories: PlatformAccessory[] = []
|
|
71
|
+
public readonly api: API
|
|
72
|
+
public readonly log: Logging
|
|
73
|
+
|
|
74
|
+
// Configuration properties
|
|
75
|
+
version!: string
|
|
76
|
+
Logging?: string
|
|
77
|
+
debugMode!: boolean
|
|
78
|
+
maxRetries!: number
|
|
79
|
+
delayBetweenRetries!: number
|
|
80
|
+
platformConfig!: SwitchBotPlatformConfig['options']
|
|
81
|
+
platformLogging!: SwitchBotPlatformConfig['logging']
|
|
82
|
+
config!: SwitchBotPlatformConfig
|
|
83
|
+
|
|
84
|
+
// MQTT and Webhook properties
|
|
85
|
+
mqttClient: MqttClient | null = null
|
|
86
|
+
webhookEventListener: Server | null = null
|
|
87
|
+
|
|
88
|
+
// External APIs
|
|
89
|
+
public readonly eve: any
|
|
90
|
+
public readonly fakegatoAPI: any
|
|
91
|
+
|
|
92
|
+
// Event Handlers
|
|
93
|
+
public readonly webhookEventHandler: { [x: string]: (context: any) => void } = {}
|
|
94
|
+
public readonly bleEventHandler: { [x: string]: (context: any) => void } = {}
|
|
86
95
|
|
|
87
96
|
constructor(
|
|
88
97
|
log: Logging,
|
|
89
98
|
config: SwitchBotPlatformConfig,
|
|
90
99
|
api: API,
|
|
91
100
|
) {
|
|
92
|
-
|
|
93
|
-
this.
|
|
94
|
-
this.api = api;
|
|
95
|
-
this.log = log;
|
|
101
|
+
this.api = api
|
|
102
|
+
this.log = log
|
|
96
103
|
|
|
97
104
|
// only load if configured
|
|
98
105
|
if (!config) {
|
|
99
|
-
return
|
|
106
|
+
return
|
|
100
107
|
}
|
|
101
108
|
|
|
102
109
|
// Plugin options into our config variables.
|
|
@@ -105,142 +112,138 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
105
112
|
name: config.name,
|
|
106
113
|
credentials: config.credentials as object,
|
|
107
114
|
options: config.options as object,
|
|
108
|
-
}
|
|
115
|
+
}
|
|
109
116
|
|
|
110
117
|
// Plugin Configuration
|
|
111
|
-
this.getPlatformLogSettings()
|
|
112
|
-
this.getPlatformConfigSettings()
|
|
113
|
-
this.getVersion()
|
|
118
|
+
this.getPlatformLogSettings()
|
|
119
|
+
this.getPlatformConfigSettings()
|
|
120
|
+
this.getVersion()
|
|
114
121
|
|
|
115
122
|
// Finish initializing the platform
|
|
116
|
-
this.debugLog(`Finished initializing platform: ${config.name}`)
|
|
123
|
+
this.debugLog(`Finished initializing platform: ${config.name}`)
|
|
117
124
|
|
|
118
125
|
// verify the config
|
|
119
126
|
try {
|
|
120
|
-
this.verifyConfig()
|
|
121
|
-
this.debugLog('Config OK')
|
|
127
|
+
this.verifyConfig()
|
|
128
|
+
this.debugLog('Config OK')
|
|
122
129
|
} catch (e: any) {
|
|
123
|
-
this.errorLog(`Verify Config, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug')
|
|
124
|
-
this.debugErrorLog(`Verify Config, Error: ${e}`)
|
|
125
|
-
return
|
|
130
|
+
this.errorLog(`Verify Config, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug')
|
|
131
|
+
this.debugErrorLog(`Verify Config, Error: ${e}`)
|
|
132
|
+
return
|
|
126
133
|
}
|
|
127
134
|
|
|
128
135
|
// import fakegato-history module and EVE characteristics
|
|
129
|
-
this.fakegatoAPI = fakegato(api)
|
|
130
|
-
this.eve = new EveHomeKitTypes(api)
|
|
136
|
+
this.fakegatoAPI = fakegato(api)
|
|
137
|
+
this.eve = new EveHomeKitTypes(api)
|
|
131
138
|
|
|
132
139
|
// When this event is fired it means Homebridge has restored all cached accessories from disk.
|
|
133
140
|
// Dynamic Platform plugins should only register new accessories after this event was fired,
|
|
134
141
|
// in order to ensure they weren't added to homebridge already. This event can also be used
|
|
135
142
|
// to start discovery of new accessories.
|
|
136
143
|
this.api.on('didFinishLaunching', async () => {
|
|
137
|
-
this.debugLog('Executed didFinishLaunching callback')
|
|
144
|
+
await this.debugLog('Executed didFinishLaunching callback')
|
|
138
145
|
// run the method to discover / register your devices as accessories
|
|
139
146
|
try {
|
|
140
147
|
if (this.config.credentials?.openToken && !this.config.credentials.token) {
|
|
141
|
-
await this.updateToken()
|
|
148
|
+
await this.updateToken()
|
|
142
149
|
} else if (this.config.credentials?.token && !this.config.credentials?.secret) {
|
|
143
|
-
|
|
144
|
-
this.errorLog('"secret" config is not populated, you must populate then please restart Homebridge.');
|
|
150
|
+
await this.errorLog('"secret" config is not populated, you must populate then please restart Homebridge.')
|
|
145
151
|
} else {
|
|
146
|
-
this.discoverDevices()
|
|
152
|
+
await this.discoverDevices()
|
|
147
153
|
}
|
|
148
154
|
} catch (e: any) {
|
|
149
|
-
this.errorLog(`Failed to Discover, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug')
|
|
150
|
-
await this.debugErrorLog(`Failed to Discover, Error: ${e}`)
|
|
155
|
+
await this.errorLog(`Failed to Discover, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug')
|
|
156
|
+
await this.debugErrorLog(`Failed to Discover, Error: ${e}`)
|
|
151
157
|
}
|
|
152
|
-
})
|
|
158
|
+
})
|
|
153
159
|
|
|
154
160
|
try {
|
|
155
|
-
this.setupMqtt()
|
|
161
|
+
this.setupMqtt()
|
|
156
162
|
} catch (e: any) {
|
|
157
|
-
this.errorLog(`Setup MQTT, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug')
|
|
163
|
+
this.errorLog(`Setup MQTT, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug')
|
|
158
164
|
}
|
|
159
165
|
try {
|
|
160
|
-
this.setupwebhook()
|
|
166
|
+
this.setupwebhook()
|
|
161
167
|
} catch (e: any) {
|
|
162
|
-
this.errorLog(`Setup Webhook, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug')
|
|
168
|
+
this.errorLog(`Setup Webhook, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug')
|
|
163
169
|
}
|
|
164
170
|
try {
|
|
165
|
-
this.setupBlE()
|
|
171
|
+
this.setupBlE()
|
|
166
172
|
} catch (e: any) {
|
|
167
|
-
this.errorLog(`Setup Platform BLE, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug')
|
|
173
|
+
this.errorLog(`Setup Platform BLE, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug')
|
|
168
174
|
}
|
|
169
175
|
}
|
|
170
176
|
|
|
171
177
|
async setupMqtt(): Promise<void> {
|
|
172
178
|
if (this.config.options?.mqttURL) {
|
|
173
179
|
try {
|
|
174
|
-
const { connectAsync } = asyncmqtt
|
|
175
|
-
this.mqttClient = await connectAsync(this.config.options?.mqttURL, this.config.options.mqttOptions || {})
|
|
176
|
-
await this.debugLog('MQTT connection has been established successfully.')
|
|
180
|
+
const { connectAsync } = asyncmqtt
|
|
181
|
+
this.mqttClient = await connectAsync(this.config.options?.mqttURL, this.config.options.mqttOptions || {})
|
|
182
|
+
await this.debugLog('MQTT connection has been established successfully.')
|
|
177
183
|
this.mqttClient.on('error', async (e: Error) => {
|
|
178
|
-
await this.errorLog(`Failed to publish MQTT messages. ${e}`)
|
|
179
|
-
})
|
|
184
|
+
await this.errorLog(`Failed to publish MQTT messages. ${e}`)
|
|
185
|
+
})
|
|
180
186
|
if (!this.config.options?.webhookURL) {
|
|
181
187
|
// receive webhook events via MQTT
|
|
182
|
-
await this.infoLog(`Webhook is configured to be received through ${this.config.options.mqttURL}/homebridge-switchbot/webhook.`)
|
|
183
|
-
this.mqttClient.subscribe('homebridge-switchbot/webhook/+')
|
|
188
|
+
await this.infoLog(`Webhook is configured to be received through ${this.config.options.mqttURL}/homebridge-switchbot/webhook.`)
|
|
189
|
+
this.mqttClient.subscribe('homebridge-switchbot/webhook/+')
|
|
184
190
|
this.mqttClient.on('message', async (topic: string, message) => {
|
|
185
191
|
try {
|
|
186
|
-
await
|
|
187
|
-
const context = JSON.parse(message.toString())
|
|
188
|
-
this.webhookEventHandler[context.deviceMac]?.(context)
|
|
192
|
+
await this.debugLog(`Received Webhook via MQTT: ${topic}=${message}`)
|
|
193
|
+
const context = JSON.parse(message.toString())
|
|
194
|
+
this.webhookEventHandler[context.deviceMac]?.(context)
|
|
189
195
|
} catch (e: any) {
|
|
190
|
-
await this.errorLog(`Failed to handle webhook event. Error:${e}`)
|
|
196
|
+
await this.errorLog(`Failed to handle webhook event. Error:${e}`)
|
|
191
197
|
}
|
|
192
|
-
})
|
|
198
|
+
})
|
|
193
199
|
}
|
|
194
200
|
} catch (e) {
|
|
195
|
-
this.mqttClient = null
|
|
196
|
-
await this.errorLog(`Failed to establish MQTT connection. ${e}`)
|
|
201
|
+
this.mqttClient = null
|
|
202
|
+
await this.errorLog(`Failed to establish MQTT connection. ${e}`)
|
|
197
203
|
}
|
|
198
204
|
}
|
|
199
205
|
}
|
|
200
206
|
|
|
201
207
|
async setupwebhook() {
|
|
202
|
-
//webhook configuration
|
|
208
|
+
// webhook configuration
|
|
203
209
|
if (this.config.options?.webhookURL) {
|
|
204
|
-
const url = this.config.options?.webhookURL
|
|
210
|
+
const url = this.config.options?.webhookURL
|
|
205
211
|
|
|
206
212
|
try {
|
|
207
|
-
const xurl = new URL(url)
|
|
208
|
-
const port = Number(xurl.port)
|
|
209
|
-
const path = xurl.pathname
|
|
213
|
+
const xurl = new URL(url)
|
|
214
|
+
const port = Number(xurl.port)
|
|
215
|
+
const path = xurl.pathname
|
|
210
216
|
this.webhookEventListener = createServer((request: IncomingMessage, response: ServerResponse) => {
|
|
211
217
|
try {
|
|
212
218
|
if (request.url === path && request.method === 'POST') {
|
|
213
219
|
request.on('data', async (data) => {
|
|
214
220
|
try {
|
|
215
|
-
const body = JSON.parse(data)
|
|
216
|
-
await this.debugLog(`Received Webhook: ${JSON.stringify(body)}`)
|
|
221
|
+
const body = JSON.parse(data)
|
|
222
|
+
await this.debugLog(`Received Webhook: ${JSON.stringify(body)}`)
|
|
217
223
|
if (this.config.options?.mqttURL) {
|
|
218
|
-
const mac = body.context.deviceMac
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
?.join(':');
|
|
222
|
-
const options = this.config.options?.mqttPubOptions || {};
|
|
223
|
-
this.mqttClient?.publish(`homebridge-switchbot/webhook/${mac}`, `${JSON.stringify(body.context)}`, options);
|
|
224
|
+
const mac = body.context.deviceMac?.toLowerCase().match(/[\s\S]{1,2}/g)?.join(':')
|
|
225
|
+
const options = this.config.options?.mqttPubOptions || {}
|
|
226
|
+
this.mqttClient?.publish(`homebridge-switchbot/webhook/${mac}`, `${JSON.stringify(body.context)}`, options)
|
|
224
227
|
}
|
|
225
|
-
this.webhookEventHandler[body.context.deviceMac]?.(body.context)
|
|
228
|
+
this.webhookEventHandler[body.context.deviceMac]?.(body.context)
|
|
226
229
|
} catch (e: any) {
|
|
227
|
-
this.errorLog(`Failed to handle webhook event. Error:${e}`)
|
|
230
|
+
await this.errorLog(`Failed to handle webhook event. Error:${e}`)
|
|
228
231
|
}
|
|
229
|
-
})
|
|
230
|
-
response.writeHead(200, { 'Content-Type': 'text/plain' })
|
|
231
|
-
response.end('OK')
|
|
232
|
+
})
|
|
233
|
+
response.writeHead(200, { 'Content-Type': 'text/plain' })
|
|
234
|
+
response.end('OK')
|
|
232
235
|
}
|
|
233
236
|
// else {
|
|
234
237
|
// response.writeHead(403, {'Content-Type': 'text/plain'});
|
|
235
238
|
// response.end(`NG`);
|
|
236
239
|
// }
|
|
237
240
|
} catch (e: any) {
|
|
238
|
-
this.errorLog(`Failed to handle webhook event. Error:${e}`)
|
|
241
|
+
this.errorLog(`Failed to handle webhook event. Error:${e}`)
|
|
239
242
|
}
|
|
240
|
-
}).listen(port
|
|
243
|
+
}).listen(port || 80)
|
|
241
244
|
} catch (e: any) {
|
|
242
|
-
this.errorLog(`Failed to create webhook listener. Error:${e.message}`)
|
|
243
|
-
return
|
|
245
|
+
await this.errorLog(`Failed to create webhook listener. Error:${e.message}`)
|
|
246
|
+
return
|
|
244
247
|
}
|
|
245
248
|
|
|
246
249
|
try {
|
|
@@ -248,42 +251,39 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
248
251
|
method: 'POST',
|
|
249
252
|
headers: this.generateHeaders(),
|
|
250
253
|
body: JSON.stringify({
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
+
action: 'setupWebhook',
|
|
255
|
+
url,
|
|
256
|
+
deviceList: 'ALL',
|
|
254
257
|
}),
|
|
255
|
-
})
|
|
256
|
-
const response: any = await body.json()
|
|
257
|
-
await this.debugLog(`setupWebhook: url:${url}`)
|
|
258
|
-
await this.debugLog(`setupWebhook: body:${JSON.stringify(response)}`);
|
|
259
|
-
await this.debugLog(`setupWebhook: statusCode:${statusCode}`);
|
|
258
|
+
})
|
|
259
|
+
const response: any = await body.json()
|
|
260
|
+
await this.debugLog(`setupWebhook: url:${url}, body:${JSON.stringify(response)}, statusCode:${statusCode}`)
|
|
260
261
|
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
261
|
-
this.errorLog(`Failed to configure webhook. Existing webhook well be overridden. HTTP:${statusCode} API:${response?.statusCode} `
|
|
262
|
-
+ `message:${response?.message}`);
|
|
262
|
+
await this.errorLog(`Failed to configure webhook. Existing webhook well be overridden. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`)
|
|
263
263
|
}
|
|
264
264
|
} catch (e: any) {
|
|
265
|
-
this.errorLog(`Failed to configure webhook. Error: ${e.message}`)
|
|
265
|
+
await this.errorLog(`Failed to configure webhook. Error: ${e.message}`)
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
try {
|
|
269
269
|
const { body, statusCode } = await request(updateWebhook, {
|
|
270
|
-
method: 'POST',
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
270
|
+
method: 'POST',
|
|
271
|
+
headers: this.generateHeaders(),
|
|
272
|
+
body: JSON.stringify({
|
|
273
|
+
action: 'updateWebhook',
|
|
274
|
+
config: {
|
|
275
|
+
url,
|
|
276
|
+
enable: true,
|
|
275
277
|
},
|
|
276
278
|
}),
|
|
277
|
-
})
|
|
278
|
-
const response: any = await body.json()
|
|
279
|
-
await this.debugLog(`updateWebhook: url:${url}`)
|
|
280
|
-
await this.debugLog(`updateWebhook: body:${JSON.stringify(response)}`);
|
|
281
|
-
await this.debugLog(`updateWebhook: statusCode:${statusCode}`);
|
|
279
|
+
})
|
|
280
|
+
const response: any = await body.json()
|
|
281
|
+
await this.debugLog(`updateWebhook: url:${url}, body:${JSON.stringify(response)}, statusCode:${statusCode}`)
|
|
282
282
|
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
283
|
-
this.errorLog(`Failed to update webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`)
|
|
283
|
+
await this.errorLog(`Failed to update webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`)
|
|
284
284
|
}
|
|
285
285
|
} catch (e: any) {
|
|
286
|
-
this.errorLog(`Failed to update webhook. Error:${e.message}`)
|
|
286
|
+
await this.errorLog(`Failed to update webhook. Error:${e.message}`)
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
try {
|
|
@@ -291,19 +291,19 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
291
291
|
method: 'POST',
|
|
292
292
|
headers: this.generateHeaders(),
|
|
293
293
|
body: JSON.stringify({
|
|
294
|
-
|
|
294
|
+
action: 'queryUrl',
|
|
295
295
|
}),
|
|
296
|
-
})
|
|
297
|
-
const response: any = await body.json()
|
|
298
|
-
await this.debugLog(`queryWebhook: body:${JSON.stringify(response)}`)
|
|
299
|
-
await this.debugLog(`queryWebhook: statusCode:${statusCode}`)
|
|
296
|
+
})
|
|
297
|
+
const response: any = await body.json()
|
|
298
|
+
await this.debugLog(`queryWebhook: body:${JSON.stringify(response)}`)
|
|
299
|
+
await this.debugLog(`queryWebhook: statusCode:${statusCode}`)
|
|
300
300
|
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
301
|
-
this.errorLog(`Failed to query webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`)
|
|
301
|
+
await this.errorLog(`Failed to query webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`)
|
|
302
302
|
} else {
|
|
303
|
-
this.infoLog(`Listening webhook on ${response?.body?.urls[0]}`)
|
|
303
|
+
await this.infoLog(`Listening webhook on ${response?.body?.urls[0]}`)
|
|
304
304
|
}
|
|
305
305
|
} catch (e: any) {
|
|
306
|
-
this.errorLog(`Failed to query webhook. Error:${e}`)
|
|
306
|
+
await this.errorLog(`Failed to query webhook. Error:${e}`)
|
|
307
307
|
}
|
|
308
308
|
|
|
309
309
|
this.api.on('shutdown', async () => {
|
|
@@ -312,58 +312,57 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
312
312
|
method: 'POST',
|
|
313
313
|
headers: this.generateHeaders(),
|
|
314
314
|
body: JSON.stringify({
|
|
315
|
-
|
|
316
|
-
|
|
315
|
+
action: 'deleteWebhook',
|
|
316
|
+
url,
|
|
317
317
|
}),
|
|
318
|
-
})
|
|
319
|
-
const response: any = await body.json()
|
|
320
|
-
await this.debugLog(`deleteWebhook: url:${url}, body:${JSON.stringify(response)}, statusCode:${statusCode}`)
|
|
318
|
+
})
|
|
319
|
+
const response: any = await body.json()
|
|
320
|
+
await this.debugLog(`deleteWebhook: url:${url}, body:${JSON.stringify(response)}, statusCode:${statusCode}`)
|
|
321
321
|
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
322
|
-
this.errorLog(`Failed to delete webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`)
|
|
322
|
+
await this.errorLog(`Failed to delete webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`)
|
|
323
323
|
} else {
|
|
324
|
-
this.infoLog('Unregistered webhook to close listening.')
|
|
324
|
+
await this.infoLog('Unregistered webhook to close listening.')
|
|
325
325
|
}
|
|
326
326
|
} catch (e: any) {
|
|
327
|
-
this.errorLog(`Failed to delete webhook. Error:${e.message}`)
|
|
327
|
+
await this.errorLog(`Failed to delete webhook. Error:${e.message}`)
|
|
328
328
|
}
|
|
329
|
-
})
|
|
329
|
+
})
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
332
|
|
|
333
333
|
async setupBlE() {
|
|
334
334
|
if (this.config.options?.BLE) {
|
|
335
|
-
await this.debugLog('setupBLE')
|
|
336
|
-
const
|
|
337
|
-
const switchbot = new SwitchBot();
|
|
335
|
+
await this.debugLog('setupBLE')
|
|
336
|
+
const switchbot = new SwitchBot()
|
|
338
337
|
if (switchbot === undefined) {
|
|
339
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
338
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
340
339
|
} else {
|
|
341
340
|
// Start to monitor advertisement packets
|
|
342
341
|
(async () => {
|
|
343
342
|
// Start to monitor advertisement packets
|
|
344
|
-
await this.debugLog('Scanning for BLE SwitchBot devices...')
|
|
345
|
-
await switchbot.startScan()
|
|
343
|
+
await this.debugLog('Scanning for BLE SwitchBot devices...')
|
|
344
|
+
await switchbot.startScan()
|
|
346
345
|
// Set an event handler to monitor advertisement packets
|
|
347
346
|
switchbot.onadvertisement = async (ad: any) => {
|
|
348
347
|
try {
|
|
349
|
-
this.bleEventHandler[ad.address]?.(ad.serviceData)
|
|
348
|
+
this.bleEventHandler[ad.address]?.(ad.serviceData)
|
|
350
349
|
} catch (e: any) {
|
|
351
|
-
await this.errorLog(`Failed to handle BLE event. Error:${e}`)
|
|
350
|
+
await this.errorLog(`Failed to handle BLE event. Error:${e}`)
|
|
352
351
|
}
|
|
353
|
-
}
|
|
354
|
-
})()
|
|
352
|
+
}
|
|
353
|
+
})()
|
|
355
354
|
|
|
356
355
|
this.api.on('shutdown', async () => {
|
|
357
356
|
try {
|
|
358
|
-
switchbot.stopScan()
|
|
359
|
-
this.infoLog('Stopped BLE scanning to close listening.')
|
|
357
|
+
switchbot.stopScan()
|
|
358
|
+
await this.infoLog('Stopped BLE scanning to close listening.')
|
|
360
359
|
} catch (e: any) {
|
|
361
|
-
this.errorLog(`Failed to stop Platform BLE scanning. Error:${e.message}`)
|
|
360
|
+
await this.errorLog(`Failed to stop Platform BLE scanning. Error:${e.message}`)
|
|
362
361
|
}
|
|
363
|
-
})
|
|
362
|
+
})
|
|
364
363
|
}
|
|
365
364
|
} else {
|
|
366
|
-
await this.debugLog('Platform BLE is not enabled')
|
|
365
|
+
await this.debugLog('Platform BLE is not enabled')
|
|
367
366
|
}
|
|
368
367
|
}
|
|
369
368
|
|
|
@@ -372,32 +371,33 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
372
371
|
* It should be used to setup event handlers for characteristics and update respective values.
|
|
373
372
|
*/
|
|
374
373
|
async configureAccessory(accessory: PlatformAccessory) {
|
|
375
|
-
|
|
374
|
+
const { displayName } = accessory
|
|
375
|
+
await this.debugLog(`Loading accessory from cache: ${displayName}`)
|
|
376
376
|
|
|
377
377
|
// add the restored accessory to the accessories cache so we can track if it has already been registered
|
|
378
|
-
this.accessories.push(accessory)
|
|
378
|
+
this.accessories.push(accessory)
|
|
379
379
|
}
|
|
380
380
|
|
|
381
381
|
/**
|
|
382
382
|
* Verify the config passed to the plugin is valid
|
|
383
383
|
*/
|
|
384
384
|
async verifyConfig() {
|
|
385
|
-
this.debugLog('Verifying Config')
|
|
386
|
-
this.config = this.config || {}
|
|
387
|
-
this.config.options = this.config.options || {}
|
|
385
|
+
await this.debugLog('Verifying Config')
|
|
386
|
+
this.config = this.config || {}
|
|
387
|
+
this.config.options = this.config.options || {}
|
|
388
388
|
|
|
389
|
-
const platformConfig = {}
|
|
389
|
+
const platformConfig: options = {}
|
|
390
390
|
if (this.config.options.logging) {
|
|
391
|
-
platformConfig
|
|
391
|
+
platformConfig.logging = this.config.options.logging
|
|
392
392
|
}
|
|
393
393
|
if (this.config.options.logging && this.config.options.refreshRate) {
|
|
394
|
-
platformConfig
|
|
394
|
+
platformConfig.refreshRate = this.config.options.refreshRate
|
|
395
395
|
}
|
|
396
396
|
if (this.config.options.logging && this.config.options.pushRate) {
|
|
397
|
-
platformConfig
|
|
397
|
+
platformConfig.pushRate = this.config.options.pushRate
|
|
398
398
|
}
|
|
399
399
|
if (Object.entries(platformConfig).length !== 0) {
|
|
400
|
-
await this.debugWarnLog(`Platform Config: ${JSON.stringify(platformConfig)}`)
|
|
400
|
+
await this.debugWarnLog(`Platform Config: ${JSON.stringify(platformConfig)}`)
|
|
401
401
|
}
|
|
402
402
|
|
|
403
403
|
if (this.config.options) {
|
|
@@ -406,10 +406,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
406
406
|
for (const deviceConfig of this.config.options.devices) {
|
|
407
407
|
if (!deviceConfig.hide_device) {
|
|
408
408
|
if (!deviceConfig.deviceId) {
|
|
409
|
-
throw new Error('The devices config section is missing the *Device ID* in the config. Please check your config.')
|
|
409
|
+
throw new Error('The devices config section is missing the *Device ID* in the config. Please check your config.')
|
|
410
410
|
}
|
|
411
411
|
if (!deviceConfig.configDeviceType && deviceConfig.connectionType) {
|
|
412
|
-
throw new Error('The devices config section is missing the *Device Type* in the config. Please check your config.')
|
|
412
|
+
throw new Error('The devices config section is missing the *Device Type* in the config. Please check your config.')
|
|
413
413
|
}
|
|
414
414
|
}
|
|
415
415
|
}
|
|
@@ -420,10 +420,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
420
420
|
for (const irDeviceConfig of this.config.options.irdevices) {
|
|
421
421
|
if (!irDeviceConfig.hide_device) {
|
|
422
422
|
if (!irDeviceConfig.deviceId) {
|
|
423
|
-
this.errorLog('The devices config section is missing the *Device ID* in the config. Please check your config.')
|
|
423
|
+
await this.errorLog('The devices config section is missing the *Device ID* in the config. Please check your config.')
|
|
424
424
|
}
|
|
425
425
|
if (!irDeviceConfig.deviceId && !irDeviceConfig.configRemoteType) {
|
|
426
|
-
this.errorLog('The devices config section is missing the *Device Type* in the config. Please check your config.')
|
|
426
|
+
await this.errorLog('The devices config section is missing the *Device Type* in the config. Please check your config.')
|
|
427
427
|
}
|
|
428
428
|
}
|
|
429
429
|
}
|
|
@@ -431,47 +431,47 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
431
431
|
}
|
|
432
432
|
|
|
433
433
|
if (this.config.options!.refreshRate! < 5) {
|
|
434
|
-
throw new Error('Refresh Rate must be above 5 (5 seconds).')
|
|
434
|
+
throw new Error('Refresh Rate must be above 5 (5 seconds).')
|
|
435
435
|
}
|
|
436
436
|
|
|
437
437
|
if (!this.config.options.refreshRate) {
|
|
438
438
|
// default 120 seconds (2 minutes)
|
|
439
|
-
this.config.options!.refreshRate! = 120
|
|
440
|
-
this.debugWarnLog('Using Default Refresh Rate (2 minutes).')
|
|
439
|
+
this.config.options!.refreshRate! = 120
|
|
440
|
+
await this.debugWarnLog('Using Default Refresh Rate (2 minutes).')
|
|
441
441
|
}
|
|
442
442
|
|
|
443
443
|
if (!this.config.options.pushRate) {
|
|
444
444
|
// default 100 milliseconds
|
|
445
|
-
this.config.options!.pushRate! = 0.1
|
|
446
|
-
this.debugWarnLog('Using Default Push Rate.')
|
|
445
|
+
this.config.options!.pushRate! = 0.1
|
|
446
|
+
await this.debugWarnLog('Using Default Push Rate.')
|
|
447
447
|
}
|
|
448
448
|
|
|
449
449
|
if (!this.config.options.maxRetries) {
|
|
450
|
-
this.config.options.maxRetries = 5
|
|
451
|
-
this.debugWarnLog('Using Default Max Retries.')
|
|
450
|
+
this.config.options.maxRetries = 5
|
|
451
|
+
await this.debugWarnLog('Using Default Max Retries.')
|
|
452
452
|
} else {
|
|
453
|
-
this.maxRetries = this.config.options.maxRetries
|
|
453
|
+
this.maxRetries = this.config.options.maxRetries
|
|
454
454
|
}
|
|
455
455
|
|
|
456
456
|
if (!this.config.options.delayBetweenRetries) {
|
|
457
457
|
// default 3 seconds
|
|
458
|
-
this.config.options!.delayBetweenRetries! = 3000
|
|
459
|
-
this.debugWarnLog('Using Default Delay Between Retries.')
|
|
458
|
+
this.config.options!.delayBetweenRetries! = 3000
|
|
459
|
+
await this.debugWarnLog('Using Default Delay Between Retries.')
|
|
460
460
|
} else {
|
|
461
|
-
this.delayBetweenRetries = this.config.options.delayBetweenRetries * 1000
|
|
461
|
+
this.delayBetweenRetries = this.config.options.delayBetweenRetries * 1000
|
|
462
462
|
}
|
|
463
463
|
|
|
464
464
|
if (!this.config.credentials && !this.config.options) {
|
|
465
|
-
this.debugWarnLog('Missing Credentials')
|
|
465
|
+
await this.debugWarnLog('Missing Credentials')
|
|
466
466
|
} else if (this.config.credentials && !this.config.credentials.notice) {
|
|
467
467
|
if (!this.config.credentials?.token) {
|
|
468
|
-
this.debugErrorLog('Missing token')
|
|
469
|
-
this.debugWarnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work')
|
|
468
|
+
await this.debugErrorLog('Missing token')
|
|
469
|
+
await this.debugWarnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work')
|
|
470
470
|
}
|
|
471
471
|
if (this.config.credentials?.token) {
|
|
472
472
|
if (!this.config.credentials?.secret) {
|
|
473
|
-
this.debugErrorLog('Missing secret')
|
|
474
|
-
this.debugWarnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work')
|
|
473
|
+
await this.debugErrorLog('Missing secret')
|
|
474
|
+
await this.debugWarnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work')
|
|
475
475
|
}
|
|
476
476
|
}
|
|
477
477
|
}
|
|
@@ -480,1007 +480,892 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
480
480
|
/**
|
|
481
481
|
* The openToken was old config.
|
|
482
482
|
* This method saves the openToken as the token in the config.json file
|
|
483
|
-
* @param this.config.credentials.openToken
|
|
484
483
|
*/
|
|
485
484
|
async updateToken() {
|
|
486
485
|
try {
|
|
487
486
|
// check the new token was provided
|
|
488
487
|
if (!this.config.credentials?.openToken) {
|
|
489
|
-
throw new Error('New token not provided')
|
|
488
|
+
throw new Error('New token not provided')
|
|
490
489
|
}
|
|
491
490
|
|
|
492
491
|
// load in the current config
|
|
493
|
-
const currentConfig = JSON.parse(readFileSync(this.api.user.configPath(), 'utf8'))
|
|
492
|
+
const currentConfig = JSON.parse(readFileSync(this.api.user.configPath(), 'utf8'))
|
|
494
493
|
|
|
495
494
|
// check the platforms section is an array before we do array things on it
|
|
496
495
|
if (!Array.isArray(currentConfig.platforms)) {
|
|
497
|
-
throw new
|
|
496
|
+
throw new TypeError('Cannot find platforms array in config')
|
|
498
497
|
}
|
|
499
498
|
|
|
500
499
|
// find this plugins current config
|
|
501
|
-
const pluginConfig = currentConfig.platforms.find((x: { platform: string }) => x.platform === PLATFORM_NAME)
|
|
500
|
+
const pluginConfig = currentConfig.platforms.find((x: { platform: string }) => x.platform === PLATFORM_NAME)
|
|
502
501
|
|
|
503
502
|
if (!pluginConfig) {
|
|
504
|
-
throw new Error(`Cannot find config for ${PLATFORM_NAME} in platforms array`)
|
|
503
|
+
throw new Error(`Cannot find config for ${PLATFORM_NAME} in platforms array`)
|
|
505
504
|
}
|
|
506
505
|
|
|
507
506
|
// check the .credentials is an object before doing object things with it
|
|
508
507
|
if (typeof pluginConfig.credentials !== 'object') {
|
|
509
|
-
throw new
|
|
508
|
+
throw new TypeError('pluginConfig.credentials is not an object')
|
|
510
509
|
}
|
|
511
510
|
// Move openToken to token
|
|
512
511
|
if (!this.config.credentials.secret) {
|
|
513
|
-
this.warnLog('This plugin has been updated to use OpenAPI v1.1, config is set with openToken,'
|
|
514
|
-
|
|
515
|
-
this.errorLog('"secret" config is not populated, you must populate then please restart Homebridge.');
|
|
512
|
+
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')
|
|
513
|
+
this.errorLog('"secret" config is not populated, you must populate then please restart Homebridge.')
|
|
516
514
|
} else {
|
|
517
|
-
this.warnLog('This plugin has been updated to use OpenAPI v1.1, config is set with openToken, '
|
|
518
|
-
+ '"openToken" config has been moved to the "token" config, please restart Homebridge.');
|
|
515
|
+
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.')
|
|
519
516
|
}
|
|
520
517
|
|
|
521
518
|
// set the refresh token
|
|
522
|
-
pluginConfig.credentials.token = this.config.credentials?.openToken
|
|
519
|
+
pluginConfig.credentials.token = this.config.credentials?.openToken
|
|
523
520
|
if (pluginConfig.credentials.token) {
|
|
524
|
-
pluginConfig.credentials.openToken = undefined
|
|
521
|
+
pluginConfig.credentials.openToken = undefined
|
|
525
522
|
}
|
|
526
523
|
|
|
527
|
-
await this.debugWarnLog(`token: ${pluginConfig.credentials.token}`)
|
|
524
|
+
await this.debugWarnLog(`token: ${pluginConfig.credentials.token}`)
|
|
528
525
|
|
|
529
526
|
// save the config, ensuring we maintain pretty json
|
|
530
|
-
writeFileSync(this.api.user.configPath(), JSON.stringify(currentConfig, null, 4))
|
|
531
|
-
this.verifyConfig()
|
|
527
|
+
writeFileSync(this.api.user.configPath(), JSON.stringify(currentConfig, null, 4))
|
|
528
|
+
await this.verifyConfig()
|
|
532
529
|
} catch (e: any) {
|
|
533
|
-
this.errorLog(`Update Token: ${e}`)
|
|
530
|
+
await this.errorLog(`Update Token: ${e}`)
|
|
534
531
|
}
|
|
535
532
|
}
|
|
536
533
|
|
|
537
534
|
generateHeaders = () => {
|
|
538
|
-
const t = `${Date.now()}
|
|
539
|
-
const nonce = randomUUID()
|
|
540
|
-
const data = this.config.credentials?.token + t + nonce
|
|
535
|
+
const t = `${Date.now()}`
|
|
536
|
+
const nonce = randomUUID()
|
|
537
|
+
const data = this.config.credentials?.token + t + nonce
|
|
541
538
|
const signTerm = crypto
|
|
542
539
|
.createHmac('sha256', this.config.credentials?.secret)
|
|
543
540
|
.update(Buffer.from(data, 'utf-8'))
|
|
544
|
-
.digest()
|
|
545
|
-
const sign = signTerm.toString('base64')
|
|
541
|
+
.digest()
|
|
542
|
+
const sign = signTerm.toString('base64')
|
|
546
543
|
|
|
547
544
|
return {
|
|
548
|
-
Authorization: this.config.credentials?.token,
|
|
549
|
-
sign: sign,
|
|
550
|
-
nonce: nonce,
|
|
551
|
-
t: t,
|
|
545
|
+
'Authorization': this.config.credentials?.token,
|
|
546
|
+
'sign': sign,
|
|
547
|
+
'nonce': nonce,
|
|
548
|
+
't': t,
|
|
552
549
|
'Content-Type': 'application/json',
|
|
553
|
-
}
|
|
554
|
-
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
555
552
|
|
|
556
|
-
/**
|
|
557
|
-
* this method discovers devices
|
|
558
|
-
*
|
|
559
|
-
const t = `${Date.now()}`;
|
|
560
|
-
const nonce = 'requestID';
|
|
561
|
-
const data = this.config.credentials?.token + t + nonce;
|
|
562
|
-
const signTerm = crypto.createHmac('sha256', this.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
563
|
-
const sign = signTerm.toString('base64');
|
|
564
|
-
*/
|
|
565
553
|
async discoverDevices() {
|
|
566
|
-
if (this.config.credentials?.token) {
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
const delayBetweenRetries = this.delayBetweenRetries; // Delay between retries in milliseconds
|
|
570
|
-
await this.debugWarnLog(`Retry Count: ${retryCount}`);
|
|
571
|
-
await this.debugWarnLog(`Max Retries: ${maxRetries}`);
|
|
572
|
-
await this.debugWarnLog(`Delay Between Retries: ${delayBetweenRetries}`);
|
|
573
|
-
while (retryCount < maxRetries) {
|
|
574
|
-
try {
|
|
575
|
-
const { body, statusCode } = await request(Devices, {
|
|
576
|
-
headers: this.generateHeaders(),
|
|
577
|
-
});
|
|
578
|
-
await this.debugWarnLog(`statusCode: ${statusCode}`);
|
|
579
|
-
const devicesAPI: any = await body.json();
|
|
580
|
-
await this.debugWarnLog(`devicesAPI: ${JSON.stringify(devicesAPI)}`);
|
|
581
|
-
await this.debugWarnLog(`devicesAPI Body: ${JSON.stringify(devicesAPI.body)}`);
|
|
582
|
-
await this.debugWarnLog(`devicesAPI StatusCode: ${devicesAPI.statusCode}`);
|
|
583
|
-
if ((statusCode === 200 || statusCode === 100) && (devicesAPI.statusCode === 200 || devicesAPI.statusCode === 100)) {
|
|
584
|
-
await this.debugErrorLog(`statusCode: ${statusCode} & devicesAPI StatusCode: ${devicesAPI.statusCode}`);
|
|
585
|
-
// SwitchBot Devices
|
|
586
|
-
const deviceLists = devicesAPI.body.deviceList;
|
|
587
|
-
await this.debugWarnLog(`DeviceLists: ${JSON.stringify(deviceLists)}`);
|
|
588
|
-
await this.debugWarnLog(`DeviceLists Length: ${deviceLists.length}`);
|
|
589
|
-
if (!this.config.options?.devices) {
|
|
590
|
-
await this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
591
|
-
if (deviceLists.length === 0) {
|
|
592
|
-
await this.debugLog(`SwitchBot API Has No Devices With Cloud Services Enabled: ${JSON.stringify(devicesAPI.body)}`);
|
|
593
|
-
} else {
|
|
594
|
-
const devices = deviceLists.map((v: any) => v);
|
|
595
|
-
for (const device of devices) {
|
|
596
|
-
if (device.deviceType) {
|
|
597
|
-
if (device.configDeviceName) {
|
|
598
|
-
device.deviceName = device.configDeviceName;
|
|
599
|
-
}
|
|
600
|
-
this.createDevice(device);
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
} else if (this.config.credentials?.token && this.config.options.devices) {
|
|
605
|
-
await this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
606
|
-
if (deviceLists.length === 0) {
|
|
607
|
-
await this.debugLog(`SwitchBot API Has No Devices With Cloud Services Enabled: ${JSON.stringify(devicesAPI.body)}`);
|
|
608
|
-
} else {
|
|
609
|
-
const deviceConfigs = this.config.options?.devices;
|
|
610
|
-
|
|
611
|
-
const mergeBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
|
|
612
|
-
a1.map((itm: { deviceId: string }) => ({
|
|
613
|
-
...a2.find(
|
|
614
|
-
(item: { deviceId: string }) =>
|
|
615
|
-
item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
|
|
616
|
-
),
|
|
617
|
-
...itm,
|
|
618
|
-
}));
|
|
619
|
-
|
|
620
|
-
const devices = mergeBydeviceId(deviceLists, deviceConfigs);
|
|
621
|
-
await this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
|
|
622
|
-
for (const device of devices) {
|
|
623
|
-
if (!device.deviceType) {
|
|
624
|
-
device.deviceType = device.configDeviceType;
|
|
625
|
-
this.errorLog(`API has displaying no deviceType: ${device.deviceType}, So using configDeviceType: ${device.configDeviceType}`);
|
|
626
|
-
}
|
|
627
|
-
if (device.deviceType) {
|
|
628
|
-
if (device.configDeviceName) {
|
|
629
|
-
device.deviceName = device.configDeviceName;
|
|
630
|
-
}
|
|
631
|
-
this.createDevice(device);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
} else {
|
|
636
|
-
this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
|
|
637
|
-
}
|
|
638
|
-
if (devicesAPI.body.deviceList.length !== 0) {
|
|
639
|
-
this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
640
|
-
} else {
|
|
641
|
-
await this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
642
|
-
}
|
|
554
|
+
if (!this.config.credentials?.token) {
|
|
555
|
+
return this.handleManualConfig()
|
|
556
|
+
}
|
|
643
557
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
558
|
+
let retryCount = 0
|
|
559
|
+
const maxRetries = this.maxRetries
|
|
560
|
+
const delayBetweenRetries = this.delayBetweenRetries
|
|
561
|
+
|
|
562
|
+
await this.debugWarnLog(`Retry Count: ${retryCount}`)
|
|
563
|
+
await this.debugWarnLog(`Max Retries: ${maxRetries}`)
|
|
564
|
+
await this.debugWarnLog(`Delay Between Retries: ${delayBetweenRetries}`)
|
|
565
|
+
|
|
566
|
+
while (retryCount < maxRetries) {
|
|
567
|
+
try {
|
|
568
|
+
const { body, statusCode } = await request(Devices, { headers: this.generateHeaders() })
|
|
569
|
+
await this.debugWarnLog(`statusCode: ${statusCode}`)
|
|
570
|
+
const devicesAPI: any = await body.json()
|
|
571
|
+
await this.debugWarnLog(`devicesAPI: ${JSON.stringify(devicesAPI)}`)
|
|
572
|
+
|
|
573
|
+
if (this.isSuccessfulResponse(statusCode, devicesAPI.statusCode)) {
|
|
574
|
+
await this.handleDevices(devicesAPI.body.deviceList)
|
|
575
|
+
await this.handleIRDevices(devicesAPI.body.infraredRemoteList)
|
|
576
|
+
break
|
|
577
|
+
} else {
|
|
578
|
+
await this.handleErrorResponse(statusCode, devicesAPI.statusCode, retryCount, maxRetries, delayBetweenRetries)
|
|
579
|
+
retryCount++
|
|
580
|
+
}
|
|
581
|
+
} catch (e: any) {
|
|
582
|
+
retryCount++
|
|
583
|
+
await this.debugErrorLog(`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`)
|
|
584
|
+
await this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`)
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
private async handleManualConfig() {
|
|
590
|
+
if (this.config.options?.devices) {
|
|
591
|
+
await this.debugLog(`SwitchBot Device Manual Config Set: ${JSON.stringify(this.config.options?.devices)}`)
|
|
592
|
+
const devices = this.config.options.devices.map((v: any) => v)
|
|
593
|
+
for (const device of devices) {
|
|
594
|
+
device.deviceType = device.configDeviceType
|
|
595
|
+
device.deviceName = device.configDeviceName
|
|
596
|
+
if (device.deviceType) {
|
|
597
|
+
await this.createDevice(device)
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
} else {
|
|
601
|
+
await this.errorLog('Neither SwitchBot Token or Device Config are set.')
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
private isSuccessfulResponse(statusCode: number, apiStatusCode: number): boolean {
|
|
606
|
+
return (statusCode === 200 || statusCode === 100) && (apiStatusCode === 200 || apiStatusCode === 100)
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
private async handleDevices(deviceLists: any[]) {
|
|
610
|
+
if (!this.config.options?.devices) {
|
|
611
|
+
await this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`)
|
|
612
|
+
if (deviceLists.length === 0) {
|
|
613
|
+
await this.debugLog('SwitchBot API Has No Devices With Cloud Services Enabled')
|
|
614
|
+
} else {
|
|
615
|
+
for (const device of deviceLists) {
|
|
616
|
+
if (device.deviceType) {
|
|
617
|
+
if (device.configDeviceName) {
|
|
618
|
+
device.deviceName = device.configDeviceName
|
|
686
619
|
}
|
|
620
|
+
await this.createDevice(device)
|
|
687
621
|
}
|
|
688
|
-
} catch (e: any) {
|
|
689
|
-
retryCount++;
|
|
690
|
-
this.debugErrorLog(
|
|
691
|
-
`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
692
|
-
await this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
|
|
693
622
|
}
|
|
694
623
|
}
|
|
695
|
-
} else
|
|
696
|
-
await this.debugLog(`SwitchBot Device
|
|
697
|
-
const
|
|
698
|
-
|
|
624
|
+
} else {
|
|
625
|
+
await this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`)
|
|
626
|
+
const devices = this.mergeByDeviceId(deviceLists, this.config.options.devices)
|
|
627
|
+
await this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`)
|
|
699
628
|
for (const device of devices) {
|
|
700
|
-
device.deviceType
|
|
701
|
-
|
|
629
|
+
if (!device.deviceType && device.configDeviceType) {
|
|
630
|
+
device.deviceType = device.configDeviceType
|
|
631
|
+
await this.warnLog(`API is displaying no deviceType: ${device.deviceType}, So using configDeviceType: ${device.configDeviceType}`)
|
|
632
|
+
} else if (!device.deviceType && !device.configDeviceName) {
|
|
633
|
+
await this.errorLog('No deviceType or configDeviceType for device. No device will be created.')
|
|
634
|
+
}
|
|
702
635
|
if (device.deviceType) {
|
|
703
|
-
|
|
636
|
+
if (device.configDeviceName) {
|
|
637
|
+
device.deviceName = device.configDeviceName
|
|
638
|
+
}
|
|
639
|
+
await this.createDevice(device)
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
private async handleIRDevices(irDeviceLists: any[]) {
|
|
646
|
+
if (!this.config.options?.irdevices) {
|
|
647
|
+
await this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`)
|
|
648
|
+
for (const device of irDeviceLists) {
|
|
649
|
+
if (device.remoteType) {
|
|
650
|
+
await this.createIRDevice(device)
|
|
704
651
|
}
|
|
705
652
|
}
|
|
706
653
|
} else {
|
|
707
|
-
this.
|
|
654
|
+
await this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`)
|
|
655
|
+
const devices = this.mergeByDeviceId(irDeviceLists, this.config.options.irdevices)
|
|
656
|
+
await this.debugLog(`IR Devices: ${JSON.stringify(devices)}`)
|
|
657
|
+
for (const device of devices) {
|
|
658
|
+
await this.createIRDevice(device)
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
private mergeByDeviceId(a1: { deviceId: string }[], a2: any[]) {
|
|
664
|
+
const normalizeDeviceId = (deviceId: string) => deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '')
|
|
665
|
+
return a1.map((itm) => {
|
|
666
|
+
const matchingItem = a2.find(item => normalizeDeviceId(item.deviceId) === normalizeDeviceId(itm.deviceId))
|
|
667
|
+
return { ...matchingItem, ...itm }
|
|
668
|
+
})
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
private async handleErrorResponse(statusCode: number, apiStatusCode: number, retryCount: number, maxRetries: number, delayBetweenRetries: number) {
|
|
672
|
+
await this.statusCode(statusCode)
|
|
673
|
+
await this.statusCode(apiStatusCode)
|
|
674
|
+
if (statusCode === 500) {
|
|
675
|
+
this.infoLog(`statusCode: ${statusCode} Attempt ${retryCount + 1} of ${maxRetries}`)
|
|
676
|
+
await sleep(delayBetweenRetries)
|
|
708
677
|
}
|
|
709
678
|
}
|
|
710
679
|
|
|
711
680
|
private async createDevice(device: device & devicesConfig) {
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
754
|
-
this.createContact(device);
|
|
755
|
-
break;
|
|
756
|
-
case 'Curtain':
|
|
757
|
-
case 'Curtain3':
|
|
758
|
-
await this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
|
|
759
|
-
this.createCurtain(device);
|
|
760
|
-
break;
|
|
761
|
-
case 'Blind Tilt':
|
|
762
|
-
await this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
|
|
763
|
-
this.createBlindTilt(device);
|
|
764
|
-
break;
|
|
765
|
-
case 'Plug':
|
|
766
|
-
case 'Plug Mini (US)':
|
|
767
|
-
case 'Plug Mini (JP)':
|
|
768
|
-
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
769
|
-
this.createPlug(device);
|
|
770
|
-
break;
|
|
771
|
-
case 'Smart Lock':
|
|
772
|
-
case 'Smart Lock Pro':
|
|
773
|
-
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
774
|
-
this.createLock(device);
|
|
775
|
-
break;
|
|
776
|
-
case 'Color Bulb':
|
|
777
|
-
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
778
|
-
this.createColorBulb(device);
|
|
779
|
-
break;
|
|
780
|
-
case 'K10+':
|
|
781
|
-
case 'WoSweeper':
|
|
782
|
-
case 'WoSweeperMini':
|
|
783
|
-
case 'Robot Vacuum Cleaner S1':
|
|
784
|
-
case 'Robot Vacuum Cleaner S1 Plus':
|
|
785
|
-
case 'Robot Vacuum Cleaner S10':
|
|
786
|
-
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
787
|
-
this.createRobotVacuumCleaner(device);
|
|
788
|
-
break;
|
|
789
|
-
case 'Ceiling Light':
|
|
790
|
-
case 'Ceiling Light Pro':
|
|
791
|
-
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
792
|
-
this.createCeilingLight(device);
|
|
793
|
-
break;
|
|
794
|
-
case 'Strip Light':
|
|
795
|
-
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
796
|
-
this.createStripLight(device);
|
|
797
|
-
break;
|
|
798
|
-
case 'Battery Circulator Fan':
|
|
799
|
-
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
800
|
-
this.createFan(device);
|
|
801
|
-
break;
|
|
802
|
-
case 'Remote':
|
|
803
|
-
case 'Indoor Cam':
|
|
804
|
-
case 'remote with screen+':
|
|
805
|
-
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}, is currently not supported, device: ${JSON.stringify(device)}`);
|
|
806
|
-
break;
|
|
807
|
-
default:
|
|
808
|
-
this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`,
|
|
809
|
-
+ `Submit Feature Requests Here: https://tinyurl.com/SwitchBotFeatureRequest, device: ${JSON.stringify(device)}`);
|
|
681
|
+
const deviceTypeHandlers: { [key: string]: (device: device & devicesConfig) => Promise<void> } = {
|
|
682
|
+
'Humidifier': this.createHumidifier.bind(this),
|
|
683
|
+
'Hub 2': this.createHub2.bind(this),
|
|
684
|
+
'Bot': this.createBot.bind(this),
|
|
685
|
+
'Meter': this.createMeter.bind(this),
|
|
686
|
+
'MeterPlus': this.createMeterPlus.bind(this),
|
|
687
|
+
'Meter Plus (JP)': this.createMeterPlus.bind(this),
|
|
688
|
+
'WoIOSensor': this.createIOSensor.bind(this),
|
|
689
|
+
'Water Detector': this.createWaterDetector.bind(this),
|
|
690
|
+
'Motion Sensor': this.createMotion.bind(this),
|
|
691
|
+
'Contact Sensor': this.createContact.bind(this),
|
|
692
|
+
'Curtain': this.createCurtain.bind(this),
|
|
693
|
+
'Curtain3': this.createCurtain.bind(this),
|
|
694
|
+
'WoRollerShade': this.createCurtain.bind(this),
|
|
695
|
+
'Roller Shade': this.createCurtain.bind(this),
|
|
696
|
+
'Blind Tilt': this.createBlindTilt.bind(this),
|
|
697
|
+
'Plug': this.createPlug.bind(this),
|
|
698
|
+
'Plug Mini (US)': this.createPlug.bind(this),
|
|
699
|
+
'Plug Mini (JP)': this.createPlug.bind(this),
|
|
700
|
+
'Smart Lock': this.createLock.bind(this),
|
|
701
|
+
'Smart Lock Pro': this.createLock.bind(this),
|
|
702
|
+
'Color Bulb': this.createColorBulb.bind(this),
|
|
703
|
+
'K10+': this.createRobotVacuumCleaner.bind(this),
|
|
704
|
+
'WoSweeper': this.createRobotVacuumCleaner.bind(this),
|
|
705
|
+
'WoSweeperMini': this.createRobotVacuumCleaner.bind(this),
|
|
706
|
+
'Robot Vacuum Cleaner S1': this.createRobotVacuumCleaner.bind(this),
|
|
707
|
+
'Robot Vacuum Cleaner S1 Plus': this.createRobotVacuumCleaner.bind(this),
|
|
708
|
+
'Robot Vacuum Cleaner S10': this.createRobotVacuumCleaner.bind(this),
|
|
709
|
+
'Ceiling Light': this.createCeilingLight.bind(this),
|
|
710
|
+
'Ceiling Light Pro': this.createCeilingLight.bind(this),
|
|
711
|
+
'Strip Light': this.createStripLight.bind(this),
|
|
712
|
+
'Battery Circulator Fan': this.createFan.bind(this),
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
if (deviceTypeHandlers[device.deviceType!]) {
|
|
716
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`)
|
|
717
|
+
await deviceTypeHandlers[device.deviceType!](device)
|
|
718
|
+
} else if (['Hub Mini', 'Hub Plus', 'Remote', 'Indoor Cam', 'remote with screen'].includes(device.deviceType!)) {
|
|
719
|
+
await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}, is currently not supported, device: ${JSON.stringify(device)}`)
|
|
720
|
+
} else {
|
|
721
|
+
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)}`)
|
|
810
722
|
}
|
|
811
723
|
}
|
|
812
724
|
|
|
813
725
|
private async createIRDevice(device: irdevice & devicesConfig) {
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
case 'Air Purifier':
|
|
854
|
-
case 'DIY Air Purifier':
|
|
855
|
-
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
856
|
-
this.createAirPurifier(device);
|
|
857
|
-
break;
|
|
858
|
-
case 'Water Heater':
|
|
859
|
-
case 'DIY Water Heater':
|
|
860
|
-
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
861
|
-
this.createWaterHeater(device);
|
|
862
|
-
break;
|
|
863
|
-
case 'Vacuum Cleaner':
|
|
864
|
-
case 'DIY Vacuum Cleaner':
|
|
865
|
-
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
866
|
-
this.createVacuumCleaner(device);
|
|
867
|
-
break;
|
|
868
|
-
case 'Camera':
|
|
869
|
-
case 'DIY Camera':
|
|
870
|
-
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
871
|
-
this.createCamera(device);
|
|
872
|
-
break;
|
|
873
|
-
case 'Others':
|
|
874
|
-
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
875
|
-
this.createOthers(device);
|
|
876
|
-
break;
|
|
877
|
-
default:
|
|
878
|
-
await this.debugLog(`Unsupported Device: ${JSON.stringify(device)}`);
|
|
879
|
-
this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.remoteType}, is currently not supported.`);
|
|
880
|
-
this.warnLog('Submit Feature Requests Here: ' + 'https://tinyurl.com/SwitchBotFeatureRequest');
|
|
726
|
+
device.connectionType = device.connectionType ?? 'OpenAPI'
|
|
727
|
+
const deviceTypeHandlers: { [key: string]: (device: irdevice & devicesConfig) => Promise<void> } = {
|
|
728
|
+
'TV': this.createTV.bind(this),
|
|
729
|
+
'DIY TV': this.createTV.bind(this),
|
|
730
|
+
'Projector': this.createTV.bind(this),
|
|
731
|
+
'DIY Projector': this.createTV.bind(this),
|
|
732
|
+
'Set Top Box': this.createTV.bind(this),
|
|
733
|
+
'DIY Set Top Box': this.createTV.bind(this),
|
|
734
|
+
'IPTV': this.createTV.bind(this),
|
|
735
|
+
'DIY IPTV': this.createTV.bind(this),
|
|
736
|
+
'DVD': this.createTV.bind(this),
|
|
737
|
+
'DIY DVD': this.createTV.bind(this),
|
|
738
|
+
'Speaker': this.createTV.bind(this),
|
|
739
|
+
'DIY Speaker': this.createTV.bind(this),
|
|
740
|
+
'Fan': this.createIRFan.bind(this),
|
|
741
|
+
'DIY Fan': this.createIRFan.bind(this),
|
|
742
|
+
'Air Conditioner': this.createAirConditioner.bind(this),
|
|
743
|
+
'DIY Air Conditioner': this.createAirConditioner.bind(this),
|
|
744
|
+
'Light': this.createLight.bind(this),
|
|
745
|
+
'DIY Light': this.createLight.bind(this),
|
|
746
|
+
'Air Purifier': this.createAirPurifier.bind(this),
|
|
747
|
+
'DIY Air Purifier': this.createAirPurifier.bind(this),
|
|
748
|
+
'Water Heater': this.createWaterHeater.bind(this),
|
|
749
|
+
'DIY Water Heater': this.createWaterHeater.bind(this),
|
|
750
|
+
'Vacuum Cleaner': this.createVacuumCleaner.bind(this),
|
|
751
|
+
'DIY Vacuum Cleaner': this.createVacuumCleaner.bind(this),
|
|
752
|
+
'Camera': this.createCamera.bind(this),
|
|
753
|
+
'DIY Camera': this.createCamera.bind(this),
|
|
754
|
+
'Others': this.createOthers.bind(this),
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
if (deviceTypeHandlers[device.remoteType!]) {
|
|
758
|
+
await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`)
|
|
759
|
+
if (device.remoteType.startsWith('DIY') && device.external === undefined) {
|
|
760
|
+
device.external = true
|
|
761
|
+
}
|
|
762
|
+
await deviceTypeHandlers[device.remoteType!](device)
|
|
763
|
+
} else {
|
|
764
|
+
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)}`)
|
|
881
765
|
}
|
|
882
766
|
}
|
|
883
767
|
|
|
884
768
|
private async createHumidifier(device: device & devicesConfig) {
|
|
885
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
769
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
886
770
|
|
|
887
771
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
888
772
|
// the cached devices we stored in the `configureAccessory` method above
|
|
889
|
-
const existingAccessory = this.accessories.find(
|
|
773
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
890
774
|
|
|
891
775
|
if (existingAccessory) {
|
|
892
776
|
// the accessory already exists
|
|
893
777
|
if (await this.registerDevice(device)) {
|
|
894
778
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
895
|
-
existingAccessory.context.device = device
|
|
896
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
897
|
-
existingAccessory.context.deviceType = device.deviceType
|
|
898
|
-
existingAccessory.context.model = SwitchBotModel.Humidifier
|
|
779
|
+
existingAccessory.context.device = device
|
|
780
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
781
|
+
existingAccessory.context.deviceType = device.deviceType
|
|
782
|
+
existingAccessory.context.model = SwitchBotModel.Humidifier
|
|
899
783
|
existingAccessory.displayName = device.configDeviceName
|
|
900
784
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
901
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
902
|
-
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
903
|
-
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
904
|
-
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
905
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
785
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
786
|
+
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
787
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
788
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
789
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
906
790
|
// create the accessory handler for the restored accessory
|
|
907
791
|
// this is imported from `platformAccessory.ts`
|
|
908
|
-
new Humidifier(this, existingAccessory, device)
|
|
909
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
792
|
+
new Humidifier(this, existingAccessory, device)
|
|
793
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
910
794
|
} else {
|
|
911
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
795
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
912
796
|
}
|
|
913
797
|
} else if (await this.registerDevice(device)) {
|
|
914
798
|
// create a new accessory
|
|
915
799
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
916
800
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
917
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
801
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
918
802
|
|
|
919
803
|
// store a copy of the device object in the `accessory.context`
|
|
920
804
|
// the `context` property can be used to store any data about the accessory you may need
|
|
921
|
-
accessory.context.device = device
|
|
922
|
-
accessory.context.deviceId = device.deviceId
|
|
923
|
-
accessory.context.deviceType = device.deviceType
|
|
924
|
-
accessory.context.model = SwitchBotModel.Humidifier
|
|
805
|
+
accessory.context.device = device
|
|
806
|
+
accessory.context.deviceId = device.deviceId
|
|
807
|
+
accessory.context.deviceType = device.deviceType
|
|
808
|
+
accessory.context.model = SwitchBotModel.Humidifier
|
|
925
809
|
accessory.displayName = device.configDeviceName
|
|
926
810
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
927
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
928
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
929
|
-
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
930
|
-
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
931
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
811
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
812
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
813
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
814
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
815
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
932
816
|
// create the accessory handler for the newly create accessory
|
|
933
817
|
// this is imported from `platformAccessory.ts`
|
|
934
|
-
new Humidifier(this, accessory, device)
|
|
935
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
818
|
+
new Humidifier(this, accessory, device)
|
|
819
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
936
820
|
|
|
937
821
|
// publish device externally or link the accessory to your platform
|
|
938
|
-
this.externalOrPlatform(device, accessory)
|
|
939
|
-
this.accessories.push(accessory)
|
|
822
|
+
this.externalOrPlatform(device, accessory)
|
|
823
|
+
this.accessories.push(accessory)
|
|
940
824
|
} else {
|
|
941
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
825
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
942
826
|
}
|
|
943
827
|
}
|
|
944
828
|
|
|
945
829
|
private async createBot(device: device & devicesConfig) {
|
|
946
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
830
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
947
831
|
|
|
948
832
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
949
833
|
// the cached devices we stored in the `configureAccessory` method above
|
|
950
|
-
const existingAccessory = this.accessories.find(
|
|
834
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
951
835
|
|
|
952
836
|
if (existingAccessory) {
|
|
953
837
|
// the accessory already exists
|
|
954
838
|
if (await this.registerDevice(device)) {
|
|
955
839
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
956
|
-
existingAccessory.context.device = device
|
|
957
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
958
|
-
existingAccessory.context.deviceType = device.deviceType
|
|
959
|
-
existingAccessory.context.model = SwitchBotModel.Bot
|
|
840
|
+
existingAccessory.context.device = device
|
|
841
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
842
|
+
existingAccessory.context.deviceType = device.deviceType
|
|
843
|
+
existingAccessory.context.model = SwitchBotModel.Bot
|
|
960
844
|
existingAccessory.displayName = device.configDeviceName
|
|
961
845
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
962
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
963
|
-
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
964
|
-
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
965
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
966
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
846
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
847
|
+
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
848
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
849
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
850
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
967
851
|
// create the accessory handler for the restored accessory
|
|
968
852
|
// this is imported from `platformAccessory.ts`
|
|
969
|
-
new Bot(this, existingAccessory, device)
|
|
970
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
853
|
+
new Bot(this, existingAccessory, device)
|
|
854
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
971
855
|
} else {
|
|
972
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
856
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
973
857
|
}
|
|
974
858
|
} else if (await this.registerDevice(device)) {
|
|
975
859
|
// create a new accessory
|
|
976
860
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
977
861
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
978
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
862
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
979
863
|
|
|
980
864
|
// store a copy of the device object in the `accessory.context`
|
|
981
865
|
// the `context` property can be used to store any data about the accessory you may need
|
|
982
|
-
accessory.context.device = device
|
|
983
|
-
accessory.context.deviceId = device.deviceId
|
|
984
|
-
accessory.context.deviceType = device.deviceType
|
|
985
|
-
accessory.context.model = SwitchBotModel.Bot
|
|
866
|
+
accessory.context.device = device
|
|
867
|
+
accessory.context.deviceId = device.deviceId
|
|
868
|
+
accessory.context.deviceType = device.deviceType
|
|
869
|
+
accessory.context.model = SwitchBotModel.Bot
|
|
986
870
|
accessory.displayName = device.configDeviceName
|
|
987
871
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
988
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
989
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
990
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
991
|
-
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
992
|
-
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
993
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
872
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
873
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
874
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
875
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
876
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
877
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
994
878
|
// accessory.context.version = findaccessories.accessoryAttribute.softwareRevision;
|
|
995
879
|
// create the accessory handler for the newly create accessory
|
|
996
880
|
// this is imported from `platformAccessory.ts`
|
|
997
|
-
new Bot(this, accessory, device)
|
|
998
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
881
|
+
new Bot(this, accessory, device)
|
|
882
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
999
883
|
|
|
1000
884
|
// publish device externally or link the accessory to your platform
|
|
1001
|
-
this.externalOrPlatform(device, accessory)
|
|
1002
|
-
this.accessories.push(accessory)
|
|
885
|
+
this.externalOrPlatform(device, accessory)
|
|
886
|
+
this.accessories.push(accessory)
|
|
1003
887
|
} else {
|
|
1004
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
888
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1005
889
|
}
|
|
1006
890
|
}
|
|
1007
891
|
|
|
1008
892
|
private async createMeter(device: device & devicesConfig) {
|
|
1009
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
893
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1010
894
|
|
|
1011
895
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1012
896
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1013
|
-
const existingAccessory = this.accessories.find(
|
|
897
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
1014
898
|
|
|
1015
899
|
if (existingAccessory) {
|
|
1016
900
|
// the accessory already exists
|
|
1017
901
|
if (await this.registerDevice(device)) {
|
|
1018
902
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1019
|
-
existingAccessory.context.device = device
|
|
1020
|
-
existingAccessory.context.model = SwitchBotModel.Meter
|
|
1021
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
1022
|
-
existingAccessory.context.deviceType = device.deviceType
|
|
903
|
+
existingAccessory.context.device = device
|
|
904
|
+
existingAccessory.context.model = SwitchBotModel.Meter
|
|
905
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
906
|
+
existingAccessory.context.deviceType = device.deviceType
|
|
1023
907
|
existingAccessory.displayName = device.configDeviceName
|
|
1024
908
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1025
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1026
|
-
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1027
|
-
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1028
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1029
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
909
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
910
|
+
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
911
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
912
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
913
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
1030
914
|
// create the accessory handler for the restored accessory
|
|
1031
915
|
// this is imported from `platformAccessory.ts`
|
|
1032
|
-
new Meter(this, existingAccessory, device)
|
|
1033
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
916
|
+
new Meter(this, existingAccessory, device)
|
|
917
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1034
918
|
} else {
|
|
1035
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
919
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
1036
920
|
}
|
|
1037
921
|
} else if (await this.registerDevice(device)) {
|
|
1038
922
|
// create a new accessory
|
|
1039
923
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1040
924
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1041
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
925
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1042
926
|
|
|
1043
927
|
// store a copy of the device object in the `accessory.context`
|
|
1044
928
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1045
|
-
accessory.context.device = device
|
|
1046
|
-
accessory.context.model = SwitchBotModel.Meter
|
|
1047
|
-
accessory.context.deviceId = device.deviceId
|
|
1048
|
-
accessory.context.deviceType = device.deviceType
|
|
929
|
+
accessory.context.device = device
|
|
930
|
+
accessory.context.model = SwitchBotModel.Meter
|
|
931
|
+
accessory.context.deviceId = device.deviceId
|
|
932
|
+
accessory.context.deviceType = device.deviceType
|
|
1049
933
|
accessory.displayName = device.configDeviceName
|
|
1050
934
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1051
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1052
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1053
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1054
|
-
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1055
|
-
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1056
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
935
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
936
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
937
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
938
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
939
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
940
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1057
941
|
// create the accessory handler for the newly create accessory
|
|
1058
942
|
// this is imported from `platformAccessory.ts`
|
|
1059
|
-
new Meter(this, accessory, device)
|
|
1060
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
943
|
+
new Meter(this, accessory, device)
|
|
944
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1061
945
|
|
|
1062
946
|
// publish device externally or link the accessory to your platform
|
|
1063
|
-
this.externalOrPlatform(device, accessory)
|
|
1064
|
-
this.accessories.push(accessory)
|
|
947
|
+
this.externalOrPlatform(device, accessory)
|
|
948
|
+
this.accessories.push(accessory)
|
|
1065
949
|
} else {
|
|
1066
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
950
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1067
951
|
}
|
|
1068
952
|
}
|
|
1069
953
|
|
|
1070
954
|
private async createMeterPlus(device: device & devicesConfig) {
|
|
1071
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
955
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1072
956
|
|
|
1073
957
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1074
958
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1075
|
-
const existingAccessory = this.accessories.find(
|
|
959
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
1076
960
|
|
|
1077
961
|
if (existingAccessory) {
|
|
1078
962
|
// the accessory already exists
|
|
1079
963
|
if (await this.registerDevice(device)) {
|
|
1080
964
|
// console.log("existingAccessory", existingAccessory);
|
|
1081
965
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1082
|
-
existingAccessory.context.device = device
|
|
1083
|
-
existingAccessory.context.model = SwitchBotModel.MeterPlusUS ?? SwitchBotModel.MeterPlusJP
|
|
1084
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
1085
|
-
existingAccessory.context.deviceType = device.deviceType
|
|
966
|
+
existingAccessory.context.device = device
|
|
967
|
+
existingAccessory.context.model = SwitchBotModel.MeterPlusUS ?? SwitchBotModel.MeterPlusJP
|
|
968
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
969
|
+
existingAccessory.context.deviceType = device.deviceType
|
|
1086
970
|
existingAccessory.displayName = device.configDeviceName
|
|
1087
971
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1088
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1089
|
-
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1090
|
-
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1091
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1092
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
972
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
973
|
+
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
974
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
975
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
976
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
1093
977
|
// create the accessory handler for the restored accessory
|
|
1094
978
|
// this is imported from `platformAccessory.ts`
|
|
1095
|
-
new MeterPlus(this, existingAccessory, device)
|
|
1096
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
979
|
+
new MeterPlus(this, existingAccessory, device)
|
|
980
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1097
981
|
} else {
|
|
1098
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
982
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
1099
983
|
}
|
|
1100
984
|
} else if (await this.registerDevice(device)) {
|
|
1101
985
|
// create a new accessory
|
|
1102
986
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1103
987
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1104
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
988
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1105
989
|
|
|
1106
990
|
// store a copy of the device object in the `accessory.context`
|
|
1107
991
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1108
|
-
accessory.context.device = device
|
|
1109
|
-
accessory.context.model = SwitchBotModel.MeterPlusUS ?? SwitchBotModel.MeterPlusJP
|
|
1110
|
-
accessory.context.deviceId = device.deviceId
|
|
1111
|
-
accessory.context.deviceType = device.deviceType
|
|
992
|
+
accessory.context.device = device
|
|
993
|
+
accessory.context.model = SwitchBotModel.MeterPlusUS ?? SwitchBotModel.MeterPlusJP
|
|
994
|
+
accessory.context.deviceId = device.deviceId
|
|
995
|
+
accessory.context.deviceType = device.deviceType
|
|
1112
996
|
accessory.displayName = device.configDeviceName
|
|
1113
997
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1114
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1115
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1116
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1117
|
-
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1118
|
-
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1119
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
998
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
999
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1000
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1001
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1002
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1003
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1120
1004
|
// create the accessory handler for the newly create accessory
|
|
1121
1005
|
// this is imported from `platformAccessory.ts`
|
|
1122
|
-
new MeterPlus(this, accessory, device)
|
|
1123
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1006
|
+
new MeterPlus(this, accessory, device)
|
|
1007
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1124
1008
|
|
|
1125
1009
|
// publish device externally or link the accessory to your platform
|
|
1126
|
-
this.externalOrPlatform(device, accessory)
|
|
1127
|
-
this.accessories.push(accessory)
|
|
1010
|
+
this.externalOrPlatform(device, accessory)
|
|
1011
|
+
this.accessories.push(accessory)
|
|
1128
1012
|
} else {
|
|
1129
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1013
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1130
1014
|
}
|
|
1131
1015
|
}
|
|
1132
1016
|
|
|
1133
1017
|
private async createHub2(device: device & devicesConfig) {
|
|
1134
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1018
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1135
1019
|
|
|
1136
1020
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1137
1021
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1138
|
-
const existingAccessory = this.accessories.find(
|
|
1022
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
1139
1023
|
|
|
1140
1024
|
if (existingAccessory) {
|
|
1141
1025
|
// the accessory already exists
|
|
1142
1026
|
if (await this.registerDevice(device)) {
|
|
1143
1027
|
// console.log("existingAccessory", existingAccessory);
|
|
1144
1028
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1145
|
-
existingAccessory.context.device = device
|
|
1146
|
-
existingAccessory.context.model = SwitchBotModel.Hub2
|
|
1147
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
1148
|
-
existingAccessory.context.deviceType = device.deviceType
|
|
1029
|
+
existingAccessory.context.device = device
|
|
1030
|
+
existingAccessory.context.model = SwitchBotModel.Hub2
|
|
1031
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
1032
|
+
existingAccessory.context.deviceType = device.deviceType
|
|
1149
1033
|
existingAccessory.displayName = device.configDeviceName
|
|
1150
1034
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1151
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1152
|
-
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1153
|
-
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1154
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1155
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
1035
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1036
|
+
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1037
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1038
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1039
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
1156
1040
|
// create the accessory handler for the restored accessory
|
|
1157
1041
|
// this is imported from `platformAccessory.ts`
|
|
1158
|
-
new Hub(this, existingAccessory, device)
|
|
1159
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1042
|
+
new Hub(this, existingAccessory, device)
|
|
1043
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1160
1044
|
} else {
|
|
1161
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
1045
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
1162
1046
|
}
|
|
1163
1047
|
} else if (await this.registerDevice(device)) {
|
|
1164
1048
|
// create a new accessory
|
|
1165
1049
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1166
1050
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1167
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1051
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1168
1052
|
|
|
1169
1053
|
// store a copy of the device object in the `accessory.context`
|
|
1170
1054
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1171
|
-
accessory.context.device = device
|
|
1172
|
-
accessory.context.model = SwitchBotModel.Hub2
|
|
1173
|
-
accessory.context.deviceId = device.deviceId
|
|
1174
|
-
accessory.context.deviceType = device.deviceType
|
|
1055
|
+
accessory.context.device = device
|
|
1056
|
+
accessory.context.model = SwitchBotModel.Hub2
|
|
1057
|
+
accessory.context.deviceId = device.deviceId
|
|
1058
|
+
accessory.context.deviceType = device.deviceType
|
|
1175
1059
|
accessory.displayName = device.configDeviceName
|
|
1176
1060
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1177
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1178
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1179
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1180
|
-
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1181
|
-
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1182
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1061
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1062
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1063
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1064
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1065
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1066
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1183
1067
|
// create the accessory handler for the newly create accessory
|
|
1184
1068
|
// this is imported from `platformAccessory.ts`
|
|
1185
|
-
new Hub(this, accessory, device)
|
|
1186
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1069
|
+
new Hub(this, accessory, device)
|
|
1070
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1187
1071
|
|
|
1188
1072
|
// publish device externally or link the accessory to your platform
|
|
1189
|
-
this.externalOrPlatform(device, accessory)
|
|
1190
|
-
this.accessories.push(accessory)
|
|
1073
|
+
this.externalOrPlatform(device, accessory)
|
|
1074
|
+
this.accessories.push(accessory)
|
|
1191
1075
|
} else {
|
|
1192
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1076
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1193
1077
|
}
|
|
1194
1078
|
}
|
|
1195
1079
|
|
|
1196
1080
|
private async createIOSensor(device: device & devicesConfig) {
|
|
1197
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1081
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1198
1082
|
|
|
1199
1083
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1200
1084
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1201
|
-
const existingAccessory = this.accessories.find(
|
|
1085
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
1202
1086
|
|
|
1203
1087
|
if (existingAccessory) {
|
|
1204
1088
|
// the accessory already exists
|
|
1205
1089
|
if (await this.registerDevice(device)) {
|
|
1206
1090
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1207
|
-
existingAccessory.context.device = device
|
|
1208
|
-
existingAccessory.context.model = SwitchBotModel.OutdoorMeter
|
|
1209
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
1210
|
-
existingAccessory.context.deviceType = device.deviceType
|
|
1091
|
+
existingAccessory.context.device = device
|
|
1092
|
+
existingAccessory.context.model = SwitchBotModel.OutdoorMeter
|
|
1093
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
1094
|
+
existingAccessory.context.deviceType = device.deviceType
|
|
1211
1095
|
existingAccessory.displayName = device.configDeviceName
|
|
1212
1096
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1213
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1214
|
-
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1215
|
-
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1216
|
-
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1217
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
1097
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1098
|
+
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1099
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1100
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1101
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
1218
1102
|
// create the accessory handler for the restored accessory
|
|
1219
1103
|
// this is imported from `platformAccessory.ts`
|
|
1220
|
-
new IOSensor(this, existingAccessory, device)
|
|
1221
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1104
|
+
new IOSensor(this, existingAccessory, device)
|
|
1105
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1222
1106
|
} else {
|
|
1223
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
1107
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
1224
1108
|
}
|
|
1225
1109
|
} else if (await this.registerDevice(device)) {
|
|
1226
1110
|
// create a new accessory
|
|
1227
1111
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1228
1112
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1229
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1113
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1230
1114
|
|
|
1231
1115
|
// store a copy of the device object in the `accessory.context`
|
|
1232
1116
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1233
|
-
accessory.context.device = device
|
|
1234
|
-
accessory.context.model = SwitchBotModel.OutdoorMeter
|
|
1235
|
-
accessory.context.deviceId = device.deviceId
|
|
1236
|
-
accessory.context.deviceType = device.deviceType
|
|
1117
|
+
accessory.context.device = device
|
|
1118
|
+
accessory.context.model = SwitchBotModel.OutdoorMeter
|
|
1119
|
+
accessory.context.deviceId = device.deviceId
|
|
1120
|
+
accessory.context.deviceType = device.deviceType
|
|
1237
1121
|
accessory.displayName = device.configDeviceName
|
|
1238
1122
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1239
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1240
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1241
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1242
|
-
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1243
|
-
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1244
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1123
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1124
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1125
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1126
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1127
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1128
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1245
1129
|
// create the accessory handler for the newly create accessory
|
|
1246
1130
|
// this is imported from `platformAccessory.ts`
|
|
1247
|
-
new IOSensor(this, accessory, device)
|
|
1248
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1131
|
+
new IOSensor(this, accessory, device)
|
|
1132
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1249
1133
|
|
|
1250
1134
|
// publish device externally or link the accessory to your platform
|
|
1251
|
-
this.externalOrPlatform(device, accessory)
|
|
1252
|
-
this.accessories.push(accessory)
|
|
1135
|
+
this.externalOrPlatform(device, accessory)
|
|
1136
|
+
this.accessories.push(accessory)
|
|
1253
1137
|
} else {
|
|
1254
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1138
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1255
1139
|
}
|
|
1256
1140
|
}
|
|
1257
1141
|
|
|
1258
1142
|
private async createWaterDetector(device: device & devicesConfig) {
|
|
1259
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1143
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1260
1144
|
|
|
1261
1145
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1262
1146
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1263
|
-
const existingAccessory = this.accessories.find(
|
|
1147
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
1264
1148
|
|
|
1265
1149
|
if (existingAccessory) {
|
|
1266
1150
|
// the accessory already exists
|
|
1267
1151
|
if (await this.registerDevice(device)) {
|
|
1268
1152
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1269
|
-
existingAccessory.context.device = device
|
|
1270
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
1271
|
-
existingAccessory.context.deviceType = device.deviceType
|
|
1272
|
-
existingAccessory.context.model = SwitchBotModel.WaterDetector
|
|
1153
|
+
existingAccessory.context.device = device
|
|
1154
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
1155
|
+
existingAccessory.context.deviceType = device.deviceType
|
|
1156
|
+
existingAccessory.context.model = SwitchBotModel.WaterDetector
|
|
1273
1157
|
existingAccessory.displayName = device.configDeviceName
|
|
1274
1158
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1275
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1276
|
-
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1277
|
-
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1278
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1279
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
1159
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1160
|
+
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1161
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1162
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1163
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
1280
1164
|
// create the accessory handler for the restored accessory
|
|
1281
1165
|
// this is imported from `platformAccessory.ts`
|
|
1282
|
-
new WaterDetector(this, existingAccessory, device)
|
|
1283
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1166
|
+
new WaterDetector(this, existingAccessory, device)
|
|
1167
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1284
1168
|
} else {
|
|
1285
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
1169
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
1286
1170
|
}
|
|
1287
1171
|
} else if (await this.registerDevice(device)) {
|
|
1288
1172
|
// create a new accessory
|
|
1289
1173
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1290
1174
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1291
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1175
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1292
1176
|
|
|
1293
1177
|
// store a copy of the device object in the `accessory.context`
|
|
1294
1178
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1295
|
-
accessory.context.device = device
|
|
1296
|
-
accessory.context.deviceId = device.deviceId
|
|
1297
|
-
accessory.context.deviceType = device.deviceType
|
|
1298
|
-
accessory.context.model = SwitchBotModel.WaterDetector
|
|
1179
|
+
accessory.context.device = device
|
|
1180
|
+
accessory.context.deviceId = device.deviceId
|
|
1181
|
+
accessory.context.deviceType = device.deviceType
|
|
1182
|
+
accessory.context.model = SwitchBotModel.WaterDetector
|
|
1299
1183
|
accessory.displayName = device.configDeviceName
|
|
1300
1184
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1301
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1302
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1303
|
-
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1304
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1305
|
-
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1306
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1185
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1186
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1187
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1188
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1189
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1190
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1307
1191
|
// create the accessory handler for the newly create accessory
|
|
1308
1192
|
// this is imported from `platformAccessory.ts`
|
|
1309
|
-
new WaterDetector(this, accessory, device)
|
|
1310
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1193
|
+
new WaterDetector(this, accessory, device)
|
|
1194
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1311
1195
|
|
|
1312
1196
|
// publish device externally or link the accessory to your platform
|
|
1313
|
-
this.externalOrPlatform(device, accessory)
|
|
1314
|
-
this.accessories.push(accessory)
|
|
1197
|
+
this.externalOrPlatform(device, accessory)
|
|
1198
|
+
this.accessories.push(accessory)
|
|
1315
1199
|
} else {
|
|
1316
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1200
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1317
1201
|
}
|
|
1318
1202
|
}
|
|
1319
1203
|
|
|
1320
1204
|
private async createMotion(device: device & devicesConfig) {
|
|
1321
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1205
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1322
1206
|
|
|
1323
1207
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1324
1208
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1325
|
-
const existingAccessory = this.accessories.find(
|
|
1209
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
1326
1210
|
|
|
1327
1211
|
if (existingAccessory) {
|
|
1328
1212
|
// the accessory already exists
|
|
1329
1213
|
if (await this.registerDevice(device)) {
|
|
1330
1214
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1331
|
-
existingAccessory.context.device = device
|
|
1332
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
1333
|
-
existingAccessory.context.deviceType = device.deviceType
|
|
1334
|
-
existingAccessory.context.model = SwitchBotModel.MotionSensor
|
|
1215
|
+
existingAccessory.context.device = device
|
|
1216
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
1217
|
+
existingAccessory.context.deviceType = device.deviceType
|
|
1218
|
+
existingAccessory.context.model = SwitchBotModel.MotionSensor
|
|
1335
1219
|
existingAccessory.displayName = device.configDeviceName
|
|
1336
1220
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1337
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1338
|
-
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1339
|
-
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1340
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1341
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
1221
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1222
|
+
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1223
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1224
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1225
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
1342
1226
|
// create the accessory handler for the restored accessory
|
|
1343
1227
|
// this is imported from `platformAccessory.ts`
|
|
1344
|
-
new Motion(this, existingAccessory, device)
|
|
1345
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1228
|
+
new Motion(this, existingAccessory, device)
|
|
1229
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1346
1230
|
} else {
|
|
1347
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
1231
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
1348
1232
|
}
|
|
1349
1233
|
} else if (await this.registerDevice(device)) {
|
|
1350
1234
|
// create a new accessory
|
|
1351
1235
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1352
1236
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1353
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1237
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1354
1238
|
|
|
1355
1239
|
// store a copy of the device object in the `accessory.context`
|
|
1356
1240
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1357
|
-
accessory.context.device = device
|
|
1358
|
-
accessory.context.deviceId = device.deviceId
|
|
1359
|
-
accessory.context.deviceType = device.deviceType
|
|
1360
|
-
accessory.context.model = SwitchBotModel.MotionSensor
|
|
1241
|
+
accessory.context.device = device
|
|
1242
|
+
accessory.context.deviceId = device.deviceId
|
|
1243
|
+
accessory.context.deviceType = device.deviceType
|
|
1244
|
+
accessory.context.model = SwitchBotModel.MotionSensor
|
|
1361
1245
|
accessory.displayName = device.configDeviceName
|
|
1362
1246
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1363
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1364
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1365
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1366
|
-
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1367
|
-
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1368
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1247
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1248
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1249
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1250
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1251
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1252
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1369
1253
|
// create the accessory handler for the newly create accessory
|
|
1370
1254
|
// this is imported from `platformAccessory.ts`
|
|
1371
|
-
new Motion(this, accessory, device)
|
|
1372
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1255
|
+
new Motion(this, accessory, device)
|
|
1256
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1373
1257
|
|
|
1374
1258
|
// publish device externally or link the accessory to your platform
|
|
1375
|
-
this.externalOrPlatform(device, accessory)
|
|
1376
|
-
this.accessories.push(accessory)
|
|
1259
|
+
this.externalOrPlatform(device, accessory)
|
|
1260
|
+
this.accessories.push(accessory)
|
|
1377
1261
|
} else {
|
|
1378
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1262
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1379
1263
|
}
|
|
1380
1264
|
}
|
|
1381
1265
|
|
|
1382
1266
|
private async createContact(device: device & devicesConfig) {
|
|
1383
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1267
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1384
1268
|
|
|
1385
1269
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1386
1270
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1387
|
-
const existingAccessory = this.accessories.find(
|
|
1271
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
1388
1272
|
|
|
1389
1273
|
if (existingAccessory) {
|
|
1390
1274
|
// the accessory already exists
|
|
1391
1275
|
if (await this.registerDevice(device)) {
|
|
1392
1276
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1393
|
-
existingAccessory.context.device = device
|
|
1394
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
1395
|
-
existingAccessory.context.deviceType = device.deviceType
|
|
1396
|
-
existingAccessory.context.model = SwitchBotModel.ContactSensor
|
|
1277
|
+
existingAccessory.context.device = device
|
|
1278
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
1279
|
+
existingAccessory.context.deviceType = device.deviceType
|
|
1280
|
+
existingAccessory.context.model = SwitchBotModel.ContactSensor
|
|
1397
1281
|
existingAccessory.displayName = device.configDeviceName
|
|
1398
1282
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1399
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1400
|
-
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1401
|
-
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1402
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1403
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
1283
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1284
|
+
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1285
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1286
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1287
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
1404
1288
|
// create the accessory handler for the restored accessory
|
|
1405
1289
|
// this is imported from `platformAccessory.ts`
|
|
1406
|
-
new Contact(this, existingAccessory, device)
|
|
1407
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1290
|
+
new Contact(this, existingAccessory, device)
|
|
1291
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1408
1292
|
} else {
|
|
1409
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
1293
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
1410
1294
|
}
|
|
1411
1295
|
} else if (await this.registerDevice(device)) {
|
|
1412
1296
|
// create a new accessory
|
|
1413
1297
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1414
1298
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1415
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1299
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1416
1300
|
|
|
1417
1301
|
// store a copy of the device object in the `accessory.context`
|
|
1418
1302
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1419
|
-
accessory.context.device = device
|
|
1420
|
-
accessory.context.deviceId = device.deviceId
|
|
1421
|
-
accessory.context.deviceType = device.deviceType
|
|
1422
|
-
accessory.context.model = SwitchBotModel.ContactSensor
|
|
1303
|
+
accessory.context.device = device
|
|
1304
|
+
accessory.context.deviceId = device.deviceId
|
|
1305
|
+
accessory.context.deviceType = device.deviceType
|
|
1306
|
+
accessory.context.model = SwitchBotModel.ContactSensor
|
|
1423
1307
|
accessory.displayName = device.configDeviceName
|
|
1424
1308
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1425
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1426
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1427
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1428
|
-
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1429
|
-
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1430
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1309
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1310
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1311
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1312
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1313
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1314
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1431
1315
|
// create the accessory handler for the newly create accessory
|
|
1432
1316
|
// this is imported from `platformAccessory.ts`
|
|
1433
|
-
new Contact(this, accessory, device)
|
|
1434
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1317
|
+
new Contact(this, accessory, device)
|
|
1318
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1435
1319
|
|
|
1436
1320
|
// publish device externally or link the accessory to your platform
|
|
1437
|
-
this.externalOrPlatform(device, accessory)
|
|
1438
|
-
this.accessories.push(accessory)
|
|
1321
|
+
this.externalOrPlatform(device, accessory)
|
|
1322
|
+
this.accessories.push(accessory)
|
|
1439
1323
|
} else {
|
|
1440
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1324
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1441
1325
|
}
|
|
1442
1326
|
}
|
|
1443
1327
|
|
|
1444
1328
|
private async createBlindTilt(device: device & devicesConfig) {
|
|
1445
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1329
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1446
1330
|
|
|
1447
1331
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1448
1332
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1449
|
-
const existingAccessory = this.accessories.find(
|
|
1333
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
1450
1334
|
|
|
1451
1335
|
if (existingAccessory) {
|
|
1452
1336
|
// the accessory already exists
|
|
1453
1337
|
if (await this.registerDevice(device)) {
|
|
1454
1338
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1455
|
-
existingAccessory.context.device = device
|
|
1456
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
1457
|
-
existingAccessory.context.deviceType = device.deviceType
|
|
1458
|
-
existingAccessory.context.model = SwitchBotModel.BlindTilt
|
|
1339
|
+
existingAccessory.context.device = device
|
|
1340
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
1341
|
+
existingAccessory.context.deviceType = device.deviceType
|
|
1342
|
+
existingAccessory.context.model = SwitchBotModel.BlindTilt
|
|
1459
1343
|
existingAccessory.displayName = device.configDeviceName
|
|
1460
1344
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1461
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1462
|
-
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1463
|
-
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1464
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1465
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
1345
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1346
|
+
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1347
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1348
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1349
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
1466
1350
|
// create the accessory handler for the restored accessory
|
|
1467
1351
|
// this is imported from `platformAccessory.ts`
|
|
1468
|
-
new BlindTilt(this, existingAccessory, device)
|
|
1469
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1352
|
+
new BlindTilt(this, existingAccessory, device)
|
|
1353
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1470
1354
|
} else {
|
|
1471
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
1355
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
1472
1356
|
}
|
|
1473
1357
|
} else if (await this.registerDevice(device)) {
|
|
1474
1358
|
if (isBlindTiltDevice(device)) {
|
|
1475
1359
|
if (device.group && !device.curtain?.disable_group) {
|
|
1476
1360
|
this.debugLog(
|
|
1477
|
-
'Your Curtains are grouped, '
|
|
1478
|
-
`, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}
|
|
1361
|
+
'Your Curtains are grouped, '
|
|
1362
|
+
+ `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`,
|
|
1363
|
+
)
|
|
1479
1364
|
} else {
|
|
1480
1365
|
if (device.master) {
|
|
1481
|
-
this.warnLog(`Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`)
|
|
1366
|
+
this.warnLog(`Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`)
|
|
1482
1367
|
} else {
|
|
1483
|
-
this.errorLog(`Secondary Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`)
|
|
1368
|
+
this.errorLog(`Secondary Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`)
|
|
1484
1369
|
}
|
|
1485
1370
|
}
|
|
1486
1371
|
}
|
|
@@ -1488,75 +1373,76 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1488
1373
|
// create a new accessory
|
|
1489
1374
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1490
1375
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1491
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1376
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1492
1377
|
|
|
1493
1378
|
// store a copy of the device object in the `accessory.context`
|
|
1494
1379
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1495
|
-
accessory.context.device = device
|
|
1496
|
-
accessory.context.deviceId = device.deviceId
|
|
1497
|
-
accessory.context.deviceType = device.deviceType
|
|
1498
|
-
accessory.context.model = SwitchBotModel.BlindTilt
|
|
1380
|
+
accessory.context.device = device
|
|
1381
|
+
accessory.context.deviceId = device.deviceId
|
|
1382
|
+
accessory.context.deviceType = device.deviceType
|
|
1383
|
+
accessory.context.model = SwitchBotModel.BlindTilt
|
|
1499
1384
|
accessory.displayName = device.configDeviceName
|
|
1500
1385
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1501
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1502
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1503
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1504
|
-
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1505
|
-
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1506
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1386
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1387
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1388
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1389
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1390
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1391
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1507
1392
|
// create the accessory handler for the newly create accessory
|
|
1508
1393
|
// this is imported from `platformAccessory.ts`
|
|
1509
|
-
new BlindTilt(this, accessory, device)
|
|
1510
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1394
|
+
new BlindTilt(this, accessory, device)
|
|
1395
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1511
1396
|
|
|
1512
1397
|
// publish device externally or link the accessory to your platform
|
|
1513
|
-
this.externalOrPlatform(device, accessory)
|
|
1514
|
-
this.accessories.push(accessory)
|
|
1398
|
+
this.externalOrPlatform(device, accessory)
|
|
1399
|
+
this.accessories.push(accessory)
|
|
1515
1400
|
} else {
|
|
1516
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1401
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1517
1402
|
}
|
|
1518
1403
|
}
|
|
1519
1404
|
|
|
1520
1405
|
private async createCurtain(device: device & devicesConfig) {
|
|
1521
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1406
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1522
1407
|
|
|
1523
1408
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1524
1409
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1525
|
-
const existingAccessory = this.accessories.find(
|
|
1410
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
1526
1411
|
|
|
1527
1412
|
if (existingAccessory) {
|
|
1528
1413
|
// the accessory already exists
|
|
1529
1414
|
if (await this.registerDevice(device)) {
|
|
1530
1415
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1531
|
-
existingAccessory.context.device = device
|
|
1532
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
1533
|
-
existingAccessory.context.deviceType = device.deviceType
|
|
1534
|
-
existingAccessory.context.model = device.deviceType === 'Curtain3' ? SwitchBotModel.Curtain3 : SwitchBotModel.Curtain
|
|
1416
|
+
existingAccessory.context.device = device
|
|
1417
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
1418
|
+
existingAccessory.context.deviceType = device.deviceType
|
|
1419
|
+
existingAccessory.context.model = device.deviceType === 'Curtain3' ? SwitchBotModel.Curtain3 : SwitchBotModel.Curtain
|
|
1535
1420
|
existingAccessory.displayName = device.configDeviceName
|
|
1536
1421
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1537
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1538
|
-
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1539
|
-
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1540
|
-
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1541
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
1422
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1423
|
+
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1424
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1425
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1426
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
1542
1427
|
// create the accessory handler for the restored accessory
|
|
1543
1428
|
// this is imported from `platformAccessory.ts`
|
|
1544
|
-
new Curtain(this, existingAccessory, device)
|
|
1545
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1429
|
+
new Curtain(this, existingAccessory, device)
|
|
1430
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1546
1431
|
} else {
|
|
1547
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
1432
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
1548
1433
|
}
|
|
1549
1434
|
} else if (await this.registerDevice(device)) {
|
|
1550
1435
|
if (isCurtainDevice(device)) {
|
|
1551
1436
|
if (device.group && !device.curtain?.disable_group) {
|
|
1552
1437
|
this.debugLog(
|
|
1553
|
-
'Your Curtains are grouped, '
|
|
1554
|
-
`, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}
|
|
1438
|
+
'Your Curtains are grouped, '
|
|
1439
|
+
+ `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`,
|
|
1440
|
+
)
|
|
1555
1441
|
} else {
|
|
1556
1442
|
if (device.master) {
|
|
1557
|
-
this.warnLog(`Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`)
|
|
1443
|
+
this.warnLog(`Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`)
|
|
1558
1444
|
} else {
|
|
1559
|
-
this.errorLog(`Secondary Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`)
|
|
1445
|
+
this.errorLog(`Secondary Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`)
|
|
1560
1446
|
}
|
|
1561
1447
|
}
|
|
1562
1448
|
}
|
|
@@ -1564,1375 +1450,1277 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1564
1450
|
// create a new accessory
|
|
1565
1451
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1566
1452
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1567
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1453
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1568
1454
|
|
|
1569
1455
|
// store a copy of the device object in the `accessory.context`
|
|
1570
1456
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1571
|
-
accessory.context.device = device
|
|
1572
|
-
accessory.context.deviceId = device.deviceId
|
|
1573
|
-
accessory.context.deviceType = device.deviceType
|
|
1574
|
-
accessory.context.model = device.deviceType === 'Curtain3' ? SwitchBotModel.Curtain3 : SwitchBotModel.Curtain
|
|
1457
|
+
accessory.context.device = device
|
|
1458
|
+
accessory.context.deviceId = device.deviceId
|
|
1459
|
+
accessory.context.deviceType = device.deviceType
|
|
1460
|
+
accessory.context.model = device.deviceType === 'Curtain3' ? SwitchBotModel.Curtain3 : SwitchBotModel.Curtain
|
|
1575
1461
|
accessory.displayName = device.configDeviceName
|
|
1576
1462
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1577
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1578
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1579
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1580
|
-
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1581
|
-
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1582
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1463
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1464
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1465
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1466
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1467
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1468
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1583
1469
|
// create the accessory handler for the newly create accessory
|
|
1584
1470
|
// this is imported from `platformAccessory.ts`
|
|
1585
|
-
new Curtain(this, accessory, device)
|
|
1586
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1471
|
+
new Curtain(this, accessory, device)
|
|
1472
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1587
1473
|
|
|
1588
1474
|
// publish device externally or link the accessory to your platform
|
|
1589
|
-
this.externalOrPlatform(device, accessory)
|
|
1590
|
-
this.accessories.push(accessory)
|
|
1475
|
+
this.externalOrPlatform(device, accessory)
|
|
1476
|
+
this.accessories.push(accessory)
|
|
1591
1477
|
} else {
|
|
1592
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1478
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1593
1479
|
}
|
|
1594
1480
|
}
|
|
1595
1481
|
|
|
1596
1482
|
private async createPlug(device: device & devicesConfig) {
|
|
1597
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1483
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1598
1484
|
|
|
1599
1485
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1600
1486
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1601
|
-
const existingAccessory = this.accessories.find(
|
|
1487
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
1602
1488
|
|
|
1603
1489
|
if (existingAccessory) {
|
|
1604
1490
|
// the accessory already exists
|
|
1605
1491
|
if (await this.registerDevice(device)) {
|
|
1606
1492
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1607
|
-
existingAccessory.context.device = device
|
|
1608
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
1609
|
-
existingAccessory.context.deviceType = device.deviceType
|
|
1610
|
-
existingAccessory.context.model = device.deviceType === 'Plug Mini (US)'
|
|
1611
|
-
? SwitchBotModel.
|
|
1493
|
+
existingAccessory.context.device = device
|
|
1494
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
1495
|
+
existingAccessory.context.deviceType = device.deviceType
|
|
1496
|
+
existingAccessory.context.model = device.deviceType === 'Plug Mini (US)'
|
|
1497
|
+
? SwitchBotModel.PlugMiniUS
|
|
1498
|
+
: device.deviceType === 'Plug Mini (JP)'
|
|
1499
|
+
? SwitchBotModel.PlugMiniJP
|
|
1500
|
+
: SwitchBotModel.Plug
|
|
1612
1501
|
existingAccessory.displayName = device.configDeviceName
|
|
1613
1502
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1614
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1615
|
-
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1616
|
-
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1617
|
-
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1618
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
1503
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1504
|
+
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1505
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1506
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1507
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
1619
1508
|
// create the accessory handler for the restored accessory
|
|
1620
1509
|
// this is imported from `platformAccessory.ts`
|
|
1621
|
-
new Plug(this, existingAccessory, device)
|
|
1622
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1510
|
+
new Plug(this, existingAccessory, device)
|
|
1511
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1623
1512
|
} else {
|
|
1624
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
1513
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
1625
1514
|
}
|
|
1626
1515
|
} else if (await this.registerDevice(device)) {
|
|
1627
1516
|
// create a new accessory
|
|
1628
1517
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1629
1518
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1630
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1519
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1631
1520
|
|
|
1632
1521
|
// store a copy of the device object in the `accessory.context`
|
|
1633
1522
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1634
|
-
accessory.context.device = device
|
|
1635
|
-
accessory.context.deviceId = device.deviceId
|
|
1636
|
-
accessory.context.deviceType = device.deviceType
|
|
1637
|
-
accessory.context.model = device.deviceType === 'Plug Mini (US)'
|
|
1638
|
-
? SwitchBotModel.
|
|
1523
|
+
accessory.context.device = device
|
|
1524
|
+
accessory.context.deviceId = device.deviceId
|
|
1525
|
+
accessory.context.deviceType = device.deviceType
|
|
1526
|
+
accessory.context.model = device.deviceType === 'Plug Mini (US)'
|
|
1527
|
+
? SwitchBotModel.PlugMiniUS
|
|
1528
|
+
: device.deviceType === 'Plug Mini (JP)'
|
|
1529
|
+
? SwitchBotModel.PlugMiniJP
|
|
1530
|
+
: SwitchBotModel.Plug
|
|
1639
1531
|
accessory.displayName = device.configDeviceName
|
|
1640
1532
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1641
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1642
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1643
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1644
|
-
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1645
|
-
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1646
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1533
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1534
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1535
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1536
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1537
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1538
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1647
1539
|
// create the accessory handler for the newly create accessory
|
|
1648
1540
|
// this is imported from `platformAccessory.ts`
|
|
1649
|
-
new Plug(this, accessory, device)
|
|
1650
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1541
|
+
new Plug(this, accessory, device)
|
|
1542
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1651
1543
|
|
|
1652
1544
|
// publish device externally or link the accessory to your platform
|
|
1653
|
-
this.externalOrPlatform(device, accessory)
|
|
1654
|
-
this.accessories.push(accessory)
|
|
1545
|
+
this.externalOrPlatform(device, accessory)
|
|
1546
|
+
this.accessories.push(accessory)
|
|
1655
1547
|
} else {
|
|
1656
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1548
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1657
1549
|
}
|
|
1658
1550
|
}
|
|
1659
1551
|
|
|
1660
1552
|
private async createLock(device: device & devicesConfig) {
|
|
1661
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1553
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1662
1554
|
|
|
1663
1555
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1664
1556
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1665
|
-
const existingAccessory = this.accessories.find(
|
|
1557
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
1666
1558
|
|
|
1667
1559
|
if (existingAccessory) {
|
|
1668
1560
|
// the accessory already exists
|
|
1669
1561
|
if (await this.registerDevice(device)) {
|
|
1670
1562
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1671
|
-
existingAccessory.context.device = device
|
|
1672
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
1673
|
-
existingAccessory.context.deviceType = device.deviceType
|
|
1674
|
-
existingAccessory.context.model = device.deviceType === 'Smart Lock Pro' ? SwitchBotModel.LockPro : SwitchBotModel.Lock
|
|
1563
|
+
existingAccessory.context.device = device
|
|
1564
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
1565
|
+
existingAccessory.context.deviceType = device.deviceType
|
|
1566
|
+
existingAccessory.context.model = device.deviceType === 'Smart Lock Pro' ? SwitchBotModel.LockPro : SwitchBotModel.Lock
|
|
1675
1567
|
existingAccessory.displayName = device.configDeviceName
|
|
1676
1568
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1677
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1678
|
-
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1679
|
-
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1680
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1681
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
1569
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1570
|
+
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1571
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1572
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1573
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
1682
1574
|
// create the accessory handler for the restored accessory
|
|
1683
1575
|
// this is imported from `platformAccessory.ts`
|
|
1684
|
-
new Lock(this, existingAccessory, device)
|
|
1685
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1576
|
+
new Lock(this, existingAccessory, device)
|
|
1577
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1686
1578
|
} else {
|
|
1687
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
1579
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
1688
1580
|
}
|
|
1689
1581
|
} else if (await this.registerDevice(device)) {
|
|
1690
1582
|
// create a new accessory
|
|
1691
1583
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1692
1584
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1693
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1585
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1694
1586
|
|
|
1695
1587
|
// store a copy of the device object in the `accessory.context`
|
|
1696
1588
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1697
|
-
accessory.context.device = device
|
|
1698
|
-
accessory.context.deviceId = device.deviceId
|
|
1699
|
-
accessory.context.deviceType = device.deviceType
|
|
1700
|
-
accessory.context.model = device.deviceType === 'Smart Lock Pro' ? SwitchBotModel.LockPro : SwitchBotModel.Lock
|
|
1589
|
+
accessory.context.device = device
|
|
1590
|
+
accessory.context.deviceId = device.deviceId
|
|
1591
|
+
accessory.context.deviceType = device.deviceType
|
|
1592
|
+
accessory.context.model = device.deviceType === 'Smart Lock Pro' ? SwitchBotModel.LockPro : SwitchBotModel.Lock
|
|
1701
1593
|
accessory.displayName = device.configDeviceName
|
|
1702
1594
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1703
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1704
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1705
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1706
|
-
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1707
|
-
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1708
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1595
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1596
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1597
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1598
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1599
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1600
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1709
1601
|
// create the accessory handler for the newly create accessory
|
|
1710
1602
|
// this is imported from `platformAccessory.ts`
|
|
1711
|
-
new Lock(this, accessory, device)
|
|
1712
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1603
|
+
new Lock(this, accessory, device)
|
|
1604
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1713
1605
|
|
|
1714
1606
|
// publish device externally or link the accessory to your platform
|
|
1715
|
-
this.externalOrPlatform(device, accessory)
|
|
1716
|
-
this.accessories.push(accessory)
|
|
1607
|
+
this.externalOrPlatform(device, accessory)
|
|
1608
|
+
this.accessories.push(accessory)
|
|
1717
1609
|
} else {
|
|
1718
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1610
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1719
1611
|
}
|
|
1720
1612
|
}
|
|
1721
1613
|
|
|
1722
1614
|
private async createColorBulb(device: device & devicesConfig) {
|
|
1723
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1615
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1724
1616
|
|
|
1725
1617
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1726
1618
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1727
|
-
const existingAccessory = this.accessories.find(
|
|
1619
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
1728
1620
|
|
|
1729
1621
|
if (existingAccessory) {
|
|
1730
1622
|
// the accessory already exists
|
|
1731
1623
|
if (await this.registerDevice(device)) {
|
|
1732
1624
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1733
|
-
existingAccessory.context.device = device
|
|
1734
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
1735
|
-
existingAccessory.context.deviceType = device.deviceType
|
|
1736
|
-
existingAccessory.context.model = SwitchBotModel.ColorBulb
|
|
1625
|
+
existingAccessory.context.device = device
|
|
1626
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
1627
|
+
existingAccessory.context.deviceType = device.deviceType
|
|
1628
|
+
existingAccessory.context.model = SwitchBotModel.ColorBulb
|
|
1737
1629
|
existingAccessory.displayName = device.configDeviceName
|
|
1738
1630
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1739
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1740
|
-
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1741
|
-
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1742
|
-
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1743
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
1631
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1632
|
+
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1633
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1634
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1635
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
1744
1636
|
// create the accessory handler for the restored accessory
|
|
1745
1637
|
// this is imported from `platformAccessory.ts`
|
|
1746
|
-
new ColorBulb(this, existingAccessory, device)
|
|
1747
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1638
|
+
new ColorBulb(this, existingAccessory, device)
|
|
1639
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1748
1640
|
} else {
|
|
1749
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
1641
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
1750
1642
|
}
|
|
1751
1643
|
} else if (await this.registerDevice(device)) {
|
|
1752
1644
|
// create a new accessory
|
|
1753
1645
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1754
1646
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1755
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1647
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1756
1648
|
|
|
1757
1649
|
// store a copy of the device object in the `accessory.context`
|
|
1758
1650
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1759
|
-
accessory.context.device = device
|
|
1760
|
-
accessory.context.deviceId = device.deviceId
|
|
1761
|
-
accessory.context.deviceType = device.deviceType
|
|
1762
|
-
accessory.context.model = SwitchBotModel.ColorBulb
|
|
1651
|
+
accessory.context.device = device
|
|
1652
|
+
accessory.context.deviceId = device.deviceId
|
|
1653
|
+
accessory.context.deviceType = device.deviceType
|
|
1654
|
+
accessory.context.model = SwitchBotModel.ColorBulb
|
|
1763
1655
|
accessory.displayName = device.configDeviceName
|
|
1764
1656
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1765
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1766
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1767
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1768
|
-
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1769
|
-
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1770
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1657
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1658
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1659
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1660
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1661
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1662
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1771
1663
|
// create the accessory handler for the newly create accessory
|
|
1772
1664
|
// this is imported from `platformAccessory.ts`
|
|
1773
|
-
new ColorBulb(this, accessory, device)
|
|
1774
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1665
|
+
new ColorBulb(this, accessory, device)
|
|
1666
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1775
1667
|
|
|
1776
1668
|
// publish device externally or link the accessory to your platform
|
|
1777
|
-
this.externalOrPlatform(device, accessory)
|
|
1778
|
-
this.accessories.push(accessory)
|
|
1669
|
+
this.externalOrPlatform(device, accessory)
|
|
1670
|
+
this.accessories.push(accessory)
|
|
1779
1671
|
} else {
|
|
1780
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1672
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1781
1673
|
}
|
|
1782
1674
|
}
|
|
1783
1675
|
|
|
1784
1676
|
private async createCeilingLight(device: device & devicesConfig) {
|
|
1785
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1677
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1786
1678
|
|
|
1787
1679
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1788
1680
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1789
|
-
const existingAccessory = this.accessories.find(
|
|
1681
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
1790
1682
|
|
|
1791
1683
|
if (existingAccessory) {
|
|
1792
1684
|
// the accessory already exists
|
|
1793
1685
|
if (await this.registerDevice(device)) {
|
|
1794
1686
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1795
|
-
existingAccessory.context.device = device
|
|
1796
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
1797
|
-
existingAccessory.context.deviceType = device.deviceType
|
|
1798
|
-
existingAccessory.context.model = device.deviceType === 'Ceiling Light Pro' ? SwitchBotModel.CeilingLightPro : SwitchBotModel.CeilingLight
|
|
1687
|
+
existingAccessory.context.device = device
|
|
1688
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
1689
|
+
existingAccessory.context.deviceType = device.deviceType
|
|
1690
|
+
existingAccessory.context.model = device.deviceType === 'Ceiling Light Pro' ? SwitchBotModel.CeilingLightPro : SwitchBotModel.CeilingLight
|
|
1799
1691
|
existingAccessory.displayName = device.configDeviceName
|
|
1800
1692
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1801
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1802
|
-
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1803
|
-
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1804
|
-
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1805
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
1693
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1694
|
+
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1695
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1696
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1697
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
1806
1698
|
// create the accessory handler for the restored accessory
|
|
1807
1699
|
// this is imported from `platformAccessory.ts`
|
|
1808
|
-
new CeilingLight(this, existingAccessory, device)
|
|
1809
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1700
|
+
new CeilingLight(this, existingAccessory, device)
|
|
1701
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1810
1702
|
} else {
|
|
1811
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
1703
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
1812
1704
|
}
|
|
1813
1705
|
} else if (await this.registerDevice(device)) {
|
|
1814
1706
|
// create a new accessory
|
|
1815
1707
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1816
1708
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1817
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1709
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1818
1710
|
|
|
1819
1711
|
// store a copy of the device object in the `accessory.context`
|
|
1820
1712
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1821
|
-
accessory.context.device = device
|
|
1822
|
-
accessory.context.deviceId = device.deviceId
|
|
1823
|
-
accessory.context.deviceType = device.deviceType
|
|
1824
|
-
accessory.context.model = device.deviceType === 'Ceiling Light Pro' ? SwitchBotModel.CeilingLightPro : SwitchBotModel.CeilingLight
|
|
1713
|
+
accessory.context.device = device
|
|
1714
|
+
accessory.context.deviceId = device.deviceId
|
|
1715
|
+
accessory.context.deviceType = device.deviceType
|
|
1716
|
+
accessory.context.model = device.deviceType === 'Ceiling Light Pro' ? SwitchBotModel.CeilingLightPro : SwitchBotModel.CeilingLight
|
|
1825
1717
|
accessory.displayName = device.configDeviceName
|
|
1826
1718
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1827
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1828
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1829
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1830
|
-
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1831
|
-
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1832
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1719
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1720
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1721
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1722
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1723
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1724
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1833
1725
|
// create the accessory handler for the newly create accessory
|
|
1834
1726
|
// this is imported from `platformAccessory.ts`
|
|
1835
|
-
new CeilingLight(this, accessory, device)
|
|
1836
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1727
|
+
new CeilingLight(this, accessory, device)
|
|
1728
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1837
1729
|
|
|
1838
1730
|
// publish device externally or link the accessory to your platform
|
|
1839
|
-
this.externalOrPlatform(device, accessory)
|
|
1840
|
-
this.accessories.push(accessory)
|
|
1731
|
+
this.externalOrPlatform(device, accessory)
|
|
1732
|
+
this.accessories.push(accessory)
|
|
1841
1733
|
} else {
|
|
1842
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1734
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1843
1735
|
}
|
|
1844
1736
|
}
|
|
1845
1737
|
|
|
1846
1738
|
private async createStripLight(device: device & devicesConfig) {
|
|
1847
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1739
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1848
1740
|
|
|
1849
1741
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1850
1742
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1851
|
-
const existingAccessory = this.accessories.find(
|
|
1743
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
1852
1744
|
|
|
1853
1745
|
if (existingAccessory) {
|
|
1854
1746
|
// the accessory already exists
|
|
1855
1747
|
if (await this.registerDevice(device)) {
|
|
1856
1748
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1857
|
-
existingAccessory.context.device = device
|
|
1858
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
1859
|
-
existingAccessory.context.deviceType = device.deviceType
|
|
1860
|
-
existingAccessory.context.model = SwitchBotModel.StripLight
|
|
1749
|
+
existingAccessory.context.device = device
|
|
1750
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
1751
|
+
existingAccessory.context.deviceType = device.deviceType
|
|
1752
|
+
existingAccessory.context.model = SwitchBotModel.StripLight
|
|
1861
1753
|
existingAccessory.displayName = device.configDeviceName
|
|
1862
1754
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1863
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1864
|
-
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1865
|
-
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1866
|
-
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1867
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
1755
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1756
|
+
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1757
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1758
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1759
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
1868
1760
|
// create the accessory handler for the restored accessory
|
|
1869
1761
|
// this is imported from `platformAccessory.ts`
|
|
1870
|
-
new StripLight(this, existingAccessory, device)
|
|
1871
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1762
|
+
new StripLight(this, existingAccessory, device)
|
|
1763
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1872
1764
|
} else {
|
|
1873
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
1765
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
1874
1766
|
}
|
|
1875
1767
|
} else if (await this.registerDevice(device)) {
|
|
1876
1768
|
// create a new accessory
|
|
1877
1769
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1878
1770
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1879
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1771
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1880
1772
|
|
|
1881
1773
|
// store a copy of the device object in the `accessory.context`
|
|
1882
1774
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1883
|
-
accessory.context.device = device
|
|
1884
|
-
accessory.context.deviceId = device.deviceId
|
|
1885
|
-
accessory.context.deviceType = device.deviceType
|
|
1886
|
-
accessory.context.model = SwitchBotModel.StripLight
|
|
1775
|
+
accessory.context.device = device
|
|
1776
|
+
accessory.context.deviceId = device.deviceId
|
|
1777
|
+
accessory.context.deviceType = device.deviceType
|
|
1778
|
+
accessory.context.model = SwitchBotModel.StripLight
|
|
1887
1779
|
accessory.displayName = device.configDeviceName
|
|
1888
1780
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1889
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1890
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1891
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1892
|
-
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1893
|
-
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1894
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1781
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1782
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1783
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1784
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1785
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1786
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1895
1787
|
// create the accessory handler for the newly create accessory
|
|
1896
1788
|
// this is imported from `platformAccessory.ts`
|
|
1897
|
-
new StripLight(this, accessory, device)
|
|
1898
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1789
|
+
new StripLight(this, accessory, device)
|
|
1790
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1899
1791
|
|
|
1900
1792
|
// publish device externally or link the accessory to your platform
|
|
1901
|
-
this.externalOrPlatform(device, accessory)
|
|
1902
|
-
this.accessories.push(accessory)
|
|
1793
|
+
this.externalOrPlatform(device, accessory)
|
|
1794
|
+
this.accessories.push(accessory)
|
|
1903
1795
|
} else {
|
|
1904
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1796
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1905
1797
|
}
|
|
1906
1798
|
}
|
|
1907
1799
|
|
|
1908
1800
|
private async createFan(device: device & devicesConfig) {
|
|
1909
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1801
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1910
1802
|
|
|
1911
1803
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1912
1804
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1913
|
-
const existingAccessory = this.accessories.find(
|
|
1805
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
1914
1806
|
|
|
1915
1807
|
if (existingAccessory) {
|
|
1916
1808
|
// the accessory already exists
|
|
1917
1809
|
if (await this.registerDevice(device)) {
|
|
1918
1810
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1919
|
-
existingAccessory.context.device = device
|
|
1920
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
1921
|
-
existingAccessory.context.deviceType = device.deviceType
|
|
1922
|
-
existingAccessory.context.model = SwitchBotModel.BatteryCirculatorFan
|
|
1811
|
+
existingAccessory.context.device = device
|
|
1812
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
1813
|
+
existingAccessory.context.deviceType = device.deviceType
|
|
1814
|
+
existingAccessory.context.model = SwitchBotModel.BatteryCirculatorFan
|
|
1923
1815
|
existingAccessory.displayName = device.configDeviceName
|
|
1924
1816
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1925
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1926
|
-
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1927
|
-
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1928
|
-
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1929
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
1817
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1818
|
+
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1819
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1820
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1821
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
1930
1822
|
// create the accessory handler for the restored accessory
|
|
1931
1823
|
// this is imported from `platformAccessory.ts`
|
|
1932
|
-
new Fan(this, existingAccessory, device)
|
|
1933
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1824
|
+
new Fan(this, existingAccessory, device)
|
|
1825
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1934
1826
|
} else {
|
|
1935
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
1827
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
1936
1828
|
}
|
|
1937
1829
|
} else if (await this.registerDevice(device)) {
|
|
1938
1830
|
// create a new accessory
|
|
1939
1831
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1940
1832
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1941
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1833
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1942
1834
|
|
|
1943
1835
|
// store a copy of the device object in the `accessory.context`
|
|
1944
1836
|
// the `context` property can be used to store any data about the accessory you may need
|
|
1945
|
-
accessory.context.device = device
|
|
1946
|
-
accessory.context.deviceId = device.deviceId
|
|
1947
|
-
accessory.context.deviceType = device.deviceType
|
|
1948
|
-
accessory.context.model = SwitchBotModel.BatteryCirculatorFan
|
|
1837
|
+
accessory.context.device = device
|
|
1838
|
+
accessory.context.deviceId = device.deviceId
|
|
1839
|
+
accessory.context.deviceType = device.deviceType
|
|
1840
|
+
accessory.context.model = SwitchBotModel.BatteryCirculatorFan
|
|
1949
1841
|
accessory.displayName = device.configDeviceName
|
|
1950
1842
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1951
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1952
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1953
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
1954
|
-
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1955
|
-
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1956
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1843
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1844
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1845
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1846
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1847
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1848
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1957
1849
|
// create the accessory handler for the newly create accessory
|
|
1958
1850
|
// this is imported from `platformAccessory.ts`
|
|
1959
|
-
new Fan(this, accessory, device)
|
|
1960
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1851
|
+
new Fan(this, accessory, device)
|
|
1852
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1961
1853
|
|
|
1962
1854
|
// publish device externally or link the accessory to your platform
|
|
1963
|
-
this.externalOrPlatform(device, accessory)
|
|
1964
|
-
this.accessories.push(accessory)
|
|
1855
|
+
this.externalOrPlatform(device, accessory)
|
|
1856
|
+
this.accessories.push(accessory)
|
|
1965
1857
|
} else {
|
|
1966
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1858
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1967
1859
|
}
|
|
1968
1860
|
}
|
|
1969
1861
|
|
|
1970
1862
|
private async createRobotVacuumCleaner(device: device & devicesConfig) {
|
|
1971
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1863
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
|
|
1972
1864
|
|
|
1973
1865
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1974
1866
|
// the cached devices we stored in the `configureAccessory` method above
|
|
1975
|
-
const existingAccessory = this.accessories.find(
|
|
1867
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
1976
1868
|
|
|
1977
1869
|
if (existingAccessory) {
|
|
1978
1870
|
// the accessory already exists
|
|
1979
1871
|
if (await this.registerDevice(device)) {
|
|
1980
1872
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1981
|
-
existingAccessory.context.device = device
|
|
1982
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
1983
|
-
existingAccessory.context.deviceType = device.deviceType
|
|
1984
|
-
existingAccessory.context.model = device.deviceType === 'Robot Vacuum Cleaner S1'
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1873
|
+
existingAccessory.context.device = device
|
|
1874
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
1875
|
+
existingAccessory.context.deviceType = device.deviceType
|
|
1876
|
+
existingAccessory.context.model = device.deviceType === 'Robot Vacuum Cleaner S1'
|
|
1877
|
+
? SwitchBotModel.RobotVacuumCleanerS1
|
|
1878
|
+
: device.deviceType === 'Robot Vacuum Cleaner S1 Plus'
|
|
1879
|
+
? SwitchBotModel.RobotVacuumCleanerS1Plus
|
|
1880
|
+
: device.deviceType === 'Robot Vacuum Cleaner S10'
|
|
1881
|
+
? SwitchBotModel.RobotVacuumCleanerS10
|
|
1882
|
+
: device.deviceType === 'WoSweeper'
|
|
1883
|
+
? SwitchBotModel.WoSweeper
|
|
1884
|
+
: device.deviceType === 'WoSweeperMini'
|
|
1885
|
+
? SwitchBotModel.WoSweeperMini
|
|
1886
|
+
: SwitchBotModel.Unknown
|
|
1989
1887
|
existingAccessory.displayName = device.configDeviceName
|
|
1990
1888
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1991
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1992
|
-
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1993
|
-
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1994
|
-
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1995
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
1889
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1890
|
+
existingAccessory.context.connectionType = await this.connectionType(device)
|
|
1891
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1892
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1893
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
1996
1894
|
// create the accessory handler for the restored accessory
|
|
1997
1895
|
// this is imported from `platformAccessory.ts`
|
|
1998
|
-
new RobotVacuumCleaner(this, existingAccessory, device)
|
|
1999
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
1896
|
+
new RobotVacuumCleaner(this, existingAccessory, device)
|
|
1897
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
|
|
2000
1898
|
} else {
|
|
2001
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
1899
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
2002
1900
|
}
|
|
2003
1901
|
} else if (await this.registerDevice(device)) {
|
|
2004
1902
|
// create a new accessory
|
|
2005
1903
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
2006
1904
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2007
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1905
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
2008
1906
|
|
|
2009
1907
|
// store a copy of the device object in the `accessory.context`
|
|
2010
1908
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2011
|
-
accessory.context.device = device
|
|
2012
|
-
accessory.context.deviceId = device.deviceId
|
|
2013
|
-
accessory.context.deviceType = device.deviceType
|
|
2014
|
-
accessory.context.model = device.deviceType === 'Robot Vacuum Cleaner S1'
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
1909
|
+
accessory.context.device = device
|
|
1910
|
+
accessory.context.deviceId = device.deviceId
|
|
1911
|
+
accessory.context.deviceType = device.deviceType
|
|
1912
|
+
accessory.context.model = device.deviceType === 'Robot Vacuum Cleaner S1'
|
|
1913
|
+
? SwitchBotModel.RobotVacuumCleanerS1
|
|
1914
|
+
: device.deviceType === 'Robot Vacuum Cleaner S1 Plus'
|
|
1915
|
+
? SwitchBotModel.RobotVacuumCleanerS1Plus
|
|
1916
|
+
: device.deviceType === 'Robot Vacuum Cleaner S10'
|
|
1917
|
+
? SwitchBotModel.RobotVacuumCleanerS10
|
|
1918
|
+
: device.deviceType === 'WoSweeper'
|
|
1919
|
+
? SwitchBotModel.WoSweeper
|
|
1920
|
+
: device.deviceType === 'WoSweeperMini'
|
|
1921
|
+
? SwitchBotModel.WoSweeperMini
|
|
1922
|
+
: SwitchBotModel.Unknown
|
|
2019
1923
|
accessory.displayName = device.configDeviceName
|
|
2020
1924
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2021
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2022
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
2023
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
2024
|
-
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
2025
|
-
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
2026
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
1925
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1926
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1927
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1928
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1929
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1930
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
2027
1931
|
// create the accessory handler for the newly create accessory
|
|
2028
1932
|
// this is imported from `platformAccessory.ts`
|
|
2029
|
-
new RobotVacuumCleaner(this, accessory, device)
|
|
2030
|
-
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
1933
|
+
new RobotVacuumCleaner(this, accessory, device)
|
|
1934
|
+
await this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
|
|
2031
1935
|
|
|
2032
1936
|
// publish device externally or link the accessory to your platform
|
|
2033
|
-
this.externalOrPlatform(device, accessory)
|
|
2034
|
-
this.accessories.push(accessory)
|
|
1937
|
+
this.externalOrPlatform(device, accessory)
|
|
1938
|
+
this.accessories.push(accessory)
|
|
2035
1939
|
} else {
|
|
2036
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
1940
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
|
|
2037
1941
|
}
|
|
2038
1942
|
}
|
|
2039
1943
|
|
|
2040
1944
|
private async createTV(device: irdevice & devicesConfig) {
|
|
2041
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
|
|
1945
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
|
|
2042
1946
|
|
|
2043
1947
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
2044
1948
|
// the cached devices we stored in the `configureAccessory` method above
|
|
2045
|
-
const existingAccessory = this.accessories.find(
|
|
1949
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
2046
1950
|
|
|
2047
1951
|
if (!device.hide_device && existingAccessory) {
|
|
2048
1952
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
2049
|
-
existingAccessory.context.device = device
|
|
2050
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
2051
|
-
existingAccessory.context.deviceType = `IR: ${device.remoteType}
|
|
2052
|
-
existingAccessory.context.model = device.remoteType
|
|
1953
|
+
existingAccessory.context.device = device
|
|
1954
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
1955
|
+
existingAccessory.context.deviceType = `IR: ${device.remoteType}`
|
|
1956
|
+
existingAccessory.context.model = device.remoteType
|
|
2053
1957
|
existingAccessory.displayName = device.configDeviceName
|
|
2054
1958
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2055
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2056
|
-
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
2057
|
-
existingAccessory.context.connectionType = device.connectionType
|
|
2058
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
1959
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1960
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
1961
|
+
existingAccessory.context.connectionType = device.connectionType
|
|
1962
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
2059
1963
|
// create the accessory handler for the restored accessory
|
|
2060
1964
|
// this is imported from `platformAccessory.ts`
|
|
2061
|
-
new TV(this, existingAccessory, device)
|
|
2062
|
-
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`)
|
|
1965
|
+
new TV(this, existingAccessory, device)
|
|
1966
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`)
|
|
2063
1967
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
2064
1968
|
// create a new accessory
|
|
2065
1969
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
2066
1970
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2067
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
1971
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
2068
1972
|
|
|
2069
1973
|
// store a copy of the device object in the `accessory.context`
|
|
2070
1974
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2071
|
-
accessory.context.device = device
|
|
2072
|
-
accessory.context.deviceId = device.deviceId
|
|
2073
|
-
accessory.context.deviceType = `IR: ${device.remoteType}
|
|
2074
|
-
accessory.context.model = device.remoteType
|
|
1975
|
+
accessory.context.device = device
|
|
1976
|
+
accessory.context.deviceId = device.deviceId
|
|
1977
|
+
accessory.context.deviceType = `IR: ${device.remoteType}`
|
|
1978
|
+
accessory.context.model = device.remoteType
|
|
2075
1979
|
accessory.displayName = device.configDeviceName
|
|
2076
1980
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2077
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2078
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
2079
|
-
accessory.context.
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
1981
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
1982
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
1983
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
1984
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
1985
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
2083
1986
|
// create the accessory handler for the newly create accessory
|
|
2084
1987
|
// this is imported from `platformAccessory.ts`
|
|
2085
|
-
new TV(this, accessory, device)
|
|
2086
|
-
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`)
|
|
1988
|
+
new TV(this, accessory, device)
|
|
1989
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`)
|
|
2087
1990
|
|
|
2088
|
-
this.
|
|
2089
|
-
this.accessories.push(accessory)
|
|
1991
|
+
this.externalOrPlatform(device, accessory)
|
|
1992
|
+
this.accessories.push(accessory)
|
|
2090
1993
|
} else {
|
|
2091
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`)
|
|
1994
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`)
|
|
2092
1995
|
}
|
|
2093
1996
|
}
|
|
2094
1997
|
|
|
2095
1998
|
private async createIRFan(device: irdevice & devicesConfig) {
|
|
2096
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
|
|
1999
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
|
|
2097
2000
|
|
|
2098
2001
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
2099
2002
|
// the cached devices we stored in the `configureAccessory` method above
|
|
2100
|
-
const existingAccessory = this.accessories.find(
|
|
2003
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
2101
2004
|
|
|
2102
2005
|
if (existingAccessory) {
|
|
2103
2006
|
// the accessory already exists
|
|
2104
2007
|
if (!device.hide_device && device.hubDeviceId) {
|
|
2105
2008
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
2106
|
-
existingAccessory.context.device = device
|
|
2107
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
2108
|
-
existingAccessory.context.deviceType = `IR: ${device.remoteType}
|
|
2109
|
-
existingAccessory.context.model = device.remoteType
|
|
2009
|
+
existingAccessory.context.device = device
|
|
2010
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
2011
|
+
existingAccessory.context.deviceType = `IR: ${device.remoteType}`
|
|
2012
|
+
existingAccessory.context.model = device.remoteType
|
|
2110
2013
|
existingAccessory.displayName = device.configDeviceName
|
|
2111
2014
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2112
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2113
|
-
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
2114
|
-
existingAccessory.context.connectionType = device.connectionType
|
|
2115
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
2015
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2016
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
2017
|
+
existingAccessory.context.connectionType = device.connectionType
|
|
2018
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
2116
2019
|
// create the accessory handler for the restored accessory
|
|
2117
2020
|
// this is imported from `platformAccessory.ts`
|
|
2118
|
-
new IRFan(this, existingAccessory, device)
|
|
2119
|
-
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`)
|
|
2021
|
+
new IRFan(this, existingAccessory, device)
|
|
2022
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`)
|
|
2120
2023
|
} else {
|
|
2121
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
2024
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
2122
2025
|
}
|
|
2123
2026
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
2124
2027
|
// create a new accessory
|
|
2125
2028
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
2126
2029
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2127
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
2030
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
2128
2031
|
|
|
2129
2032
|
// store a copy of the device object in the `accessory.context`
|
|
2130
2033
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2131
|
-
accessory.context.device = device
|
|
2132
|
-
accessory.context.deviceId = device.deviceId
|
|
2133
|
-
accessory.context.deviceType = `IR: ${device.remoteType}
|
|
2134
|
-
accessory.context.model = device.remoteType
|
|
2034
|
+
accessory.context.device = device
|
|
2035
|
+
accessory.context.deviceId = device.deviceId
|
|
2036
|
+
accessory.context.deviceType = `IR: ${device.remoteType}`
|
|
2037
|
+
accessory.context.model = device.remoteType
|
|
2135
2038
|
accessory.displayName = device.configDeviceName
|
|
2136
2039
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2137
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2138
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
2139
|
-
accessory.context.
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
2040
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2041
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
2042
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
2043
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
2044
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
2143
2045
|
// create the accessory handler for the newly create accessory
|
|
2144
2046
|
// this is imported from `platformAccessory.ts`
|
|
2145
|
-
new IRFan(this, accessory, device)
|
|
2146
|
-
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`)
|
|
2047
|
+
new IRFan(this, accessory, device)
|
|
2048
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`)
|
|
2147
2049
|
|
|
2148
2050
|
// publish device externally or link the accessory to your platform
|
|
2149
|
-
this.
|
|
2150
|
-
this.accessories.push(accessory)
|
|
2051
|
+
this.externalOrPlatform(device, accessory)
|
|
2052
|
+
this.accessories.push(accessory)
|
|
2151
2053
|
} else {
|
|
2152
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`)
|
|
2054
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`)
|
|
2153
2055
|
}
|
|
2154
2056
|
}
|
|
2155
2057
|
|
|
2156
2058
|
private async createLight(device: irdevice & devicesConfig) {
|
|
2157
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
|
|
2059
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
|
|
2158
2060
|
|
|
2159
2061
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
2160
2062
|
// the cached devices we stored in the `configureAccessory` method above
|
|
2161
|
-
const existingAccessory = this.accessories.find(
|
|
2063
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
2162
2064
|
|
|
2163
2065
|
if (existingAccessory) {
|
|
2164
2066
|
// the accessory already exists
|
|
2165
2067
|
if (!device.hide_device && device.hubDeviceId) {
|
|
2166
2068
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
2167
|
-
existingAccessory.context.device = device
|
|
2168
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
2169
|
-
existingAccessory.context.deviceType = `IR: ${device.remoteType}
|
|
2170
|
-
existingAccessory.context.model = device.remoteType
|
|
2069
|
+
existingAccessory.context.device = device
|
|
2070
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
2071
|
+
existingAccessory.context.deviceType = `IR: ${device.remoteType}`
|
|
2072
|
+
existingAccessory.context.model = device.remoteType
|
|
2171
2073
|
existingAccessory.displayName = device.configDeviceName
|
|
2172
2074
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2173
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2174
|
-
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
2175
|
-
existingAccessory.context.connectionType = device.connectionType
|
|
2176
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
2075
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2076
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
2077
|
+
existingAccessory.context.connectionType = device.connectionType
|
|
2078
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
2177
2079
|
// create the accessory handler for the restored accessory
|
|
2178
2080
|
// this is imported from `platformAccessory.ts`
|
|
2179
|
-
new Light(this, existingAccessory, device)
|
|
2180
|
-
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`)
|
|
2081
|
+
new Light(this, existingAccessory, device)
|
|
2082
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`)
|
|
2181
2083
|
} else {
|
|
2182
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
2084
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
2183
2085
|
}
|
|
2184
2086
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
2185
2087
|
// create a new accessory
|
|
2186
2088
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
2187
2089
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2188
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
2090
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
2189
2091
|
|
|
2190
2092
|
// store a copy of the device object in the `accessory.context`
|
|
2191
2093
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2192
|
-
accessory.context.device = device
|
|
2193
|
-
accessory.context.deviceId = device.deviceId
|
|
2194
|
-
accessory.context.deviceType = `IR: ${device.remoteType}
|
|
2195
|
-
accessory.context.model = device.remoteType
|
|
2094
|
+
accessory.context.device = device
|
|
2095
|
+
accessory.context.deviceId = device.deviceId
|
|
2096
|
+
accessory.context.deviceType = `IR: ${device.remoteType}`
|
|
2097
|
+
accessory.context.model = device.remoteType
|
|
2196
2098
|
accessory.displayName = device.configDeviceName
|
|
2197
2099
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2198
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2199
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
2200
|
-
accessory.context.
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
2100
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2101
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
2102
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
2103
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
2104
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
2204
2105
|
// create the accessory handler for the newly create accessory
|
|
2205
2106
|
// this is imported from `platformAccessory.ts`
|
|
2206
|
-
new Light(this, accessory, device)
|
|
2207
|
-
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`)
|
|
2107
|
+
new Light(this, accessory, device)
|
|
2108
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`)
|
|
2208
2109
|
|
|
2209
2110
|
// publish device externally or link the accessory to your platform
|
|
2210
|
-
this.
|
|
2211
|
-
this.accessories.push(accessory)
|
|
2111
|
+
this.externalOrPlatform(device, accessory)
|
|
2112
|
+
this.accessories.push(accessory)
|
|
2212
2113
|
} else {
|
|
2213
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`)
|
|
2114
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`)
|
|
2214
2115
|
}
|
|
2215
2116
|
}
|
|
2216
2117
|
|
|
2217
2118
|
private async createAirConditioner(device: irdevice & devicesConfig & irDevicesConfig) {
|
|
2218
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
|
|
2119
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
|
|
2219
2120
|
|
|
2220
2121
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
2221
2122
|
// the cached devices we stored in the `configureAccessory` method above
|
|
2222
|
-
const existingAccessory = this.accessories.find(
|
|
2123
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
2223
2124
|
|
|
2224
2125
|
if (existingAccessory) {
|
|
2225
2126
|
// the accessory already exists
|
|
2226
2127
|
if (!device.hide_device && device.hubDeviceId) {
|
|
2227
2128
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
2228
|
-
existingAccessory.context.device = device
|
|
2229
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
2230
|
-
existingAccessory.context.deviceType = `IR: ${device.remoteType}
|
|
2231
|
-
existingAccessory.context.model = device.remoteType
|
|
2129
|
+
existingAccessory.context.device = device
|
|
2130
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
2131
|
+
existingAccessory.context.deviceType = `IR: ${device.remoteType}`
|
|
2132
|
+
existingAccessory.context.model = device.remoteType
|
|
2232
2133
|
existingAccessory.displayName = device.configDeviceName
|
|
2233
2134
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2234
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2235
|
-
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
2236
|
-
existingAccessory.context.connectionType = device.connectionType
|
|
2237
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
2135
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2136
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
2137
|
+
existingAccessory.context.connectionType = device.connectionType
|
|
2138
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
2238
2139
|
// create the accessory handler for the restored accessory
|
|
2239
2140
|
// this is imported from `platformAccessory.ts`
|
|
2240
|
-
new AirConditioner(this, existingAccessory, device)
|
|
2241
|
-
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`)
|
|
2141
|
+
new AirConditioner(this, existingAccessory, device)
|
|
2142
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`)
|
|
2242
2143
|
} else {
|
|
2243
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
2144
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
2244
2145
|
}
|
|
2245
2146
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
2246
2147
|
// create a new accessory
|
|
2247
2148
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
2248
2149
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2249
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
2150
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
2250
2151
|
|
|
2251
2152
|
// store a copy of the device object in the `accessory.context`
|
|
2252
2153
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2253
|
-
accessory.context.device = device
|
|
2254
|
-
accessory.context.deviceId = device.deviceId
|
|
2255
|
-
accessory.context.deviceType = `IR: ${device.remoteType}
|
|
2256
|
-
accessory.context.model = device.remoteType
|
|
2154
|
+
accessory.context.device = device
|
|
2155
|
+
accessory.context.deviceId = device.deviceId
|
|
2156
|
+
accessory.context.deviceType = `IR: ${device.remoteType}`
|
|
2157
|
+
accessory.context.model = device.remoteType
|
|
2257
2158
|
accessory.displayName = device.configDeviceName
|
|
2258
2159
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2259
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2260
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
2261
|
-
accessory.context.
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
2160
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2161
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
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}`)
|
|
2265
2165
|
// create the accessory handler for the newly create accessory
|
|
2266
2166
|
// this is imported from `platformAccessory.ts`
|
|
2267
|
-
new AirConditioner(this, accessory, device)
|
|
2268
|
-
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`)
|
|
2167
|
+
new AirConditioner(this, accessory, device)
|
|
2168
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`)
|
|
2269
2169
|
|
|
2270
2170
|
// publish device externally or link the accessory to your platform
|
|
2271
|
-
this.
|
|
2272
|
-
this.accessories.push(accessory)
|
|
2171
|
+
this.externalOrPlatform(device, accessory)
|
|
2172
|
+
this.accessories.push(accessory)
|
|
2273
2173
|
} else {
|
|
2274
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`)
|
|
2174
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`)
|
|
2275
2175
|
}
|
|
2276
2176
|
}
|
|
2277
2177
|
|
|
2278
2178
|
private async createAirPurifier(device: irdevice & devicesConfig) {
|
|
2279
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
|
|
2179
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
|
|
2280
2180
|
|
|
2281
2181
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
2282
2182
|
// the cached devices we stored in the `configureAccessory` method above
|
|
2283
|
-
const existingAccessory = this.accessories.find(
|
|
2183
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
2284
2184
|
|
|
2285
2185
|
if (existingAccessory) {
|
|
2286
2186
|
// the accessory already exists
|
|
2287
2187
|
if (!device.hide_device && device.hubDeviceId) {
|
|
2288
2188
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
2289
|
-
existingAccessory.context.device = device
|
|
2290
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
2291
|
-
existingAccessory.context.deviceType = `IR: ${device.remoteType}
|
|
2292
|
-
existingAccessory.context.model = device.remoteType
|
|
2189
|
+
existingAccessory.context.device = device
|
|
2190
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
2191
|
+
existingAccessory.context.deviceType = `IR: ${device.remoteType}`
|
|
2192
|
+
existingAccessory.context.model = device.remoteType
|
|
2293
2193
|
existingAccessory.displayName = device.configDeviceName
|
|
2294
2194
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2295
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2296
|
-
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
2297
|
-
existingAccessory.context.connectionType = device.connectionType
|
|
2298
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
2195
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2196
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
2197
|
+
existingAccessory.context.connectionType = device.connectionType
|
|
2198
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
2299
2199
|
// create the accessory handler for the restored accessory
|
|
2300
2200
|
// this is imported from `platformAccessory.ts`
|
|
2301
|
-
new AirPurifier(this, existingAccessory, device)
|
|
2302
|
-
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`)
|
|
2201
|
+
new AirPurifier(this, existingAccessory, device)
|
|
2202
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`)
|
|
2303
2203
|
} else {
|
|
2304
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
2204
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
2305
2205
|
}
|
|
2306
2206
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
2307
2207
|
// create a new accessory
|
|
2308
2208
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
2309
2209
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2310
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
2210
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
2311
2211
|
|
|
2312
2212
|
// store a copy of the device object in the `accessory.context`
|
|
2313
2213
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2314
|
-
accessory.context.device = device
|
|
2315
|
-
accessory.context.deviceId = device.deviceId
|
|
2316
|
-
accessory.context.deviceType = `IR: ${device.remoteType}
|
|
2317
|
-
accessory.context.model = device.remoteType
|
|
2214
|
+
accessory.context.device = device
|
|
2215
|
+
accessory.context.deviceId = device.deviceId
|
|
2216
|
+
accessory.context.deviceType = `IR: ${device.remoteType}`
|
|
2217
|
+
accessory.context.model = device.remoteType
|
|
2318
2218
|
accessory.displayName = device.configDeviceName
|
|
2319
2219
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2320
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2321
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
2322
|
-
accessory.context.
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
2220
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2221
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
2222
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
2223
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
2224
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
2326
2225
|
// create the accessory handler for the newly create accessory
|
|
2327
2226
|
// this is imported from `platformAccessory.ts`
|
|
2328
|
-
new AirPurifier(this, accessory, device)
|
|
2329
|
-
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`)
|
|
2227
|
+
new AirPurifier(this, accessory, device)
|
|
2228
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`)
|
|
2330
2229
|
|
|
2331
2230
|
// publish device externally or link the accessory to your platform
|
|
2332
|
-
this.
|
|
2333
|
-
this.accessories.push(accessory)
|
|
2231
|
+
this.externalOrPlatform(device, accessory)
|
|
2232
|
+
this.accessories.push(accessory)
|
|
2334
2233
|
} else {
|
|
2335
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`)
|
|
2234
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`)
|
|
2336
2235
|
}
|
|
2337
2236
|
}
|
|
2338
2237
|
|
|
2339
2238
|
private async createWaterHeater(device: irdevice & devicesConfig) {
|
|
2340
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
|
|
2239
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
|
|
2341
2240
|
|
|
2342
2241
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
2343
2242
|
// the cached devices we stored in the `configureAccessory` method above
|
|
2344
|
-
const existingAccessory = this.accessories.find(
|
|
2243
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
2345
2244
|
|
|
2346
2245
|
if (existingAccessory) {
|
|
2347
2246
|
// the accessory already exists
|
|
2348
2247
|
if (!device.hide_device && device.hubDeviceId) {
|
|
2349
2248
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
2350
|
-
existingAccessory.context.device = device
|
|
2351
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
2352
|
-
existingAccessory.context.deviceType = `IR: ${device.remoteType}
|
|
2353
|
-
existingAccessory.context.model = device.remoteType
|
|
2249
|
+
existingAccessory.context.device = device
|
|
2250
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
2251
|
+
existingAccessory.context.deviceType = `IR: ${device.remoteType}`
|
|
2252
|
+
existingAccessory.context.model = device.remoteType
|
|
2354
2253
|
existingAccessory.displayName = device.configDeviceName
|
|
2355
2254
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2356
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2357
|
-
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
2358
|
-
existingAccessory.context.connectionType = device.connectionType
|
|
2359
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
2255
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2256
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
2257
|
+
existingAccessory.context.connectionType = device.connectionType
|
|
2258
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
2360
2259
|
// create the accessory handler for the restored accessory
|
|
2361
2260
|
// this is imported from `platformAccessory.ts`
|
|
2362
|
-
new WaterHeater(this, existingAccessory, device)
|
|
2363
|
-
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`)
|
|
2261
|
+
new WaterHeater(this, existingAccessory, device)
|
|
2262
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`)
|
|
2364
2263
|
} else {
|
|
2365
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
2264
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
2366
2265
|
}
|
|
2367
2266
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
2368
2267
|
// create a new accessory
|
|
2369
2268
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
2370
2269
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2371
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
2270
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
2372
2271
|
|
|
2373
2272
|
// store a copy of the device object in the `accessory.context`
|
|
2374
2273
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2375
|
-
accessory.context.device = device
|
|
2376
|
-
accessory.context.deviceId = device.deviceId
|
|
2377
|
-
accessory.context.deviceType = `IR: ${device.remoteType}
|
|
2378
|
-
accessory.context.model = device.remoteType
|
|
2274
|
+
accessory.context.device = device
|
|
2275
|
+
accessory.context.deviceId = device.deviceId
|
|
2276
|
+
accessory.context.deviceType = `IR: ${device.remoteType}`
|
|
2277
|
+
accessory.context.model = device.remoteType
|
|
2379
2278
|
accessory.displayName = device.configDeviceName
|
|
2380
2279
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2381
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2382
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
2383
|
-
accessory.context.
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
2280
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2281
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
2282
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
2283
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
2284
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
2387
2285
|
// create the accessory handler for the newly create accessory
|
|
2388
2286
|
// this is imported from `platformAccessory.ts`
|
|
2389
|
-
new WaterHeater(this, accessory, device)
|
|
2390
|
-
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`)
|
|
2287
|
+
new WaterHeater(this, accessory, device)
|
|
2288
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`)
|
|
2391
2289
|
|
|
2392
2290
|
// publish device externally or link the accessory to your platform
|
|
2393
|
-
this.
|
|
2394
|
-
this.accessories.push(accessory)
|
|
2291
|
+
this.externalOrPlatform(device, accessory)
|
|
2292
|
+
this.accessories.push(accessory)
|
|
2395
2293
|
} else {
|
|
2396
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`)
|
|
2294
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`)
|
|
2397
2295
|
}
|
|
2398
2296
|
}
|
|
2399
2297
|
|
|
2400
2298
|
private async createVacuumCleaner(device: irdevice & devicesConfig) {
|
|
2401
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
|
|
2299
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
|
|
2402
2300
|
|
|
2403
2301
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
2404
2302
|
// the cached devices we stored in the `configureAccessory` method above
|
|
2405
|
-
const existingAccessory = this.accessories.find(
|
|
2303
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
2406
2304
|
|
|
2407
2305
|
if (existingAccessory) {
|
|
2408
2306
|
// the accessory already exists
|
|
2409
2307
|
if (!device.hide_device && device.hubDeviceId) {
|
|
2410
2308
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
2411
|
-
existingAccessory.context.device = device
|
|
2412
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
2413
|
-
existingAccessory.context.deviceType = `IR: ${device.remoteType}
|
|
2414
|
-
existingAccessory.context.model = device.remoteType
|
|
2309
|
+
existingAccessory.context.device = device
|
|
2310
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
2311
|
+
existingAccessory.context.deviceType = `IR: ${device.remoteType}`
|
|
2312
|
+
existingAccessory.context.model = device.remoteType
|
|
2415
2313
|
existingAccessory.displayName = device.configDeviceName
|
|
2416
2314
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2417
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2418
|
-
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
2419
|
-
existingAccessory.context.connectionType = device.connectionType
|
|
2420
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
2315
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2316
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
2317
|
+
existingAccessory.context.connectionType = device.connectionType
|
|
2318
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
2421
2319
|
// create the accessory handler for the restored accessory
|
|
2422
2320
|
// this is imported from `platformAccessory.ts`
|
|
2423
|
-
new VacuumCleaner(this, existingAccessory, device)
|
|
2424
|
-
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`)
|
|
2321
|
+
new VacuumCleaner(this, existingAccessory, device)
|
|
2322
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`)
|
|
2425
2323
|
} else {
|
|
2426
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
2324
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
2427
2325
|
}
|
|
2428
2326
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
2429
2327
|
// create a new accessory
|
|
2430
2328
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
2431
2329
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2432
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
2330
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
2433
2331
|
|
|
2434
2332
|
// store a copy of the device object in the `accessory.context`
|
|
2435
2333
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2436
|
-
accessory.context.device = device
|
|
2437
|
-
accessory.context.deviceId = device.deviceId
|
|
2438
|
-
accessory.context.deviceType = `IR: ${device.remoteType}
|
|
2439
|
-
accessory.context.model = device.remoteType
|
|
2334
|
+
accessory.context.device = device
|
|
2335
|
+
accessory.context.deviceId = device.deviceId
|
|
2336
|
+
accessory.context.deviceType = `IR: ${device.remoteType}`
|
|
2337
|
+
accessory.context.model = device.remoteType
|
|
2440
2338
|
accessory.displayName = device.configDeviceName
|
|
2441
2339
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2442
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2443
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
2444
|
-
accessory.context.
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
2340
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2341
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
2342
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
2343
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
2344
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
2448
2345
|
// create the accessory handler for the newly create accessory
|
|
2449
2346
|
// this is imported from `platformAccessory.ts`
|
|
2450
|
-
new VacuumCleaner(this, accessory, device)
|
|
2451
|
-
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`)
|
|
2347
|
+
new VacuumCleaner(this, accessory, device)
|
|
2348
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`)
|
|
2452
2349
|
|
|
2453
2350
|
// publish device externally or link the accessory to your platform
|
|
2454
|
-
this.
|
|
2455
|
-
this.accessories.push(accessory)
|
|
2351
|
+
this.externalOrPlatform(device, accessory)
|
|
2352
|
+
this.accessories.push(accessory)
|
|
2456
2353
|
} else {
|
|
2457
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`)
|
|
2354
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`)
|
|
2458
2355
|
}
|
|
2459
2356
|
}
|
|
2460
2357
|
|
|
2461
2358
|
private async createCamera(device: irdevice & devicesConfig) {
|
|
2462
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
|
|
2359
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
|
|
2463
2360
|
|
|
2464
2361
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
2465
2362
|
// the cached devices we stored in the `configureAccessory` method above
|
|
2466
|
-
const existingAccessory = this.accessories.find(
|
|
2363
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
2467
2364
|
|
|
2468
2365
|
if (existingAccessory) {
|
|
2469
2366
|
// the accessory already exists
|
|
2470
2367
|
if (!device.hide_device && device.hubDeviceId) {
|
|
2471
2368
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
2472
|
-
existingAccessory.context.device = device
|
|
2473
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
2474
|
-
existingAccessory.context.deviceType = `IR: ${device.remoteType}
|
|
2475
|
-
existingAccessory.context.model = device.remoteType
|
|
2369
|
+
existingAccessory.context.device = device
|
|
2370
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
2371
|
+
existingAccessory.context.deviceType = `IR: ${device.remoteType}`
|
|
2372
|
+
existingAccessory.context.model = device.remoteType
|
|
2476
2373
|
existingAccessory.displayName = device.configDeviceName
|
|
2477
2374
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2478
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2479
|
-
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
2480
|
-
existingAccessory.context.connectionType = device.connectionType
|
|
2481
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
2375
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2376
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
2377
|
+
existingAccessory.context.connectionType = device.connectionType
|
|
2378
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
2482
2379
|
// create the accessory handler for the restored accessory
|
|
2483
2380
|
// this is imported from `platformAccessory.ts`
|
|
2484
|
-
new Camera(this, existingAccessory, device)
|
|
2485
|
-
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`)
|
|
2381
|
+
new Camera(this, existingAccessory, device)
|
|
2382
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`)
|
|
2486
2383
|
} else {
|
|
2487
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
2384
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
2488
2385
|
}
|
|
2489
2386
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
2490
2387
|
// create a new accessory
|
|
2491
2388
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
2492
2389
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2493
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
2390
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
2494
2391
|
|
|
2495
2392
|
// store a copy of the device object in the `accessory.context`
|
|
2496
2393
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2497
|
-
accessory.context.device = device
|
|
2498
|
-
accessory.context.deviceId = device.deviceId
|
|
2499
|
-
accessory.context.deviceType = `IR: ${device.remoteType}
|
|
2500
|
-
accessory.context.model = device.remoteType
|
|
2394
|
+
accessory.context.device = device
|
|
2395
|
+
accessory.context.deviceId = device.deviceId
|
|
2396
|
+
accessory.context.deviceType = `IR: ${device.remoteType}`
|
|
2397
|
+
accessory.context.model = device.remoteType
|
|
2501
2398
|
accessory.displayName = device.configDeviceName
|
|
2502
2399
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2503
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2504
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
2505
|
-
accessory.context.
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
2400
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2401
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
2402
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
2403
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
2404
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
2509
2405
|
// create the accessory handler for the newly create accessory
|
|
2510
2406
|
// this is imported from `platformAccessory.ts`
|
|
2511
|
-
new Camera(this, accessory, device)
|
|
2512
|
-
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`)
|
|
2407
|
+
new Camera(this, accessory, device)
|
|
2408
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`)
|
|
2513
2409
|
|
|
2514
2410
|
// publish device externally or link the accessory to your platform
|
|
2515
|
-
this.
|
|
2516
|
-
this.accessories.push(accessory)
|
|
2411
|
+
this.externalOrPlatform(device, accessory)
|
|
2412
|
+
this.accessories.push(accessory)
|
|
2517
2413
|
} else {
|
|
2518
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`)
|
|
2414
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`)
|
|
2519
2415
|
}
|
|
2520
2416
|
}
|
|
2521
2417
|
|
|
2522
2418
|
private async createOthers(device: irdevice & devicesConfig) {
|
|
2523
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
|
|
2419
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
|
|
2524
2420
|
|
|
2525
2421
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
2526
2422
|
// the cached devices we stored in the `configureAccessory` method above
|
|
2527
|
-
const existingAccessory = this.accessories.find(
|
|
2423
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
|
|
2528
2424
|
|
|
2529
2425
|
if (existingAccessory) {
|
|
2530
2426
|
// the accessory already exists
|
|
2531
2427
|
if (!device.hide_device && device.hubDeviceId) {
|
|
2532
2428
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
2533
|
-
existingAccessory.context.device = device
|
|
2534
|
-
existingAccessory.context.deviceId = device.deviceId
|
|
2535
|
-
existingAccessory.context.deviceType = `IR: ${device.remoteType}
|
|
2536
|
-
existingAccessory.context.model = device.remoteType
|
|
2429
|
+
existingAccessory.context.device = device
|
|
2430
|
+
existingAccessory.context.deviceId = device.deviceId
|
|
2431
|
+
existingAccessory.context.deviceType = `IR: ${device.remoteType}`
|
|
2432
|
+
existingAccessory.context.model = device.remoteType
|
|
2537
2433
|
existingAccessory.displayName = device.configDeviceName
|
|
2538
2434
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2539
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2540
|
-
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
2541
|
-
existingAccessory.context.connectionType = device.connectionType
|
|
2542
|
-
this.api.updatePlatformAccessories([existingAccessory])
|
|
2435
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2436
|
+
await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
|
|
2437
|
+
existingAccessory.context.connectionType = device.connectionType
|
|
2438
|
+
this.api.updatePlatformAccessories([existingAccessory])
|
|
2543
2439
|
// create the accessory handler for the restored accessory
|
|
2544
2440
|
// this is imported from `platformAccessory.ts`
|
|
2545
|
-
new Others(this, existingAccessory, device)
|
|
2546
|
-
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`)
|
|
2441
|
+
new Others(this, existingAccessory, device)
|
|
2442
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`)
|
|
2547
2443
|
} else {
|
|
2548
|
-
this.unregisterPlatformAccessories(existingAccessory)
|
|
2444
|
+
this.unregisterPlatformAccessories(existingAccessory)
|
|
2549
2445
|
}
|
|
2550
2446
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
2551
2447
|
// create a new accessory
|
|
2552
2448
|
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
2553
2449
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2554
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
2450
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
|
|
2555
2451
|
|
|
2556
2452
|
// store a copy of the device object in the `accessory.context`
|
|
2557
2453
|
// the `context` property can be used to store any data about the accessory you may need
|
|
2558
|
-
accessory.context.device = device
|
|
2559
|
-
accessory.context.deviceId = device.deviceId
|
|
2560
|
-
accessory.context.deviceType = `IR: ${device.remoteType}
|
|
2561
|
-
accessory.context.model = device.remoteType
|
|
2454
|
+
accessory.context.device = device
|
|
2455
|
+
accessory.context.deviceId = device.deviceId
|
|
2456
|
+
accessory.context.deviceType = `IR: ${device.remoteType}`
|
|
2457
|
+
accessory.context.model = device.remoteType
|
|
2562
2458
|
accessory.displayName = device.configDeviceName
|
|
2563
2459
|
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
2564
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2565
|
-
accessory.context.connectionType = await this.connectionType(device)
|
|
2566
|
-
accessory.context.
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
2460
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
|
|
2461
|
+
accessory.context.connectionType = await this.connectionType(device)
|
|
2462
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
|
|
2463
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
|
|
2464
|
+
await this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
|
|
2570
2465
|
// create the accessory handler for the newly create accessory
|
|
2571
2466
|
// this is imported from `platformAccessory.ts`
|
|
2572
|
-
new Others(this, accessory, device)
|
|
2573
|
-
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`)
|
|
2467
|
+
new Others(this, accessory, device)
|
|
2468
|
+
await this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`)
|
|
2574
2469
|
|
|
2575
2470
|
// publish device externally or link the accessory to your platform
|
|
2576
|
-
this.
|
|
2577
|
-
this.accessories.push(accessory)
|
|
2471
|
+
this.externalOrPlatform(device, accessory)
|
|
2472
|
+
this.accessories.push(accessory)
|
|
2578
2473
|
} else {
|
|
2579
|
-
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`)
|
|
2474
|
+
await this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`)
|
|
2580
2475
|
}
|
|
2581
2476
|
}
|
|
2582
2477
|
|
|
2583
2478
|
async registerCurtains(device: device & devicesConfig): Promise<boolean> {
|
|
2584
|
-
|
|
2585
|
-
return device.deviceType === 'Curtain' || device.deviceType === 'Curtain3';
|
|
2586
|
-
}
|
|
2587
|
-
|
|
2588
|
-
function isBlindTiltDevice(device: device & devicesConfig): device is blindTilt & devicesConfig {
|
|
2589
|
-
return device.deviceType === 'Blind Tilt';
|
|
2590
|
-
}*/
|
|
2591
|
-
let registerWindowCovering: boolean;
|
|
2479
|
+
let registerWindowCovering: boolean
|
|
2592
2480
|
if (isCurtainDevice(device)) {
|
|
2593
|
-
await this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds}
|
|
2594
|
-
|
|
2595
|
-
+ ` connectionType: ${device.connectionType}`);
|
|
2596
|
-
registerWindowCovering = await this.registerWindowCovering(device);
|
|
2481
|
+
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}`)
|
|
2482
|
+
registerWindowCovering = await this.registerWindowCovering(device)
|
|
2597
2483
|
} else if (isBlindTiltDevice(device)) {
|
|
2598
|
-
await this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, blindTiltDevicesIds: ${device.blindTiltDevicesIds}
|
|
2599
|
-
|
|
2600
|
-
+ ` connectionType: ${device.connectionType}`);
|
|
2601
|
-
registerWindowCovering = await this.registerWindowCovering(device);
|
|
2484
|
+
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}`)
|
|
2485
|
+
registerWindowCovering = await this.registerWindowCovering(device)
|
|
2602
2486
|
} else {
|
|
2603
|
-
registerWindowCovering = false
|
|
2487
|
+
registerWindowCovering = false
|
|
2604
2488
|
}
|
|
2605
|
-
return registerWindowCovering
|
|
2489
|
+
return registerWindowCovering
|
|
2606
2490
|
}
|
|
2607
2491
|
|
|
2608
2492
|
async registerWindowCovering(device: ((curtain | curtain3) & devicesConfig) | (blindTilt & devicesConfig)) {
|
|
2609
|
-
await this.debugLog(`master: ${device.master}`)
|
|
2610
|
-
let registerCurtain: boolean
|
|
2493
|
+
await this.debugLog(`master: ${device.master}`)
|
|
2494
|
+
let registerCurtain: boolean
|
|
2611
2495
|
if (device.master && device.group) {
|
|
2612
2496
|
// OpenAPI: Master Curtains/Blind Tilt in Group
|
|
2613
|
-
registerCurtain = true
|
|
2614
|
-
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}
|
|
2615
|
-
|
|
2616
|
-
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2497
|
+
registerCurtain = true
|
|
2498
|
+
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, device.group: ${device.group} connectionType; ${device.connectionType}`)
|
|
2499
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`)
|
|
2617
2500
|
} else if (!device.master && device.curtain?.disable_group) {
|
|
2618
|
-
|
|
2501
|
+
// !device.group && device.connectionType === 'BLE'
|
|
2619
2502
|
// OpenAPI: Non-Master Curtains/Blind Tilts that has Disable Grouping Checked
|
|
2620
|
-
registerCurtain = true
|
|
2621
|
-
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, disable_group: `
|
|
2622
|
-
|
|
2623
|
-
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2503
|
+
registerCurtain = true
|
|
2504
|
+
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, disable_group: ${device.curtain?.disable_group}, connectionType; ${device.connectionType}`)
|
|
2505
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`)
|
|
2624
2506
|
} else if (device.master && !device.group) {
|
|
2625
2507
|
// OpenAPI: Master Curtains/Blind Tilts not in Group
|
|
2626
|
-
registerCurtain = true
|
|
2627
|
-
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}
|
|
2628
|
-
|
|
2629
|
-
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2508
|
+
registerCurtain = true
|
|
2509
|
+
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, device.group: ${device.group} connectionType; ${device.connectionType}`)
|
|
2510
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`)
|
|
2630
2511
|
} else if (device.connectionType === 'BLE') {
|
|
2631
2512
|
// BLE: Curtains/Blind Tilt
|
|
2632
|
-
registerCurtain = true
|
|
2633
|
-
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] connectionType: ${device.connectionType}, `
|
|
2634
|
-
|
|
2635
|
-
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
2513
|
+
registerCurtain = true
|
|
2514
|
+
await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] connectionType: ${device.connectionType}, group: ${device.group}`)
|
|
2515
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`)
|
|
2636
2516
|
} else {
|
|
2637
|
-
registerCurtain = false
|
|
2638
|
-
await this.debugErrorLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] disable_group: ${device.curtain?.disable_group}
|
|
2639
|
-
|
|
2640
|
-
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}, device.connectionType: ${device.connectionType}`);
|
|
2517
|
+
registerCurtain = false
|
|
2518
|
+
await this.debugErrorLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] disable_group: ${device.curtain?.disable_group}, device.master: ${device.master}, device.group: ${device.group}`)
|
|
2519
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}, device.connectionType: ${device.connectionType}`)
|
|
2641
2520
|
}
|
|
2642
|
-
return registerCurtain
|
|
2521
|
+
return registerCurtain
|
|
2643
2522
|
}
|
|
2644
2523
|
|
|
2645
2524
|
async connectionType(device: device & devicesConfig): Promise<any> {
|
|
2646
|
-
let connectionType: string
|
|
2525
|
+
let connectionType: string
|
|
2647
2526
|
if (!device.connectionType && this.config.credentials?.token && this.config.credentials.secret) {
|
|
2648
|
-
connectionType = 'OpenAPI'
|
|
2527
|
+
connectionType = 'OpenAPI'
|
|
2649
2528
|
} else {
|
|
2650
|
-
connectionType = device.connectionType
|
|
2529
|
+
connectionType = device.connectionType!
|
|
2651
2530
|
}
|
|
2652
|
-
return connectionType
|
|
2531
|
+
return connectionType
|
|
2653
2532
|
}
|
|
2654
2533
|
|
|
2655
2534
|
async registerDevice(device: device & devicesConfig) {
|
|
2656
|
-
device.connectionType = await this.connectionType(device)
|
|
2657
|
-
let registerDevice: boolean
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
registerDevice = await this.registerCurtains(device);
|
|
2664
|
-
await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2665
|
-
break;
|
|
2666
|
-
default:
|
|
2667
|
-
registerDevice = true;
|
|
2668
|
-
await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2669
|
-
}
|
|
2670
|
-
if (registerDevice === true) {
|
|
2671
|
-
await this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
2672
|
-
} else {
|
|
2673
|
-
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2674
|
-
}
|
|
2675
|
-
} else if (!device.hide_device && device.deviceId && device.configDeviceType && device.configDeviceName && device.connectionType === 'BLE') {
|
|
2676
|
-
switch (device.deviceType) {
|
|
2677
|
-
case 'Curtain':
|
|
2678
|
-
case 'Curtain3':
|
|
2679
|
-
case 'Blind Tilt':
|
|
2680
|
-
registerDevice = await this.registerCurtains(device);
|
|
2681
|
-
await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2682
|
-
break;
|
|
2683
|
-
default:
|
|
2684
|
-
registerDevice = true;
|
|
2685
|
-
await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2686
|
-
}
|
|
2687
|
-
if (registerDevice === true) {
|
|
2688
|
-
await this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
2689
|
-
} else {
|
|
2690
|
-
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2691
|
-
}
|
|
2692
|
-
} else if (!device.hide_device && device.connectionType === 'OpenAPI') {
|
|
2693
|
-
switch (device.deviceType) {
|
|
2694
|
-
case 'Curtain':
|
|
2695
|
-
case 'Curtain3':
|
|
2696
|
-
case 'Blind Tilt':
|
|
2697
|
-
registerDevice = await this.registerCurtains(device);
|
|
2698
|
-
await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2699
|
-
break;
|
|
2700
|
-
default:
|
|
2701
|
-
registerDevice = true;
|
|
2702
|
-
await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2703
|
-
}
|
|
2704
|
-
if (registerDevice === true) {
|
|
2705
|
-
await this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
2706
|
-
} else {
|
|
2707
|
-
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2708
|
-
}
|
|
2709
|
-
} else if (!device.hide_device && device.connectionType === 'Disabled') {
|
|
2710
|
-
switch (device.deviceType) {
|
|
2711
|
-
case 'Curtain':
|
|
2712
|
-
case 'Curtain3':
|
|
2713
|
-
case 'Blind Tilt':
|
|
2714
|
-
registerDevice = await this.registerCurtains(device);
|
|
2715
|
-
await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
|
|
2716
|
-
break;
|
|
2717
|
-
default:
|
|
2718
|
-
registerDevice = true;
|
|
2719
|
-
await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
2720
|
-
}
|
|
2721
|
-
await this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will continue to display in HomeKit`);
|
|
2722
|
-
} else if (!device.connectionType && !device.hide_device) {
|
|
2723
|
-
registerDevice = false;
|
|
2724
|
-
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
2725
|
-
} else if (device.hide_device) {
|
|
2726
|
-
registerDevice = false;
|
|
2727
|
-
await this.debugErrorLog(`Device: ${device.deviceName} hide_device: ${device.hide_device}, will not display in HomeKit`);
|
|
2728
|
-
} else {
|
|
2729
|
-
registerDevice = false;
|
|
2730
|
-
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, hide_device: `
|
|
2731
|
-
+ `${device.hide_device}, will not display in HomeKit`);
|
|
2732
|
-
}
|
|
2733
|
-
return registerDevice;
|
|
2734
|
-
}
|
|
2735
|
-
|
|
2736
|
-
public async externalOrPlatformIR(device: device & irDevicesConfig, accessory: PlatformAccessory) {
|
|
2737
|
-
/**
|
|
2738
|
-
* Publish as external accessory
|
|
2739
|
-
* Only one TV can exist per bridge, to bypass this limitation, you should
|
|
2740
|
-
* publish your TV as an external accessory.
|
|
2741
|
-
*/
|
|
2742
|
-
if (device.external) {
|
|
2743
|
-
await this.debugWarnLog(`${accessory.displayName} External Accessory Mode`);
|
|
2744
|
-
this.externalAccessory(accessory);
|
|
2535
|
+
device.connectionType = await this.connectionType(device)
|
|
2536
|
+
let registerDevice: boolean
|
|
2537
|
+
|
|
2538
|
+
const shouldRegister = !device.hide_device && (device.connectionType === 'BLE/OpenAPI' || (device.deviceId && device.configDeviceType && device.configDeviceName && device.connectionType === 'BLE') || device.connectionType === 'OpenAPI' || device.connectionType === 'Disabled')
|
|
2539
|
+
|
|
2540
|
+
if (shouldRegister) {
|
|
2541
|
+
registerDevice = await this.handleDeviceRegistration(device)
|
|
2745
2542
|
} else {
|
|
2746
|
-
|
|
2747
|
-
this.
|
|
2543
|
+
registerDevice = false
|
|
2544
|
+
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, hide_device: ${device.hide_device}, will not display in HomeKit`)
|
|
2748
2545
|
}
|
|
2546
|
+
|
|
2547
|
+
return registerDevice
|
|
2749
2548
|
}
|
|
2750
2549
|
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2550
|
+
async handleDeviceRegistration(device: device & devicesConfig): Promise<boolean> {
|
|
2551
|
+
let registerDevice: boolean
|
|
2552
|
+
|
|
2553
|
+
switch (device.deviceType) {
|
|
2554
|
+
case 'Curtain':
|
|
2555
|
+
case 'Curtain3':
|
|
2556
|
+
case 'Blind Tilt':
|
|
2557
|
+
registerDevice = await this.registerCurtains(device)
|
|
2558
|
+
await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`)
|
|
2559
|
+
break
|
|
2560
|
+
default:
|
|
2561
|
+
registerDevice = true
|
|
2562
|
+
await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`)
|
|
2563
|
+
}
|
|
2564
|
+
|
|
2565
|
+
if (registerDevice) {
|
|
2566
|
+
await this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`)
|
|
2755
2567
|
} else {
|
|
2756
|
-
await this.
|
|
2757
|
-
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
2568
|
+
await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`)
|
|
2758
2569
|
}
|
|
2570
|
+
|
|
2571
|
+
return registerDevice
|
|
2759
2572
|
}
|
|
2760
2573
|
|
|
2761
|
-
public async
|
|
2762
|
-
|
|
2574
|
+
public async externalOrPlatform(device: device & (irDevicesConfig | devicesConfig), accessory: PlatformAccessory) {
|
|
2575
|
+
const { displayName } = accessory
|
|
2576
|
+
const isExternal = device.external ?? false
|
|
2577
|
+
|
|
2578
|
+
if (isExternal) {
|
|
2579
|
+
await this.debugWarnLog(`${displayName} External Accessory Mode`)
|
|
2580
|
+
this.api.publishExternalAccessories(PLUGIN_NAME, [accessory])
|
|
2581
|
+
} else {
|
|
2582
|
+
await this.debugLog(`${displayName} External Accessory Mode: ${isExternal}`)
|
|
2583
|
+
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory])
|
|
2584
|
+
}
|
|
2763
2585
|
}
|
|
2764
2586
|
|
|
2765
2587
|
public unregisterPlatformAccessories(existingAccessory: PlatformAccessory) {
|
|
2588
|
+
const { displayName } = existingAccessory
|
|
2766
2589
|
// remove platform accessories when no longer present
|
|
2767
|
-
this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [existingAccessory])
|
|
2768
|
-
this.warnLog(`Removing existing accessory from cache: ${
|
|
2590
|
+
this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [existingAccessory])
|
|
2591
|
+
this.warnLog(`Removing existing accessory from cache: ${displayName}`)
|
|
2769
2592
|
}
|
|
2770
2593
|
|
|
2594
|
+
/**
|
|
2595
|
+
* Handles the status codes returned by the device and logs appropriate messages.
|
|
2596
|
+
*
|
|
2597
|
+
* @param statusCode - The status code returned by the device.
|
|
2598
|
+
* @returns A promise that resolves when the logging is complete.
|
|
2599
|
+
*/
|
|
2771
2600
|
async statusCode(statusCode: number): Promise<void> {
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
+ `statusCode: ${statusCode}`);
|
|
2805
|
-
break;
|
|
2806
|
-
case 403:
|
|
2807
|
-
await this.errorLog('Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not '
|
|
2808
|
-
+ `found, statusCode: ${statusCode}`);
|
|
2809
|
-
break;
|
|
2810
|
-
case 404:
|
|
2811
|
-
await this.errorLog(`Not Found, Specifies the requested path does not exist, statusCode: ${statusCode}`);
|
|
2812
|
-
break;
|
|
2813
|
-
case 406:
|
|
2814
|
-
await this.errorLog('Not Acceptable, The client has requested a MIME type via the Accept header for a value not supported by the server, '
|
|
2815
|
-
+ `statusCode: ${statusCode}`);
|
|
2816
|
-
break;
|
|
2817
|
-
case 415:
|
|
2818
|
-
await this.errorLog('Unsupported Media Type, The client has defined a contentType header that is not supported by the server, '
|
|
2819
|
-
+ `statusCode: ${statusCode}`);
|
|
2820
|
-
break;
|
|
2821
|
-
case 422:
|
|
2822
|
-
await this.errorLog('Unprocessable Entity, The client has made a valid request, but the server cannot process it. This is often used for '
|
|
2823
|
-
+ `APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
2824
|
-
break;
|
|
2825
|
-
case 429:
|
|
2826
|
-
await this.errorLog('Too Many Requests, The client has exceeded the number of requests allowed for a given time window, '
|
|
2827
|
-
+ `statusCode: ${statusCode}`);
|
|
2828
|
-
break;
|
|
2829
|
-
case 500:
|
|
2830
|
-
await this.errorLog('Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, '
|
|
2831
|
-
+ `statusCode: ${statusCode}`);
|
|
2832
|
-
break;
|
|
2833
|
-
default:
|
|
2834
|
-
await this.errorLog(`Unknown statusCode, statusCode: ${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
2601
|
+
const messages: { [key: number]: string } = {
|
|
2602
|
+
151: `Command not supported by this device type, statusCode: ${statusCode}, Submit Feature Request Here:
|
|
2603
|
+
https://tinyurl.com/SwitchBotFeatureRequest`,
|
|
2604
|
+
152: `Device not found, statusCode: ${statusCode}`,
|
|
2605
|
+
160: `Command is not supported, statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`,
|
|
2606
|
+
161: `Device is offline, statusCode: ${statusCode}`,
|
|
2607
|
+
171: `is offline, statusCode: ${statusCode}`,
|
|
2608
|
+
190: `Requests reached the daily limit, statusCode: ${statusCode}`,
|
|
2609
|
+
100: `Command successfully sent, statusCode: ${statusCode}`,
|
|
2610
|
+
200: `Request successful, statusCode: ${statusCode}`,
|
|
2611
|
+
400: `Bad Request, The client has issued an invalid request. This is commonly used to specify validation errors in a request payload,
|
|
2612
|
+
statusCode: ${statusCode}`,
|
|
2613
|
+
401: `Unauthorized, Authorization for the API is required, but the request has not been authenticated, statusCode: ${statusCode}`,
|
|
2614
|
+
403: `Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not found,
|
|
2615
|
+
statusCode: ${statusCode}`,
|
|
2616
|
+
404: `Not Found, Specifies the requested path does not exist, statusCode: ${statusCode}`,
|
|
2617
|
+
406: `Not Acceptable, The client has requested a MIME type via the Accept header for a value not supported by the server,
|
|
2618
|
+
statusCode: ${statusCode}`,
|
|
2619
|
+
415: `Unsupported Media Type, The client has defined a contentType header that is not supported by the server, statusCode: ${statusCode}`,
|
|
2620
|
+
422: `Unprocessable Entity, The client has made a valid request, but the server cannot process it. This is often used for APIs for which
|
|
2621
|
+
certain limits have been exceeded, statusCode: ${statusCode}`,
|
|
2622
|
+
429: `Too Many Requests, The client has exceeded the number of requests allowed for a given time window, statusCode: ${statusCode}`,
|
|
2623
|
+
500: `Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare,
|
|
2624
|
+
statusCode: ${statusCode}`,
|
|
2625
|
+
}
|
|
2626
|
+
|
|
2627
|
+
const message = messages[statusCode] ?? `Unknown statusCode, statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`
|
|
2628
|
+
|
|
2629
|
+
if ([100, 200].includes(statusCode)) {
|
|
2630
|
+
await this.debugLog(message)
|
|
2631
|
+
} else {
|
|
2632
|
+
await this.errorLog(message)
|
|
2835
2633
|
}
|
|
2836
2634
|
}
|
|
2837
2635
|
|
|
2838
|
-
async retryRequest(deviceMaxRetries: number, deviceDelayBetweenRetries: number, url: string | URL | UrlObject,
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
const maxRetries = deviceMaxRetries;
|
|
2843
|
-
const delayBetweenRetries = deviceDelayBetweenRetries;
|
|
2636
|
+
async retryRequest(deviceMaxRetries: number, deviceDelayBetweenRetries: number, url: string | URL | UrlObject, options?: { dispatcher?: Dispatcher } & Omit<Dispatcher.RequestOptions, 'origin' | 'path' | 'method'> & Partial<Pick<Dispatcher.RequestOptions, 'method'>>): Promise<{ body: any, statusCode: number }> {
|
|
2637
|
+
let retryCount = 0
|
|
2638
|
+
const maxRetries = deviceMaxRetries
|
|
2639
|
+
const delayBetweenRetries = deviceDelayBetweenRetries
|
|
2844
2640
|
while (retryCount < maxRetries) {
|
|
2845
2641
|
try {
|
|
2846
|
-
const { body, statusCode } = await request(url, options)
|
|
2642
|
+
const { body, statusCode } = await request(url, options)
|
|
2847
2643
|
if (statusCode === 200 || statusCode === 100) {
|
|
2848
|
-
return { body, statusCode }
|
|
2644
|
+
return { body, statusCode }
|
|
2849
2645
|
} else {
|
|
2850
|
-
await this.debugLog(`Received status code: ${statusCode}`)
|
|
2646
|
+
await this.debugLog(`Received status code: ${statusCode}`)
|
|
2851
2647
|
}
|
|
2852
2648
|
} catch (error: any) {
|
|
2853
|
-
await this.errorLog(`Error making request: ${error.message}`)
|
|
2649
|
+
await this.errorLog(`Error making request: ${error.message}`)
|
|
2854
2650
|
}
|
|
2855
|
-
retryCount
|
|
2856
|
-
await this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`)
|
|
2857
|
-
await sleep(delayBetweenRetries)
|
|
2651
|
+
retryCount++
|
|
2652
|
+
await this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`)
|
|
2653
|
+
await sleep(delayBetweenRetries)
|
|
2858
2654
|
}
|
|
2859
|
-
return { body: null, statusCode: -1 }
|
|
2655
|
+
return { body: null, statusCode: -1 }
|
|
2860
2656
|
}
|
|
2861
2657
|
|
|
2862
2658
|
// BLE Connection
|
|
2863
|
-
async connectBLE(accessory: PlatformAccessory, device: device & devicesConfig) {
|
|
2864
|
-
let switchbot: any;
|
|
2659
|
+
async connectBLE(accessory: PlatformAccessory, device: device & devicesConfig): Promise<any> {
|
|
2865
2660
|
try {
|
|
2866
|
-
const
|
|
2867
|
-
queueScheduler.schedule(() =>
|
|
2868
|
-
await this.debugLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${switchbot}`)
|
|
2661
|
+
const switchbot = new SwitchBot()
|
|
2662
|
+
queueScheduler.schedule(async () => switchbot)
|
|
2663
|
+
await this.debugLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${switchbot}`)
|
|
2664
|
+
return switchbot
|
|
2869
2665
|
} catch (e: any) {
|
|
2870
|
-
switchbot
|
|
2871
|
-
|
|
2666
|
+
await this.errorLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' not found, Error: ${e}`)
|
|
2667
|
+
return false
|
|
2872
2668
|
}
|
|
2873
|
-
return switchbot;
|
|
2874
2669
|
}
|
|
2875
2670
|
|
|
2876
|
-
async getVersion() {
|
|
2671
|
+
async getVersion(): Promise<string> {
|
|
2877
2672
|
const json = JSON.parse(
|
|
2878
2673
|
readFileSync(
|
|
2879
2674
|
new URL('../package.json', import.meta.url),
|
|
2880
2675
|
'utf-8',
|
|
2881
2676
|
),
|
|
2882
|
-
)
|
|
2883
|
-
await this.debugLog(`Plugin Version: ${json.version}`)
|
|
2884
|
-
this.version = json.version
|
|
2677
|
+
)
|
|
2678
|
+
await this.debugLog(`Plugin Version: ${json.version}`)
|
|
2679
|
+
this.version = json.version
|
|
2680
|
+
return json.version
|
|
2885
2681
|
}
|
|
2886
2682
|
|
|
2887
2683
|
async getPlatformConfigSettings() {
|
|
2888
|
-
const
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
if (
|
|
2900
|
-
|
|
2901
|
-
}
|
|
2902
|
-
if (this.config.options.maxRetries) {
|
|
2903
|
-
this.maxRetries = this.config.options.maxRetries;
|
|
2904
|
-
platformConfig.maxRetries = this.config.options.maxRetries;
|
|
2905
|
-
} else {
|
|
2906
|
-
this.maxRetries = 3;
|
|
2907
|
-
this.debugWarnLog('Using Default Max Retries');
|
|
2908
|
-
platformConfig.maxRetries = this.maxRetries;
|
|
2684
|
+
const { options } = this.config
|
|
2685
|
+
const platformConfig: SwitchBotPlatformConfig['options'] = {}
|
|
2686
|
+
|
|
2687
|
+
if (options) {
|
|
2688
|
+
platformConfig.logging = options.logging
|
|
2689
|
+
platformConfig.refreshRate = options.refreshRate
|
|
2690
|
+
platformConfig.updateRate = options.updateRate
|
|
2691
|
+
platformConfig.pushRate = options.pushRate
|
|
2692
|
+
|
|
2693
|
+
this.maxRetries = options.maxRetries || 3
|
|
2694
|
+
platformConfig.maxRetries = this.maxRetries
|
|
2695
|
+
if (!options.maxRetries) {
|
|
2696
|
+
await this.debugWarnLog('Using Default Max Retries')
|
|
2909
2697
|
}
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
this.
|
|
2915
|
-
this.debugWarnLog('Using Default Delay Between Retries');
|
|
2916
|
-
platformConfig.delayBetweenRetries = this.delayBetweenRetries / 1000;
|
|
2698
|
+
|
|
2699
|
+
this.delayBetweenRetries = (options.delayBetweenRetries || 3) * 1000
|
|
2700
|
+
platformConfig.delayBetweenRetries = this.delayBetweenRetries / 1000
|
|
2701
|
+
if (!options.delayBetweenRetries) {
|
|
2702
|
+
await this.debugWarnLog('Using Default Delay Between Retries')
|
|
2917
2703
|
}
|
|
2918
|
-
|
|
2919
|
-
|
|
2704
|
+
|
|
2705
|
+
if (Object.keys(platformConfig).length) {
|
|
2706
|
+
await this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`)
|
|
2920
2707
|
}
|
|
2921
|
-
|
|
2708
|
+
|
|
2709
|
+
this.platformConfig = platformConfig
|
|
2922
2710
|
}
|
|
2923
2711
|
}
|
|
2924
2712
|
|
|
2925
2713
|
async getPlatformLogSettings() {
|
|
2926
|
-
this.debugMode = process.argv.includes('-D') ?? process.argv.includes('--debug')
|
|
2714
|
+
this.debugMode = process.argv.includes('-D') ?? process.argv.includes('--debug')
|
|
2927
2715
|
if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
|
|
2928
|
-
this.platformLogging = this.config.options.logging
|
|
2929
|
-
await this.debugWarnLog(`Using Config Logging: ${this.platformLogging}`)
|
|
2716
|
+
this.platformLogging = this.config.options.logging
|
|
2717
|
+
await this.debugWarnLog(`Using Config Logging: ${this.platformLogging}`)
|
|
2930
2718
|
} else if (this.debugMode) {
|
|
2931
|
-
this.platformLogging = 'debugMode'
|
|
2932
|
-
await this.debugWarnLog(`Using ${this.platformLogging} Logging`)
|
|
2719
|
+
this.platformLogging = 'debugMode'
|
|
2720
|
+
await this.debugWarnLog(`Using ${this.platformLogging} Logging`)
|
|
2933
2721
|
} else {
|
|
2934
|
-
this.platformLogging = 'standard'
|
|
2935
|
-
await this.debugWarnLog(`Using ${this.platformLogging} Logging`)
|
|
2722
|
+
this.platformLogging = 'standard'
|
|
2723
|
+
await this.debugWarnLog(`Using ${this.platformLogging} Logging`)
|
|
2936
2724
|
}
|
|
2937
2725
|
}
|
|
2938
2726
|
|
|
@@ -2942,40 +2730,36 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2942
2730
|
* @param name - The name of the characteristic.
|
|
2943
2731
|
* @param value - The value to be validated and cleaned.
|
|
2944
2732
|
* @returns The cleaned string value.
|
|
2945
|
-
|
|
2733
|
+
*/
|
|
2946
2734
|
async validateAndCleanDisplayName(displayName: string, name: string, value: string): Promise<string> {
|
|
2947
2735
|
if (this.config.options?.allowInvalidCharacters) {
|
|
2948
|
-
return value
|
|
2736
|
+
return value
|
|
2949
2737
|
} else {
|
|
2950
|
-
const validPattern =
|
|
2951
|
-
const invalidCharsPattern = /[^\p{L}\p{N} ']/gu
|
|
2952
|
-
const invalidStartEndPattern = /^[^\p{L}\p{N}]+|[^\p{L}\p{N}]+$/gu
|
|
2738
|
+
const validPattern = /^[\p{L}\p{N}][\p{L}\p{N} ']*[\p{L}\p{N}]$/u
|
|
2739
|
+
const invalidCharsPattern = /[^\p{L}\p{N} ']/gu
|
|
2740
|
+
const invalidStartEndPattern = /^[^\p{L}\p{N}]+|[^\p{L}\p{N}]+$/gu
|
|
2953
2741
|
|
|
2954
2742
|
if (typeof value === 'string' && !validPattern.test(value)) {
|
|
2955
|
-
this.warnLog(`WARNING: The accessory '${displayName}' has an invalid '${name}' characteristic ('${value}'). Please use only alphanumeric
|
|
2956
|
-
+ ' space, and apostrophe characters. Ensure it starts and ends with an alphabetic or numeric character, and avoid emojis. This may'
|
|
2957
|
-
+ ' prevent the accessory from being added in the Home App or cause unresponsiveness.');
|
|
2743
|
+
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.`)
|
|
2958
2744
|
|
|
2959
2745
|
// Remove invalid characters
|
|
2960
2746
|
if (invalidCharsPattern.test(value)) {
|
|
2961
|
-
const before = value
|
|
2962
|
-
this.warnLog(`Removing invalid characters from '${name}' characteristic, if you feel this is incorrect
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
this.warnLog(`${name} Before: '${before}' After: '${value}'`);
|
|
2747
|
+
const before = value
|
|
2748
|
+
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`)
|
|
2749
|
+
value = value.replace(invalidCharsPattern, '')
|
|
2750
|
+
await this.warnLog(`${name} Before: '${before}' After: '${value}'`)
|
|
2966
2751
|
}
|
|
2967
2752
|
|
|
2968
2753
|
// Ensure it starts and ends with an alphanumeric character
|
|
2969
2754
|
if (invalidStartEndPattern.test(value)) {
|
|
2970
|
-
const before = value
|
|
2971
|
-
this.warnLog(`Removing invalid starting or ending characters from '${name}' characteristic, if you feel this is incorrect
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
this.warnLog(`${name} Before: '${before}' After: '${value}'`);
|
|
2755
|
+
const before = value
|
|
2756
|
+
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`)
|
|
2757
|
+
value = value.replace(invalidStartEndPattern, '')
|
|
2758
|
+
await this.warnLog(`${name} Before: '${before}' After: '${value}'`)
|
|
2975
2759
|
}
|
|
2976
2760
|
}
|
|
2977
2761
|
|
|
2978
|
-
return value
|
|
2762
|
+
return value
|
|
2979
2763
|
}
|
|
2980
2764
|
}
|
|
2981
2765
|
|
|
@@ -2985,48 +2769,48 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2985
2769
|
*/
|
|
2986
2770
|
async infoLog(...log: any[]): Promise<void> {
|
|
2987
2771
|
if (await this.enablingPlatformLogging()) {
|
|
2988
|
-
this.log.info(String(...log))
|
|
2772
|
+
this.log.info(String(...log))
|
|
2989
2773
|
}
|
|
2990
2774
|
}
|
|
2991
2775
|
|
|
2992
2776
|
async successLog(...log: any[]): Promise<void> {
|
|
2993
2777
|
if (await this.enablingPlatformLogging()) {
|
|
2994
|
-
this.log.success(String(...log))
|
|
2778
|
+
this.log.success(String(...log))
|
|
2995
2779
|
}
|
|
2996
2780
|
}
|
|
2997
2781
|
|
|
2998
2782
|
async debugSuccessLog(...log: any[]): Promise<void> {
|
|
2999
2783
|
if (await this.enablingPlatformLogging()) {
|
|
3000
2784
|
if (await this.loggingIsDebug()) {
|
|
3001
|
-
this.log.success('[DEBUG]', String(...log))
|
|
2785
|
+
this.log.success('[DEBUG]', String(...log))
|
|
3002
2786
|
}
|
|
3003
2787
|
}
|
|
3004
2788
|
}
|
|
3005
2789
|
|
|
3006
2790
|
async warnLog(...log: any[]): Promise<void> {
|
|
3007
2791
|
if (await this.enablingPlatformLogging()) {
|
|
3008
|
-
this.log.warn(String(...log))
|
|
2792
|
+
this.log.warn(String(...log))
|
|
3009
2793
|
}
|
|
3010
2794
|
}
|
|
3011
2795
|
|
|
3012
2796
|
async debugWarnLog(...log: any[]): Promise<void> {
|
|
3013
2797
|
if (await this.enablingPlatformLogging()) {
|
|
3014
2798
|
if (await this.loggingIsDebug()) {
|
|
3015
|
-
this.log.warn('[DEBUG]', String(...log))
|
|
2799
|
+
this.log.warn('[DEBUG]', String(...log))
|
|
3016
2800
|
}
|
|
3017
2801
|
}
|
|
3018
2802
|
}
|
|
3019
2803
|
|
|
3020
2804
|
async errorLog(...log: any[]): Promise<void> {
|
|
3021
2805
|
if (await this.enablingPlatformLogging()) {
|
|
3022
|
-
this.log.error(String(...log))
|
|
2806
|
+
this.log.error(String(...log))
|
|
3023
2807
|
}
|
|
3024
2808
|
}
|
|
3025
2809
|
|
|
3026
2810
|
async debugErrorLog(...log: any[]): Promise<void> {
|
|
3027
2811
|
if (await this.enablingPlatformLogging()) {
|
|
3028
2812
|
if (await this.loggingIsDebug()) {
|
|
3029
|
-
this.log.error('[DEBUG]', String(...log))
|
|
2813
|
+
this.log.error('[DEBUG]', String(...log))
|
|
3030
2814
|
}
|
|
3031
2815
|
}
|
|
3032
2816
|
}
|
|
@@ -3034,18 +2818,18 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
3034
2818
|
async debugLog(...log: any[]): Promise<void> {
|
|
3035
2819
|
if (await this.enablingPlatformLogging()) {
|
|
3036
2820
|
if (this.platformLogging === 'debug') {
|
|
3037
|
-
this.log.info('[DEBUG]', String(...log))
|
|
2821
|
+
this.log.info('[DEBUG]', String(...log))
|
|
3038
2822
|
} else if (this.platformLogging === 'debugMode') {
|
|
3039
|
-
this.log.debug(String(...log))
|
|
2823
|
+
this.log.debug(String(...log))
|
|
3040
2824
|
}
|
|
3041
2825
|
}
|
|
3042
2826
|
}
|
|
3043
2827
|
|
|
3044
2828
|
async loggingIsDebug(): Promise<boolean> {
|
|
3045
|
-
return this.platformLogging === 'debugMode' || this.platformLogging === 'debug'
|
|
2829
|
+
return this.platformLogging === 'debugMode' || this.platformLogging === 'debug'
|
|
3046
2830
|
}
|
|
3047
2831
|
|
|
3048
2832
|
async enablingPlatformLogging(): Promise<boolean> {
|
|
3049
|
-
return this.platformLogging === 'debugMode' || this.platformLogging === 'debug' || this.platformLogging === 'standard'
|
|
2833
|
+
return this.platformLogging === 'debugMode' || this.platformLogging === 'debug' || this.platformLogging === 'standard'
|
|
3050
2834
|
}
|
|
3051
2835
|
}
|