@switchbot/homebridge-switchbot 3.7.1-beta.12 → 3.7.1-beta.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/dist/device/blindtilt.d.ts +8 -8
  2. package/dist/device/blindtilt.d.ts.map +1 -1
  3. package/dist/device/blindtilt.js +34 -66
  4. package/dist/device/blindtilt.js.map +1 -1
  5. package/dist/device/bot.d.ts +9 -9
  6. package/dist/device/bot.d.ts.map +1 -1
  7. package/dist/device/bot.js +61 -97
  8. package/dist/device/bot.js.map +1 -1
  9. package/dist/device/ceilinglight.d.ts +13 -13
  10. package/dist/device/ceilinglight.d.ts.map +1 -1
  11. package/dist/device/ceilinglight.js +38 -73
  12. package/dist/device/ceilinglight.js.map +1 -1
  13. package/dist/device/colorbulb.d.ts +12 -12
  14. package/dist/device/colorbulb.d.ts.map +1 -1
  15. package/dist/device/colorbulb.js +41 -79
  16. package/dist/device/colorbulb.js.map +1 -1
  17. package/dist/device/contact.d.ts +5 -5
  18. package/dist/device/contact.d.ts.map +1 -1
  19. package/dist/device/contact.js +20 -42
  20. package/dist/device/contact.js.map +1 -1
  21. package/dist/device/curtain.d.ts +5 -5
  22. package/dist/device/curtain.d.ts.map +1 -1
  23. package/dist/device/curtain.js +36 -71
  24. package/dist/device/curtain.js.map +1 -1
  25. package/dist/device/device.d.ts +18 -18
  26. package/dist/device/device.d.ts.map +1 -1
  27. package/dist/device/device.js +33 -36
  28. package/dist/device/device.js.map +1 -1
  29. package/dist/device/fan.d.ts +8 -8
  30. package/dist/device/fan.d.ts.map +1 -1
  31. package/dist/device/fan.js +43 -75
  32. package/dist/device/fan.js.map +1 -1
  33. package/dist/device/hub.d.ts +5 -5
  34. package/dist/device/hub.d.ts.map +1 -1
  35. package/dist/device/hub.js +18 -39
  36. package/dist/device/hub.js.map +1 -1
  37. package/dist/device/humidifier.d.ts +5 -5
  38. package/dist/device/humidifier.d.ts.map +1 -1
  39. package/dist/device/humidifier.js +38 -78
  40. package/dist/device/humidifier.js.map +1 -1
  41. package/dist/device/iosensor.d.ts +5 -5
  42. package/dist/device/iosensor.d.ts.map +1 -1
  43. package/dist/device/iosensor.js +21 -40
  44. package/dist/device/iosensor.js.map +1 -1
  45. package/dist/device/lightstrip.d.ts +6 -6
  46. package/dist/device/lightstrip.d.ts.map +1 -1
  47. package/dist/device/lightstrip.js +34 -73
  48. package/dist/device/lightstrip.js.map +1 -1
  49. package/dist/device/lock.d.ts +9 -9
  50. package/dist/device/lock.d.ts.map +1 -1
  51. package/dist/device/lock.js +37 -52
  52. package/dist/device/lock.js.map +1 -1
  53. package/dist/device/meter.d.ts +5 -5
  54. package/dist/device/meter.d.ts.map +1 -1
  55. package/dist/device/meter.js +21 -39
  56. package/dist/device/meter.js.map +1 -1
  57. package/dist/device/meterplus.d.ts +5 -5
  58. package/dist/device/meterplus.d.ts.map +1 -1
  59. package/dist/device/meterplus.js +21 -38
  60. package/dist/device/meterplus.js.map +1 -1
  61. package/dist/device/motion.d.ts +5 -5
  62. package/dist/device/motion.d.ts.map +1 -1
  63. package/dist/device/motion.js +14 -32
  64. package/dist/device/motion.js.map +1 -1
  65. package/dist/device/plug.d.ts +12 -12
  66. package/dist/device/plug.d.ts.map +1 -1
  67. package/dist/device/plug.js +16 -25
  68. package/dist/device/plug.js.map +1 -1
  69. package/dist/device/robotvacuumcleaner.d.ts +11 -11
  70. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  71. package/dist/device/robotvacuumcleaner.js +42 -56
  72. package/dist/device/robotvacuumcleaner.js.map +1 -1
  73. package/dist/device/waterdetector.d.ts +5 -5
  74. package/dist/device/waterdetector.d.ts.map +1 -1
  75. package/dist/device/waterdetector.js +22 -37
  76. package/dist/device/waterdetector.js.map +1 -1
  77. package/dist/homebridge-ui/server.js +2 -2
  78. package/dist/homebridge-ui/server.js.map +1 -1
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +0 -4
  81. package/dist/index.js.map +1 -1
  82. package/dist/irdevice/airconditioner.d.ts +8 -8
  83. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  84. package/dist/irdevice/airconditioner.js +64 -105
  85. package/dist/irdevice/airconditioner.js.map +1 -1
  86. package/dist/irdevice/airpurifier.d.ts +10 -10
  87. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  88. package/dist/irdevice/airpurifier.js +22 -42
  89. package/dist/irdevice/airpurifier.js.map +1 -1
  90. package/dist/irdevice/camera.d.ts +9 -9
  91. package/dist/irdevice/camera.d.ts.map +1 -1
  92. package/dist/irdevice/camera.js +15 -25
  93. package/dist/irdevice/camera.js.map +1 -1
  94. package/dist/irdevice/fan.d.ts +8 -8
  95. package/dist/irdevice/fan.d.ts.map +1 -1
  96. package/dist/irdevice/fan.js +21 -40
  97. package/dist/irdevice/fan.js.map +1 -1
  98. package/dist/irdevice/irdevice.d.ts +11 -11
  99. package/dist/irdevice/irdevice.d.ts.map +1 -1
  100. package/dist/irdevice/irdevice.js +14 -22
  101. package/dist/irdevice/irdevice.js.map +1 -1
  102. package/dist/irdevice/light.d.ts +9 -9
  103. package/dist/irdevice/light.d.ts.map +1 -1
  104. package/dist/irdevice/light.js +24 -47
  105. package/dist/irdevice/light.js.map +1 -1
  106. package/dist/irdevice/other.d.ts +9 -9
  107. package/dist/irdevice/other.d.ts.map +1 -1
  108. package/dist/irdevice/other.js +40 -83
  109. package/dist/irdevice/other.js.map +1 -1
  110. package/dist/irdevice/tv.d.ts +9 -9
  111. package/dist/irdevice/tv.d.ts.map +1 -1
  112. package/dist/irdevice/tv.js +29 -54
  113. package/dist/irdevice/tv.js.map +1 -1
  114. package/dist/irdevice/vacuumcleaner.d.ts +5 -5
  115. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  116. package/dist/irdevice/vacuumcleaner.js +11 -21
  117. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  118. package/dist/irdevice/waterheater.d.ts +5 -5
  119. package/dist/irdevice/waterheater.d.ts.map +1 -1
  120. package/dist/irdevice/waterheater.js +11 -22
  121. package/dist/irdevice/waterheater.js.map +1 -1
  122. package/dist/platform.d.ts +5 -6
  123. package/dist/platform.d.ts.map +1 -1
  124. package/dist/platform.js +141 -146
  125. package/dist/platform.js.map +1 -1
  126. package/dist/settings.d.ts +2 -2
  127. package/dist/settings.d.ts.map +1 -1
  128. package/dist/settings.js.map +1 -1
  129. package/dist/types/bledevicestatus.d.ts +9 -9
  130. package/dist/types/bledevicestatus.d.ts.map +1 -1
  131. package/dist/types/devicelist.d.ts +6 -6
  132. package/dist/types/devicelist.d.ts.map +1 -1
  133. package/dist/types/deviceresponse.d.ts +4 -4
  134. package/dist/types/deviceresponse.d.ts.map +1 -1
  135. package/dist/types/devicestatus.d.ts +2 -2
  136. package/dist/types/devicestatus.d.ts.map +1 -1
  137. package/dist/types/devicewebhookstatus.d.ts +5 -5
  138. package/dist/types/devicewebhookstatus.d.ts.map +1 -1
  139. package/dist/types/irdevicelist.d.ts +4 -4
  140. package/dist/types/irdevicelist.d.ts.map +1 -1
  141. package/dist/types/pushbody.d.ts +2 -2
  142. package/dist/types/pushbody.d.ts.map +1 -1
  143. package/dist/utils.d.ts +4 -4
  144. package/dist/utils.d.ts.map +1 -1
  145. package/dist/utils.js +9 -13
  146. package/dist/utils.js.map +1 -1
  147. package/eslint.config.js +48 -93
  148. package/package.json +54 -47
  149. package/src/device/blindtilt.ts +419 -456
  150. package/src/device/bot.ts +656 -693
  151. package/src/device/ceilinglight.ts +331 -364
  152. package/src/device/colorbulb.ts +412 -448
  153. package/src/device/contact.ts +200 -221
  154. package/src/device/curtain.ts +400 -435
  155. package/src/device/device.ts +206 -208
  156. package/src/device/fan.ts +307 -340
  157. package/src/device/hub.ts +184 -209
  158. package/src/device/humidifier.ts +297 -342
  159. package/src/device/iosensor.ts +182 -204
  160. package/src/device/lightstrip.ts +362 -399
  161. package/src/device/lock.ts +262 -276
  162. package/src/device/meter.ts +183 -205
  163. package/src/device/meterplus.ts +183 -204
  164. package/src/device/motion.ts +169 -185
  165. package/src/device/plug.ts +174 -177
  166. package/src/device/robotvacuumcleaner.ts +256 -269
  167. package/src/device/waterdetector.ts +169 -184
  168. package/src/homebridge-ui/server.ts +16 -15
  169. package/src/index.ts +5 -6
  170. package/src/irdevice/airconditioner.ts +280 -326
  171. package/src/irdevice/airpurifier.ts +124 -143
  172. package/src/irdevice/camera.ts +58 -64
  173. package/src/irdevice/fan.ts +106 -123
  174. package/src/irdevice/irdevice.ts +116 -119
  175. package/src/irdevice/light.ts +119 -143
  176. package/src/irdevice/other.ts +417 -461
  177. package/src/irdevice/tv.ts +155 -177
  178. package/src/irdevice/vacuumcleaner.ts +54 -60
  179. package/src/irdevice/waterheater.ts +56 -63
  180. package/src/platform.ts +1281 -1281
  181. package/src/settings.ts +170 -170
  182. package/src/types/bledevicestatus.ts +255 -255
  183. package/src/types/devicelist.ts +79 -79
  184. package/src/types/deviceresponse.ts +12 -13
  185. package/src/types/devicestatus.ts +124 -124
  186. package/src/types/devicewebhookstatus.ts +126 -127
  187. package/src/types/irdevicelist.ts +10 -10
  188. package/src/types/pushbody.ts +5 -5
  189. package/src/utils.ts +64 -65
  190. 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 { Hub } from './device/hub.js';
6
- import { Bot } from './device/bot.js';
7
- import { Plug } from './device/plug.js';
8
- import { Lock } from './device/lock.js';
9
- import { Meter } from './device/meter.js';
10
- import { Motion } from './device/motion.js';
11
- import { Contact } from './device/contact.js';
12
- import { Curtain } from './device/curtain.js';
13
- import { IOSensor } from './device/iosensor.js';
14
- import { MeterPlus } from './device/meterplus.js';
15
- import { ColorBulb } from './device/colorbulb.js';
16
- import { StripLight } from './device/lightstrip.js';
17
- import { Humidifier } from './device/humidifier.js';
18
- import { CeilingLight } from './device/ceilinglight.js';
19
- import { WaterDetector } from './device/waterdetector.js';
20
- import { RobotVacuumCleaner } from './device/robotvacuumcleaner.js';
21
-
22
- import { Fan } from './device/fan.js';
23
- import { TV } from './irdevice/tv.js';
24
- import { IRFan } from './irdevice/fan.js';
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 ? port : 80);
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
- 'action': 'setupWebhook',
253
- 'url': url,
254
- 'deviceList': 'ALL',
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', headers: this.generateHeaders(), body: JSON.stringify({
270
- 'action': 'updateWebhook',
271
- 'config': {
272
- 'url': url,
273
- 'enable': true,
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
- 'action': 'queryUrl',
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
- 'action': 'deleteWebhook',
313
- 'url': url,
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['logging'] = this.config.options.logging;
392
+ platformConfig.logging = this.config.options.logging
390
393
  }
391
394
  if (this.config.options.logging && this.config.options.refreshRate) {
392
- platformConfig['refreshRate'] = this.config.options.refreshRate;
395
+ platformConfig.refreshRate = this.config.options.refreshRate
393
396
  }
394
397
  if (this.config.options.logging && this.config.options.pushRate) {
395
- platformConfig['pushRate'] = this.config.options.pushRate;
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 Error('Cannot find platforms array in config');
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 Error('pluginConfig.credentials is not an object');
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
- + ' "openToken" cconfig has been moved to the "token" config');
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
- + ' Submit Bugs Here: https://tinyurl.com/SwitchBotBug');
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
 
@@ -711,21 +710,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
711
710
  'Ceiling Light Pro': this.createCeilingLight.bind(this),
712
711
  'Strip Light': this.createStripLight.bind(this),
713
712
  'Battery Circulator Fan': this.createFan.bind(this),
714
- };
713
+ }
715
714
 
