@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
@@ -1,7 +1,7 @@
1
- import { AxiosResponse } from 'axios';
2
- import { SwitchBotPlatform } from '../platform';
3
- import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
1
+ import { AxiosResponse } from "axios";
2
+ import { SwitchBotPlatform } from "../platform";
3
+ import { irDevicesConfig, DeviceURL, irdevice, payload } from "../settings";
4
+ import { CharacteristicValue, PlatformAccessory, Service } from "homebridge";
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -36,15 +36,19 @@ export class Light {
36
36
  // set accessory information
37
37
  accessory
38
38
  .getService(this.platform.Service.AccessoryInformation)!
39
- .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
39
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
40
40
  .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
41
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
41
+ .setCharacteristic(
42
+ this.platform.Characteristic.SerialNumber,
43
+ device.deviceId!,
44
+ );
42
45
 
43
46
  // get the Television service if it exists, otherwise create a new Television service
44
47
  // you can create multiple services for each accessory
45
48
  (this.service =
46
49
  accessory.getService(this.platform.Service.Lightbulb) ||
47
- accessory.addService(this.platform.Service.Lightbulb)), `${accessory.displayName} Light Bulb`;
50
+ accessory.addService(this.platform.Service.Lightbulb)),
51
+ `${accessory.displayName} Light Bulb`;
48
52
 
49
53
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
50
54
  // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
