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