716
715
  if (deviceTypeHandlers[device.deviceType!]) {
717
- await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
718
- await deviceTypeHandlers[device.deviceType!](device);
716
+ await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`)
717
+ await deviceTypeHandlers[device.deviceType!](device)
719
718
  } else if (['Hub Mini', 'Hub Plus', 'Remote', 'Indoor Cam', 'remote with screen'].includes(device.deviceType!)) {
720
- 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)}`)
721
720
  } else {
722
- await this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`
723
- + ` 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)}`)
724
722
  }
725
723
  }
726
724
 
727
725
  private async createIRDevice(device: irdevice & devicesConfig) {
728
- device.connectionType = device.connectionType ?? 'OpenAPI';
726
+ device.connectionType = device.connectionType ?? 'OpenAPI'
729
727
  const deviceTypeHandlers: { [key: string]: (device: irdevice & devicesConfig) => Promise<void> } = {
730
728
  'TV': this.createTV.bind(this),
731
729
  'DIY TV': this.createTV.bind(this),
@@ -754,620 +752,620 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
754
752
  'Camera': this.createCamera.bind(this),
755
753
  'DIY Camera': this.createCamera.bind(this),
756
754
  'Others': this.createOthers.bind(this),
757
- };
755
+ }
758
756
 
759
757
  if (deviceTypeHandlers[device.remoteType!]) {
760
- await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
758
+ await this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`)
761
759
  if (device.remoteType.startsWith('DIY') && device.external === undefined) {
762
- device.external = true;
760
+ device.external = true
763
761
  }
764
- await deviceTypeHandlers[device.remoteType!](device);
762
+ await deviceTypeHandlers[device.remoteType!](device)
765
763
  } else {
766
- await this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.remoteType}, is currently not supported.`
767
- + ` 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)}`)
768
765
  }
769
766
  }
770
767
 
771
768
  private async createHumidifier(device: device & devicesConfig) {
772
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
769
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
773
770
 
774
771
  // see if an accessory with the same uuid has already been registered and restored from
775
772
  // the cached devices we stored in the `configureAccessory` method above
776
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
773
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
777
774
 
778
775
  if (existingAccessory) {
779
776
  // the accessory already exists
780
777
  if (await this.registerDevice(device)) {
781
778
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
782
- existingAccessory.context.device = device;
783
- existingAccessory.context.deviceId = device.deviceId;
784
- existingAccessory.context.deviceType = device.deviceType;
785
- 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
786
783
  existingAccessory.displayName = device.configDeviceName
787
784
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
788
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
789
- existingAccessory.context.connectionType = await this.connectionType(device);
790
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
791
- await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
792
- 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])
793
790
  // create the accessory handler for the restored accessory
794
791
  // this is imported from `platformAccessory.ts`
795
- new Humidifier(this, existingAccessory, device);
796
- 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})`)
797
794
  } else {
798
- this.unregisterPlatformAccessories(existingAccessory);
795
+ this.unregisterPlatformAccessories(existingAccessory)
799
796
  }
800
797
  } else if (await this.registerDevice(device)) {
801
798
  // create a new accessory
802
799
  const accessory = new this.api.platformAccessory(device.configDeviceName
803
800
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
804
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
801
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
805
802
 
806
803
  // store a copy of the device object in the `accessory.context`
807
804
  // the `context` property can be used to store any data about the accessory you may need
808
- accessory.context.device = device;
809
- accessory.context.deviceId = device.deviceId;
810
- accessory.context.deviceType = device.deviceType;
811
- 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
812
809
  accessory.displayName = device.configDeviceName
813
810
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
814
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
815
- accessory.context.connectionType = await this.connectionType(device);
816
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
817
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
818
- 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}`)
819
816
  // create the accessory handler for the newly create accessory
820
817
  // this is imported from `platformAccessory.ts`
821
- new Humidifier(this, accessory, device);
822
- 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})`)
823
820
 
824
821
  // publish device externally or link the accessory to your platform
825
- this.externalOrPlatform(device, accessory);
826
- this.accessories.push(accessory);
822
+ this.externalOrPlatform(device, accessory)
823
+ this.accessories.push(accessory)
827
824
  } else {
828
- 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}`)
829
826
  }
830
827
  }
831
828
 
832
829
  private async createBot(device: device & devicesConfig) {
833
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
830
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
834
831
 
835
832
  // see if an accessory with the same uuid has already been registered and restored from
836
833
  // the cached devices we stored in the `configureAccessory` method above
837
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
834
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
838
835
 
839
836
  if (existingAccessory) {
840
837
  // the accessory already exists
841
838
  if (await this.registerDevice(device)) {
842
839
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
843
- existingAccessory.context.device = device;
844
- existingAccessory.context.deviceId = device.deviceId;
845
- existingAccessory.context.deviceType = device.deviceType;
846
- 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
847
844
  existingAccessory.displayName = device.configDeviceName
848
845
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
849
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
850
- existingAccessory.context.connectionType = await this.connectionType(device);
851
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
852
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
853
- 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])
854
851
  // create the accessory handler for the restored accessory
855
852
  // this is imported from `platformAccessory.ts`
856
- new Bot(this, existingAccessory, device);
857
- 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})`)
858
855
  } else {
859
- this.unregisterPlatformAccessories(existingAccessory);
856
+ this.unregisterPlatformAccessories(existingAccessory)
860
857
  }
861
858
  } else if (await this.registerDevice(device)) {
862
859
  // create a new accessory
863
860
  const accessory = new this.api.platformAccessory(device.configDeviceName
864
861
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
865
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
862
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
866
863
 
867
864
  // store a copy of the device object in the `accessory.context`
868
865
  // the `context` property can be used to store any data about the accessory you may need
869
- accessory.context.device = device;
870
- accessory.context.deviceId = device.deviceId;
871
- accessory.context.deviceType = device.deviceType;
872
- 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
873
870
  accessory.displayName = device.configDeviceName
874
871
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
875
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
876
- accessory.context.connectionType = await this.connectionType(device);
877
- accessory.context.connectionType = await this.connectionType(device);
878
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
879
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
880
- 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}`)
881
878
  // accessory.context.version = findaccessories.accessoryAttribute.softwareRevision;
882
879
  // create the accessory handler for the newly create accessory
883
880
  // this is imported from `platformAccessory.ts`
884
- new Bot(this, accessory, device);
885
- 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})`)
886
883
 
887
884
  // publish device externally or link the accessory to your platform
888
- this.externalOrPlatform(device, accessory);
889
- this.accessories.push(accessory);
885
+ this.externalOrPlatform(device, accessory)
886
+ this.accessories.push(accessory)
890
887
  } else {
891
- 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}`)
892
889
  }
893
890
  }
894
891
 
895
892
  private async createMeter(device: device & devicesConfig) {
896
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
893
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
897
894
 
898
895
  // see if an accessory with the same uuid has already been registered and restored from
899
896
  // the cached devices we stored in the `configureAccessory` method above
900
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
897
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
901
898
 
902
899
  if (existingAccessory) {
903
900
  // the accessory already exists
904
901
  if (await this.registerDevice(device)) {
905
902
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
906
- existingAccessory.context.device = device;
907
- existingAccessory.context.model = SwitchBotModel.Meter;
908
- existingAccessory.context.deviceId = device.deviceId;
909
- 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
910
907
  existingAccessory.displayName = device.configDeviceName
911
908
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
912
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
913
- existingAccessory.context.connectionType = await this.connectionType(device);
914
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
915
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
916
- 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])
917
914
  // create the accessory handler for the restored accessory
918
915
  // this is imported from `platformAccessory.ts`
919
- new Meter(this, existingAccessory, device);
920
- 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})`)
921
918
  } else {
922
- this.unregisterPlatformAccessories(existingAccessory);
919
+ this.unregisterPlatformAccessories(existingAccessory)
923
920
  }
924
921
  } else if (await this.registerDevice(device)) {
925
922
  // create a new accessory
926
923
  const accessory = new this.api.platformAccessory(device.configDeviceName
927
924
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
928
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
925
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
929
926
 
930
927
  // store a copy of the device object in the `accessory.context`
931
928
  // the `context` property can be used to store any data about the accessory you may need
932
- accessory.context.device = device;
933
- accessory.context.model = SwitchBotModel.Meter;
934
- accessory.context.deviceId = device.deviceId;
935
- 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
936
933
  accessory.displayName = device.configDeviceName
937
934
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
938
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
939
- accessory.context.connectionType = await this.connectionType(device);
940
- accessory.context.connectionType = await this.connectionType(device);
941
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
942
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
943
- 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}`)
944
941
  // create the accessory handler for the newly create accessory
945
942
  // this is imported from `platformAccessory.ts`
946
- new Meter(this, accessory, device);
947
- 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})`)
948
945
 
949
946
  // publish device externally or link the accessory to your platform
950
- this.externalOrPlatform(device, accessory);
951
- this.accessories.push(accessory);
947
+ this.externalOrPlatform(device, accessory)
948
+ this.accessories.push(accessory)
952
949
  } else {
953
- 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}`)
954
951
  }
955
952
  }
956
953
 
957
954
  private async createMeterPlus(device: device & devicesConfig) {
958
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
955
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
959
956
 
960
957
  // see if an accessory with the same uuid has already been registered and restored from
961
958
  // the cached devices we stored in the `configureAccessory` method above
962
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
959
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
963
960
 
964
961
  if (existingAccessory) {
965
962
  // the accessory already exists
966
963
  if (await this.registerDevice(device)) {
967
964
  // console.log("existingAccessory", existingAccessory);
968
965
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
969
- existingAccessory.context.device = device;
970
- existingAccessory.context.model = SwitchBotModel.MeterPlusUS ?? SwitchBotModel.MeterPlusJP;
971
- existingAccessory.context.deviceId = device.deviceId;
972
- 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
973
970
  existingAccessory.displayName = device.configDeviceName
974
971
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
975
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
976
- existingAccessory.context.connectionType = await this.connectionType(device);
977
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
978
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
979
- 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])
980
977
  // create the accessory handler for the restored accessory
981
978
  // this is imported from `platformAccessory.ts`
982
- new MeterPlus(this, existingAccessory, device);
983
- 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})`)
984
981
  } else {
985
- this.unregisterPlatformAccessories(existingAccessory);
982
+ this.unregisterPlatformAccessories(existingAccessory)
986
983
  }
987
984
  } else if (await this.registerDevice(device)) {
988
985
  // create a new accessory
989
986
  const accessory = new this.api.platformAccessory(device.configDeviceName
990
987
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
991
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
988
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
992
989
 
993
990
  // store a copy of the device object in the `accessory.context`
994
991
  // the `context` property can be used to store any data about the accessory you may need
995
- accessory.context.device = device;
996
- accessory.context.model = SwitchBotModel.MeterPlusUS ?? SwitchBotModel.MeterPlusJP;
997
- accessory.context.deviceId = device.deviceId;
998
- 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
999
996
  accessory.displayName = device.configDeviceName
1000
997
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1001
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1002
- accessory.context.connectionType = await this.connectionType(device);
1003
- accessory.context.connectionType = await this.connectionType(device);
1004
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1005
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1006
- 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}`)
1007
1004
  // create the accessory handler for the newly create accessory
1008
1005
  // this is imported from `platformAccessory.ts`
1009
- new MeterPlus(this, accessory, device);
1010
- 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})`)
1011
1008
 
1012
1009
  // publish device externally or link the accessory to your platform
1013
- this.externalOrPlatform(device, accessory);
1014
- this.accessories.push(accessory);
1010
+ this.externalOrPlatform(device, accessory)
1011
+ this.accessories.push(accessory)
1015
1012
  } else {
1016
- 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}`)
1017
1014
  }
1018
1015
  }
1019
1016
 
1020
1017
  private async createHub2(device: device & devicesConfig) {
1021
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1018
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
1022
1019
 
1023
1020
  // see if an accessory with the same uuid has already been registered and restored from
1024
1021
  // the cached devices we stored in the `configureAccessory` method above
1025
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1022
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
1026
1023
 
1027
1024
  if (existingAccessory) {
1028
1025
  // the accessory already exists
1029
1026
  if (await this.registerDevice(device)) {
1030
1027
  // console.log("existingAccessory", existingAccessory);
1031
1028
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1032
- existingAccessory.context.device = device;
1033
- existingAccessory.context.model = SwitchBotModel.Hub2;
1034
- existingAccessory.context.deviceId = device.deviceId;
1035
- 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
1036
1033
  existingAccessory.displayName = device.configDeviceName
1037
1034
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1038
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1039
- existingAccessory.context.connectionType = await this.connectionType(device);
1040
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1041
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1042
- 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])
1043
1040
  // create the accessory handler for the restored accessory
1044
1041
  // this is imported from `platformAccessory.ts`
1045
- new Hub(this, existingAccessory, device);
1046
- 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})`)
1047
1044
  } else {
1048
- this.unregisterPlatformAccessories(existingAccessory);
1045
+ this.unregisterPlatformAccessories(existingAccessory)
1049
1046
  }
1050
1047
  } else if (await this.registerDevice(device)) {
1051
1048
  // create a new accessory
1052
1049
  const accessory = new this.api.platformAccessory(device.configDeviceName
1053
1050
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1054
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1051
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
1055
1052
 
1056
1053
  // store a copy of the device object in the `accessory.context`
1057
1054
  // the `context` property can be used to store any data about the accessory you may need
1058
- accessory.context.device = device;
1059
- accessory.context.model = SwitchBotModel.Hub2;
1060
- accessory.context.deviceId = device.deviceId;
1061
- 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
1062
1059
  accessory.displayName = device.configDeviceName
1063
1060
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1064
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1065
- accessory.context.connectionType = await this.connectionType(device);
1066
- accessory.context.connectionType = await this.connectionType(device);
1067
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1068
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1069
- 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}`)
1070
1067
  // create the accessory handler for the newly create accessory
1071
1068
  // this is imported from `platformAccessory.ts`
1072
- new Hub(this, accessory, device);
1073
- 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})`)
1074
1071
 
