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