@switchbot/homebridge-switchbot 1.8.3-beta.0 → 1.10.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/.eslintrc +14 -45
  2. package/.github/ISSUE_TEMPLATE/bug-report.yml +3 -3
  3. package/.github/ISSUE_TEMPLATE/feature-request.yml +2 -2
  4. package/.github/ISSUE_TEMPLATE/support-request.yml +3 -3
  5. package/.github/labeler.yml +1 -1
  6. package/.github/workflows/codeql-analysis.yml +29 -29
  7. package/.github/workflows/nodejs-beta.yml +1 -1
  8. package/.github/workflows/prerelease-beta.js +1 -1
  9. package/.github/workflows/stale.yml +1 -1
  10. package/.prettierrc +9 -0
  11. package/.vscode/extensions.json +2 -4
  12. package/.vscode/settings.json +14 -2
  13. package/CHANGELOG.md +16 -0
  14. package/README.md +100 -99
  15. package/SECURITY.md +2 -2
  16. package/config.schema.json +17 -0
  17. package/dist/devices/bots.d.ts +35 -32
  18. package/dist/devices/bots.d.ts.map +1 -1
  19. package/dist/devices/bots.js +168 -210
  20. package/dist/devices/bots.js.map +1 -1
  21. package/dist/devices/colorbulb.d.ts +35 -35
  22. package/dist/devices/colorbulb.d.ts.map +1 -1
  23. package/dist/devices/colorbulb.js +83 -108
  24. package/dist/devices/colorbulb.js.map +1 -1
  25. package/dist/devices/contact.d.ts +27 -25
  26. package/dist/devices/contact.d.ts.map +1 -1
  27. package/dist/devices/contact.js +110 -131
  28. package/dist/devices/contact.js.map +1 -1
  29. package/dist/devices/curtains.d.ts +29 -27
  30. package/dist/devices/curtains.d.ts.map +1 -1
  31. package/dist/devices/curtains.js +147 -182
  32. package/dist/devices/curtains.js.map +1 -1
  33. package/dist/devices/humidifiers.d.ts +31 -31
  34. package/dist/devices/humidifiers.d.ts.map +1 -1
  35. package/dist/devices/humidifiers.js +154 -181
  36. package/dist/devices/humidifiers.js.map +1 -1
  37. package/dist/devices/meters.d.ts +29 -28
  38. package/dist/devices/meters.d.ts.map +1 -1
  39. package/dist/devices/meters.js +98 -120
  40. package/dist/devices/meters.js.map +1 -1
  41. package/dist/devices/motion.d.ts +24 -23
  42. package/dist/devices/motion.d.ts.map +1 -1
  43. package/dist/devices/motion.js +97 -113
  44. package/dist/devices/motion.js.map +1 -1
  45. package/dist/devices/plugs.d.ts +16 -16
  46. package/dist/devices/plugs.d.ts.map +1 -1
  47. package/dist/devices/plugs.js +48 -71
  48. package/dist/devices/plugs.js.map +1 -1
  49. package/dist/index.d.ts +2 -2
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +3 -22
  52. package/dist/index.js.map +1 -1
  53. package/dist/irdevices/airconditioners.d.ts +7 -4
  54. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  55. package/dist/irdevices/airconditioners.js +72 -93
  56. package/dist/irdevices/airconditioners.js.map +1 -1
  57. package/dist/irdevices/airpurifiers.d.ts +3 -3
  58. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  59. package/dist/irdevices/airpurifiers.js +32 -51
  60. package/dist/irdevices/airpurifiers.js.map +1 -1
  61. package/dist/irdevices/cameras.d.ts +3 -3
  62. package/dist/irdevices/cameras.d.ts.map +1 -1
  63. package/dist/irdevices/cameras.js +19 -26
  64. package/dist/irdevices/cameras.js.map +1 -1
  65. package/dist/irdevices/fans.d.ts +3 -3
  66. package/dist/irdevices/fans.d.ts.map +1 -1
  67. package/dist/irdevices/fans.js +35 -44
  68. package/dist/irdevices/fans.js.map +1 -1
  69. package/dist/irdevices/lights.d.ts +3 -3
  70. package/dist/irdevices/lights.d.ts.map +1 -1
  71. package/dist/irdevices/lights.js +25 -32
  72. package/dist/irdevices/lights.js.map +1 -1
  73. package/dist/irdevices/others.d.ts +3 -3
  74. package/dist/irdevices/others.d.ts.map +1 -1
  75. package/dist/irdevices/others.js +21 -29
  76. package/dist/irdevices/others.js.map +1 -1
  77. package/dist/irdevices/tvs.d.ts +3 -3
  78. package/dist/irdevices/tvs.d.ts.map +1 -1
  79. package/dist/irdevices/tvs.js +66 -89
  80. package/dist/irdevices/tvs.js.map +1 -1
  81. package/dist/irdevices/vacuumcleaners.d.ts +3 -3
  82. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  83. package/dist/irdevices/vacuumcleaners.js +18 -24
  84. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  85. package/dist/irdevices/waterheaters.d.ts +3 -3
  86. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  87. package/dist/irdevices/waterheaters.js +19 -26
  88. package/dist/irdevices/waterheaters.js.map +1 -1
  89. package/dist/platform.d.ts +10 -10
  90. package/dist/platform.d.ts.map +1 -1
  91. package/dist/platform.js +163 -233
  92. package/dist/platform.js.map +1 -1
  93. package/dist/settings.d.ts +3 -1
  94. package/dist/settings.d.ts.map +1 -1
  95. package/dist/settings.js +4 -4
  96. package/dist/settings.js.map +1 -1
  97. package/homebridge-ui/public/index.html +231 -245
  98. package/homebridge-ui/server.js +2 -4
  99. package/nodemon.json +2 -4
  100. package/package.json +17 -12
  101. package/src/devices/bots.ts +411 -854
  102. package/src/devices/colorbulb.ts +187 -408
  103. package/src/devices/contact.ts +210 -376
  104. package/src/devices/curtains.ts +288 -563
  105. package/src/devices/humidifiers.ts +291 -537
  106. package/src/devices/meters.ts +189 -331
  107. package/src/devices/motion.ts +188 -322
  108. package/src/devices/plugs.ts +88 -160
  109. package/src/index.ts +5 -5
  110. package/src/irdevices/airconditioners.ts +139 -318
  111. package/src/irdevices/airpurifiers.ts +71 -170
  112. package/src/irdevices/cameras.ts +44 -103
  113. package/src/irdevices/fans.ts +70 -165
  114. package/src/irdevices/lights.ts +49 -104
  115. package/src/irdevices/others.ts +55 -131
  116. package/src/irdevices/tvs.ts +114 -247
  117. package/src/irdevices/vacuumcleaners.ts +44 -104
  118. package/src/irdevices/waterheaters.ts +49 -121
  119. package/src/platform.ts +341 -753
  120. package/src/settings.ts +8 -11
  121. package/tsconfig.json +5 -14
  122. package/.github/PULL_REQUEST_TEMPLATE/pull_requests.md +0 -27
package/src/platform.ts CHANGED
@@ -1,28 +1,23 @@
1
- import axios, { AxiosInstance, AxiosRequestConfig } from "axios";
2
- import {
3
- API, Characteristic, DynamicPlatformPlugin,
4
- Logger,
5
- PlatformAccessory,
6
- Service,
7
- } from "homebridge";
8
- import { Bot } from "./devices/bots";
9
- import { ColorBulb } from "./devices/colorbulb";
10
- import { Contact } from "./devices/contact";
11
- import { Curtain } from "./devices/curtains";
12
- import { Humidifier } from "./devices/humidifiers";
13
- import { Meter } from "./devices/meters";
14
- import { Motion } from "./devices/motion";
15
- import { Plug } from "./devices/plugs";
16
- import { AirConditioner } from "./irdevices/airconditioners";
17
- import { AirPurifier } from "./irdevices/airpurifiers";
18
- import { Camera } from "./irdevices/cameras";
19
- import { Fan } from "./irdevices/fans";
20
- import { Light } from "./irdevices/lights";
21
- import { Others } from "./irdevices/others";
22
- import { TV } from "./irdevices/tvs";
23
- import { VacuumCleaner } from "./irdevices/vacuumcleaners";
24
- import { WaterHeater } from "./irdevices/waterheaters";
25
- import * as settings from "./settings";
1
+ import { Bot } from './devices/bots';
2
+ import { Plug } from './devices/plugs';
3
+ import { Meter } from './devices/meters';
4
+ import { Motion } from './devices/motion';
5
+ import { Contact } from './devices/contact';
6
+ import { Curtain } from './devices/curtains';
7
+ import { ColorBulb } from './devices/colorbulb';
8
+ import { Humidifier } from './devices/humidifiers';
9
+ import { TV } from './irdevices/tvs';
10
+ import { Fan } from './irdevices/fans';
11
+ import { Light } from './irdevices/lights';
12
+ import { Others } from './irdevices/others';
13
+ import { Camera } from './irdevices/cameras';
14
+ import { AirPurifier } from './irdevices/airpurifiers';
15
+ import { WaterHeater } from './irdevices/waterheaters';
16
+ import { VacuumCleaner } from './irdevices/vacuumcleaners';
17
+ import { AirConditioner } from './irdevices/airconditioners';
18
+ import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
19
+ import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, Service, Characteristic } from 'homebridge';
20
+ import { PLATFORM_NAME, PLUGIN_NAME, DeviceURL, irdevice, device, SwitchBotPlatformConfig, deviceResponses, devicesConfig } from './settings';
26
21
 
27
22
  /**
28
23
  * HomebridgePlatform
@@ -31,49 +26,41 @@ import * as settings from "./settings";
31
26
  */