1075
1072
  // publish device externally or link the accessory to your platform
1076
- this.externalOrPlatform(device, accessory);
1077
- this.accessories.push(accessory);
1073
+ this.externalOrPlatform(device, accessory)
1074
+ this.accessories.push(accessory)
1078
1075
  } else {
1079
- 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}`)
1080
1077
  }
1081
1078
  }
1082
1079
 
1083
1080
  private async createIOSensor(device: device & devicesConfig) {
1084
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1081
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
1085
1082
 
1086
1083
  // see if an accessory with the same uuid has already been registered and restored from
1087
1084
  // the cached devices we stored in the `configureAccessory` method above
1088
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1085
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
1089
1086
 
1090
1087
  if (existingAccessory) {
1091
1088
  // the accessory already exists
1092
1089
  if (await this.registerDevice(device)) {
1093
1090
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1094
- existingAccessory.context.device = device;
1095
- existingAccessory.context.model = SwitchBotModel.OutdoorMeter;
1096
- existingAccessory.context.deviceId = device.deviceId;
1097
- 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
1098
1095
  existingAccessory.displayName = device.configDeviceName
1099
1096
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1100
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1101
- existingAccessory.context.connectionType = await this.connectionType(device);
1102
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1103
- await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1104
- 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])
1105
1102
  // create the accessory handler for the restored accessory
1106
1103
  // this is imported from `platformAccessory.ts`
1107
- new IOSensor(this, existingAccessory, device);
1108
- 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})`)
1109
1106
  } else {
1110
- this.unregisterPlatformAccessories(existingAccessory);
1107
+ this.unregisterPlatformAccessories(existingAccessory)
1111
1108
  }
1112
1109
  } else if (await this.registerDevice(device)) {
1113
1110
  // create a new accessory
1114
1111
  const accessory = new this.api.platformAccessory(device.configDeviceName
1115
1112
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1116
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1113
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
1117
1114
 
1118
1115
  // store a copy of the device object in the `accessory.context`
1119
1116
  // the `context` property can be used to store any data about the accessory you may need
1120
- accessory.context.device = device;
1121
- accessory.context.model = SwitchBotModel.OutdoorMeter;
1122
- accessory.context.deviceId = device.deviceId;
1123
- 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
1124
1121
  accessory.displayName = device.configDeviceName
1125
1122
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1126
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1127
- accessory.context.connectionType = await this.connectionType(device);
1128
- accessory.context.connectionType = await this.connectionType(device);
1129
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1130
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1131
- 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}`)
1132
1129
  // create the accessory handler for the newly create accessory
1133
1130
  // this is imported from `platformAccessory.ts`
1134
- new IOSensor(this, accessory, device);
1135
- 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})`)
1136
1133
 
1137
1134
  // publish device externally or link the accessory to your platform
1138
- this.externalOrPlatform(device, accessory);
1139
- this.accessories.push(accessory);
1135
+ this.externalOrPlatform(device, accessory)
1136
+ this.accessories.push(accessory)
1140
1137
  } else {
1141
- 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}`)
1142
1139
  }
1143
1140
  }
1144
1141
 
1145
1142
  private async createWaterDetector(device: device & devicesConfig) {
1146
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1143
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
1147
1144
 
1148
1145
  // see if an accessory with the same uuid has already been registered and restored from
1149
1146
  // the cached devices we stored in the `configureAccessory` method above
1150
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1147
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
1151
1148
 
1152
1149
  if (existingAccessory) {
1153
1150
  // the accessory already exists
1154
1151
  if (await this.registerDevice(device)) {
1155
1152
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1156
- existingAccessory.context.device = device;
1157
- existingAccessory.context.deviceId = device.deviceId;
1158
- existingAccessory.context.deviceType = device.deviceType;
1159
- 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
1160
1157
  existingAccessory.displayName = device.configDeviceName
1161
1158
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1162
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1163
- existingAccessory.context.connectionType = await this.connectionType(device);
1164
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1165
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1166
- 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])
1167
1164
  // create the accessory handler for the restored accessory
1168
1165
  // this is imported from `platformAccessory.ts`
1169
- new WaterDetector(this, existingAccessory, device);
1170
- 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})`)
1171
1168
  } else {
1172
- this.unregisterPlatformAccessories(existingAccessory);
1169
+ this.unregisterPlatformAccessories(existingAccessory)
1173
1170
  }
1174
1171
  } else if (await this.registerDevice(device)) {
1175
1172
  // create a new accessory
1176
1173
  const accessory = new this.api.platformAccessory(device.configDeviceName
1177
1174
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1178
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1175
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
1179
1176
 
1180
1177
  // store a copy of the device object in the `accessory.context`
1181
1178
  // the `context` property can be used to store any data about the accessory you may need
1182
- accessory.context.device = device;
1183
- accessory.context.deviceId = device.deviceId;
1184
- accessory.context.deviceType = device.deviceType;
1185
- 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
1186
1183
  accessory.displayName = device.configDeviceName
1187
1184
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1188
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1189
- accessory.context.connectionType = await this.connectionType(device);
1190
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1191
- accessory.context.connectionType = await this.connectionType(device);
1192
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1193
- 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}`)
1194
1191
  // create the accessory handler for the newly create accessory
1195
1192
  // this is imported from `platformAccessory.ts`
1196
- new WaterDetector(this, accessory, device);
1197
- 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})`)
1198
1195
 
1199
1196
  // publish device externally or link the accessory to your platform
1200
- this.externalOrPlatform(device, accessory);
1201
- this.accessories.push(accessory);
1197
+ this.externalOrPlatform(device, accessory)
1198
+ this.accessories.push(accessory)
1202
1199
  } else {
1203
- 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}`)
1204
1201
  }
1205
1202
  }
1206
1203
 
1207
1204
  private async createMotion(device: device & devicesConfig) {
1208
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1205
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
1209
1206
 
1210
1207
  // see if an accessory with the same uuid has already been registered and restored from
1211
1208
  // the cached devices we stored in the `configureAccessory` method above
1212
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1209
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
1213
1210
 
1214
1211
  if (existingAccessory) {
1215
1212
  // the accessory already exists
1216
1213
  if (await this.registerDevice(device)) {
1217
1214
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1218
- existingAccessory.context.device = device;
1219
- existingAccessory.context.deviceId = device.deviceId;
1220
- existingAccessory.context.deviceType = device.deviceType;
1221
- 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
1222
1219
  existingAccessory.displayName = device.configDeviceName
1223
1220
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1224
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1225
- existingAccessory.context.connectionType = await this.connectionType(device);
1226
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1227
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1228
- 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])
1229
1226
  // create the accessory handler for the restored accessory
1230
1227
  // this is imported from `platformAccessory.ts`
1231
- new Motion(this, existingAccessory, device);
1232
- 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})`)
1233
1230
  } else {
1234
- this.unregisterPlatformAccessories(existingAccessory);
1231
+ this.unregisterPlatformAccessories(existingAccessory)
1235
1232
  }
1236
1233
  } else if (await this.registerDevice(device)) {
1237
1234
  // create a new accessory
1238
1235
  const accessory = new this.api.platformAccessory(device.configDeviceName
1239
1236
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1240
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1237
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
1241
1238
 
1242
1239
  // store a copy of the device object in the `accessory.context`
1243
1240
  // the `context` property can be used to store any data about the accessory you may need
1244
- accessory.context.device = device;
1245
- accessory.context.deviceId = device.deviceId;
1246
- accessory.context.deviceType = device.deviceType;
1247
- 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
1248
1245
  accessory.displayName = device.configDeviceName
1249
1246
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1250
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1251
- accessory.context.connectionType = await this.connectionType(device);
1252
- accessory.context.connectionType = await this.connectionType(device);
1253
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1254
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1255
- 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}`)
1256
1253
  // create the accessory handler for the newly create accessory
1257
1254
  // this is imported from `platformAccessory.ts`
1258
- new Motion(this, accessory, device);
1259
- 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})`)
1260
1257
 
1261
1258
  // publish device externally or link the accessory to your platform
1262
- this.externalOrPlatform(device, accessory);
1263
- this.accessories.push(accessory);
1259
+ this.externalOrPlatform(device, accessory)
1260
+ this.accessories.push(accessory)
1264
1261
  } else {
1265
- 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}`)
1266
1263
  }
1267
1264
  }
1268
1265
 
1269
1266
  private async createContact(device: device & devicesConfig) {
1270
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1267
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
1271
1268
 
1272
1269
  // see if an accessory with the same uuid has already been registered and restored from
1273
1270
  // the cached devices we stored in the `configureAccessory` method above
1274
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1271
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
1275
1272
 
1276
1273
  if (existingAccessory) {
1277
1274
  // the accessory already exists
1278
1275
  if (await this.registerDevice(device)) {
1279
1276
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1280
- existingAccessory.context.device = device;
1281
- existingAccessory.context.deviceId = device.deviceId;
1282
- existingAccessory.context.deviceType = device.deviceType;
1283
- 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
1284
1281
  existingAccessory.displayName = device.configDeviceName
1285
1282
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1286
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1287
- existingAccessory.context.connectionType = await this.connectionType(device);
1288
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1289
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1290
- 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])
1291
1288
  // create the accessory handler for the restored accessory
1292
1289
  // this is imported from `platformAccessory.ts`
1293
- new Contact(this, existingAccessory, device);
1294
- 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})`)
1295
1292
  } else {
1296
- this.unregisterPlatformAccessories(existingAccessory);
1293
+ this.unregisterPlatformAccessories(existingAccessory)
1297
1294
  }
1298
1295
  } else if (await this.registerDevice(device)) {
1299
1296
  // create a new accessory
1300
1297
  const accessory = new this.api.platformAccessory(device.configDeviceName
1301
1298
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1302
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1299
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
1303
1300
 
1304
1301
  // store a copy of the device object in the `accessory.context`
1305
1302
  // the `context` property can be used to store any data about the accessory you may need
1306
- accessory.context.device = device;
1307
- accessory.context.deviceId = device.deviceId;
1308
- accessory.context.deviceType = device.deviceType;
1309
- 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
1310
1307
  accessory.displayName = device.configDeviceName
1311
1308
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1312
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1313
- accessory.context.connectionType = await this.connectionType(device);
1314
- accessory.context.connectionType = await this.connectionType(device);
1315
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1316
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1317
- 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}`)
1318
1315
  // create the accessory handler for the newly create accessory
1319
1316
  // this is imported from `platformAccessory.ts`
1320
- new Contact(this, accessory, device);
1321
- 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})`)
1322
1319
 
1323
1320
  // publish device externally or link the accessory to your platform
1324
- this.externalOrPlatform(device, accessory);
1325
- this.accessories.push(accessory);
1321
+ this.externalOrPlatform(device, accessory)
1322
+ this.accessories.push(accessory)
1326
1323
  } else {
1327
- 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}`)
1328
1325
  }
1329
1326
  }
1330
1327
 
1331
1328
  private async createBlindTilt(device: device & devicesConfig) {
1332
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1329
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
1333
1330
 
1334
1331
  // see if an accessory with the same uuid has already been registered and restored from
1335
1332
  // the cached devices we stored in the `configureAccessory` method above
1336
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1333
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
1337
1334
 
1338
1335
  if (existingAccessory) {
1339
1336
  // the accessory already exists
1340
1337
  if (await this.registerDevice(device)) {
1341
1338
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1342
- existingAccessory.context.device = device;
1343
- existingAccessory.context.deviceId = device.deviceId;
1344
- existingAccessory.context.deviceType = device.deviceType;
1345
- 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
1346
1343
  existingAccessory.displayName = device.configDeviceName
1347
1344
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1348
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1349
- existingAccessory.context.connectionType = await this.connectionType(device);
1350
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1351
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1352
- 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])
1353
1350
  // create the accessory handler for the restored accessory
1354
1351
  // this is imported from `platformAccessory.ts`
1355
- new BlindTilt(this, existingAccessory, device);
1356
- 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})`)
1357
1354
  } else {
1358
- this.unregisterPlatformAccessories(existingAccessory);
1355
+ this.unregisterPlatformAccessories(existingAccessory)
1359
1356
  }
1360
1357
  } else if (await this.registerDevice(device)) {
1361
1358
  if (isBlindTiltDevice(device)) {
1362
1359
  if (device.group && !device.curtain?.disable_group) {
1363
1360
  this.debugLog(
1364
- 'Your Curtains are grouped, ' +
1365
- `, 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
+ )
1366
1364
  } else {
1367
1365
  if (device.master) {
1368
- this.warnLog(`Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
1366
+ this.warnLog(`Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`)
1369
1367
  } else {
1370
- this.errorLog(`Secondary Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
1368
+ this.errorLog(`Secondary Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`)
1371
1369
  }
1372
1370
  }
1373
1371
  }
@@ -1375,75 +1373,76 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1375
1373
  // create a new accessory
1376
1374
  const accessory = new this.api.platformAccessory(device.configDeviceName
1377
1375
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1378
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1376
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
1379
1377
 
1380
1378
  // store a copy of the device object in the `accessory.context`
1381
1379
  // the `context` property can be used to store any data about the accessory you may need
1382
- accessory.context.device = device;;
1383
- accessory.context.deviceId = device.deviceId;
1384
- accessory.context.deviceType = device.deviceType;
1385
- 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
1386
1384
  accessory.displayName = device.configDeviceName
1387
1385
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1388
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1389
- accessory.context.connectionType = await this.connectionType(device);
1390
- accessory.context.connectionType = await this.connectionType(device);
1391
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1392
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1393
- 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}`)
1394
1392
  // create the accessory handler for the newly create accessory
1395
1393
  // this is imported from `platformAccessory.ts`
1396
- new BlindTilt(this, accessory, device);
1397
- 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})`)
1398
1396
 
1399
1397
  // publish device externally or link the accessory to your platform
1400
- this.externalOrPlatform(device, accessory);
1401
- this.accessories.push(accessory);
1398
+ this.externalOrPlatform(device, accessory)
1399
+ this.accessories.push(accessory)
1402
1400
  } else {
1403
- 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}`)
1404
1402
  }
