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