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