1405
1403
  }
1406
1404
 
1407
1405
  private async createCurtain(device: device & devicesConfig) {
1408
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1406
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
1409
1407
 
1410
1408
  // see if an accessory with the same uuid has already been registered and restored from
1411
1409
  // the cached devices we stored in the `configureAccessory` method above
1412
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1410
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
1413
1411
 
1414
1412
  if (existingAccessory) {
1415
1413
  // the accessory already exists
1416
1414
  if (await this.registerDevice(device)) {
1417
1415
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1418
- existingAccessory.context.device = device;
1419
- existingAccessory.context.deviceId = device.deviceId;
1420
- existingAccessory.context.deviceType = device.deviceType;
1421
- 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
1422
1420
  existingAccessory.displayName = device.configDeviceName
1423
1421
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1424
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1425
- existingAccessory.context.connectionType = await this.connectionType(device);
1426
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1427
- await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1428
- 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])
1429
1427
  // create the accessory handler for the restored accessory
1430
1428
  // this is imported from `platformAccessory.ts`
1431
- new Curtain(this, existingAccessory, device);
1432
- 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})`)
1433
1431
  } else {
1434
- this.unregisterPlatformAccessories(existingAccessory);
1432
+ this.unregisterPlatformAccessories(existingAccessory)
1435
1433
  }
1436
1434
  } else if (await this.registerDevice(device)) {
1437
1435
  if (isCurtainDevice(device)) {
1438
1436
  if (device.group && !device.curtain?.disable_group) {
1439
1437
  this.debugLog(
1440
- 'Your Curtains are grouped, ' +
1441
- `, 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
+ )
1442
1441
  } else {
1443
1442
  if (device.master) {
1444
- this.warnLog(`Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
1443
+ this.warnLog(`Main Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`)
1445
1444
  } else {
1446
- this.errorLog(`Secondary Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`);
1445
+ this.errorLog(`Secondary Curtain: ${device.deviceName}, deviceId: ${device.deviceId}`)
1447
1446
  }
1448
1447
  }
1449
1448
  }
@@ -1451,1177 +1450,1185 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1451
1450
  // create a new accessory
1452
1451
  const accessory = new this.api.platformAccessory(device.configDeviceName
1453
1452
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1454
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1453
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
1455
1454
 
1456
1455
  // store a copy of the device object in the `accessory.context`
1457
1456
  // the `context` property can be used to store any data about the accessory you may need
1458
- accessory.context.device = device;
1459
- accessory.context.deviceId = device.deviceId;
1460
- accessory.context.deviceType = device.deviceType;
1461
- 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
1462
1461
  accessory.displayName = device.configDeviceName
1463
1462
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1464
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1465
- accessory.context.connectionType = await this.connectionType(device);
1466
- accessory.context.connectionType = await this.connectionType(device);
1467
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1468
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1469
- 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}`)
1470
1469
  // create the accessory handler for the newly create accessory
1471
1470
  // this is imported from `platformAccessory.ts`
1472
- new Curtain(this, accessory, device);
1473
- 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})`)
1474
1473
 
1475
1474
  // publish device externally or link the accessory to your platform
1476
- this.externalOrPlatform(device, accessory);
1477
- this.accessories.push(accessory);
1475
+ this.externalOrPlatform(device, accessory)
1476
+ this.accessories.push(accessory)
1478
1477
  } else {
1479
- 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}`)
1480
1479
  }
1481
1480
  }
1482
1481
 
1483
1482
  private async createPlug(device: device & devicesConfig) {
1484
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1483
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
1485
1484
 
1486
1485
  // see if an accessory with the same uuid has already been registered and restored from
1487
1486
  // the cached devices we stored in the `configureAccessory` method above
1488
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1487
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
1489
1488
 
1490
1489
  if (existingAccessory) {
1491
1490
  // the accessory already exists
1492
1491
  if (await this.registerDevice(device)) {
1493
1492
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1494
- existingAccessory.context.device = device;
1495
- existingAccessory.context.deviceId = device.deviceId;
1496
- existingAccessory.context.deviceType = device.deviceType;
1497
- existingAccessory.context.model = device.deviceType === 'Plug Mini (US)' ? SwitchBotModel.PlugMiniUS : device.deviceType === 'Plug Mini (JP)'
1498
- ? SwitchBotModel.PlugMiniJP : SwitchBotModel.Plug;
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
1499
1501
  existingAccessory.displayName = device.configDeviceName
1500
1502
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1501
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1502
- existingAccessory.context.connectionType = await this.connectionType(device);
1503
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1504
- await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1505
- 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])
1506
1508
  // create the accessory handler for the restored accessory
1507
1509
  // this is imported from `platformAccessory.ts`
1508
- new Plug(this, existingAccessory, device);
1509
- 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})`)
1510
1512
  } else {
1511
- this.unregisterPlatformAccessories(existingAccessory);
1513
+ this.unregisterPlatformAccessories(existingAccessory)
1512
1514
  }
1513
1515
  } else if (await this.registerDevice(device)) {
1514
1516
  // create a new accessory
1515
1517
  const accessory = new this.api.platformAccessory(device.configDeviceName
1516
1518
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1517
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1519
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
1518
1520
 
1519
1521
  // store a copy of the device object in the `accessory.context`
1520
1522
  // the `context` property can be used to store any data about the accessory you may need
1521
- accessory.context.device = device;
1522
- accessory.context.deviceId = device.deviceId;
1523
- accessory.context.deviceType = device.deviceType;
1524
- accessory.context.model = device.deviceType === 'Plug Mini (US)' ? SwitchBotModel.PlugMiniUS : device.deviceType === 'Plug Mini (JP)'
1525
- ? SwitchBotModel.PlugMiniJP : SwitchBotModel.Plug;
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
1526
1531
  accessory.displayName = device.configDeviceName
1527
1532
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1528
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1529
- accessory.context.connectionType = await this.connectionType(device);
1530
- accessory.context.connectionType = await this.connectionType(device);
1531
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1532
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1533
- 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}`)
1534
1539
  // create the accessory handler for the newly create accessory
1535
1540
  // this is imported from `platformAccessory.ts`
1536
- new Plug(this, accessory, device);
1537
- 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})`)
1538
1543
 
1539
1544
  // publish device externally or link the accessory to your platform
1540
- this.externalOrPlatform(device, accessory);
1541
- this.accessories.push(accessory);
1545
+ this.externalOrPlatform(device, accessory)
1546
+ this.accessories.push(accessory)
1542
1547
  } else {
1543
- 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}`)
1544
1549
  }
1545
1550
  }
1546
1551
 
1547
1552
  private async createLock(device: device & devicesConfig) {
1548
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1553
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
1549
1554
 
1550
1555
  // see if an accessory with the same uuid has already been registered and restored from
1551
1556
  // the cached devices we stored in the `configureAccessory` method above
1552
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1557
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
1553
1558
 
1554
1559
  if (existingAccessory) {
1555
1560
  // the accessory already exists
1556
1561
  if (await this.registerDevice(device)) {
1557
1562
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1558
- existingAccessory.context.device = device;
1559
- existingAccessory.context.deviceId = device.deviceId;
1560
- existingAccessory.context.deviceType = device.deviceType;
1561
- 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
1562
1567
  existingAccessory.displayName = device.configDeviceName
1563
1568
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1564
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1565
- existingAccessory.context.connectionType = await this.connectionType(device);
1566
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1567
- this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1568
- 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])
1569
1574
  // create the accessory handler for the restored accessory
1570
1575
  // this is imported from `platformAccessory.ts`
1571
- new Lock(this, existingAccessory, device);
1572
- 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})`)
1573
1578
  } else {
1574
- this.unregisterPlatformAccessories(existingAccessory);
1579
+ this.unregisterPlatformAccessories(existingAccessory)
1575
1580
  }
1576
1581
  } else if (await this.registerDevice(device)) {
1577
1582
  // create a new accessory
1578
1583
  const accessory = new this.api.platformAccessory(device.configDeviceName
1579
1584
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1580
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1585
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
1581
1586
 
1582
1587
  // store a copy of the device object in the `accessory.context`
1583
1588
  // the `context` property can be used to store any data about the accessory you may need
1584
- accessory.context.device = device;
1585
- accessory.context.deviceId = device.deviceId;
1586
- accessory.context.deviceType = device.deviceType;
1587
- 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
1588
1593
  accessory.displayName = device.configDeviceName
1589
1594
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1590
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1591
- accessory.context.connectionType = await this.connectionType(device);
1592
- accessory.context.connectionType = await this.connectionType(device);
1593
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1594
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1595
- 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}`)
1596
1601
  // create the accessory handler for the newly create accessory
1597
1602
  // this is imported from `platformAccessory.ts`
1598
- new Lock(this, accessory, device);
1599
- 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})`)
1600
1605
 
1601
1606
  // publish device externally or link the accessory to your platform
1602
- this.externalOrPlatform(device, accessory);
1603
- this.accessories.push(accessory);
1607
+ this.externalOrPlatform(device, accessory)
1608
+ this.accessories.push(accessory)
1604
1609
  } else {
1605
- 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}`)
1606
1611
  }
1607
1612
  }
1608
1613
 
1609
1614
  private async createColorBulb(device: device & devicesConfig) {
1610
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1615
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
1611
1616
 
1612
1617
  // see if an accessory with the same uuid has already been registered and restored from
1613
1618
  // the cached devices we stored in the `configureAccessory` method above
1614
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1619
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
1615
1620
 
1616
1621
  if (existingAccessory) {
1617
1622
  // the accessory already exists
1618
1623
  if (await this.registerDevice(device)) {
1619
1624
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1620
- existingAccessory.context.device = device;
1621
- existingAccessory.context.deviceId = device.deviceId;
1622
- existingAccessory.context.deviceType = device.deviceType;
1623
- 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
1624
1629
  existingAccessory.displayName = device.configDeviceName
1625
1630
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1626
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1627
- existingAccessory.context.connectionType = await this.connectionType(device);
1628
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1629
- await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1630
- 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])
1631
1636
  // create the accessory handler for the restored accessory
1632
1637
  // this is imported from `platformAccessory.ts`
1633
- new ColorBulb(this, existingAccessory, device);
1634
- 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})`)
1635
1640
  } else {
1636
- this.unregisterPlatformAccessories(existingAccessory);
1641
+ this.unregisterPlatformAccessories(existingAccessory)
1637
1642
  }
1638
1643
  } else if (await this.registerDevice(device)) {
1639
1644
  // create a new accessory
1640
1645
  const accessory = new this.api.platformAccessory(device.configDeviceName
1641
1646
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1642
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1647
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
1643
1648
 
1644
1649
  // store a copy of the device object in the `accessory.context`
1645
1650
  // the `context` property can be used to store any data about the accessory you may need
1646
- accessory.context.device = device;
1647
- accessory.context.deviceId = device.deviceId;
1648
- accessory.context.deviceType = device.deviceType;
1649
- 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
1650
1655
  accessory.displayName = device.configDeviceName
1651
1656
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1652
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1653
- accessory.context.connectionType = await this.connectionType(device);
1654
- accessory.context.connectionType = await this.connectionType(device);
1655
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1656
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1657
- 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}`)
1658
1663
  // create the accessory handler for the newly create accessory
1659
1664
  // this is imported from `platformAccessory.ts`
1660
- new ColorBulb(this, accessory, device);
1661
- 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})`)
1662
1667
 
1663
1668
  // publish device externally or link the accessory to your platform
1664
- this.externalOrPlatform(device, accessory);
1665
- this.accessories.push(accessory);
1669
+ this.externalOrPlatform(device, accessory)
1670
+ this.accessories.push(accessory)
1666
1671
  } else {
1667
- 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}`)
1668
1673
  }
1669
1674
  }
1670
1675
 
1671
1676
  private async createCeilingLight(device: device & devicesConfig) {
1672
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1677
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
1673
1678
 
1674
1679
  // see if an accessory with the same uuid has already been registered and restored from
1675
1680
  // the cached devices we stored in the `configureAccessory` method above
1676
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1681
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
1677
1682
 
1678
1683
  if (existingAccessory) {
1679
1684
  // the accessory already exists
1680
1685
  if (await this.registerDevice(device)) {
1681
1686
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1682
- existingAccessory.context.device = device;
1683
- existingAccessory.context.deviceId = device.deviceId;
1684
- existingAccessory.context.deviceType = device.deviceType;
1685
- 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
1686
1691
  existingAccessory.displayName = device.configDeviceName
1687
1692
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1688
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1689
- existingAccessory.context.connectionType = await this.connectionType(device);
1690
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1691
- await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1692
- 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])
1693
1698
  // create the accessory handler for the restored accessory
1694
1699
  // this is imported from `platformAccessory.ts`
1695
- new CeilingLight(this, existingAccessory, device);
1696
- 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})`)
1697
1702
  } else {
1698
- this.unregisterPlatformAccessories(existingAccessory);
1703
+ this.unregisterPlatformAccessories(existingAccessory)
1699
1704
  }
1700
1705
  } else if (await this.registerDevice(device)) {
1701
1706
  // create a new accessory
1702
1707
  const accessory = new this.api.platformAccessory(device.configDeviceName
1703
1708
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1704
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1709
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
1705
1710
 
1706
1711
  // store a copy of the device object in the `accessory.context`
1707
1712
  // the `context` property can be used to store any data about the accessory you may need
1708
- accessory.context.device = device;
1709
- accessory.context.deviceId = device.deviceId;
1710
- accessory.context.deviceType = device.deviceType;
1711
- 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
1712
1717
  accessory.displayName = device.configDeviceName
1713
1718
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1714
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1715
- accessory.context.connectionType = await this.connectionType(device);
1716
- accessory.context.connectionType = await this.connectionType(device);
1717
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1718
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1719
- 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}`)
1720
1725
  // create the accessory handler for the newly create accessory