@@ -52,10 +56,15 @@ export class Light {
52
56
 
53
57
  // set the service name, this is what is displayed as the default name on the Home app
54
58
  // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
55
- this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
59
+ this.service.setCharacteristic(
60
+ this.platform.Characteristic.Name,
61
+ accessory.displayName,
62
+ );
56
63
 
57
64
  // handle on / off events using the On characteristic
58
- this.service.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
65
+ this.service
66
+ .getCharacteristic(this.platform.Characteristic.On)
67
+ .onSet(this.OnSet.bind(this));
59
68
 
60
69
  // handle Brightness events using the Brightness characteristic
61
70
  /* this.service
@@ -87,8 +96,13 @@ export class Light {
87
96
  if (this.On === undefined) {
88
97
  this.debugLog(`Light: ${this.accessory.displayName} On: ${this.On}`);
89
98
  } else {
90
- this.service?.updateCharacteristic(this.platform.Characteristic.On, this.On);
91
- this.debugLog(`Light: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
99
+ this.service?.updateCharacteristic(
100
+ this.platform.Characteristic.On,
101
+ this.On,
102
+ );
103
+ this.debugLog(
104
+ `Light: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`,
105
+ );
92
106
  }
93
107
  }
94
108
 
@@ -105,9 +119,9 @@ export class Light {
105
119
  async pushLightOnChanges() {
106
120
  if (this.On) {
107
121
  const payload = {
108
- commandType: 'command',
109
- parameter: 'default',
110
- command: 'turnOn',
122
+ commandType: "command",
123
+ parameter: "default",
124
+ command: "turnOn",
111
125
  } as payload;
112
126
  await this.pushChanges(payload);
113
127
  }
@@ -116,9 +130,9 @@ export class Light {
116
130
  async pushLightOffChanges() {
117
131
  if (!this.On) {
118
132
  const payload = {
119
- commandType: 'command',
120
- parameter: 'default',
121
- command: 'turnOff',
133
+ commandType: "command",
134
+ parameter: "default",
135
+ command: "turnOff",
122
136
  } as payload;
123
137
  await this.pushChanges(payload);
124
138
  }
@@ -126,75 +140,103 @@ export class Light {
126
140
 
127
141
  async pushLightBrightnessUpChanges() {
128
142
  const payload = {
129
- commandType: 'command',
130
- parameter: 'default',
131
- command: 'brightnessUp',
143
+ commandType: "command",
144
+ parameter: "default",
145
+ command: "brightnessUp",
132
146
  } as payload;
133
147
  await this.pushChanges(payload);
134
148
  }
135
149
 
136
150
  async pushLightBrightnessDownChanges() {
137
151
  const payload = {
138
- commandType: 'command',
139
- parameter: 'default',
140
- command: 'brightnessDown',
152
+ commandType: "command",
153
+ parameter: "default",
154
+ command: "brightnessDown",
141
155
  } as payload;
142
156
  await this.pushChanges(payload);
143
157
  }
144
158
 
145
159
  public async pushChanges(payload: payload) {
146
160
  try {
147
- this.infoLog(`Light: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
148
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
161
+ this.infoLog(
162
+ `Light: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
163
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
164
+ );
149
165
 
150
166
  // Make the API request
151
- const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
152
- this.debugLog(`Light: ${this.accessory.displayName} pushChanges: ${push.data}`);
167
+ const push = await this.platform.axios.post(
168
+ `${DeviceURL}/${this.device.deviceId}/commands`,
169
+ payload,
170
+ );
171
+ this.debugLog(
172
+ `Light: ${this.accessory.displayName} pushChanges: ${push.data}`,
173
+ );
153
174
  this.statusCode(push);
154
175
  this.OnCached = this.On;
155
176
  this.accessory.context.On = this.OnCached;
156
177
  this.updateHomeKitCharacteristics();
157
178
  } catch (e: any) {
158
- this.errorLog(`Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
159
- if (this.deviceLogging === 'debug') {
160
- this.errorLog(`Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
161
- + ` Error Message: ${JSON.stringify(e.message)}`);
179
+ this.errorLog(
180
+ `Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`,
181
+ );
182
+ if (this.deviceLogging === "debug") {
183
+ this.errorLog(
184
+ `Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
185
+ ` Error Message: ${JSON.stringify(e.message)}`,
186
+ );
162
187
  }
163
188
  if (this.platform.debugMode) {
164
- this.errorLog(`Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
165
- + ` Error: ${JSON.stringify(e)}`);
189
+ this.errorLog(
190
+ `Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
191
+ ` Error: ${JSON.stringify(e)}`,
192
+ );
166
193
  }
167
194
  this.apiError(e);
168
195
  }
169
196
  }
170
197
 
171
-
172
- private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
198
+ private statusCode(push: AxiosResponse<{ statusCode: number }>) {
173
199
  switch (push.data.statusCode) {
174
200
  case 151:
175
- this.errorLog(`Light: ${this.accessory.displayName} Command not supported by this device type.`);
201
+ this.errorLog(
202
+ `Light: ${this.accessory.displayName} Command not supported by this device type.`,
203
+ );
176
204
  break;
177
205
  case 152:
178
206
  this.errorLog(`Light: ${this.accessory.displayName} Device not found.`);
179
207
  break;
180
208
  case 160:
181
- this.errorLog(`Light: ${this.accessory.displayName} Command is not supported.`);
209
+ this.errorLog(
210
+ `Light: ${this.accessory.displayName} Command is not supported.`,
211
+ );
182
212
  break;
183
213
  case 161:
184
- this.errorLog(`Light: ${this.accessory.displayName} Device is offline.`);
214
+ this.errorLog(
215
+ `Light: ${this.accessory.displayName} Device is offline.`,
216
+ );
185
217
  break;
186
218
  case 171:
187
- this.errorLog(`Light: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
219
+ this.errorLog(
220
+ `Light: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
221
+ );
188
222
  break;
189
223
  case 190:
190
- this.errorLog(`Light: ${this.accessory.displayName} Device internal error due to device states not synchronized`
191
- + ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
224
+ this.errorLog(
225
+ `Light: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
226
+ ` with server, Or command: ${JSON.stringify(
227
+ push.data,
228
+ )} format is invalid`,
229
+ );
192
230
  break;
193
231
  case 100:
194
- this.debugLog(`Light: ${this.accessory.displayName} Command successfully sent.`);
232
+ this.debugLog(
233
+ `Light: ${this.accessory.displayName} Command successfully sent.`,
234
+ );
195
235
  break;
196
236
  default:
197
- this.debugLog(`Light: ${this.accessory.displayName} Unknown statusCode.`);
237
+ this.debugLog(
238
+ `Light: ${this.accessory.displayName} Unknown statusCode.`,
239
+ );
198
240
  }
199
241
  }
200
242
 
@@ -209,32 +251,43 @@ export class Light {
209
251
  config = device.irlight;
210
252
  }
211
253
  if (device.logging !== undefined) {
212
- config['logging'] = device.logging;
254
+ config["logging"] = device.logging;
213
255
  }
214
256
  if (Object.entries(config).length !== 0) {
215
- this.warnLog(`Light: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
257
+ this.warnLog(
258
+ `Light: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`,
259
+ );
216
260
  }
217
261
  }
218
262
 
219
263
  logs(device: irdevice & irDevicesConfig) {
220
264
  if (this.platform.debugMode) {
221
- this.deviceLogging = this.accessory.context.logging = 'debugMode';
222
- this.debugLog(`Light: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
265
+ this.deviceLogging = this.accessory.context.logging = "debugMode";
266
+ this.debugLog(
267
+ `Light: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
268
+ );
223
269
  } else if (device.logging) {
224
270
  this.deviceLogging = this.accessory.context.logging = device.logging;
225
- this.debugLog(`Light: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
271
+ this.debugLog(
272
+ `Light: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
273
+ );
226
274
  } else if (this.platform.config.options?.logging) {
227
- this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
228
- this.debugLog(`Light: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
275
+ this.deviceLogging = this.accessory.context.logging =
276
+ this.platform.config.options?.logging;
277
+ this.debugLog(
278
+ `Light: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
279
+ );
229
280
  } else {
230
- this.deviceLogging = this.accessory.context.logging = 'standard';
231
- this.debugLog(`Light: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
281
+ this.deviceLogging = this.accessory.context.logging = "standard";
282
+ this.debugLog(
283
+ `Light: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
284
+ );
232
285
  }
233
286
  }
234
287
 
235
288
  /**
236
- * Logging for Device
237
- */
289
+ * Logging for Device
290
+ */
238
291
  infoLog(...log: any[]) {
239
292
  if (this.enablingDeviceLogging()) {
240
293
  this.platform.log.info(String(...log));
@@ -255,8 +308,8 @@ export class Light {
255
308
 
256
309
  debugLog(...log: any[]) {
257
310
  if (this.enablingDeviceLogging()) {
258
- if (this.deviceLogging === 'debug') {
259
- this.platform.log.info('[DEBUG]', String(...log));
311
+ if (this.deviceLogging === "debug") {
312
+ this.platform.log.info("[DEBUG]", String(...log));
260
313
  } else {
261
314
  this.platform.log.debug(String(...log));
262
315
  }
@@ -264,6 +317,6 @@ export class Light {
264
317
  }
265
318
 
266
319
  enablingDeviceLogging(): boolean {
267
- return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
320
+ return this.deviceLogging.includes("debug") || this.deviceLogging === "standard";
268
321
  }
269
322
  }
@@ -1,7 +1,7 @@
1
- import { AxiosResponse } from 'axios';
2
- import { SwitchBotPlatform } from '../platform';
3
- import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
1
+ import { AxiosResponse } from "axios";
2
+ import { SwitchBotPlatform } from "../platform";
3
+ import { irDevicesConfig, DeviceURL, irdevice, payload } from "../settings";
4
+ import { CharacteristicValue, PlatformAccessory, Service } from "homebridge";
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -38,31 +38,44 @@ export class Others {
38
38
  // set accessory information
39
39
  accessory
40
40
  .getService(this.platform.Service.AccessoryInformation)!
41
- .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
41
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
42
42
  .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
43
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
43
+ .setCharacteristic(
44
+ this.platform.Characteristic.SerialNumber,
45
+ device.deviceId!,
46
+ );
44
47
 
45
48
  // get the Television service if it exists, otherwise create a new Television service
46
49
  // you can create multiple services for each accessory
47
- if (this.otherDeviceType !== 'Fan') {
50
+ if (this.otherDeviceType !== "Fan") {
48
51
  this.debugLog(`Other: ${accessory.displayName} Removing Fanv2 Service`);
49
52
 
50
53
  if (this.otherDeviceType === undefined) {
51
- this.errorLog(`Other: ${this.accessory.displayName} No Device Type Set, deviceType: ${device.other?.deviceType}`);
54
+ this.errorLog(
55
+ `Other: ${this.accessory.displayName} No Device Type Set, deviceType: ${device.other?.deviceType}`,
56
+ );
52
57
  }
53
58
  this.service = this.accessory.getService(this.platform.Service.Fanv2);
54
59
  accessory.removeService(this.service!);
55
- } else if (!this.service && this.otherDeviceType === 'Fan') {
60
+ } else if (!this.service && this.otherDeviceType === "Fan") {
56
61
  this.debugLog(`Other: ${accessory.displayName} Add Fanv2 Service`);
57
62
  (this.service =
58
63
  this.accessory.getService(this.platform.Service.Fanv2) ||
59
- this.accessory.addService(this.platform.Service.Fanv2)), `${accessory.displayName} Fan`;
64
+ this.accessory.addService(this.platform.Service.Fanv2)),
65
+ `${accessory.displayName} Fan`;
60
66
 
61
- this.service.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Fan`);
67
+ this.service.setCharacteristic(
68
+ this.platform.Characteristic.Name,
69
+ `${accessory.displayName} Fan`,
70
+ );
62
71
 
63
- this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
72
+ this.service
73
+ .getCharacteristic(this.platform.Characteristic.Active)
74
+ .onSet(this.ActiveSet.bind(this));
64
75
  } else {
65
- this.debugLog(`Other: ${accessory.displayName} Fanv2 Service Not Added, deviceType: ${device.other?.deviceType}`);
76
+ this.debugLog(
77
+ `Other: ${accessory.displayName} Fanv2 Service Not Added, deviceType: ${device.other?.deviceType}`,
78
+ );
66
79
  }
67
80
  }
68
81
 
@@ -80,10 +93,17 @@ export class Others {
80
93
 
81
94
  private updateHomeKitCharacteristics() {
82
95
  if (this.Active === undefined) {
83
- this.debugLog(`Other: ${this.accessory.displayName} Active: ${this.Active}`);
96
+ this.debugLog(
97
+ `Other: ${this.accessory.displayName} Active: ${this.Active}`,
98
+ );
84
99
  } else {
85
- this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
86
- this.debugLog(`Other: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
100
+ this.service?.updateCharacteristic(
101
+ this.platform.Characteristic.Active,
102
+ this.Active,
103
+ );
104
+ this.debugLog(
105
+ `Other: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`,
106
+ );
87
107
  }
88
108
  }
89
109
 
@@ -103,17 +123,21 @@ export class Others {
103
123
  if (this.device.other.commandOn) {
104
124
  if (this.Active) {
105
125
  const payload = {
106
- commandType: 'customize',
107
- parameter: 'default',
126
+ commandType: "customize",
127
+ parameter: "default",
108
128
  command: `${this.device.other.commandOn}`,
109
129
  } as payload;
110
130
  await this.pushChanges(payload);
111
131
  }
112
132
  } else {
113
- this.errorLog(`Other: ${this.accessory.displayName} On Command not set, commandOn: ${this.device.other.commandOn}`);
133
+ this.errorLog(
134
+ `Other: ${this.accessory.displayName} On Command not set, commandOn: ${this.device.other.commandOn}`,
135
+ );
114
136
  }
115
137
  } else {
116
- this.errorLog(`Other: ${this.accessory.displayName} On Command not set, other: ${this.device.other}`);
138
+ this.errorLog(
139
+ `Other: ${this.accessory.displayName} On Command not set, other: ${this.device.other}`,
140
+ );
117
141
  }
118
142
  } else {
119
143
  this.errorLog(`Other: ${this.accessory.displayName} On Command not set`);
@@ -126,73 +150,108 @@ export class Others {
126
150
  if (this.device.other.commandOff) {
127
151
  if (!this.Active) {
128
152
  const payload = {
129
- commandType: 'customize',
130
- parameter: 'default',
153
+ commandType: "customize",
154
+ parameter: "default",
131
155
  command: `${this.device.other.commandOff}`,
132
156
  } as payload;
133
157
  await this.pushChanges(payload);
134
158
  }
135
159
  } else {
136
- this.errorLog(`Other: ${this.accessory.displayName} Off Command not set, commandOff: ${this.device.other.commandOff}`);
160
+ this.errorLog(
161
+ `Other: ${this.accessory.displayName} Off Command not set, commandOff: ${this.device.other.commandOff}`,
162
+ );
137
163
  }
138
164
  } else {
139
- this.errorLog(`Other: ${this.accessory.displayName} Off Command not set, other: ${this.device.other}`);
165
+ this.errorLog(
166
+ `Other: ${this.accessory.displayName} Off Command not set, other: ${this.device.other}`,
167
+ );
140
168
  }
141
169
  } else {
142
- this.errorLog(`Other: ${this.accessory.displayName} Off Command not set.`);
170
+ this.errorLog(
171
+ `Other: ${this.accessory.displayName} Off Command not set.`,
172
+ );
143
173
  }
144
174
  }
145
175
 
146
176
  public async pushChanges(payload: payload) {
147
177
  try {
148
- this.infoLog(`Other: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
149
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
178
+ this.infoLog(
179
+ `Other: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
180
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
181
+ );
150
182
 
151
183
  // Make the API request
152
- const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
153
- this.debugLog(`Other: ${this.accessory.displayName} pushChanges: ${push.data}`);
184
+ const push = await this.platform.axios.post(
185
+ `${DeviceURL}/${this.device.deviceId}/commands`,
186
+ payload,
187
+ );
188
+ this.debugLog(
189
+ `Other: ${this.accessory.displayName} pushChanges: ${push.data}`,
190
+ );
154
191
  this.statusCode(push);
155
192
  this.updateHomeKitCharacteristics();
156
193
  } catch (e: any) {
157
- this.errorLog(`Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
158
- if (this.deviceLogging === 'debug') {
159
- this.errorLog(`Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
160
- + ` Error Message: ${JSON.stringify(e.message)}`);
194
+ this.errorLog(
195
+ `Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`,
196
+ );
197
+ if (this.deviceLogging === "debug") {
198
+ this.errorLog(
199
+ `Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
200
+ ` Error Message: ${JSON.stringify(e.message)}`,
201
+ );
161
202
  }
162
203
  if (this.platform.debugMode) {
163
- this.errorLog(`Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
164
- + ` Error: ${JSON.stringify(e)}`);
204
+ this.errorLog(
205
+ `Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
206
+ ` Error: ${JSON.stringify(e)}`,
207
+ );
165
208
  }
166
209
  this.apiError(e);
167
210
  }
168
211
  }
169
212
 
170
- private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
213
+ private statusCode(push: AxiosResponse<{ statusCode: number }>) {
171
214
  switch (push.data.statusCode) {
172
215
  case 151:
173
- this.errorLog(`Other: ${this.accessory.displayName} Command not supported by this device type.`);
216
+ this.errorLog(
217
+ `Other: ${this.accessory.displayName} Command not supported by this device type.`,
218
+ );
174
219
  break;
175
220
  case 152:
176
221
  this.errorLog(`Other: ${this.accessory.displayName} Device not found.`);
177
222
  break;
178
223
  case 160:
179
- this.errorLog(`Other: ${this.accessory.displayName} Command is not supported.`);
224
+ this.errorLog(
225
+ `Other: ${this.accessory.displayName} Command is not supported.`,
226
+ );
180
227
  break;
181
228
  case 161:
182
- this.errorLog(`Other: ${this.accessory.displayName} Device is offline.`);
229
+ this.errorLog(
230
+ `Other: ${this.accessory.displayName} Device is offline.`,
231
+ );
183
232
  break;
184
233
  case 171:
185
- this.errorLog(`Other: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
234
+ this.errorLog(
235
+ `Other: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
236
+ );
186
237
  break;
187
238
  case 190:
188
- this.errorLog(`Other: ${this.accessory.displayName} Device internal error due to device states not synchronized`
189
- + ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
239
+ this.errorLog(
240
+ `Other: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
241
+ ` with server, Or command: ${JSON.stringify(
242
+ push.data,
243
+ )} format is invalid`,
244
+ );
190
245
  break;
191
246
  case 100:
192
- this.debugLog(`Other: ${this.accessory.displayName} Command successfully sent.`);
247
+ this.debugLog(
248
+ `Other: ${this.accessory.displayName} Command successfully sent.`,
249
+ );
193
250
  break;
194
251
  default:
195
- this.debugLog(`Other: ${this.accessory.displayName} Unknown statusCode.`);
252
+ this.debugLog(
253
+ `Other: ${this.accessory.displayName} Unknown statusCode.`,
254
+ );
196
255
  }
197
256
  }
198
257
 
@@ -203,12 +262,17 @@ export class Others {
203
262
 
204
263
  deviceType(device: irdevice & irDevicesConfig) {
205
264
  if (device.other?.deviceType) {
206
- this.otherDeviceType = this.accessory.context.deviceType = device.other.deviceType;
207
- if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
208
- this.warnLog(`Other: ${this.accessory.displayName} Using Device Type: ${this.otherDeviceType}`);
265
+ this.otherDeviceType = this.accessory.context.deviceType =
266
+ device.other.deviceType;
267
+ if (this.deviceLogging === "debug" || this.deviceLogging === "standard") {
268
+ this.warnLog(
269
+ `Other: ${this.accessory.displayName} Using Device Type: ${this.otherDeviceType}`,
270
+ );
209
271
  }
210
272
  } else {
211
- this.errorLog(`Other: ${this.accessory.displayName} No Device Type Set, deviceType: ${this.device.other?.deviceType}`);
273
+ this.errorLog(
274
+ `Other: ${this.accessory.displayName} No Device Type Set, deviceType: ${this.device.other?.deviceType}`,
275
+ );
212
276
  }
213
277
  }
214
278
 
@@ -218,32 +282,43 @@ export class Others {
218
282
  config = device.other;
219
283
  }
220
284
  if (device.logging !== undefined) {
221
- config['logging'] = device.logging;
285
+ config["logging"] = device.logging;
222
286
  }
223
287
  if (Object.entries(config).length !== 0) {
224
- this.warnLog(`Other: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
288
+ this.warnLog(
289
+ `Other: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`,
290
+ );
225
291
  }
226
292
  }
227
293
 
228
294
  logs(device: irdevice & irDevicesConfig) {
229
295
  if (this.platform.debugMode) {
230
- this.deviceLogging = this.accessory.context.logging = 'debugMode';
231
- this.debugLog(`Other: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
296
+ this.deviceLogging = this.accessory.context.logging = "debugMode";
297
+ this.debugLog(
298
+ `Other: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
299
+ );
232
300
  } else if (device.logging) {
233
301
  this.deviceLogging = this.accessory.context.logging = device.logging;
234
- this.debugLog(`Other: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
302
+ this.debugLog(
303
+ `Other: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
304
+ );
235
305
  } else if (this.platform.config.options?.logging) {
236
- this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
237
- this.debugLog(`Other: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
306
+ this.deviceLogging = this.accessory.context.logging =
307
+ this.platform.config.options?.logging;
308
+ this.debugLog(
309
+ `Other: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
310
+ );
238
311
  } else {
239
- this.deviceLogging = this.accessory.context.logging = 'standard';
240
- this.debugLog(`Other: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
312
+ this.deviceLogging = this.accessory.context.logging = "standard";
313
+ this.debugLog(
314
+ `Other: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
315
+ );
241
316
  }
242
317
  }
243
318
 
244
319
  /**
245
- * Logging for Device
246
- */
320
+ * Logging for Device
321
+ */
247
322
  infoLog(...log: any[]) {
248
323
  if (this.enablingDeviceLogging()) {
249
324
  this.platform.log.info(String(...log));
@@ -264,8 +339,8 @@ export class Others {
264
339
 
265
340
  debugLog(...log: any[]) {
266
341
  if (this.enablingDeviceLogging()) {
267
- if (this.deviceLogging === 'debug') {
268
- this.platform.log.info('[DEBUG]', String(...log));
342
+ if (this.deviceLogging === "debug") {
343
+ this.platform.log.info("[DEBUG]", String(...log));
269
344
  } else {
270
345
  this.platform.log.debug(String(...log));
271
346
  }
@@ -273,6 +348,6 @@ export class Others {
273
348
  }
274
349
 
275
350
  enablingDeviceLogging(): boolean {
276
- return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
351
+ return this.deviceLogging.includes("debug") || this.deviceLogging === "standard";
277
352
  }
278
353
  }