32
27
  export class SwitchBotPlatform implements DynamicPlatformPlugin {
33
28
  public readonly Service: typeof Service = this.api.hap.Service;
34
- public readonly Characteristic: typeof Characteristic =
35
- this.api.hap.Characteristic;
29
+ public readonly Characteristic: typeof Characteristic = this.api.hap.Characteristic;
36
30
 
37
31
  // this is used to track restored cached accessories
38
32
  public readonly accessories: PlatformAccessory[] = [];
39
33
 
40
34
  public axios: AxiosInstance = axios.create({
41
- responseType: "json",
35
+ responseType: 'json',
42
36
  });
43
37
 
44
- version = require("../package.json").version; // eslint-disable-line @typescript-eslint/no-var-requires
45
- deviceStatus!: settings.deviceResponses;
38
+ version = require('../package.json').version; // eslint-disable-line @typescript-eslint/no-var-requires
39
+ deviceStatus!: deviceResponses;
46
40
  registeringDevice!: boolean;
47
41
  debugMode!: boolean;
48
42
  platformLogging?: string;
49
43
 
50
- constructor(
51
- public readonly log: Logger,
52
- public readonly config: settings.SwitchBotPlatformConfig,
53
- public readonly api: API,
54
- ) {
44
+ constructor(public readonly log: Logger, public readonly config: SwitchBotPlatformConfig, public readonly api: API) {
55
45
  this.logs();
56
- this.debugLog("Finished initializing platform:", this.config.name);
46
+ this.debugLog('Finished initializing platform:', this.config.name);
57
47
  // only load if configured
58
48
  if (!this.config) {
59
49
  return;
60
50
  }
61
51
 
62
52
  // HOOBS notice
63
- if (__dirname.includes("hoobs")) {
64
- this.log.warn(
65
- "This plugin has not been tested under HOOBS, it is highly recommended that " +
66
- "you switch to Homebridge: https://git.io/Jtxb0",
67
- );
53
+ if (__dirname.includes('hoobs')) {
54
+ this.log.warn('This plugin has not been tested under HOOBS, it is highly recommended that you switch to Homebridge: https://git.io/Jtxb0');
68
55
  }
69
56
 
70
57
  // verify the config
71
58
  try {
72
59
  this.verifyConfig();
73
- this.debugLog("Config OK");
60
+ this.debugLog('Config OK');
74
61
  } catch (e: any) {
75
62
  this.errorLog(JSON.stringify(e.message));
76
- if (this.platformLogging === "debugMode") {
63
+ if (this.platformLogging === 'debugMode') {
77
64
  this.errorLog(JSON.stringify(e));
78
65
  }
79
66
  return;
@@ -82,7 +69,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
82
69
  // setup axios interceptor to add headers / api key to each request
83
70
  this.axios.interceptors.request.use((request: AxiosRequestConfig) => {
84
71
  request.headers!.Authorization = this.config.credentials?.openToken;
85
- request.headers!["Content-Type"] = "application/json; charset=utf8";
72
+ request.headers!['Content-Type'] = 'application/json; charset=utf8';
86
73
  return request;
87
74
  });
88
75
 
@@ -90,14 +77,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
90
77
  // Dynamic Platform plugins should only register new accessories after this event was fired,
91
78
  // in order to ensure they weren't added to homebridge already. This event can also be used
92
79
  // to start discovery of new accessories.
93
- this.api.on("didFinishLaunching", async () => {
94
- this.debugLog("Executed didFinishLaunching callback");
80
+ this.api.on('didFinishLaunching', async () => {
81
+ this.debugLog('Executed didFinishLaunching callback');
95
82
  // run the method to discover / register your devices as accessories
96
83
  try {
97
84
  this.discoverDevices();
98
85
  } catch (e: any) {
99
- this.errorLog("Failed to Discover Devices.", JSON.stringify(e.message));
100
- if (this.platformLogging === "debugMode") {
86
+ this.errorLog('Failed to Discover Devices.', JSON.stringify(e.message));
87
+ if (this.platformLogging === 'debugMode') {
101
88
  this.errorLog(JSON.stringify(e));
102
89
  }
103
90
  }
@@ -105,25 +92,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
105
92
  }
106
93
 
107
94
  logs() {
108
- this.debugMode =
109
- process.argv.includes("-D") || process.argv.includes("--debug");
110
- if (
111
- this.config.options?.logging === "debug" ||
112
- this.config.options?.logging === "standard" ||
113
- this.config.options?.logging === "none"
114
- ) {
95
+ this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
96
+ if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
115
97
  this.platformLogging = this.config.options!.logging;
116
- if (this.platformLogging.includes("debug")) {
98
+ if (this.platformLogging.includes('debug')) {
117
99
  this.log.warn(`Using Config Logging: ${this.platformLogging}`);
118
100
  }
119
101
  } else if (this.debugMode) {
120
- this.platformLogging = "debugMode";
121
- if (this.platformLogging?.includes("debug")) {
102
+ this.platformLogging = 'debugMode';
103
+ if (this.platformLogging?.includes('debug')) {
122
104
  this.log.warn(`Using ${this.platformLogging} Logging`);
123
105
  }
124
106
  } else {
125
- this.platformLogging = "standard";
126
- if (this.platformLogging?.includes("debug")) {
107
+ this.platformLogging = 'standard';
108
+ if (this.platformLogging?.includes('debug')) {
127
109
  this.log.warn(`Using ${this.platformLogging} Logging`);
128
110
  }
129
111
  }
@@ -148,13 +130,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
148
130
 
149
131
  const platformConfig = {};
150
132
  if (this.config.options.logging) {
151
- platformConfig["logging"] = this.config.options.logging;
133
+ platformConfig['logging'] = this.config.options.logging;
152
134
  }
153
135
  if (this.config.options.logging) {
154
- platformConfig["refreshRate"] = this.config.options.refreshRate;
136
+ platformConfig['refreshRate'] = this.config.options.refreshRate;
155
137
  }
156
138
  if (this.config.options.logging) {
157
- platformConfig["pushRate"] = this.config.options.pushRate;
139
+ platformConfig['pushRate'] = this.config.options.pushRate;
158
140
  }
159
141
  if (Object.entries(platformConfig).length !== 0) {
160
142
  this.warnLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
@@ -166,14 +148,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
166
148
  for (const deviceConfig of this.config.options.devices) {
167
149
  if (!deviceConfig.hide_device) {
168
150
  if (!deviceConfig.deviceId) {
169
- throw new Error(
170
- "The devices config section is missing the *Device ID* in the config, Check Your Conifg.",
171
- );
151
+ throw new Error('The devices config section is missing the *Device ID* in the config, Check Your Conifg.');
172
152
  }
173
153
  if (!deviceConfig.configDeviceType && deviceConfig.ble) {
174
- throw new Error(
175
- "The devices config section is missing the *Device Type* in the config, Check Your Conifg.",
176
- );
154
+ throw new Error('The devices config section is missing the *Device Type* in the config, Check Your Conifg.');
177
155
  }
178
156
  }
179
157
  }
@@ -184,14 +162,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
184
162
  for (const irDeviceConfig of this.config.options.irdevices) {
185
163
  if (!irDeviceConfig.hide_device) {
186
164
  if (!irDeviceConfig.deviceId) {
187
- this.errorLog(
188
- "The devices config section is missing the *Device ID* in the config, Check Your Conifg.",
189
- );
165
+ this.errorLog('The devices config section is missing the *Device ID* in the config, Check Your Conifg.');
190
166
  }
191
167
  if (!irDeviceConfig.deviceId && !irDeviceConfig.configRemoteType) {
192
- this.errorLog(
193
- "The devices config section is missing the *Device Type* in the config, Check Your Conifg.",
194
- );
168
+ this.errorLog('The devices config section is missing the *Device Type* in the config, Check Your Conifg.');
195
169
  }
196
170
  }
197
171
  }
@@ -199,35 +173,33 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
199
173
  }
200
174
 
201
175
  if (this.config.options!.refreshRate! < 30) {
202
- throw new Error("Refresh Rate must be above 30 (30 seconds).");
176
+ throw new Error('Refresh Rate must be above 30 (30 seconds).');
203
177
  }
204
178
 
205
179
  if (!this.config.options.refreshRate) {
206
180
  // default 120 seconds (2 minutes)
207
181
  this.config.options!.refreshRate! = 120;
208
- if (this.platformLogging?.includes("debug")) {
209
- this.debugLog("Using Default Refresh Rate (2 minutes).");
182
+ if (this.platformLogging?.includes('debug')) {
183
+ this.debugLog('Using Default Refresh Rate (2 minutes).');
210
184
  }
211
185
 
212
186
  if (!this.config.options.pushRate) {
213
187
  // default 100 milliseconds
214
188
  this.config.options!.pushRate! = 0.1;
215
- if (this.platformLogging?.includes("debug")) {
216
- this.warnLog("Using Default Push Rate.");
189
+ if (this.platformLogging?.includes('debug')) {
190
+ this.warnLog('Using Default Push Rate.');
217
191
  }
218
192
  }
219
193
 
220
194
  if (!this.config.credentials) {
221
- if (this.platformLogging?.includes("debug")) {
222
- this.debugLog("Missing Credentials");
195
+ if (this.platformLogging?.includes('debug')) {
196
+ this.debugLog('Missing Credentials');
223
197
  }
224
198
  }
225
199
  if (!this.config.credentials?.openToken) {
226
- if (this.platformLogging?.includes("debug")) {
227
- this.errorLog("Missing openToken");
228
- this.warnLog(
229
- "Cloud Enabled SwitchBot Devices & IR Devices will not work",
230
- );
200
+ if (this.platformLogging?.includes('debug')) {
201
+ this.errorLog('Missing openToken');
202
+ this.warnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
231
203
  }
232
204
  }
233
205
  }
@@ -239,21 +211,15 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
239
211
  async discoverDevices() {
240
212
  try {
241
213
  if (this.config.credentials?.openToken) {
242
- const devicesAPI: any = (await this.axios.get(settings.DeviceURL)).data;
214
+ const devicesAPI: any = (await this.axios.get(DeviceURL)).data;
243
215
  this.deviceListInfo(devicesAPI);
244
216
  this.debugLog(JSON.stringify(devicesAPI));
245
217
 
246
218
  // SwitchBot Devices
247
- this.infoLog(
248
- `Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`,
249
- );
219
+ this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
250
220
  const deviceLists = devicesAPI.body.deviceList;
251
221
  if (!this.config.options?.devices) {
252
- this.debugLog(
253
- `SwitchBot Device Config Not Set: ${JSON.stringify(
254
- this.config.options?.devices,
255
- )}`,
256
- );
222
+ this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
257
223
  const devices = deviceLists.map((v: any) => v);
258
224
  for (const device of devices) {
259
225
  if (device.deviceType) {
@@ -263,24 +229,15 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
263
229
  this.createDevice(device);
264
230
  }
265
231
  }
266
- } else if (
267
- this.config.credentials?.openToken &&
268
- this.config.options.devices
269
- ) {
270
- this.debugLog(
271
- `SwitchBot Device Config Set: ${JSON.stringify(
272
- this.config.options?.devices,
273
- )}`,
274
- );
232
+ } else if (this.config.credentials?.openToken && this.config.options.devices) {
233
+ this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
275
234
  const deviceConfigs = this.config.options?.devices;
276
235
 
277
236
  const mergeBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
278
237
  a1.map((itm: { deviceId: string }) => ({
279
238
  ...a2.find(
280
239
  (item: { deviceId: string }) =>
281
- item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, "") ===
282
- itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, "") &&
283
- item,
240
+ item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
284
241
  ),
285
242
  ...itm,
286
243
  }));
@@ -296,21 +253,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
296
253
  }
297
254
  }
298
255
  } else {
299
- this.errorLog(
300
- "Neither SwitchBot OpenToken or Device Config are not set.",
301
- );
256
+ this.errorLog('Neither SwitchBot OpenToken or Device Config are not set.');
302
257
  }
303
258
  // IR Devices
304
- this.infoLog(
305
- `Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`,
306
- );
259
+ this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
307
260
  const irDeviceLists = devicesAPI.body.infraredRemoteList;
308
261
  if (!this.config.options?.irdevices) {
309
- this.debugLog(
310
- `IR Device Config Not Set: ${JSON.stringify(
311
- this.config.options?.irdevices,
312
- )}`,
313
- );
262
+ this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
314
263
  const devices = irDeviceLists.map((v: any) => v);
315
264
  for (const device of devices) {
316
265
  if (device.remoteType) {
@@ -318,20 +267,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
318
267
  }
319
268
  }
320
269
  } else {
321
- this.debugLog(
322
- `IR Device Config Set: ${JSON.stringify(
323
- this.config.options?.irdevices,
324
- )}`,
325
- );
270
+ this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
326
271
  const irDeviceConfig = this.config.options?.irdevices;
327
272
 
328
273
  const mergeIRBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
329
274
  a1.map((itm: { deviceId: string }) => ({
330
275
  ...a2.find(
331
276
  (item: { deviceId: string }) =>
332
- item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, "") ===
333
- itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, "") &&
334
- item,
277
+ item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
335
278
  ),
336
279
  ...itm,
337
280
  }));
@@ -344,15 +287,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
344
287
  }
345
288
  }
346
289
  }
347
- } else if (
348
- !this.config.credentials?.openToken &&
349
- this.config.options?.devices
350
- ) {
351
- this.debugLog(
352
- `SwitchBot Device Manual Config Set: ${JSON.stringify(
353
- this.config.options?.devices,
354
- )}`,
355
- );
290
+ } else if (!this.config.credentials?.openToken && this.config.options?.devices) {
291
+ this.debugLog(`SwitchBot Device Manual Config Set: ${JSON.stringify(this.config.options?.devices)}`);
356
292
  const deviceConfigs = this.config.options?.devices;
357
293
  const devices = deviceConfigs.map((v: any) => v);
358
294
  for (const device of devices) {
@@ -363,9 +299,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
363
299
  }
364
300
  }
365
301
  } else {
366
- this.errorLog(
367
- "Neither SwitchBot OpenToken or Device Config are not set.",
368
- );
302
+ this.errorLog('Neither SwitchBot OpenToken or Device Config are not set.');
369
303
  }
370
304
  } catch (e: any) {
371
305
  this.deviceError(e);
@@ -373,239 +307,193 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
373
307
  }
374
308
 
375
309
  deviceError(e: any) {
376
- if (e.message.includes("400")) {
377
- this.errorLog("Failed to Discover Devices: Bad Request");
378
- this.debugLog(
379
- "The client has issued an invalid request. This is commonly used to specify validation errors in a request payload.",
380
- );
381
- } else if (e.message.includes("401")) {
382
- this.errorLog("Failed to Discover Devices: Unauthorized Request");
383
- this.debugLog(
384
- "Authorization for the API is required, but the request has not been authenticated.",
385
- );
386
- } else if (e.message.includes("403")) {
387
- this.errorLog("Failed to Discover Devices: Forbidden Request");
310
+ if (e.message.includes('400')) {
311
+ this.errorLog('Failed to Discover Devices: Bad Request');
312
+ this.debugLog('The client has issued an invalid request. This is commonly used to specify validation errors in a request payload.');
313
+ } else if (e.message.includes('401')) {
314
+ this.errorLog('Failed to Discover Devices: Unauthorized Request');
315
+ this.debugLog('Authorization for the API is required, but the request has not been authenticated.');
316
+ } else if (e.message.includes('403')) {
317
+ this.errorLog('Failed to Discover Devices: Forbidden Request');
318
+ this.debugLog('The request has been authenticated but does not have appropriate permissions, or a requested resource is not found.');
319
+ } else if (e.message.includes('404')) {
320
+ this.errorLog('Failed to Discover Devices: Requst Not Found');
321
+ this.debugLog('Specifies the requested path does not exist.');
322
+ } else if (e.message.includes('406')) {
323
+ this.errorLog('Failed to Discover Devices: Request Not Acceptable');
324
+ this.debugLog('The client has requested a MIME type via the Accept header for a value not supported by the server.');
325
+ } else if (e.message.includes('415')) {
326
+ this.errorLog('Failed to Discover Devices: Unsupported Requst Header');
327
+ this.debugLog('The client has defined a contentType header that is not supported by the server.');
328
+ } else if (e.message.includes('422')) {
329
+ this.errorLog('Failed to Discover Devices: Unprocessable Entity');
388
330
  this.debugLog(
389
- "The request has been authenticated but does not have appropriate permissions, or a requested resource is not found.",
390
- );
391
- } else if (e.message.includes("404")) {
392
- this.errorLog("Failed to Discover Devices: Requst Not Found");
393
- this.debugLog("Specifies the requested path does not exist.");
394
- } else if (e.message.includes("406")) {
395
- this.errorLog("Failed to Discover Devices: Request Not Acceptable");
396
- this.debugLog(
397
- "The client has requested a MIME type via the Accept header for a value not supported by the server.",
398
- );
399
- } else if (e.message.includes("415")) {
400
- this.errorLog("Failed to Discover Devices: Unsupported Requst Header");
401
- this.debugLog(
402
- "The client has defined a contentType header that is not supported by the server.",
403
- );
404
- } else if (e.message.includes("422")) {
405
- this.errorLog("Failed to Discover Devices: Unprocessable Entity");
406
- this.debugLog(
407
- "The client has made a valid request, but the server cannot process it." +
408
- " This is often used for APIs for which certain limits have been exceeded.",
409
- );
410
- } else if (e.message.includes("429")) {
411
- this.errorLog("Failed to Discover Devices: Too Many Requests");
412
- this.debugLog(
413
- "The client has exceeded the number of requests allowed for a given time window.",
414
- );
415
- } else if (e.message.includes("500")) {
416
- this.errorLog("Failed to Discover Devices: Internal Server Error");
417
- this.debugLog(
418
- "An unexpected error on the SmartThings servers has occurred. These errors should be rare.",
419
- );
331
+ 'The client has made a valid request, but the server cannot process it.' +
332
+ ' This is often used for APIs for which certain limits have been exceeded.',
333
+ );
334
+ } else if (e.message.includes('429')) {
335
+ this.errorLog('Failed to Discover Devices: Too Many Requests');
336
+ this.debugLog('The client has exceeded the number of requests allowed for a given time window.');
337
+ } else if (e.message.includes('500')) {
338
+ this.errorLog('Failed to Discover Devices: Internal Server Error');
339
+ this.debugLog('An unexpected error on the SmartThings servers has occurred. These errors should be rare.');
420
340
  } else {
421
- this.errorLog("Failed to Discover Devices");
341
+ this.errorLog('Failed to Discover Devices');
422
342
  }
423
- if (this.platformLogging === "debug") {
424
- this.errorLog(
425
- `Failed to Discover Devices, Error Message: ${JSON.stringify(
426
- e.message,
427
- )}`,
428
- );
343
+ if (this.platformLogging === 'debug') {
344
+ this.errorLog(`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}`);
429
345
  }
430
- if (this.platformLogging === "debugMode") {
346
+ if (this.platformLogging === 'debugMode') {
431
347
  this.errorLog(`Failed to Discover Devices, Error: ${JSON.stringify(e)}`);
432
348
  }
433
349
  }
434
350
 
435
- private createDevice(device: settings.device & settings.devicesConfig) {
351
+ private createDevice(device: device & devicesConfig) {
436
352
  switch (device.deviceType!) {
437
- case "Humidifier":
353
+ case 'Humidifier':
438
354
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
439
355
  this.createHumidifier(device);
440
356
  break;
441
- case "Hub Mini":
357
+ case 'Hub Mini':
442
358
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
443
359
  break;
444
- case "Hub Plus":
360
+ case 'Hub Plus':
445
361
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
446
362
  break;
447
- case "Bot":
363
+ case 'Bot':
448
364
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
449
365
  this.createBot(device);
450
366
  break;
451
- case "Meter":
367
+ case 'Meter':
452
368
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
453
369
  this.createMeter(device);
454
370
  break;
455
- case "Motion Sensor":
371
+ case 'Motion Sensor':
456
372
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
457
373
  this.createMotion(device);
458
374
  break;
459
- case "Contact Sensor":
375
+ case 'Contact Sensor':
460
376
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
461
377
  this.createContact(device);
462
378
  break;
463
- case "Curtain":
379
+ case 'Curtain':
464
380
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
465
381
  this.createCurtain(device);
466
382
  break;
467
- case "Plug":
383
+ case 'Plug':
468
384
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
469
385
  this.createPlug(device);
470
386
  break;
471
- case "Color Bulb":
387
+ case 'Color Bulb':
472
388
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
473
389
  this.createColorBulb(device);
474
390
  break;
475
- case "Indoor Cam":
391
+ case 'Indoor Cam':
476
392
  this.deviceInfo(device);
477
393
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
478
- this.warnLog(
479
- `Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`,
480
- );
394
+ this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`);
481
395
  break;
482
- case "Remote":
483
- this.debugLog(
484
- `Discovered ${device.deviceType}: ${device.deviceId} is Not Supported.`,
485
- );
396
+ case 'Remote':
397
+ this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId} is Not Supported.`);
486
398
  break;
487
399
  default:
488
400
  this.deviceInfo(device);
489
- this.warnLog(
490
- `Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`,
491
- );
492
- this.warnLog("Submit Feature Requests Here: https://git.io/JL14Z");
401
+ this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`);
402
+ this.warnLog('Submit Feature Requests Here: https://git.io/JL14Z');
493
403
  }
494
404
  }
495
405
 
496
- private createIRDevice(device: settings.irdevice & settings.devicesConfig) {
406
+ private createIRDevice(device: irdevice & devicesConfig) {
497
407
  switch (device.remoteType!) {
498
- case "TV":
499
- case "DIY TV":
500
- case "Projector":
501
- case "DIY Projector":
502
- case "Set Top Box":
503
- case "DIY Set Top Box":
504
- case "IPTV":
505
- case "DIY IPTV":
506
- case "DVD":
507
- case "DIY DVD":
508
- case "Speaker":
509
- case "DIY Speaker":
408
+ case 'TV':
409
+ case 'DIY TV':
410
+ case 'Projector':
411
+ case 'DIY Projector':
412
+ case 'Set Top Box':
413
+ case 'DIY Set Top Box':
414
+ case 'IPTV':
415
+ case 'DIY IPTV':
416
+ case 'DVD':
417
+ case 'DIY DVD':
418
+ case 'Speaker':
419
+ case 'DIY Speaker':
510
420
  this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
511
421
  this.createTV(device);
512
422
  break;
513
- case "Fan":
514
- case "DIY Fan":
423
+ case 'Fan':
424
+ case 'DIY Fan':
515
425
  this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
516
426
  this.createFan(device);
517
427
  break;
518
- case "Air Conditioner":
519
- case "DIY Air Conditioner":
428
+ case 'Air Conditioner':
429
+ case 'DIY Air Conditioner':
520
430
  this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
521
431
  this.createAirConditioner(device);
522
432
  break;
523
- case "Light":
524
- case "DIY Light":
433
+ case 'Light':
434
+ case 'DIY Light':
525
435
  this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
526
436
  this.createLight(device);
527
437
  break;
528
- case "Air Purifier":
529
- case "DIY Air Purifier":
438
+ case 'Air Purifier':
439
+ case 'DIY Air Purifier':
530
440
  this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
531
441
  this.createAirPurifier(device);
532
442
  break;
533
- case "Water Heater":
534
- case "DIY Water Heater":
443
+ case 'Water Heater':
444
+ case 'DIY Water Heater':
535
445
  this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
536
446
  this.createWaterHeater(device);
537
447
  break;
538
- case "Vacuum Cleaner":
539
- case "DIY Vacuum Cleaner":
448
+ case 'Vacuum Cleaner':
449
+ case 'DIY Vacuum Cleaner':
540
450
  this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
541
451
  this.createVacuumCleaner(device);
542
452
  break;
543
- case "Camera":
544
- case "DIY Camera":
453
+ case 'Camera':
454
+ case 'DIY Camera':
545
455
  this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
546
456
  this.createCamera(device);
547
457
  break;
548
- case "Others":
458
+ case 'Others':
549
459
  this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
550
460
  this.createOthers(device);
551
461
  break;
552
462
  default:
553
463
  this.deviceInfo(device);
554
- this.warnLog(
555
- `Device: ${device.deviceName} with Device Type: ${device.remoteType}, is currently not supported.`,
556
- );
557
- this.warnLog("Submit Feature Requests Here: https://git.io/JL14Z");
464
+ this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.remoteType}, is currently not supported.`);
465
+ this.warnLog('Submit Feature Requests Here: https://git.io/JL14Z');
558
466
  }
559
467
  }
560
468
 
561
- private registerDevice(device: settings.device & settings.devicesConfig) {
469
+ private registerDevice(device: device & devicesConfig) {
562
470
  if (!device.hide_device && device.enableCloudService && device.ble) {
563
471
  this.registeringDevice = true;
564
- this.debugLog(
565
- `Device: ${device.deviceName} Both OpenAPI and BLE Connections Enabled`,
566
- );
567
- } else if (
568
- !device.hide_device &&
569
- device.deviceId &&
570
- device.configDeviceType &&
571
- device.configDeviceName &&
572
- !device.enableCloudService
573
- ) {
472
+ this.debugLog(`Device: ${device.deviceName} Both OpenAPI and BLE Connections Enabled`);
473
+ } else if (!device.hide_device && device.deviceId && device.configDeviceType && device.configDeviceName && !device.enableCloudService) {
574
474
  this.registeringDevice = true;
575
475
  this.debugLog(`Device: ${device.deviceName} BLE Connection Enabled`);
576
- } else if (
577
- !device.hide_device &&
578
- device.enableCloudService &&
579
- !device.ble
580
- ) {
476
+ } else if (!device.hide_device && device.enableCloudService && !device.ble) {
581
477
  this.registeringDevice = true;
582
478
  this.debugLog(`Device: ${device.deviceName} OpenAPI Connection Enabled`);
583
479
  } else {
584
480
  this.registeringDevice = false;
585
- this.debugLog(
586
- `Device: ${device.deviceName} Neither OpenAPI and BLE Enabled`,
587
- );
481
+ this.debugLog(`Device: ${device.deviceName} Neither OpenAPI and BLE Enabled`);
588
482
  }
589
483
  return this.registeringDevice;
590
484
  }
591
485
 
592
- private async createHumidifier(device: settings.device & settings.devicesConfig) {
593
- const uuid = this.api.hap.uuid.generate(
594
- `${device.deviceId}-${device.deviceType}`,
595
- );
486
+ private async createHumidifier(device: device & devicesConfig) {
487
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
596
488
 
597
489
  // see if an accessory with the same uuid has already been registered and restored from
598
490
  // the cached devices we stored in the `configureAccessory` method above
599
- const existingAccessory = this.accessories.find(
600
- (accessory) => accessory.UUID === uuid,
601
- );
491
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
602
492
 
603
493
  if (existingAccessory) {
604
494
  // the accessory already exists
605
495
  if (this.registerDevice(device)) {
606
- this.infoLog(
607
- `Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
608
- );
496
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
609
497
 
610
498
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
611
499
  //existingAccessory.context.firmwareRevision = firmware;
@@ -619,17 +507,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
619
507
  // create the accessory handler for the restored accessory
620
508
  // this is imported from `platformAccessory.ts`
621
509
  new Humidifier(this, existingAccessory, device);
622
- this.debugLog(
623
- `${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`,
624
- );
510
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
625
511
  } else {
626
512
  this.unregisterPlatformAccessories(existingAccessory);
627
513
  }
628
514
  } else if (this.registerDevice(device)) {
629
515
  // the accessory does not yet exist, so we need to create it
630
- this.infoLog(
631
- `Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`,
632
- );
516
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
633
517
 
634
518
  // create a new accessory
635
519
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
@@ -645,39 +529,27 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
645
529
  // create the accessory handler for the newly create accessory
646
530
  // this is imported from `platformAccessory.ts`
647
531
  new Humidifier(this, accessory, device);
648
- this.debugLog(
649
- `${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`,
650
- );
532
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
651
533
 
652
534
  // link the accessory to your platform
653
- this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
654
- accessory,
655
- ]);
535
+ this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
656
536
  this.accessories.push(accessory);
657
537
  } else {
658
- this.debugLog(
659
- `Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`,
660
- );
538
+ this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
661
539
  }
662
540
  }
663
541
 
664
- private async createBot(device: settings.device & settings.devicesConfig) {
665
- const uuid = this.api.hap.uuid.generate(
666
- `${device.deviceId}-${device.deviceType}`,
667
- );
542
+ private async createBot(device: device & devicesConfig) {
543
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
668
544
 
669
545
  // see if an accessory with the same uuid has already been registered and restored from
670
546
  // the cached devices we stored in the `configureAccessory` method above
671
- const existingAccessory = this.accessories.find(
672
- (accessory) => accessory.UUID === uuid,
673
- );
547
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
674
548
 
675
549
  if (existingAccessory) {
676
550
  // the accessory already exists
677
551
  if (this.registerDevice(device)) {
678
- this.infoLog(
679
- `Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
680
- );
552
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
681
553
 
682
554
  this.debugLog(JSON.stringify(device.bot?.mode));
683
555
 
@@ -692,17 +564,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
692
564
  // create the accessory handler for the restored accessory
693
565
  // this is imported from `platformAccessory.ts`
694
566
  new Bot(this, existingAccessory, device);
695
- this.debugLog(
696
- `${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`,
697
- );
567
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
698
568
  } else {
699
569
  this.unregisterPlatformAccessories(existingAccessory);
700
570
  }
701
571
  } else if (this.registerDevice(device)) {
702
572
  // the accessory does not yet exist, so we need to create it
703
- this.infoLog(
704
- `Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`,
705
- );
573
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
706
574
 
707
575
  this.debugLog(JSON.stringify(device.bot?.mode));
708
576
 
@@ -721,39 +589,27 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
721
589
  // create the accessory handler for the newly create accessory
722
590
  // this is imported from `platformAccessory.ts`
723
591
  new Bot(this, accessory, device);
724
- this.debugLog(
725
- `${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`,
726
- );
592
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
727
593
 
728
594
  // link the accessory to your platform
729
- this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
730
- accessory,
731
- ]);
595
+ this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
732
596
  this.accessories.push(accessory);
733
597
  } else {
734
- this.debugLog(
735
- `Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`,
736
- );
598
+ this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
737
599
  }
738
600
  }
739
601
 
740
- private async createMeter(device: settings.device & settings.devicesConfig) {
741
- const uuid = this.api.hap.uuid.generate(
742
- `${device.deviceId}-${device.deviceType}`,
743
- );
602
+ private async createMeter(device: device & devicesConfig) {
603
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
744
604
 
745
605
  // see if an accessory with the same uuid has already been registered and restored from
746
606
  // the cached devices we stored in the `configureAccessory` method above
747
- const existingAccessory = this.accessories.find(
748
- (accessory) => accessory.UUID === uuid,
749
- );
607
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
750
608
 
751
609
  if (existingAccessory) {
752
610
  // the accessory already exists
753
611
  if (this.registerDevice(device)) {
754
- this.infoLog(
755
- `Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
756
- );
612
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
757
613
 
758
614
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
759
615
  existingAccessory.context.model = device.deviceType;
@@ -766,17 +622,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
766
622
  // create the accessory handler for the restored accessory
767
623
  // this is imported from `platformAccessory.ts`
768
624
  new Meter(this, existingAccessory, device);
769
- this.debugLog(
770
- `${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`,
771
- );
625
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
772
626
  } else {
773
627
  this.unregisterPlatformAccessories(existingAccessory);
774
628
  }
775
629
  } else if (this.registerDevice(device)) {
776
630
  // the accessory does not yet exist, so we need to create it
777
- this.infoLog(
778
- `Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`,
779
- );
631
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
780
632
 
781
633
  // create a new accessory
782
634
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
@@ -792,39 +644,27 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
792
644
  // create the accessory handler for the newly create accessory
793
645
  // this is imported from `platformAccessory.ts`
794
646
  new Meter(this, accessory, device);
795
- this.debugLog(
796
- `${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`,
797
- );
647
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
798
648
 
799
649
  // link the accessory to your platform
800
- this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
801
- accessory,
802
- ]);
650
+ this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
803
651
  this.accessories.push(accessory);
804
652
  } else {
805
- this.debugLog(
806
- `Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`,
807
- );
653
+ this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
808
654
  }
809
655
  }
810
656
 
811
- private async createMotion(device: settings.device & settings.devicesConfig) {
812
- const uuid = this.api.hap.uuid.generate(
813
- `${device.deviceId}-${device.deviceType}`,
814
- );
657
+ private async createMotion(device: device & devicesConfig) {
658
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
815
659
 
816
660
  // see if an accessory with the same uuid has already been registered and restored from
817
661
  // the cached devices we stored in the `configureAccessory` method above
818
- const existingAccessory = this.accessories.find(
819
- (accessory) => accessory.UUID === uuid,
820
- );
662
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
821
663
 
822
664
  if (existingAccessory) {
823
665
  // the accessory already exists
824
666
  if (this.registerDevice(device)) {
825
- this.infoLog(
826
- `Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
827
- );
667
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
828
668
 
829
669
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
830
670
  existingAccessory.context.model = device.deviceType;
@@ -837,17 +677,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
837
677
  // create the accessory handler for the restored accessory
838
678
  // this is imported from `platformAccessory.ts`
839
679
  new Motion(this, existingAccessory, device);
840
- this.debugLog(
841
- `${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`,
842
- );
680
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
843
681
  } else {
844
682
  this.unregisterPlatformAccessories(existingAccessory);
845
683
  }
846
684
  } else if (this.registerDevice(device)) {
847
685
  // the accessory does not yet exist, so we need to create it
848
- this.infoLog(
849
- `Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`,
850
- );
686
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
851
687
 
852
688
  // create a new accessory
853
689
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
@@ -863,39 +699,27 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
863
699
  // create the accessory handler for the newly create accessory
864
700
  // this is imported from `platformAccessory.ts`
865
701
  new Motion(this, accessory, device);
866
- this.debugLog(
867
- `${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`,
868
- );
702
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
869
703
 
870
704
  // link the accessory to your platform
871
- this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
872
- accessory,
873
- ]);
705
+ this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
874
706
  this.accessories.push(accessory);
875
707
  } else {
876
- this.debugLog(
877
- `Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`,
878
- );
708
+ this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
879
709
  }
880
710
  }
881
711
 
882
- private async createContact(device: settings.device & settings.devicesConfig) {
883
- const uuid = this.api.hap.uuid.generate(
884
- `${device.deviceId}-${device.deviceType}`,
885
- );
712
+ private async createContact(device: device & devicesConfig) {
713
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
886
714
 
887
715
  // see if an accessory with the same uuid has already been registered and restored from
888
716
  // the cached devices we stored in the `configureAccessory` method above
889
- const existingAccessory = this.accessories.find(
890
- (accessory) => accessory.UUID === uuid,
891
- );
717
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
892
718
 
893
719
  if (existingAccessory) {
894
720
  // the accessory already exists
895
721
  if (this.registerDevice(device)) {
896
- this.infoLog(
897
- `Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
898
- );
722
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
899
723
 
900
724
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
901
725
  existingAccessory.context.model = device.deviceType;
@@ -908,17 +732,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
908
732
  // create the accessory handler for the restored accessory
909
733
  // this is imported from `platformAccessory.ts`
910
734
  new Contact(this, existingAccessory, device);
911
- this.debugLog(
912
- `${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`,
913
- );
735
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
914
736
  } else {
915
737
  this.unregisterPlatformAccessories(existingAccessory);
916
738
  }
917
739
  } else if (this.registerDevice(device)) {
918
740
  // the accessory does not yet exist, so we need to create it
919
- this.infoLog(
920
- `Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`,
921
- );
741
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
922
742
 
923
743
  // create a new accessory
924
744
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
@@ -934,39 +754,27 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
934
754
  // create the accessory handler for the newly create accessory
935
755
  // this is imported from `platformAccessory.ts`
936
756
  new Contact(this, accessory, device);
937
- this.debugLog(
938
- `${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`,
939
- );
757
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
940
758
 
941
759
  // link the accessory to your platform
942
- this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
943
- accessory,
944
- ]);
760
+ this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
945
761
  this.accessories.push(accessory);
946
762
  } else {
947
- this.debugLog(
948
- `Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`,
949
- );
763
+ this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
950
764
  }
951
765
  }
952
766
 
953
- private async createCurtain(device: settings.device & settings.devicesConfig) {
954
- const uuid = this.api.hap.uuid.generate(
955
- `${device.deviceId}-${device.deviceType}`,
956
- );
767
+ private async createCurtain(device: device & devicesConfig) {
768
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
957
769
 
958
770
  // see if an accessory with the same uuid has already been registered and restored from
959
771
  // the cached devices we stored in the `configureAccessory` method above
960
- const existingAccessory = this.accessories.find(
961
- (accessory) => accessory.UUID === uuid,
962
- );
772
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
963
773
 
964
774
  if (existingAccessory) {
965
775
  // the accessory already exists
966
776
  if (this.isCurtainGrouped(device)) {
967
- this.infoLog(
968
- `Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
969
- );
777
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
970
778
 
971
779
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
972
780
  existingAccessory.context.model = device.deviceType;
@@ -979,30 +787,22 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
979
787
  // create the accessory handler for the restored accessory
980
788
  // this is imported from `platformAccessory.ts`
981
789
  new Curtain(this, existingAccessory, device);
982
- this.debugLog(
983
- `${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`,
984
- );
790
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
985
791
  } else {
986
792
  this.unregisterPlatformAccessories(existingAccessory);
987
793
  }
988
794
  } else if (this.isCurtainGrouped(device)) {
989
795
  // the accessory does not yet exist, so we need to create it
990
- this.infoLog(
991
- `Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`,
992
- );
796
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
993
797
 
994
798
  if (device.group && !device.curtain?.disable_group) {
995
799
  this.debugLog(`Your Curtains are grouped
996
800
  , Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
997
801
  } else {
998
802
  if (device.master) {
999
- this.debugLog(
1000
- `Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`,
1001
- );
803
+ this.debugLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1002
804
  } else {
1003
- this.debugLog(
1004
- `Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`,
1005
- );
805
+ this.debugLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1006
806
  }
1007
807
  }
1008
808
 
@@ -1020,58 +820,42 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1020
820
  // create the accessory handler for the newly create accessory
1021
821
  // this is imported from `platformAccessory.ts`
1022
822
  new Curtain(this, accessory, device);
1023
- this.debugLog(
1024
- `${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`,
1025
- );
823
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1026
824
 
1027
825
  // link the accessory to your platform
1028
- this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
1029
- accessory,
1030
- ]);
826
+ this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
1031
827
  this.accessories.push(accessory);
1032
828
  } else {
1033
- this.debugLog(
1034
- `Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`,
1035
- );
829
+ this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
1036
830
  }
1037
831
  }
1038
832
 
1039
- private isCurtainGrouped(device: settings.device & settings.devicesConfig) {
833
+ private isCurtainGrouped(device: device & devicesConfig) {
1040
834
  this.debugLog(
1041
835
  `deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds},` +
1042
836
  ` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}`,
1043
837
  );
1044
838
 
1045
839
  if (device.group && !device.curtain?.disable_group) {
1046
- this.debugLog(
1047
- `[Curtain Config] disable_group: ${device.curtain?.disable_group}`,
1048
- );
840
+ this.debugLog(`[Curtain Config] disable_group: ${device.curtain?.disable_group}`);
1049
841
  return device.master && this.registerDevice(device);
1050
842
  } else {
1051
- this.debugLog(
1052
- `[Curtain Config] disable_group: ${device.curtain?.disable_group}, UnGrouping ${device.master}`,
1053
- );
843
+ this.debugLog(`[Curtain Config] disable_group: ${device.curtain?.disable_group}, UnGrouping ${device.master}`);
1054
844
  return this.registerDevice(device);
1055
845
  }
1056
846
  }
1057
847
 
1058
- private async createPlug(device: settings.device & settings.devicesConfig) {
1059
- const uuid = this.api.hap.uuid.generate(
1060
- `${device.deviceId}-${device.deviceType}`,
1061
- );
848
+ private async createPlug(device: device & devicesConfig) {
849
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1062
850
 
1063
851
  // see if an accessory with the same uuid has already been registered and restored from
1064
852
  // the cached devices we stored in the `configureAccessory` method above
1065
- const existingAccessory = this.accessories.find(
1066
- (accessory) => accessory.UUID === uuid,
1067
- );
853
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1068
854
 
1069
855
  if (existingAccessory) {
1070
856
  // the accessory already exists
1071
857
  if (!device.hide_device && device.enableCloudService) {
1072
- this.infoLog(
1073
- `Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
1074
- );
858
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1075
859
 
1076
860
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1077
861
  existingAccessory.context.model = device.deviceType;
@@ -1084,17 +868,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1084
868
  // create the accessory handler for the restored accessory
1085
869
  // this is imported from `platformAccessory.ts`
1086
870
  new Plug(this, existingAccessory, device);
1087
- this.debugLog(
1088
- `${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`,
1089
- );
871
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
1090
872
  } else {
1091
873
  this.unregisterPlatformAccessories(existingAccessory);
1092
874
  }
1093
875
  } else if (!device.hide_device && device.enableCloudService) {
1094
876
  // the accessory does not yet exist, so we need to create it
1095
- this.infoLog(
1096
- `Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`,
1097
- );
877
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1098
878
 
1099
879
  // create a new accessory
1100
880
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
@@ -1110,39 +890,27 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1110
890
  // create the accessory handler for the newly create accessory
1111
891
  // this is imported from `platformAccessory.ts`
1112
892
  new Plug(this, accessory, device);
1113
- this.debugLog(
1114
- `${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`,
1115
- );
893
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1116
894
 
1117
895
  // link the accessory to your platform
1118
- this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
1119
- accessory,
1120
- ]);
896
+ this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
1121
897
  this.accessories.push(accessory);
1122
898
  } else {
1123
- this.debugLog(
1124
- `Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`,
1125
- );
899
+ this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
1126
900
  }
1127
901
  }
1128
902
 
1129
- private async createColorBulb(device: settings.device & settings.devicesConfig) {
1130
- const uuid = this.api.hap.uuid.generate(
1131
- `${device.deviceId}-${device.deviceType}`,
1132
- );
903
+ private async createColorBulb(device: device & devicesConfig) {
904
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1133
905
 
1134
906
  // see if an accessory with the same uuid has already been registered and restored from
1135
907
  // the cached devices we stored in the `configureAccessory` method above
1136
- const existingAccessory = this.accessories.find(
1137
- (accessory) => accessory.UUID === uuid,
1138
- );
908
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1139
909
 
1140
910
  if (existingAccessory) {
1141
911
  // the accessory already exists
1142
912
  if (!device.hide_device && device.enableCloudService) {
1143
- this.infoLog(
1144
- `Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
1145
- );
913
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1146
914
 
1147
915
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1148
916
  existingAccessory.context.model = device.deviceType;
@@ -1155,17 +923,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1155
923
  // create the accessory handler for the restored accessory
1156
924
  // this is imported from `platformAccessory.ts`
1157
925
  new ColorBulb(this, existingAccessory, device);
1158
- this.debugLog(
1159
- `${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`,
1160
- );
926
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
1161
927
  } else {
1162
928
  this.unregisterPlatformAccessories(existingAccessory);
1163
929
  }
1164
930
  } else if (!device.hide_device && device.enableCloudService) {
1165
931
  // the accessory does not yet exist, so we need to create it
1166
- this.infoLog(
1167
- `Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`,
1168
- );
932
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1169
933
 
1170
934
  // create a new accessory
1171
935
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
@@ -1181,37 +945,25 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1181
945
  // create the accessory handler for the newly create accessory
1182
946
  // this is imported from `platformAccessory.ts`
1183
947
  new ColorBulb(this, accessory, device);
1184
- this.debugLog(
1185
- `${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`,
1186
- );
948
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1187
949
 
1188
950
  // link the accessory to your platform
1189
- this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
1190
- accessory,
1191
- ]);
951
+ this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
1192
952
  this.accessories.push(accessory);
1193
953
  } else {
1194
- this.debugLog(
1195
- `Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`,
1196
- );
954
+ this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
1197
955
  }
1198
956
  }
1199
957
 
1200
- private async createTV(device: settings.irdevice & settings.devicesConfig) {
1201
- const uuid = this.api.hap.uuid.generate(
1202
- `${device.deviceId}-${device.remoteType}`,
1203
- );
958
+ private async createTV(device: irdevice & devicesConfig) {
959
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
1204
960
 
1205
961
  // see if an accessory with the same uuid has already been registered and restored from
1206
962
  // the cached devices we stored in the `configureAccessory` method above
1207
- const existingAccessory = this.accessories.find(
1208
- (accessory) => accessory.UUID === uuid,
1209
- );
963
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1210
964
 
1211
965
  if (!device.hide_device && existingAccessory) {
1212
- this.infoLog(
1213
- `Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
1214
- );
966
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1215
967
 
1216
968
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1217
969
  existingAccessory.context.model = device.remoteType;
@@ -1224,14 +976,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1224
976
  // create the accessory handler for the restored accessory
1225
977
  // this is imported from `platformAccessory.ts`
1226
978
  new TV(this, existingAccessory, device);
1227
- this.debugLog(
1228
- `${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`,
1229
- );
979
+ this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
1230
980
  } else if (!device.hide_device && device.hubDeviceId) {
1231
981
  // the accessory does not yet exist, so we need to create it
1232
- this.infoLog(
1233
- `Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`,
1234
- );
982
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1235
983
 
1236
984
  // create a new accessory
1237
985
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
@@ -1247,41 +995,31 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1247
995
  // create the accessory handler for the newly create accessory
1248
996
  // this is imported from `platformAccessory.ts`
1249
997
  new TV(this, accessory, device);
1250
- this.debugLog(
1251
- `${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`,
1252
- );
998
+ this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
1253
999
 
1254
1000
  /**
1255
1001
  * Publish as external accessory
1256
1002
  * Only one TV can exist per bridge, to bypass this limitation, you should
1257
1003
  * publish your TV as an external accessory.
1258
1004
  */
1259
- this.api.publishExternalAccessories(settings.PLUGIN_NAME, [accessory]);
1005
+ this.api.publishExternalAccessories(PLUGIN_NAME, [accessory]);
1260
1006
  this.accessories.push(accessory);
1261
1007
  } else {
1262
- this.debugLog(
1263
- `Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`,
1264
- );
1008
+ this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1265
1009
  }
1266
1010
  }
1267
1011
 
1268
- private async createFan(device: settings.irdevice & settings.devicesConfig) {
1269
- const uuid = this.api.hap.uuid.generate(
1270
- `${device.deviceId}-${device.remoteType}`,
1271
- );
1012
+ private async createFan(device: irdevice & devicesConfig) {
1013
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
1272
1014
 
1273
1015
  // see if an accessory with the same uuid has already been registered and restored from
1274
1016
  // the cached devices we stored in the `configureAccessory` method above
1275
- const existingAccessory = this.accessories.find(
1276
- (accessory) => accessory.UUID === uuid,
1277
- );
1017
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1278
1018
 
1279
1019
  if (existingAccessory) {
1280
1020
  // the accessory already exists
1281
1021
  if (!device.hide_device && device.hubDeviceId) {
1282
- this.infoLog(
1283
- `Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
1284
- );
1022
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1285
1023
 
1286
1024
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1287
1025
 
@@ -1295,17 +1033,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1295
1033
  // create the accessory handler for the restored accessory
1296
1034
  // this is imported from `platformAccessory.ts`
1297
1035
  new Fan(this, existingAccessory, device);
1298
- this.debugLog(
1299
- `${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`,
1300
- );
1036
+ this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
1301
1037
  } else {
1302
1038
  this.unregisterPlatformAccessories(existingAccessory);
1303
1039
  }
1304
1040
  } else if (!device.hide_device && device.hubDeviceId) {
1305
1041
  // the accessory does not yet exist, so we need to create it
1306
- this.infoLog(
1307
- `Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`,
1308
- );
1042
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1309
1043
 
1310
1044
  // create a new accessory
1311
1045
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
@@ -1321,39 +1055,27 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1321
1055
  // create the accessory handler for the newly create accessory
1322
1056
  // this is imported from `platformAccessory.ts`
1323
1057
  new Fan(this, accessory, device);
1324
- this.debugLog(
1325
- `${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`,
1326
- );
1058
+ this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
1327
1059
 
1328
1060
  // link the accessory to your platform
1329
- this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
1330
- accessory,
1331
- ]);
1061
+ this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
1332
1062
  this.accessories.push(accessory);
1333
1063
  } else {
1334
- this.debugLog(
1335
- `Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`,
1336
- );
1064
+ this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1337
1065
  }
1338
1066
  }
1339
1067
 
1340
- private async createLight(device: settings.irdevice & settings.devicesConfig) {
1341
- const uuid = this.api.hap.uuid.generate(
1342
- `${device.deviceId}-${device.remoteType}`,
1343
- );
1068
+ private async createLight(device: irdevice & devicesConfig) {
1069
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
1344
1070
 
1345
1071
  // see if an accessory with the same uuid has already been registered and restored from
1346
1072
  // the cached devices we stored in the `configureAccessory` method above
1347
- const existingAccessory = this.accessories.find(
1348
- (accessory) => accessory.UUID === uuid,
1349
- );
1073
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1350
1074
 
1351
1075
  if (existingAccessory) {
1352
1076
  // the accessory already exists
1353
1077
  if (!device.hide_device && device.hubDeviceId) {
1354
- this.infoLog(
1355
- `Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
1356
- );
1078
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1357
1079
 
1358
1080
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1359
1081
  existingAccessory.context.model = device.remoteType;
@@ -1366,17 +1088,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1366
1088
  // create the accessory handler for the restored accessory
1367
1089
  // this is imported from `platformAccessory.ts`
1368
1090
  new Light(this, existingAccessory, device);
1369
- this.debugLog(
1370
- `${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`,
1371
- );
1091
+ this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
1372
1092
  } else {
1373
1093
  this.unregisterPlatformAccessories(existingAccessory);
1374
1094
  }
1375
1095
  } else if (!device.hide_device && device.hubDeviceId) {
1376
1096
  // the accessory does not yet exist, so we need to create it
1377
- this.infoLog(
1378
- `Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`,
1379
- );
1097
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1380
1098
 
1381
1099
  // create a new accessory
1382
1100
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
@@ -1392,39 +1110,27 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1392
1110
  // create the accessory handler for the newly create accessory
1393
1111
  // this is imported from `platformAccessory.ts`
1394
1112
  new Light(this, accessory, device);
1395
- this.debugLog(
1396
- `${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`,
1397
- );
1113
+ this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
1398
1114
 
1399
1115
  // link the accessory to your platform
1400
- this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
1401
- accessory,
1402
- ]);
1116
+ this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
1403
1117
  this.accessories.push(accessory);
1404
1118
  } else {
1405
- this.debugLog(
1406
- `Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`,
1407
- );
1119
+ this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1408
1120
  }
1409
1121
  }
1410
1122
 
1411
- private async createAirConditioner(device: settings.irdevice & settings.devicesConfig) {
1412
- const uuid = this.api.hap.uuid.generate(
1413
- `${device.deviceId}-${device.remoteType}`,
1414
- );
1123
+ private async createAirConditioner(device: irdevice & devicesConfig) {
1124
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
1415
1125
 
1416
1126
  // see if an accessory with the same uuid has already been registered and restored from
1417
1127
  // the cached devices we stored in the `configureAccessory` method above
1418
- const existingAccessory = this.accessories.find(
1419
- (accessory) => accessory.UUID === uuid,
1420
- );
1128
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1421
1129
 
1422
1130
  if (existingAccessory) {
1423
1131
  // the accessory already exists
1424
1132
  if (!device.hide_device && device.hubDeviceId) {
1425
- this.infoLog(
1426
- `Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
1427
- );
1133
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1428
1134
 
1429
1135
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1430
1136
  existingAccessory.context.model = device.remoteType;
@@ -1437,17 +1143,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1437
1143
  // create the accessory handler for the restored accessory
1438
1144
  // this is imported from `platformAccessory.ts`
1439
1145
  new AirConditioner(this, existingAccessory, device);
1440
- this.debugLog(
1441
- `${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`,
1442
- );
1146
+ this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
1443
1147
  } else {
1444
1148
  this.unregisterPlatformAccessories(existingAccessory);
1445
1149
  }
1446
1150
  } else if (!device.hide_device && device.hubDeviceId) {
1447
1151
  // the accessory does not yet exist, so we need to create it
1448
- this.infoLog(
1449
- `Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`,
1450
- );
1152
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1451
1153
 
1452
1154
  // create a new accessory
1453
1155
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
@@ -1463,39 +1165,27 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1463
1165
  // create the accessory handler for the newly create accessory
1464
1166
  // this is imported from `platformAccessory.ts`
1465
1167
  new AirConditioner(this, accessory, device);
1466
- this.debugLog(
1467
- `${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`,
1468
- );
1168
+ this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
1469
1169
 
1470
1170
  // link the accessory to your platform
1471
- this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
1472
- accessory,
1473
- ]);
1171
+ this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
1474
1172
  this.accessories.push(accessory);
1475
1173
  } else {
1476
- this.debugLog(
1477
- `Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`,
1478
- );
1174
+ this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1479
1175
  }
1480
1176
  }
1481
1177
 
1482
- private async createAirPurifier(device: settings.irdevice & settings.devicesConfig) {
1483
- const uuid = this.api.hap.uuid.generate(
1484
- `${device.deviceId}-${device.remoteType}`,
1485
- );
1178
+ private async createAirPurifier(device: irdevice & devicesConfig) {
1179
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
1486
1180
 
1487
1181
  // see if an accessory with the same uuid has already been registered and restored from
1488
1182
  // the cached devices we stored in the `configureAccessory` method above
1489
- const existingAccessory = this.accessories.find(
1490
- (accessory) => accessory.UUID === uuid,
1491
- );
1183
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1492
1184
 
1493
1185
  if (existingAccessory) {
1494
1186
  // the accessory already exists
1495
1187
  if (!device.hide_device && device.hubDeviceId) {
1496
- this.infoLog(
1497
- `Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
1498
- );
1188
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1499
1189
 
1500
1190
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1501
1191
  existingAccessory.context.model = device.remoteType;
@@ -1508,17 +1198,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1508
1198
  // create the accessory handler for the restored accessory
1509
1199
  // this is imported from `platformAccessory.ts`
1510
1200
  new AirPurifier(this, existingAccessory, device);
1511
- this.debugLog(
1512
- `${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`,
1513
- );
1201
+ this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
1514
1202
  } else {
1515
1203
  this.unregisterPlatformAccessories(existingAccessory);
1516
1204
  }
1517
1205
  } else if (!device.hide_device && device.hubDeviceId) {
1518
1206
  // the accessory does not yet exist, so we need to create it
1519
- this.infoLog(
1520
- `Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`,
1521
- );
1207
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1522
1208
 
1523
1209
  // create a new accessory
1524
1210
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
@@ -1534,39 +1220,27 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1534
1220
  // create the accessory handler for the newly create accessory
1535
1221
  // this is imported from `platformAccessory.ts`
1536
1222
  new AirPurifier(this, accessory, device);
1537
- this.debugLog(
1538
- `${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`,
1539
- );
1223
+ this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
1540
1224
 
1541
1225
  // link the accessory to your platform
1542
- this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
1543
- accessory,
1544
- ]);
1226
+ this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
1545
1227
  this.accessories.push(accessory);
1546
1228
  } else {
1547
- this.debugLog(
1548
- `Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`,
1549
- );
1229
+ this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1550
1230
  }
1551
1231
  }
1552
1232
 
1553
- private async createWaterHeater(device: settings.irdevice & settings.devicesConfig) {
1554
- const uuid = this.api.hap.uuid.generate(
1555
- `${device.deviceId}-${device.remoteType}`,
1556
- );
1233
+ private async createWaterHeater(device: irdevice & devicesConfig) {
1234
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
1557
1235
 
1558
1236
  // see if an accessory with the same uuid has already been registered and restored from
1559
1237
  // the cached devices we stored in the `configureAccessory` method above
1560
- const existingAccessory = this.accessories.find(
1561
- (accessory) => accessory.UUID === uuid,
1562
- );
1238
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1563
1239
 
1564
1240
  if (existingAccessory) {
1565
1241
  // the accessory already exists
1566
1242
  if (!device.hide_device && device.hubDeviceId) {
1567
- this.infoLog(
1568
- `Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
1569
- );
1243
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1570
1244
 
1571
1245
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1572
1246
  existingAccessory.context.model = device.remoteType;
@@ -1579,17 +1253,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1579
1253
  // create the accessory handler for the restored accessory
1580
1254
  // this is imported from `platformAccessory.ts`
1581
1255
  new WaterHeater(this, existingAccessory, device);
1582
- this.debugLog(
1583
- `${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`,
1584
- );
1256
+ this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
1585
1257
  } else {
1586
1258
  this.unregisterPlatformAccessories(existingAccessory);
1587
1259
  }
1588
1260
  } else if (!device.hide_device && device.hubDeviceId) {
1589
1261
  // the accessory does not yet exist, so we need to create it
1590
- this.infoLog(
1591
- `Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`,
1592
- );
1262
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1593
1263
 
1594
1264
  // create a new accessory
1595
1265
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
@@ -1605,39 +1275,27 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1605
1275
  // create the accessory handler for the newly create accessory
1606
1276
  // this is imported from `platformAccessory.ts`
1607
1277
  new WaterHeater(this, accessory, device);
1608
- this.debugLog(
1609
- `${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`,
1610
- );
1278
+ this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
1611
1279
 
1612
1280
  // link the accessory to your platform
1613
- this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
1614
- accessory,
1615
- ]);
1281
+ this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
1616
1282
  this.accessories.push(accessory);
1617
1283
  } else {
1618
- this.debugLog(
1619
- `Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`,
1620
- );
1284
+ this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1621
1285
  }
1622
1286
  }
1623
1287
 
1624
- private async createVacuumCleaner(device: settings.irdevice & settings.devicesConfig) {
1625
- const uuid = this.api.hap.uuid.generate(
1626
- `${device.deviceId}-${device.remoteType}`,
1627
- );
1288
+ private async createVacuumCleaner(device: irdevice & devicesConfig) {
1289
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
1628
1290
 
1629
1291
  // see if an accessory with the same uuid has already been registered and restored from
1630
1292
  // the cached devices we stored in the `configureAccessory` method above
1631
- const existingAccessory = this.accessories.find(
1632
- (accessory) => accessory.UUID === uuid,
1633
- );
1293
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1634
1294
 
1635
1295
  if (existingAccessory) {
1636
1296
  // the accessory already exists
1637
1297
  if (!device.hide_device && device.hubDeviceId) {
1638
- this.infoLog(
1639
- `Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
1640
- );
1298
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1641
1299
 
1642
1300
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1643
1301
  existingAccessory.context.model = device.remoteType;
@@ -1650,17 +1308,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1650
1308
  // create the accessory handler for the restored accessory
1651
1309
  // this is imported from `platformAccessory.ts`
1652
1310
  new VacuumCleaner(this, existingAccessory, device);
1653
- this.debugLog(
1654
- `${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`,
1655
- );
1311
+ this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
1656
1312
  } else {
1657
1313
  this.unregisterPlatformAccessories(existingAccessory);
1658
1314
  }
1659
1315
  } else if (!device.hide_device && device.hubDeviceId) {
1660
1316
  // the accessory does not yet exist, so we need to create it
1661
- this.infoLog(
1662
- `Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`,
1663
- );
1317
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1664
1318
 
1665
1319
  // create a new accessory
1666
1320
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
@@ -1676,39 +1330,27 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1676
1330
  // create the accessory handler for the newly create accessory
1677
1331
  // this is imported from `platformAccessory.ts`
1678
1332
  new VacuumCleaner(this, accessory, device);
1679
- this.debugLog(
1680
- `${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`,
1681
- );
1333
+ this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
1682
1334
 
1683
1335
  // link the accessory to your platform
1684
- this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
1685
- accessory,
1686
- ]);
1336
+ this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
1687
1337
  this.accessories.push(accessory);
1688
1338
  } else {
1689
- this.debugLog(
1690
- `Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`,
1691
- );
1339
+ this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1692
1340
  }
1693
1341
  }
1694
1342
 
1695
- private async createCamera(device: settings.irdevice & settings.devicesConfig) {
1696
- const uuid = this.api.hap.uuid.generate(
1697
- `${device.deviceId}-${device.remoteType}`,
1698
- );
1343
+ private async createCamera(device: irdevice & devicesConfig) {
1344
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
1699
1345
 
1700
1346
  // see if an accessory with the same uuid has already been registered and restored from
1701
1347
  // the cached devices we stored in the `configureAccessory` method above
1702
- const existingAccessory = this.accessories.find(
1703
- (accessory) => accessory.UUID === uuid,
1704
- );
1348
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1705
1349
 
1706
1350
  if (existingAccessory) {
1707
1351
  // the accessory already exists
1708
1352
  if (!device.hide_device && device.hubDeviceId) {
1709
- this.infoLog(
1710
- `Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
1711
- );
1353
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1712
1354
 
1713
1355
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1714
1356
  existingAccessory.context.model = device.remoteType;
@@ -1721,17 +1363,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1721
1363
  // create the accessory handler for the restored accessory
1722
1364
  // this is imported from `platformAccessory.ts`
1723
1365
  new Camera(this, existingAccessory, device);
1724
- this.debugLog(
1725
- `${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`,
1726
- );
1366
+ this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
1727
1367
  } else {
1728
1368
  this.unregisterPlatformAccessories(existingAccessory);
1729
1369
  }
1730
1370
  } else if (!device.hide_device && device.hubDeviceId) {
1731
1371
  // the accessory does not yet exist, so we need to create it
1732
- this.infoLog(
1733
- `Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`,
1734
- );
1372
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1735
1373
 
1736
1374
  // create a new accessory
1737
1375
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
@@ -1747,39 +1385,27 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1747
1385
  // create the accessory handler for the newly create accessory
1748
1386
  // this is imported from `platformAccessory.ts`
1749
1387
  new Camera(this, accessory, device);
1750
- this.debugLog(
1751
- `${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`,
1752
- );
1388
+ this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
1753
1389
 
1754
1390
  // link the accessory to your platform
1755
- this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
1756
- accessory,
1757
- ]);
1391
+ this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
1758
1392
  this.accessories.push(accessory);
1759
1393
  } else {
1760
- this.debugLog(
1761
- `Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`,
1762
- );
1394
+ this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1763
1395
  }
1764
1396
  }
1765
1397
 
1766
- private async createOthers(device: settings.irdevice & settings.devicesConfig) {
1767
- const uuid = this.api.hap.uuid.generate(
1768
- `${device.deviceId}-${device.remoteType}`,
1769
- );
1398
+ private async createOthers(device: irdevice & devicesConfig) {
1399
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
1770
1400
 
1771
1401
  // see if an accessory with the same uuid has already been registered and restored from
1772
1402
  // the cached devices we stored in the `configureAccessory` method above
1773
- const existingAccessory = this.accessories.find(
1774
- (accessory) => accessory.UUID === uuid,
1775
- );
1403
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1776
1404
 
1777
1405
  if (existingAccessory) {
1778
1406
  // the accessory already exists
1779
1407
  if (!device.hide_device && device.hubDeviceId) {
1780
- this.infoLog(
1781
- `Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`,
1782
- );
1408
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1783
1409
 
1784
1410
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1785
1411
  existingAccessory.context.model = device.remoteType;
@@ -1792,17 +1418,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1792
1418
  // create the accessory handler for the restored accessory
1793
1419
  // this is imported from `platformAccessory.ts`
1794
1420
  new Others(this, existingAccessory, device);
1795
- this.debugLog(
1796
- `${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`,
1797
- );
1421
+ this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
1798
1422
  } else {
1799
1423
  this.unregisterPlatformAccessories(existingAccessory);
1800
1424
  }
1801
1425
  } else if (!device.hide_device && device.hubDeviceId) {
1802
1426
  // the accessory does not yet exist, so we need to create it
1803
- this.infoLog(
1804
- `Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`,
1805
- );
1427
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
1806
1428
 
1807
1429
  // create a new accessory
1808
1430
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
@@ -1818,92 +1440,61 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1818
1440
  // create the accessory handler for the newly create accessory
1819
1441
  // this is imported from `platformAccessory.ts`
1820
1442
  new Others(this, accessory, device);
1821
- this.debugLog(
1822
- `${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`,
1823
- );
1443
+ this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
1824
1444
 
1825
1445
  // link the accessory to your platform
1826
- this.api.registerPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
1827
- accessory,
1828
- ]);
1446
+ this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
1829
1447
  this.accessories.push(accessory);
1830
1448
  } else {
1831
- this.debugLog(
1832
- `Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`,
1833
- );
1449
+ this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
1834
1450
  }
1835
1451
  }
1836
1452
 
1837
- public async connectionTypeNewAccessory(
1838
- device: settings.device & settings.devicesConfig,
1839
- accessory: PlatformAccessory,
1840
- ) {
1453
+ public async connectionTypeNewAccessory(device: device & devicesConfig, accessory: PlatformAccessory) {
1841
1454
  if (device.ble) {
1842
- accessory.context.connectionType = "BLE";
1455
+ accessory.context.connectionType = 'BLE';
1843
1456
  } else {
1844
- accessory.context.connectionType = "OpenAPI";
1457
+ accessory.context.connectionType = 'OpenAPI';
1845
1458
  }
1846
1459
  }
1847
1460
 
1848
- public async connectionTypeExistingAccessory(
1849
- device: settings.device & settings.devicesConfig,
1850
- existingAccessory: PlatformAccessory,
1851
- ) {
1461
+ public async connectionTypeExistingAccessory(device: device & devicesConfig, existingAccessory: PlatformAccessory) {
1852
1462
  if (device.ble) {
1853
- existingAccessory.context.connectionType = "BLE";
1463
+ existingAccessory.context.connectionType = 'BLE';
1854
1464
  } else {
1855
- existingAccessory.context.connectionType = "OpenAPI";
1465
+ existingAccessory.context.connectionType = 'OpenAPI';
1856
1466
  }
1857
1467
  }
1858
1468
 
1859
1469
  public async connectionTypeNewIRAccessory(accessory: PlatformAccessory) {
1860
- accessory.context.connectionType = "IR wirth OpenAPI";
1470
+ accessory.context.connectionType = 'IR wirth OpenAPI';
1861
1471
  }
1862
1472
 
1863
- public async connectionTypeExistingIRAccessory(
1864
- existingAccessory: PlatformAccessory,
1865
- ) {
1866
- existingAccessory.context.connectionType = "IR with OpenAPI";
1473
+ public async connectionTypeExistingIRAccessory(existingAccessory: PlatformAccessory) {
1474
+ existingAccessory.context.connectionType = 'IR with OpenAPI';
1867
1475
  }
1868
1476
 
1869
1477
  public unregisterPlatformAccessories(existingAccessory: PlatformAccessory) {
1870
1478
  // remove platform accessories when no longer present
1871
- this.api.unregisterPlatformAccessories(settings.PLUGIN_NAME, settings.PLATFORM_NAME, [
1872
- existingAccessory,
1873
- ]);
1874
- this.infoLog(
1875
- "Removing existing accessory from cache:",
1876
- existingAccessory.displayName,
1877
- );
1479
+ this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [existingAccessory]);
1480
+ this.infoLog('Removing existing accessory from cache:', existingAccessory.displayName);
1878
1481
  }
1879
1482
 
1880
- public deviceListInfo(devices: settings.deviceResponses) {
1881
- if (this.platformLogging === "debug") {
1483
+ public deviceListInfo(devices: deviceResponses) {
1484
+ if (this.platformLogging === 'debug') {
1882
1485
  this.warnLog(`deviceListInfoStatus: ${JSON.stringify(devices)}`);
1883
1486
  }
1884
1487
  }
1885
1488
 
1886
- public async deviceInfo(
1887
- device: (settings.irdevice & settings.devicesConfig) | (settings.device & settings.devicesConfig),
1888
- ) {
1889
- if (this.platformLogging === "debug") {
1489
+ public async deviceInfo(device: (irdevice & devicesConfig) | (device & devicesConfig)) {
1490
+ if (this.platformLogging === 'debug') {
1890
1491
  this.warnLog(JSON.stringify(device));
1891
- this.deviceStatus = (
1892
- await this.axios.get(`${settings.DeviceURL}/${device.deviceId}/status`)
1893
- ).data;
1894
- if (this.deviceStatus.message === "success") {
1895
- this.warnLog(
1896
- `${device.deviceName} deviceInfoStatus: ${JSON.stringify(
1897
- this.deviceStatus,
1898
- )}`,
1899
- );
1492
+ this.deviceStatus = (await this.axios.get(`${DeviceURL}/${device.deviceId}/status`)).data;
1493
+ if (this.deviceStatus.message === 'success') {
1494
+ this.warnLog(`${device.deviceName} deviceInfoStatus: ${JSON.stringify(this.deviceStatus)}`);
1900
1495
  } else {
1901
- this.warnLog(
1902
- `${device.deviceName} deviceInfoStatus: ${JSON.stringify(
1903
- this.deviceStatus.message,
1904
- )}`,
1905
- );
1906
- this.warnLog("Unable to retreive deviceInfoStatus.");
1496
+ this.warnLog(`${device.deviceName} deviceInfoStatus: ${JSON.stringify(this.deviceStatus.message)}`);
1497
+ this.warnLog('Unable to retreive deviceInfoStatus.');
1907
1498
  }
1908
1499
  }
1909
1500
  }
@@ -1913,7 +1504,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1913
1504
  let Switchbot: new () => any;
1914
1505
  let switchbot: any;
1915
1506
  try {
1916
- Switchbot = require("node-switchbot");
1507
+ Switchbot = require('node-switchbot');
1917
1508
  switchbot = new Switchbot();
1918
1509
  } catch (e) {
1919
1510
  switchbot = false;
@@ -1946,18 +1537,15 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1946
1537
 
1947
1538
  debugLog(...log: any[]) {
1948
1539
  if (this.enablingPlatfromLogging()) {
1949
- if (this.platformLogging === "debugMode") {
1540
+ if (this.platformLogging === 'debugMode') {
1950
1541
  this.log.debug(String(...log));
1951
- } else if (this.platformLogging === "debug") {
1952
- this.log.info("[DEBUG]", String(...log));
1542
+ } else if (this.platformLogging === 'debug') {
1543
+ this.log.info('[DEBUG]', String(...log));
1953
1544
  }
1954
1545
  }
1955
1546
  }
1956
1547
 
1957
1548
  enablingPlatfromLogging(): boolean {
1958
- return (
1959
- this.platformLogging?.includes("debug") ||
1960
- this.platformLogging === "standard"
1961
- );
1549
+ return this.platformLogging?.includes('debug') || this.platformLogging === 'standard';
1962
1550
  }
1963
1551
  }