1721
1726
  // this is imported from `platformAccessory.ts`
1722
- new CeilingLight(this, accessory, device);
1723
- 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})`)
1724
1729
 
1725
1730
  // publish device externally or link the accessory to your platform
1726
- this.externalOrPlatform(device, accessory);
1727
- this.accessories.push(accessory);
1731
+ this.externalOrPlatform(device, accessory)
1732
+ this.accessories.push(accessory)
1728
1733
  } else {
1729
- 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}`)
1730
1735
  }
1731
1736
  }
1732
1737
 
1733
1738
  private async createStripLight(device: device & devicesConfig) {
1734
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1739
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
1735
1740
 
1736
1741
  // see if an accessory with the same uuid has already been registered and restored from
1737
1742
  // the cached devices we stored in the `configureAccessory` method above
1738
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1743
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
1739
1744
 
1740
1745
  if (existingAccessory) {
1741
1746
  // the accessory already exists
1742
1747
  if (await this.registerDevice(device)) {
1743
1748
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1744
- existingAccessory.context.device = device;
1745
- existingAccessory.context.deviceId = device.deviceId;
1746
- existingAccessory.context.deviceType = device.deviceType;
1747
- 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
1748
1753
  existingAccessory.displayName = device.configDeviceName
1749
1754
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1750
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1751
- existingAccessory.context.connectionType = await this.connectionType(device);
1752
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1753
- await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1754
- 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])
1755
1760
  // create the accessory handler for the restored accessory
1756
1761
  // this is imported from `platformAccessory.ts`
1757
- new StripLight(this, existingAccessory, device);
1758
- 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})`)
1759
1764
  } else {
1760
- this.unregisterPlatformAccessories(existingAccessory);
1765
+ this.unregisterPlatformAccessories(existingAccessory)
1761
1766
  }
1762
1767
  } else if (await this.registerDevice(device)) {
1763
1768
  // create a new accessory
1764
1769
  const accessory = new this.api.platformAccessory(device.configDeviceName
1765
1770
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1766
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1771
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
1767
1772
 
1768
1773
  // store a copy of the device object in the `accessory.context`
1769
1774
  // the `context` property can be used to store any data about the accessory you may need
1770
- accessory.context.device = device;
1771
- accessory.context.deviceId = device.deviceId;
1772
- accessory.context.deviceType = device.deviceType;
1773
- 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
1774
1779
  accessory.displayName = device.configDeviceName
1775
1780
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1776
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1777
- accessory.context.connectionType = await this.connectionType(device);
1778
- accessory.context.connectionType = await this.connectionType(device);
1779
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1780
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1781
- 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}`)
1782
1787
  // create the accessory handler for the newly create accessory
1783
1788
  // this is imported from `platformAccessory.ts`
1784
- new StripLight(this, accessory, device);
1785
- 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})`)
1786
1791
 
1787
1792
  // publish device externally or link the accessory to your platform
1788
- this.externalOrPlatform(device, accessory);
1789
- this.accessories.push(accessory);
1793
+ this.externalOrPlatform(device, accessory)
1794
+ this.accessories.push(accessory)
1790
1795
  } else {
1791
- 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}`)
1792
1797
  }
1793
1798
  }
1794
1799
 
1795
1800
  private async createFan(device: device & devicesConfig) {
1796
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1801
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
1797
1802
 
1798
1803
  // see if an accessory with the same uuid has already been registered and restored from
1799
1804
  // the cached devices we stored in the `configureAccessory` method above
1800
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1805
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
1801
1806
 
1802
1807
  if (existingAccessory) {
1803
1808
  // the accessory already exists
1804
1809
  if (await this.registerDevice(device)) {
1805
1810
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1806
- existingAccessory.context.device = device;
1807
- existingAccessory.context.deviceId = device.deviceId;
1808
- existingAccessory.context.deviceType = device.deviceType;
1809
- 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
1810
1815
  existingAccessory.displayName = device.configDeviceName
1811
1816
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1812
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1813
- existingAccessory.context.connectionType = await this.connectionType(device);
1814
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1815
- await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1816
- 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])
1817
1822
  // create the accessory handler for the restored accessory
1818
1823
  // this is imported from `platformAccessory.ts`
1819
- new Fan(this, existingAccessory, device);
1820
- 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})`)
1821
1826
  } else {
1822
- this.unregisterPlatformAccessories(existingAccessory);
1827
+ this.unregisterPlatformAccessories(existingAccessory)
1823
1828
  }
1824
1829
  } else if (await this.registerDevice(device)) {
1825
1830
  // create a new accessory
1826
1831
  const accessory = new this.api.platformAccessory(device.configDeviceName
1827
1832
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1828
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1833
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
1829
1834
 
1830
1835
  // store a copy of the device object in the `accessory.context`
1831
1836
  // the `context` property can be used to store any data about the accessory you may need
1832
- accessory.context.device = device;
1833
- accessory.context.deviceId = device.deviceId;
1834
- accessory.context.deviceType = device.deviceType;
1835
- 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
1836
1841
  accessory.displayName = device.configDeviceName
1837
1842
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1838
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1839
- accessory.context.connectionType = await this.connectionType(device);
1840
- accessory.context.connectionType = await this.connectionType(device);
1841
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1842
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1843
- 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}`)
1844
1849
  // create the accessory handler for the newly create accessory
1845
1850
  // this is imported from `platformAccessory.ts`
1846
- new Fan(this, accessory, device);
1847
- 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})`)
1848
1853
 
1849
1854
  // publish device externally or link the accessory to your platform
1850
- this.externalOrPlatform(device, accessory);
1851
- this.accessories.push(accessory);
1855
+ this.externalOrPlatform(device, accessory)
1856
+ this.accessories.push(accessory)
1852
1857
  } else {
1853
- 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}`)
1854
1859
  }
1855
1860
  }
1856
1861
 
1857
1862
  private async createRobotVacuumCleaner(device: device & devicesConfig) {
1858
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1863
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
1859
1864
 
1860
1865
  // see if an accessory with the same uuid has already been registered and restored from
1861
1866
  // the cached devices we stored in the `configureAccessory` method above
1862
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1867
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
1863
1868
 
1864
1869
  if (existingAccessory) {
1865
1870
  // the accessory already exists
1866
1871
  if (await this.registerDevice(device)) {
1867
1872
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1868
- existingAccessory.context.device = device;
1869
- existingAccessory.context.deviceId = device.deviceId;
1870
- existingAccessory.context.deviceType = device.deviceType;
1871
- existingAccessory.context.model = device.deviceType === 'Robot Vacuum Cleaner S1' ? SwitchBotModel.RobotVacuumCleanerS1
1872
- : device.deviceType === 'Robot Vacuum Cleaner S1 Plus' ? SwitchBotModel.RobotVacuumCleanerS1Plus
1873
- : device.deviceType === 'Robot Vacuum Cleaner S10' ? SwitchBotModel.RobotVacuumCleanerS10
1874
- : device.deviceType === 'WoSweeper' ? SwitchBotModel.WoSweeper : device.deviceType === 'WoSweeperMini' ? SwitchBotModel.WoSweeperMini
1875
- : SwitchBotModel.Unknown;
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
1876
1887
  existingAccessory.displayName = device.configDeviceName
1877
1888
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1878
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1879
- existingAccessory.context.connectionType = await this.connectionType(device);
1880
- existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1881
- await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1882
- 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])
1883
1894
  // create the accessory handler for the restored accessory
1884
1895
  // this is imported from `platformAccessory.ts`
1885
- new RobotVacuumCleaner(this, existingAccessory, device);
1886
- 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})`)
1887
1898
  } else {
1888
- this.unregisterPlatformAccessories(existingAccessory);
1899
+ this.unregisterPlatformAccessories(existingAccessory)
1889
1900
  }
1890
1901
  } else if (await this.registerDevice(device)) {
1891
1902
  // create a new accessory
1892
1903
  const accessory = new this.api.platformAccessory(device.configDeviceName
1893
1904
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1894
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1905
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
1895
1906
 
1896
1907
  // store a copy of the device object in the `accessory.context`
1897
1908
  // the `context` property can be used to store any data about the accessory you may need
1898
- accessory.context.device = device;
1899
- accessory.context.deviceId = device.deviceId;
1900
- accessory.context.deviceType = device.deviceType;
1901
- accessory.context.model = device.deviceType === 'Robot Vacuum Cleaner S1' ? SwitchBotModel.RobotVacuumCleanerS1
1902
- : device.deviceType === 'Robot Vacuum Cleaner S1 Plus' ? SwitchBotModel.RobotVacuumCleanerS1Plus
1903
- : device.deviceType === 'Robot Vacuum Cleaner S10' ? SwitchBotModel.RobotVacuumCleanerS10
1904
- : device.deviceType === 'WoSweeper' ? SwitchBotModel.WoSweeper : device.deviceType === 'WoSweeperMini' ? SwitchBotModel.WoSweeperMini
1905
- : SwitchBotModel.Unknown;
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
1906
1923
  accessory.displayName = device.configDeviceName
1907
1924
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1908
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1909
- accessory.context.connectionType = await this.connectionType(device);
1910
- accessory.context.connectionType = await this.connectionType(device);
1911
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1912
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1913
- 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}`)
1914
1931
  // create the accessory handler for the newly create accessory
1915
1932
  // this is imported from `platformAccessory.ts`
1916
- new RobotVacuumCleaner(this, accessory, device);
1917
- 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})`)
1918
1935
 
1919
1936
  // publish device externally or link the accessory to your platform
1920
- this.externalOrPlatform(device, accessory);
1921
- this.accessories.push(accessory);
1937
+ this.externalOrPlatform(device, accessory)
1938
+ this.accessories.push(accessory)
1922
1939
  } else {
1923
- 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}`)
1924
1941
  }
1925
1942
  }
1926
1943
 
1927
1944
  private async createTV(device: irdevice & devicesConfig) {
1928
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
1945
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
1929
1946
 
1930
1947
  // see if an accessory with the same uuid has already been registered and restored from
1931
1948
  // the cached devices we stored in the `configureAccessory` method above
1932
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1949
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
1933
1950
 
1934
1951
  if (!device.hide_device && existingAccessory) {
1935
1952
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1936
- existingAccessory.context.device = device;
1937
- existingAccessory.context.deviceId = device.deviceId;
1938
- existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1939
- 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
1940
1957
  existingAccessory.displayName = device.configDeviceName
1941
1958
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1942
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1943
- await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
1944
- existingAccessory.context.connectionType = device.connectionType;
1945
- 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])
1946
1963
  // create the accessory handler for the restored accessory
1947
1964
  // this is imported from `platformAccessory.ts`
1948
- new TV(this, existingAccessory, device);
1949
- 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})`)
1950
1967
  } else if (!device.hide_device && device.hubDeviceId) {
1951
1968
  // create a new accessory
1952
1969
  const accessory = new this.api.platformAccessory(device.configDeviceName
1953
1970
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1954
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
1971
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
1955
1972
 
1956
1973
  // store a copy of the device object in the `accessory.context`
1957
1974
  // the `context` property can be used to store any data about the accessory you may need
1958
- accessory.context.device = device;
1959
- accessory.context.deviceId = device.deviceId;
1960
- accessory.context.deviceType = `IR: ${device.remoteType}`;
1961
- 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
1962
1979
  accessory.displayName = device.configDeviceName
1963
1980
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1964
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1965
- accessory.context.connectionType = await this.connectionType(device);
1966
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
1967
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
1968
- 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}`)
1969
1986
  // create the accessory handler for the newly create accessory
1970
1987
  // this is imported from `platformAccessory.ts`
1971
- new TV(this, accessory, device);
1972
- 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})`)
1973
1990
 
1974
- this.externalOrPlatform(device, accessory);
1975
- this.accessories.push(accessory);
1991
+ this.externalOrPlatform(device, accessory)
1992
+ this.accessories.push(accessory)
1976
1993
  } else {
1977
- 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}`)
1978
1995
  }
1979
1996
  }
1980
1997
 
1981
1998
  private async createIRFan(device: irdevice & devicesConfig) {
1982
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
1999
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
1983
2000
 
1984
2001
  // see if an accessory with the same uuid has already been registered and restored from
1985
2002
  // the cached devices we stored in the `configureAccessory` method above
1986
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
2003
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
1987
2004
 
1988
2005
  if (existingAccessory) {
1989
2006
  // the accessory already exists
1990
2007
  if (!device.hide_device && device.hubDeviceId) {
1991
2008
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1992
- existingAccessory.context.device = device;
1993
- existingAccessory.context.deviceId = device.deviceId;
1994
- existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1995
- 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
1996
2013
  existingAccessory.displayName = device.configDeviceName
1997
2014
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1998
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
1999
- await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2000
- existingAccessory.context.connectionType = device.connectionType;
2001
- 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])
2002
2019
  // create the accessory handler for the restored accessory
2003
2020
  // this is imported from `platformAccessory.ts`
2004
- new IRFan(this, existingAccessory, device);
2005
- 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})`)
2006
2023
  } else {
2007
- this.unregisterPlatformAccessories(existingAccessory);
2024
+ this.unregisterPlatformAccessories(existingAccessory)
2008
2025
  }
2009
2026
  } else if (!device.hide_device && device.hubDeviceId) {
2010
2027
  // create a new accessory
2011
2028
  const accessory = new this.api.platformAccessory(device.configDeviceName
2012
2029
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2013
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
2030
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
2014
2031
 
2015
2032
  // store a copy of the device object in the `accessory.context`
2016
2033
  // the `context` property can be used to store any data about the accessory you may need
2017
- accessory.context.device = device;
2018
- accessory.context.deviceId = device.deviceId;
2019
- accessory.context.deviceType = `IR: ${device.remoteType}`;
2020
- 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
2021
2038
  accessory.displayName = device.configDeviceName
2022
2039
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2023
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2024
- accessory.context.connectionType = await this.connectionType(device);
2025
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
2026
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2027
- 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}`)
2028
2045
  // create the accessory handler for the newly create accessory
2029
2046
  // this is imported from `platformAccessory.ts`
2030
- new IRFan(this, accessory, device);
2031
- 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})`)
2032
2049
 
2033
2050
  // publish device externally or link the accessory to your platform
2034
- this.externalOrPlatform(device, accessory);
2035
- this.accessories.push(accessory);
2051
+ this.externalOrPlatform(device, accessory)
2052
+ this.accessories.push(accessory)
2036
2053
  } else {
2037
- 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}`)
2038
2055
  }
2039
2056
  }
2040
2057
 
2041
2058
  private async createLight(device: irdevice & devicesConfig) {
2042
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
2059
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
2043
2060
 
2044
2061
  // see if an accessory with the same uuid has already been registered and restored from
2045
2062
  // the cached devices we stored in the `configureAccessory` method above
2046
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
2063
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
2047
2064
 
2048
2065
  if (existingAccessory) {
2049
2066
  // the accessory already exists
2050
2067
  if (!device.hide_device && device.hubDeviceId) {
2051
2068
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2052
- existingAccessory.context.device = device;
2053
- existingAccessory.context.deviceId = device.deviceId;
2054
- existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2055
- 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
2056
2073
  existingAccessory.displayName = device.configDeviceName
2057
2074
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2058
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2059
- await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2060
- existingAccessory.context.connectionType = device.connectionType;
2061
- 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])
2062
2079
  // create the accessory handler for the restored accessory
2063
2080
  // this is imported from `platformAccessory.ts`
2064
- new Light(this, existingAccessory, device);
2065
- 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})`)
2066
2083
  } else {
2067
- this.unregisterPlatformAccessories(existingAccessory);
2084
+ this.unregisterPlatformAccessories(existingAccessory)
2068
2085
  }
2069
2086
  } else if (!device.hide_device && device.hubDeviceId) {
2070
2087
  // create a new accessory
2071
2088
  const accessory = new this.api.platformAccessory(device.configDeviceName
2072
2089
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2073
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
2090
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
2074
2091
 
2075
2092
  // store a copy of the device object in the `accessory.context`
2076
2093
  // the `context` property can be used to store any data about the accessory you may need
2077
- accessory.context.device = device;
2078
- accessory.context.deviceId = device.deviceId;
2079
- accessory.context.deviceType = `IR: ${device.remoteType}`;
2080
- 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
2081
2098
  accessory.displayName = device.configDeviceName
2082
2099
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2083
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2084
- accessory.context.connectionType = await this.connectionType(device);
2085
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
2086
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2087
- 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}`)
2088
2105
  // create the accessory handler for the newly create accessory
2089
2106
  // this is imported from `platformAccessory.ts`
2090
- new Light(this, accessory, device);
2091
- 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})`)
2092
2109
 
2093
2110
  // publish device externally or link the accessory to your platform
2094
- this.externalOrPlatform(device, accessory);
2095
- this.accessories.push(accessory);
2111
+ this.externalOrPlatform(device, accessory)
2112
+ this.accessories.push(accessory)
2096
2113
  } else {
2097
- 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}`)
2098
2115
  }
2099
2116
  }
2100
2117
 
2101
2118
  private async createAirConditioner(device: irdevice & devicesConfig & irDevicesConfig) {
2102
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
2119
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
2103
2120
 
2104
2121
  // see if an accessory with the same uuid has already been registered and restored from
2105
2122
  // the cached devices we stored in the `configureAccessory` method above
2106
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
2123
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
2107
2124
 
2108
2125
  if (existingAccessory) {
2109
2126
  // the accessory already exists
2110
2127
  if (!device.hide_device && device.hubDeviceId) {
2111
2128
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2112
- existingAccessory.context.device = device;
2113
- existingAccessory.context.deviceId = device.deviceId;
2114
- existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2115
- 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
2116
2133
  existingAccessory.displayName = device.configDeviceName
2117
2134
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2118
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2119
- await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2120
- existingAccessory.context.connectionType = device.connectionType;
2121
- 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])
2122
2139
  // create the accessory handler for the restored accessory
2123
2140
  // this is imported from `platformAccessory.ts`
2124
- new AirConditioner(this, existingAccessory, device);
2125
- 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})`)
2126
2143
  } else {
2127
- this.unregisterPlatformAccessories(existingAccessory);
2144
+ this.unregisterPlatformAccessories(existingAccessory)
2128
2145
  }
2129
2146
  } else if (!device.hide_device && device.hubDeviceId) {
2130
2147
  // create a new accessory
2131
2148
  const accessory = new this.api.platformAccessory(device.configDeviceName
2132
2149
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2133
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
2150
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
2134
2151
 
2135
2152
  // store a copy of the device object in the `accessory.context`
2136
2153
  // the `context` property can be used to store any data about the accessory you may need
2137
- accessory.context.device = device;
2138
- accessory.context.deviceId = device.deviceId;
2139
- accessory.context.deviceType = `IR: ${device.remoteType}`;
2140
- 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
2141
2158
  accessory.displayName = device.configDeviceName
2142
2159
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2143
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2144
- accessory.context.connectionType = await this.connectionType(device);
2145
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
2146
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2147
- 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}`)
2148
2165
  // create the accessory handler for the newly create accessory
2149
2166
  // this is imported from `platformAccessory.ts`
2150
- new AirConditioner(this, accessory, device);
2151
- 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})`)
2152
2169
 
2153
2170
  // publish device externally or link the accessory to your platform
2154
- this.externalOrPlatform(device, accessory);
2155
- this.accessories.push(accessory);
2171
+ this.externalOrPlatform(device, accessory)
2172
+ this.accessories.push(accessory)
2156
2173
  } else {
2157
- 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}`)
2158
2175
  }
2159
2176
  }
2160
2177
 
2161
2178
  private async createAirPurifier(device: irdevice & devicesConfig) {
2162
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
2179
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
2163
2180
 
2164
2181
  // see if an accessory with the same uuid has already been registered and restored from
2165
2182
  // the cached devices we stored in the `configureAccessory` method above
2166
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
2183
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
2167
2184
 
2168
2185
  if (existingAccessory) {
2169
2186
  // the accessory already exists
2170
2187
  if (!device.hide_device && device.hubDeviceId) {
2171
2188
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2172
- existingAccessory.context.device = device;
2173
- existingAccessory.context.deviceId = device.deviceId;
2174
- existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2175
- 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
2176
2193
  existingAccessory.displayName = device.configDeviceName
2177
2194
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2178
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2179
- await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2180
- existingAccessory.context.connectionType = device.connectionType;
2181
- 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])
2182
2199
  // create the accessory handler for the restored accessory
2183
2200
  // this is imported from `platformAccessory.ts`
2184
- new AirPurifier(this, existingAccessory, device);
2185
- 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})`)
2186
2203
  } else {
2187
- this.unregisterPlatformAccessories(existingAccessory);
2204
+ this.unregisterPlatformAccessories(existingAccessory)
2188
2205
  }
2189
2206
  } else if (!device.hide_device && device.hubDeviceId) {
2190
2207
  // create a new accessory
2191
2208
  const accessory = new this.api.platformAccessory(device.configDeviceName
2192
2209
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2193
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
2210
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
2194
2211
 
2195
2212
  // store a copy of the device object in the `accessory.context`
2196
2213
  // the `context` property can be used to store any data about the accessory you may need
2197
- accessory.context.device = device;
2198
- accessory.context.deviceId = device.deviceId;
2199
- accessory.context.deviceType = `IR: ${device.remoteType}`;
2200
- 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
2201
2218
  accessory.displayName = device.configDeviceName
2202
2219
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2203
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2204
- accessory.context.connectionType = await this.connectionType(device);
2205
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
2206
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2207
- 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}`)
2208
2225
  // create the accessory handler for the newly create accessory
2209
2226
  // this is imported from `platformAccessory.ts`
2210
- new AirPurifier(this, accessory, device);
2211
- 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})`)
2212
2229
 
2213
2230
  // publish device externally or link the accessory to your platform
2214
- this.externalOrPlatform(device, accessory);
2215
- this.accessories.push(accessory);
2231
+ this.externalOrPlatform(device, accessory)
2232
+ this.accessories.push(accessory)
2216
2233
  } else {
2217
- 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}`)
2218
2235
  }
2219
2236
  }
2220
2237
 
2221
2238
  private async createWaterHeater(device: irdevice & devicesConfig) {
2222
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
2239
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
2223
2240
 
2224
2241
  // see if an accessory with the same uuid has already been registered and restored from
2225
2242
  // the cached devices we stored in the `configureAccessory` method above
2226
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
2243
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
2227
2244
 
2228
2245
  if (existingAccessory) {
2229
2246
  // the accessory already exists
2230
2247
  if (!device.hide_device && device.hubDeviceId) {
2231
2248
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2232
- existingAccessory.context.device = device;
2233
- existingAccessory.context.deviceId = device.deviceId;
2234
- existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2235
- 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
2236
2253
  existingAccessory.displayName = device.configDeviceName
2237
2254
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2238
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2239
- await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2240
- existingAccessory.context.connectionType = device.connectionType;
2241
- 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])
2242
2259
  // create the accessory handler for the restored accessory
2243
2260
  // this is imported from `platformAccessory.ts`
2244
- new WaterHeater(this, existingAccessory, device);
2245
- 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})`)
2246
2263
  } else {
2247
- this.unregisterPlatformAccessories(existingAccessory);
2264
+ this.unregisterPlatformAccessories(existingAccessory)
2248
2265
  }
2249
2266
  } else if (!device.hide_device && device.hubDeviceId) {
2250
2267
  // create a new accessory
2251
2268
  const accessory = new this.api.platformAccessory(device.configDeviceName
2252
2269
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2253
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
2270
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
2254
2271
 
2255
2272
  // store a copy of the device object in the `accessory.context`
2256
2273
  // the `context` property can be used to store any data about the accessory you may need
2257
- accessory.context.device = device;
2258
- accessory.context.deviceId = device.deviceId;
2259
- accessory.context.deviceType = `IR: ${device.remoteType}`;
2260
- 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
2261
2278
  accessory.displayName = device.configDeviceName
2262
2279
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2263
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2264
- accessory.context.connectionType = await this.connectionType(device);
2265
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
2266
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2267
- 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}`)
2268
2285
  // create the accessory handler for the newly create accessory
2269
2286
  // this is imported from `platformAccessory.ts`
2270
- new WaterHeater(this, accessory, device);
2271
- 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})`)
2272
2289
 
2273
2290
  // publish device externally or link the accessory to your platform
2274
- this.externalOrPlatform(device, accessory);
2275
- this.accessories.push(accessory);
2291
+ this.externalOrPlatform(device, accessory)
2292
+ this.accessories.push(accessory)
2276
2293
  } else {
2277
- 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}`)
2278
2295
  }
2279
2296
  }
2280
2297
 
2281
2298
  private async createVacuumCleaner(device: irdevice & devicesConfig) {
2282
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
2299
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
2283
2300
 
2284
2301
  // see if an accessory with the same uuid has already been registered and restored from
2285
2302
  // the cached devices we stored in the `configureAccessory` method above
2286
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
2303
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
2287
2304
 
2288
2305
  if (existingAccessory) {
2289
2306
  // the accessory already exists
2290
2307
  if (!device.hide_device && device.hubDeviceId) {
2291
2308
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2292
- existingAccessory.context.device = device;
2293
- existingAccessory.context.deviceId = device.deviceId;
2294
- existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2295
- 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
2296
2313
  existingAccessory.displayName = device.configDeviceName
2297
2314
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2298
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2299
- await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2300
- existingAccessory.context.connectionType = device.connectionType;
2301
- 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])
2302
2319
  // create the accessory handler for the restored accessory
2303
2320
  // this is imported from `platformAccessory.ts`
2304
- new VacuumCleaner(this, existingAccessory, device);
2305
- 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})`)
2306
2323
  } else {
2307
- this.unregisterPlatformAccessories(existingAccessory);
2324
+ this.unregisterPlatformAccessories(existingAccessory)
2308
2325
  }
2309
2326
  } else if (!device.hide_device && device.hubDeviceId) {
2310
2327
  // create a new accessory
2311
2328
  const accessory = new this.api.platformAccessory(device.configDeviceName
2312
2329
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2313
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
2330
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
2314
2331
 
2315
2332
  // store a copy of the device object in the `accessory.context`
2316
2333
  // the `context` property can be used to store any data about the accessory you may need
2317
- accessory.context.device = device;
2318
- accessory.context.deviceId = device.deviceId;
2319
- accessory.context.deviceType = `IR: ${device.remoteType}`;
2320
- 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
2321
2338
  accessory.displayName = device.configDeviceName
2322
2339
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2323
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2324
- accessory.context.connectionType = await this.connectionType(device);
2325
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
2326
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2327
- 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}`)
2328
2345
  // create the accessory handler for the newly create accessory
2329
2346
  // this is imported from `platformAccessory.ts`
2330
- new VacuumCleaner(this, accessory, device);
2331
- 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})`)
2332
2349
 
2333
2350
  // publish device externally or link the accessory to your platform
2334
- this.externalOrPlatform(device, accessory);
2335
- this.accessories.push(accessory);
2351
+ this.externalOrPlatform(device, accessory)
2352
+ this.accessories.push(accessory)
2336
2353
  } else {
2337
- 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}`)
2338
2355
  }
2339
2356
  }
2340
2357
 
2341
2358
  private async createCamera(device: irdevice & devicesConfig) {
2342
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
2359
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
2343
2360
 
2344
2361
  // see if an accessory with the same uuid has already been registered and restored from
2345
2362
  // the cached devices we stored in the `configureAccessory` method above
2346
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
2363
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
2347
2364
 
2348
2365
  if (existingAccessory) {
2349
2366
  // the accessory already exists
2350
2367
  if (!device.hide_device && device.hubDeviceId) {
2351
2368
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2352
- existingAccessory.context.device = device;
2353
- existingAccessory.context.deviceId = device.deviceId;
2354
- existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2355
- 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
2356
2373
  existingAccessory.displayName = device.configDeviceName
2357
2374
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2358
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2359
- await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2360
- existingAccessory.context.connectionType = device.connectionType;
2361
- 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])
2362
2379
  // create the accessory handler for the restored accessory
2363
2380
  // this is imported from `platformAccessory.ts`
2364
- new Camera(this, existingAccessory, device);
2365
- 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})`)
2366
2383
  } else {
2367
- this.unregisterPlatformAccessories(existingAccessory);
2384
+ this.unregisterPlatformAccessories(existingAccessory)
2368
2385
  }
2369
2386
  } else if (!device.hide_device && device.hubDeviceId) {
2370
2387
  // create a new accessory
2371
2388
  const accessory = new this.api.platformAccessory(device.configDeviceName
2372
2389
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2373
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
2390
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
2374
2391
 
2375
2392
  // store a copy of the device object in the `accessory.context`
2376
2393
  // the `context` property can be used to store any data about the accessory you may need
2377
- accessory.context.device = device;
2378
- accessory.context.deviceId = device.deviceId;
2379
- accessory.context.deviceType = `IR: ${device.remoteType}`;
2380
- 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
2381
2398
  accessory.displayName = device.configDeviceName
2382
2399
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2383
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2384
- accessory.context.connectionType = await this.connectionType(device);
2385
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
2386
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2387
- 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}`)
2388
2405
  // create the accessory handler for the newly create accessory
2389
2406
  // this is imported from `platformAccessory.ts`
2390
- new Camera(this, accessory, device);
2391
- 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})`)
2392
2409
 
2393
2410
  // publish device externally or link the accessory to your platform
2394
- this.externalOrPlatform(device, accessory);
2395
- this.accessories.push(accessory);
2411
+ this.externalOrPlatform(device, accessory)
2412
+ this.accessories.push(accessory)
2396
2413
  } else {
2397
- 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}`)
2398
2415
  }
2399
2416
  }
2400
2417
 
2401
2418
  private async createOthers(device: irdevice & devicesConfig) {
2402
- const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
2419
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`)
2403
2420
 
2404
2421
  // see if an accessory with the same uuid has already been registered and restored from
2405
2422
  // the cached devices we stored in the `configureAccessory` method above
2406
- const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
2423
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
2407
2424
 
2408
2425
  if (existingAccessory) {
2409
2426
  // the accessory already exists
2410
2427
  if (!device.hide_device && device.hubDeviceId) {
2411
2428
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
2412
- existingAccessory.context.device = device;
2413
- existingAccessory.context.deviceId = device.deviceId;
2414
- existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
2415
- 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
2416
2433
  existingAccessory.displayName = device.configDeviceName
2417
2434
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2418
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2419
- await this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
2420
- existingAccessory.context.connectionType = device.connectionType;
2421
- 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])
2422
2439
  // create the accessory handler for the restored accessory
2423
2440
  // this is imported from `platformAccessory.ts`
2424
- new Others(this, existingAccessory, device);
2425
- 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})`)
2426
2443
  } else {
2427
- this.unregisterPlatformAccessories(existingAccessory);
2444
+ this.unregisterPlatformAccessories(existingAccessory)
2428
2445
  }
2429
2446
  } else if (!device.hide_device && device.hubDeviceId) {
2430
2447
  // create a new accessory
2431
2448
  const accessory = new this.api.platformAccessory(device.configDeviceName
2432
2449
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2433
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
2450
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
2434
2451
 
2435
2452
  // store a copy of the device object in the `accessory.context`
2436
2453
  // the `context` property can be used to store any data about the accessory you may need
2437
- accessory.context.device = device;
2438
- accessory.context.deviceId = device.deviceId;
2439
- accessory.context.deviceType = `IR: ${device.remoteType}`;
2440
- 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
2441
2458
  accessory.displayName = device.configDeviceName
2442
2459
  ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2443
- : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
2444
- accessory.context.connectionType = await this.connectionType(device);
2445
- accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
2446
- const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
2447
- 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}`)
2448
2465
  // create the accessory handler for the newly create accessory
2449
2466
  // this is imported from `platformAccessory.ts`
2450
- new Others(this, accessory, device);
2451
- 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})`)
2452
2469
 
2453
2470
  // publish device externally or link the accessory to your platform
2454
- this.externalOrPlatform(device, accessory);
2455
- this.accessories.push(accessory);
2471
+ this.externalOrPlatform(device, accessory)
2472
+ this.accessories.push(accessory)
2456
2473
  } else {
2457
- 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}`)
2458
2475
  }
2459
2476
  }
2460
2477
 
2461
2478
  async registerCurtains(device: device & devicesConfig): Promise<boolean> {
2462
- let registerWindowCovering: boolean;
2479
+ let registerWindowCovering: boolean
2463
2480
  if (isCurtainDevice(device)) {
2464
- await this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds},`
2465
- + ` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group},`
2466
- + ` connectionType: ${device.connectionType}`);
2467
- 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)
2468
2483
  } else if (isBlindTiltDevice(device)) {
2469
- await this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, blindTiltDevicesIds: ${device.blindTiltDevicesIds},`
2470
- + ` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group},`
2471
- + ` connectionType: ${device.connectionType}`);
2472
- 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)
2473
2486
  } else {
2474
- registerWindowCovering = false;
2487
+ registerWindowCovering = false
2475
2488
  }
2476
- return registerWindowCovering;
2489
+ return registerWindowCovering
2477
2490
  }
2478
2491
 
2479
2492
  async registerWindowCovering(device: ((curtain | curtain3) & devicesConfig) | (blindTilt & devicesConfig)) {
2480
- await this.debugLog(`master: ${device.master}`);
2481
- let registerCurtain: boolean;
2493
+ await this.debugLog(`master: ${device.master}`)
2494
+ let registerCurtain: boolean
2482
2495
  if (device.master && device.group) {
2483
2496
  // OpenAPI: Master Curtains/Blind Tilt in Group
2484
- registerCurtain = true;
2485
- await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master},`
2486
- + ` device.group: ${device.group} connectionType; ${device.connectionType}`);
2487
- 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}`)
2488
2500
  } else if (!device.master && device.curtain?.disable_group) {
2489
- //!device.group && device.connectionType === 'BLE'
2501
+ // !device.group && device.connectionType === 'BLE'
2490
2502
  // OpenAPI: Non-Master Curtains/Blind Tilts that has Disable Grouping Checked
2491
- registerCurtain = true;
2492
- await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, disable_group: `
2493
- + `${device.curtain?.disable_group}, connectionType; ${device.connectionType}`);
2494
- 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}`)
2495
2506
  } else if (device.master && !device.group) {
2496
2507
  // OpenAPI: Master Curtains/Blind Tilts not in Group
2497
- registerCurtain = true;
2498
- await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master},`
2499
- + ` device.group: ${device.group} connectionType; ${device.connectionType}`);
2500
- 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}`)
2501
2511
  } else if (device.connectionType === 'BLE') {
2502
2512
  // BLE: Curtains/Blind Tilt
2503
- registerCurtain = true;
2504
- await this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] connectionType: ${device.connectionType}, `
2505
- + ` group: ${device.group}`);
2506
- 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}`)
2507
2516
  } else {
2508
- registerCurtain = false;
2509
- await this.debugErrorLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] disable_group: ${device.curtain?.disable_group},`
2510
- + ` device.master: ${device.master}, device.group: ${device.group}`);
2511
- 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}`)
2512
2520
  }
2513
- return registerCurtain;
2521
+ return registerCurtain
2514
2522
  }
2515
2523
 
2516
2524
  async connectionType(device: device & devicesConfig): Promise<any> {
2517
- let connectionType: string;
2525
+ let connectionType: string
2518
2526
  if (!device.connectionType && this.config.credentials?.token && this.config.credentials.secret) {
2519
- connectionType = 'OpenAPI';
2527
+ connectionType = 'OpenAPI'
2520
2528
  } else {
2521
- connectionType = device.connectionType!;
2529
+ connectionType = device.connectionType!
2522
2530
  }
2523
- return connectionType;
2531
+ return connectionType
2524
2532
  }
2525
2533
 
2526
2534
  async registerDevice(device: device & devicesConfig) {
2527
- device.connectionType = await this.connectionType(device);
2528
- let registerDevice: boolean;
2535
+ device.connectionType = await this.connectionType(device)
2536
+ let registerDevice: boolean
2529
2537
  if (!device.hide_device && device.connectionType === 'BLE/OpenAPI') {
2530
2538
  switch (device.deviceType) {
2531
2539
  case 'Curtain':
2532
2540
  case 'Curtain3':
2533
2541
  case 'Blind Tilt':
2534
- registerDevice = await this.registerCurtains(device);
2535
- await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
2536
- break;
2542
+ registerDevice = await this.registerCurtains(device)
2543
+ await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`)
2544
+ break
2537
2545
  default:
2538
- registerDevice = true;
2539
- await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
2546
+ registerDevice = true
2547
+ await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`)
2540
2548
  }
2541
2549
  if (registerDevice === true) {
2542
- 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`)
2543
2551
  } else {
2544
- 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`)
2545
2553
  }
2546
2554
  } else if (!device.hide_device && device.deviceId && device.configDeviceType && device.configDeviceName && device.connectionType === 'BLE') {
2547
2555
  switch (device.deviceType) {
2548
2556
  case 'Curtain':
2549
2557
  case 'Curtain3':
2550
2558
  case 'Blind Tilt':
2551
- registerDevice = await this.registerCurtains(device);
2552
- await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
2553
- break;
2559
+ registerDevice = await this.registerCurtains(device)
2560
+ await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`)
2561
+ break
2554
2562
  default:
2555
- registerDevice = true;
2556
- await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
2563
+ registerDevice = true
2564
+ await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`)
2557
2565
  }
2558
2566
  if (registerDevice === true) {
2559
- 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`)
2560
2568
  } else {
2561
- 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`)
2562
2570
  }
2563
2571
  } else if (!device.hide_device && device.connectionType === 'OpenAPI') {
2564
2572
  switch (device.deviceType) {
2565
2573
  case 'Curtain':
2566
2574
  case 'Curtain3':
2567
2575
  case 'Blind Tilt':
2568
- registerDevice = await this.registerCurtains(device);
2569
- await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
2570
- break;
2576
+ registerDevice = await this.registerCurtains(device)
2577
+ await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`)
2578
+ break
2571
2579
  default:
2572
- registerDevice = true;
2573
- await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
2580
+ registerDevice = true
2581
+ await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`)
2574
2582
  }
2575
2583
  if (registerDevice === true) {
2576
- 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`)
2577
2585
  } else {
2578
- 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`)
2579
2587
  }
2580
2588
  } else if (!device.hide_device && device.connectionType === 'Disabled') {
2581
2589
  switch (device.deviceType) {
2582
2590
  case 'Curtain':
2583
2591
  case 'Curtain3':
2584
2592
  case 'Blind Tilt':
2585
- registerDevice = await this.registerCurtains(device);
2586
- await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
2587
- break;
2593
+ registerDevice = await this.registerCurtains(device)
2594
+ await this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`)
2595
+ break
2588
2596
  default:
2589
- registerDevice = true;
2590
- await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
2597
+ registerDevice = true
2598
+ await this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`)
2591
2599
  }
2592
- 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`)
2593
2601
  } else if (!device.connectionType && !device.hide_device) {
2594
- registerDevice = false;
2595
- 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`)
2596
2604
  } else if (device.hide_device) {
2597
- registerDevice = false;
2598
- 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`)
2599
2607
  } else {
2600
- registerDevice = false;
2601
- await this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, hide_device: `
2602
- + `${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`)
2603
2610
  }
2604
- return registerDevice;
2611
+ return registerDevice
2605
2612
  }
2606
2613
 
2607
2614
  public async externalOrPlatform(device: device & (irDevicesConfig | devicesConfig), accessory: PlatformAccessory) {
2608
- const { displayName } = accessory;
2609
- const isExternal = device.external ?? false;
2615
+ const { displayName } = accessory
2616
+ const isExternal = device.external ?? false
2610
2617
 
2611
2618
  if (isExternal) {
2612
- await this.debugWarnLog(`${displayName} External Accessory Mode`);
2613
- this.api.publishExternalAccessories(PLUGIN_NAME, [accessory]);
2619
+ await this.debugWarnLog(`${displayName} External Accessory Mode`)
2620
+ this.api.publishExternalAccessories(PLUGIN_NAME, [accessory])
2614
2621
  } else {
2615
- await this.debugLog(`${displayName} External Accessory Mode: ${isExternal}`);
2616
- 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])
2617
2624
  }
2618
2625
  }
2619
2626
 
2620
2627
  public unregisterPlatformAccessories(existingAccessory: PlatformAccessory) {
2621
- const { displayName } = existingAccessory;
2628
+ const { displayName } = existingAccessory
2622
2629
  // remove platform accessories when no longer present
2623
- this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [existingAccessory]);
2624
- 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}`)
2625
2632
  }
2626
2633
 
2627
2634
  /**
@@ -2655,53 +2662,50 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2655
2662
  429: `Too Many Requests, The client has exceeded the number of requests allowed for a given time window, statusCode: ${statusCode}`,
2656
2663
  500: `Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare,
2657
2664
  statusCode: ${statusCode}`,
2658
- };
2665
+ }
2659
2666
 
2660
- 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`
2661
2668
 
2662
2669
  if ([100, 200].includes(statusCode)) {
2663
- await this.debugLog(message);
2670
+ await this.debugLog(message)
2664
2671
  } else {
2665
- await this.errorLog(message);
2672
+ await this.errorLog(message)
2666
2673
  }
2667
2674
  }
2668
2675
 
2669
- async retryRequest(deviceMaxRetries: number, deviceDelayBetweenRetries: number, url: string | URL | UrlObject,
2670
- options?: { dispatcher?: Dispatcher } & Omit<Dispatcher.RequestOptions,
2671
- 'origin' | 'path' | 'method'> & Partial<Pick<Dispatcher.RequestOptions,
2672
- 'method'>>): Promise<{ body: any; statusCode: number }> {
2673
- let retryCount = 0;
2674
- const maxRetries = deviceMaxRetries;
2675
- 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
2676
2680
  while (retryCount < maxRetries) {
2677
2681
  try {
2678
- const { body, statusCode } = await request(url, options);
2682
+ const { body, statusCode } = await request(url, options)
2679
2683
  if (statusCode === 200 || statusCode === 100) {
2680
- return { body, statusCode };
2684
+ return { body, statusCode }
2681
2685
  } else {
2682
- await this.debugLog(`Received status code: ${statusCode}`);
2686
+ await this.debugLog(`Received status code: ${statusCode}`)
2683
2687
  }
2684
2688
  } catch (error: any) {
2685
- await this.errorLog(`Error making request: ${error.message}`);
2689
+ await this.errorLog(`Error making request: ${error.message}`)
2686
2690
  }
2687
- retryCount++;
2688
- await this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`);
2689
- await sleep(delayBetweenRetries);
2691
+ retryCount++
2692
+ await this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`)
2693
+ await sleep(delayBetweenRetries)
2690
2694
  }
2691
- return { body: null, statusCode: -1 };
2695
+ return { body: null, statusCode: -1 }
2692
2696
  }
2693
2697
 
2694
2698
  // BLE Connection
2695
2699
  async connectBLE(accessory: PlatformAccessory, device: device & devicesConfig): Promise<any> {
2696
2700
  try {
2697
- const { SwitchBot } = await import('node-switchbot');
2698
- const switchbot = new SwitchBot();
2699
- queueScheduler.schedule(async () => switchbot);
2700
- await this.debugLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${switchbot}`);
2701
- 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
2702
2706
  } catch (e: any) {
2703
- await this.errorLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' not found, Error: ${e}`);
2704
- return false;
2707
+ await this.errorLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' not found, Error: ${e}`)
2708
+ return false
2705
2709
  }
2706
2710
  }
2707
2711
 
@@ -2711,53 +2715,53 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2711
2715
  new URL('../package.json', import.meta.url),
2712
2716
  'utf-8',
2713
2717
  ),
2714
- );
2715
- await this.debugLog(`Plugin Version: ${json.version}`);
2716
- this.version = json.version;
2717
- return json.version;
2718
+ )
2719
+ await this.debugLog(`Plugin Version: ${json.version}`)
2720
+ this.version = json.version
2721
+ return json.version
2718
2722
  }
2719
2723
 
2720
2724
  async getPlatformConfigSettings() {
2721
- const { options } = this.config;
2722
- const platformConfig: SwitchBotPlatformConfig['options'] = {};
2725
+ const { options } = this.config
2726
+ const platformConfig: SwitchBotPlatformConfig['options'] = {}
2723
2727
 
2724
2728
  if (options) {
2725
- platformConfig.logging = options.logging;
2726
- platformConfig.refreshRate = options.refreshRate;
2727
- platformConfig.updateRate = options.updateRate;
2728
- platformConfig.pushRate = options.pushRate;
2729
+ platformConfig.logging = options.logging
2730
+ platformConfig.refreshRate = options.refreshRate
2731
+ platformConfig.updateRate = options.updateRate
2732
+ platformConfig.pushRate = options.pushRate
2729
2733
 
2730
- this.maxRetries = options.maxRetries || 3;
2731
- platformConfig.maxRetries = this.maxRetries;
2734
+ this.maxRetries = options.maxRetries || 3
2735
+ platformConfig.maxRetries = this.maxRetries
2732
2736
  if (!options.maxRetries) {
2733
- await this.debugWarnLog('Using Default Max Retries');
2737
+ await this.debugWarnLog('Using Default Max Retries')
2734
2738
  }
2735
2739
 
2736
- this.delayBetweenRetries = (options.delayBetweenRetries || 3) * 1000;
2737
- platformConfig.delayBetweenRetries = this.delayBetweenRetries / 1000;
2740
+ this.delayBetweenRetries = (options.delayBetweenRetries || 3) * 1000
2741
+ platformConfig.delayBetweenRetries = this.delayBetweenRetries / 1000
2738
2742
  if (!options.delayBetweenRetries) {
2739
- await this.debugWarnLog('Using Default Delay Between Retries');
2743
+ await this.debugWarnLog('Using Default Delay Between Retries')
2740
2744
  }
2741
2745
 
2742
2746
  if (Object.keys(platformConfig).length) {
2743
- await this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
2747
+ await this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`)
2744
2748
  }
2745
2749
 
2746
- this.platformConfig = platformConfig;
2750
+ this.platformConfig = platformConfig
2747
2751
  }
2748
2752
  }
2749
2753
 
2750
2754
  async getPlatformLogSettings() {
2751
- this.debugMode = process.argv.includes('-D') ?? process.argv.includes('--debug');
2755
+ this.debugMode = process.argv.includes('-D') ?? process.argv.includes('--debug')
2752
2756
  if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
2753
- this.platformLogging = this.config.options.logging;
2754
- await this.debugWarnLog(`Using Config Logging: ${this.platformLogging}`);
2757
+ this.platformLogging = this.config.options.logging
2758
+ await this.debugWarnLog(`Using Config Logging: ${this.platformLogging}`)
2755
2759
  } else if (this.debugMode) {
2756
- this.platformLogging = 'debugMode';
2757
- await this.debugWarnLog(`Using ${this.platformLogging} Logging`);
2760
+ this.platformLogging = 'debugMode'
2761
+ await this.debugWarnLog(`Using ${this.platformLogging} Logging`)
2758
2762
  } else {
2759
- this.platformLogging = 'standard';
2760
- await this.debugWarnLog(`Using ${this.platformLogging} Logging`);
2763
+ this.platformLogging = 'standard'
2764
+ await this.debugWarnLog(`Using ${this.platformLogging} Logging`)
2761
2765
  }
2762
2766
  }
2763
2767
 
@@ -2767,40 +2771,36 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2767
2771
  * @param name - The name of the characteristic.
2768
2772
  * @param value - The value to be validated and cleaned.
2769
2773
  * @returns The cleaned string value.
2770
- */
2774
+ */
2771
2775
  async validateAndCleanDisplayName(displayName: string, name: string, value: string): Promise<string> {
2772
2776
  if (this.config.options?.allowInvalidCharacters) {
2773
- return value;
2777
+ return value
2774
2778
  } else {
2775
- const validPattern = new RegExp(/^[\p{L}\p{N}][\p{L}\p{N} ']*[\p{L}\p{N}]$/u);
2776
- const invalidCharsPattern = /[^\p{L}\p{N} ']/gu;
2777
- 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
2778
2782
 
2779
2783
  if (typeof value === 'string' && !validPattern.test(value)) {
2780
- await this.warnLog(`WARNING: The accessory '${displayName}' has an invalid '${name}' characteristic ('${value}').`
2781
- + ' Please use only alphanumeric, space, and apostrophe characters. Ensure it starts and ends with an alphabetic or numeric character,'
2782
- + ' 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.`)
2783
2785
 
2784
2786
  // Remove invalid characters
2785
2787
  if (invalidCharsPattern.test(value)) {
2786
- const before = value;
2787
- await this.warnLog(`Removing invalid characters from '${name}' characteristic, if you feel this is incorrect,`
2788
- + ' please enable \'allowInvalidCharacter\' in the config to allow all characters');
2789
- value = value.replace(invalidCharsPattern, '');
2790
- 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}'`)
2791
2792
  }
2792
2793
 
2793
2794
  // Ensure it starts and ends with an alphanumeric character
2794
2795
  if (invalidStartEndPattern.test(value)) {
2795
- const before = value;
2796
- await this.warnLog(`Removing invalid starting or ending characters from '${name}' characteristic, if you feel this is incorrect,`
2797
- + ' please enable \'allowInvalidCharacter\' in the config to allow all characters');
2798
- value = value.replace(invalidStartEndPattern, '');
2799
- 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}'`)
2800
2800
  }
2801
2801
  }
2802
2802
 
2803
- return value;
2803
+ return value
2804
2804
  }
2805
2805
  }
2806
2806
 
@@ -2810,48 +2810,48 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2810
2810
  */
2811
2811
  async infoLog(...log: any[]): Promise<void> {
2812
2812
  if (await this.enablingPlatformLogging()) {
2813
- this.log.info(String(...log));
2813
+ this.log.info(String(...log))
2814
2814
  }
2815
2815
  }
2816
2816
 
2817
2817
  async successLog(...log: any[]): Promise<void> {
2818
2818
  if (await this.enablingPlatformLogging()) {
2819
- this.log.success(String(...log));
2819
+ this.log.success(String(...log))
2820
2820
  }
2821
2821
  }
2822
2822
 
2823
2823
  async debugSuccessLog(...log: any[]): Promise<void> {
2824
2824
  if (await this.enablingPlatformLogging()) {
2825
2825
  if (await this.loggingIsDebug()) {
2826
- this.log.success('[DEBUG]', String(...log));
2826
+ this.log.success('[DEBUG]', String(...log))
2827
2827
  }
2828
2828
  }
2829
2829
  }
2830
2830
 
2831
2831
  async warnLog(...log: any[]): Promise<void> {
2832
2832
  if (await this.enablingPlatformLogging()) {
2833
- this.log.warn(String(...log));
2833
+ this.log.warn(String(...log))
2834
2834
  }
2835
2835
  }
2836
2836
 
2837
2837
  async debugWarnLog(...log: any[]): Promise<void> {
2838
2838
  if (await this.enablingPlatformLogging()) {
2839
2839
  if (await this.loggingIsDebug()) {
2840
- this.log.warn('[DEBUG]', String(...log));
2840
+ this.log.warn('[DEBUG]', String(...log))
2841
2841
  }
2842
2842
  }
2843
2843
  }
2844
2844
 
2845
2845
  async errorLog(...log: any[]): Promise<void> {
2846
2846
  if (await this.enablingPlatformLogging()) {
2847
- this.log.error(String(...log));
2847
+ this.log.error(String(...log))
2848
2848
  }
2849
2849
  }
2850
2850
 
2851
2851
  async debugErrorLog(...log: any[]): Promise<void> {
2852
2852
  if (await this.enablingPlatformLogging()) {
2853
2853
  if (await this.loggingIsDebug()) {
2854
- this.log.error('[DEBUG]', String(...log));
2854
+ this.log.error('[DEBUG]', String(...log))
2855
2855
  }
2856
2856
  }
2857
2857
  }
@@ -2859,18 +2859,18 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2859
2859
  async debugLog(...log: any[]): Promise<void> {
2860
2860
  if (await this.enablingPlatformLogging()) {
2861
2861
  if (this.platformLogging === 'debug') {
2862
- this.log.info('[DEBUG]', String(...log));
2862
+ this.log.info('[DEBUG]', String(...log))
2863
2863
  } else if (this.platformLogging === 'debugMode') {
2864
- this.log.debug(String(...log));
2864
+ this.log.debug(String(...log))
2865
2865
  }
2866
2866
  }
2867
2867
  }
2868
2868
 
2869
2869
  async loggingIsDebug(): Promise<boolean> {
2870
- return this.platformLogging === 'debugMode' || this.platformLogging === 'debug';
2870
+ return this.platformLogging === 'debugMode' || this.platformLogging === 'debug'
2871
2871
  }
2872
2872
 
2873
2873
  async enablingPlatformLogging(): Promise<boolean> {
2874
- return this.platformLogging === 'debugMode' || this.platformLogging === 'debug' || this.platformLogging === 'standard';
2874
+ return this.platformLogging === 'debugMode' || this.platformLogging === 'debug' || this.platformLogging === 'standard'
2875
2875
  }
2876
2876
  }