@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 VacuumCleaner {
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.Switch) ||
50
- accessory.addService(this.platform.Service.Switch)),
51
- `${accessory.displayName} Vacuum`;
47
+ accessory.addService(this.platform.Service.Switch)), `${accessory.displayName} Vacuum`;
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 VacuumCleaner {
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
 
70
61
  private OnSet(value: CharacteristicValue) {
@@ -79,17 +70,10 @@ export class VacuumCleaner {
79
70
 
80
71
  private updateHomeKitCharacteristics() {
81
72
  if (this.On === undefined) {
82
- this.debugLog(
83
- `Vacuum Cleaner: ${this.accessory.displayName} On: ${this.On}`,
84
- );
73
+ this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} On: ${this.On}`);
85
74
  } else {
86
- this.service?.updateCharacteristic(
87
- this.platform.Characteristic.On,
88
- this.On,
89
- );
90
- this.debugLog(
91
- `Vacuum Cleaner: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`,
92
- );
75
+ this.service?.updateCharacteristic(this.platform.Characteristic.On, this.On);
76
+ this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
93
77
  }
94
78
  }
95
79
 
@@ -106,9 +90,9 @@ export class VacuumCleaner {
106
90
  async pushOnChanges() {
107
91
  if (this.On) {
108
92
  const payload = {
109
- commandType: "command",
110
- parameter: "default",
111
- command: "turnOn",
93
+ commandType: 'command',
94
+ parameter: 'default',
95
+ command: 'turnOn',
112
96
  } as payload;
113
97
  await this.pushChanges(payload);
114
98
  }
@@ -117,9 +101,9 @@ export class VacuumCleaner {
117
101
  async pushOffChanges() {
118
102
  if (!this.On) {
119
103
  const payload = {
120
- commandType: "command",
121
- parameter: "default",
122
- command: "turnOff",
104
+ commandType: 'command',
105
+ parameter: 'default',
106
+ command: 'turnOff',
123
107
  } as payload;
124
108
  await this.pushChanges(payload);
125
109
  }
@@ -127,87 +111,56 @@ export class VacuumCleaner {
127
111
 
128
112
  public async pushChanges(payload: payload) {
129
113
  try {
130
- this.infoLog(
131
- `Vacuum Cleaner: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
132
- ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
133
- );
114
+ this.infoLog(`Vacuum Cleaner: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
115
+ + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
134
116
 
135
117
  // Make the API request
136
- const push = await this.platform.axios.post(
137
- `${DeviceURL}/${this.device.deviceId}/commands`,
138
- payload,
139
- );
140
- this.debugLog(
141
- `Vacuum Cleaner: ${this.accessory.displayName} pushChanges: ${push.data}`,
142
- );
118
+ const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
119
+ this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} pushChanges: ${push.data}`);
143
120
  this.statusCode(push);
144
121
  this.OnCached = this.On;
145
122
  this.accessory.context.On = this.OnCached;
146
123
  this.updateHomeKitCharacteristics();
147
124
  } catch (e: any) {
148
- this.errorLog(
149
- `Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`,
150
- );
151
- if (this.deviceLogging === "debug") {
152
- this.errorLog(
153
- `Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
154
- ` Error Message: ${JSON.stringify(e.message)}`,
155
- );
125
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
126
+ if (this.deviceLogging === 'debug') {
127
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
128
+ + ` Error Message: ${JSON.stringify(e.message)}`);
156
129
  }
157
130
  if (this.platform.debugMode) {
158
- this.errorLog(
159
- `Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
160
- ` Error: ${JSON.stringify(e)}`,
161
- );
131
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
132
+ + ` Error: ${JSON.stringify(e)}`);
162
133
  }
163
134
  this.apiError(e);
164
135
  }
165
136
  }
166
137
 
167
- private statusCode(push: AxiosResponse<{ statusCode: number }>) {
138
+ private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
168
139
  switch (push.data.statusCode) {
169
140
  case 151:
170
- this.errorLog(
171
- `Vacuum Cleaner: ${this.accessory.displayName} Command not supported by this device type.`,
172
- );
141
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Command not supported by this device type.`);
173
142
  break;
174
143
  case 152:
175
- this.errorLog(
176
- `Vacuum Cleaner: ${this.accessory.displayName} Device not found.`,
177
- );
144
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Device not found.`);
178
145
  break;
179
146
  case 160:
180
- this.errorLog(
181
- `Vacuum Cleaner: ${this.accessory.displayName} Command is not supported.`,
182
- );
147
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Command is not supported.`);
183
148
  break;
184
149
  case 161:
185
- this.errorLog(
186
- `Vacuum Cleaner: ${this.accessory.displayName} Device is offline.`,
187
- );
150
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Device is offline.`);
188
151
  break;
189
152
  case 171:
190
- this.errorLog(
191
- `Vacuum Cleaner: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
192
- );
153
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
193
154
  break;
194
155
  case 190:
195
- this.errorLog(
196
- `Vacuum Cleaner: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
197
- ` with server, Or command: ${JSON.stringify(
198
- push.data,
199
- )} format is invalid`,
200
- );
156
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Device internal error due to device states not synchronized`
157
+ + ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
201
158
  break;
202
159
  case 100:
203
- this.debugLog(
204
- `Vacuum Cleaner: ${this.accessory.displayName} Command successfully sent.`,
205
- );
160
+ this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} Command successfully sent.`);
206
161
  break;
207
162
  default:
208
- this.debugLog(
209
- `Vacuum Cleaner: ${this.accessory.displayName} Unknown statusCode.`,
210
- );
163
+ this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} Unknown statusCode.`);
211
164
  }
212
165
  }
213
166
 
@@ -222,45 +175,32 @@ export class VacuumCleaner {
222
175
  config = device.irvc;
223
176
  }
224
177
  if (device.logging !== undefined) {
225
- config["logging"] = device.logging;
178
+ config['logging'] = device.logging;
226
179
  }
227
180
  if (Object.entries(config).length !== 0) {
228
- this.warnLog(
229
- `Vacuum Cleaner: ${this.accessory.displayName} Config: ${JSON.stringify(
230
- config,
231
- )}`,
232
- );
181
+ this.warnLog(`Vacuum Cleaner: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
233
182
  }
234
183
  }
235
184
 
236
185
  logs(device: irdevice & irDevicesConfig) {
237
186
  if (this.platform.debugMode) {
238
- this.deviceLogging = this.accessory.context.logging = "debugMode";
239
- this.debugLog(
240
- `Vacuum Cleaner: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
241
- );
187
+ this.deviceLogging = this.accessory.context.logging = 'debugMode';
188
+ this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
242
189
  } else if (device.logging) {
243
190
  this.deviceLogging = this.accessory.context.logging = device.logging;
244
- this.debugLog(
245
- `Vacuum Cleaner: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
246
- );
191
+ this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
247
192
  } else if (this.platform.config.options?.logging) {
248
- this.deviceLogging = this.accessory.context.logging =
249
- this.platform.config.options?.logging;
250
- this.debugLog(
251
- `Vacuum Cleaner: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
252
- );
193
+ this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
194
+ this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
253
195
  } else {
254
- this.deviceLogging = this.accessory.context.logging = "standard";
255
- this.debugLog(
256
- `Vacuum Cleaner: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
257
- );
196
+ this.deviceLogging = this.accessory.context.logging = 'standard';
197
+ this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
258
198
  }
259
199
  }
260
200
 
261
201
  /**
262
- * Logging for Device
263
- */
202
+ * Logging for Device
203
+ */
264
204
  infoLog(...log: any[]) {
265
205
  if (this.enablingDeviceLogging()) {
266
206
  this.platform.log.info(String(...log));
@@ -281,8 +221,8 @@ export class VacuumCleaner {
281
221
 
282
222
  debugLog(...log: any[]) {
283
223
  if (this.enablingDeviceLogging()) {
284
- if (this.deviceLogging === "debug") {
285
- this.platform.log.info("[DEBUG]", String(...log));
224
+ if (this.deviceLogging === 'debug') {
225
+ this.platform.log.info('[DEBUG]', String(...log));
286
226
  } else {
287
227
  this.platform.log.debug(String(...log));
288
228
  }
@@ -290,6 +230,6 @@ export class VacuumCleaner {
290
230
  }
291
231
 
292
232
  enablingDeviceLogging(): boolean {
293
- return this.deviceLogging.includes("debug") || this.deviceLogging === "standard";
233
+ return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
294
234
  }
295
235
  }
@@ -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 WaterHeater {
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.Valve) ||
50
- accessory.addService(this.platform.Service.Valve)),
51
- `${accessory.displayName} Water Heater`;
47
+ accessory.addService(this.platform.Service.Valve)), `${accessory.displayName} Water Heater`;
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:
@@ -68,15 +64,11 @@ export class WaterHeater {
68
64
  );
69
65
 
70
66
  // handle on / off events using the Active characteristic
71
- this.service
72
- .getCharacteristic(this.platform.Characteristic.Active)
73
- .onSet(this.ActiveSet.bind(this));
67
+ this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
74
68
  }
75
69
 
76
70
  private ActiveSet(value: CharacteristicValue) {
77
- this.debugLog(
78
- `Water Heater: ${this.accessory.displayName} Active: ${value}`,
79
- );
71
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Active: ${value}`);
80
72
  if (value === this.platform.Characteristic.Active.INACTIVE) {
81
73
  this.pushWaterHeaterOffChanges();
82
74
  this.service.setCharacteristic(
@@ -85,10 +77,7 @@ export class WaterHeater {
85
77
  );
86
78
  } else {
87
79
  this.pushWaterHeaterOnChanges();
88
- this.service.setCharacteristic(
89
- this.platform.Characteristic.InUse,
90
- this.platform.Characteristic.InUse.IN_USE,
91
- );
80
+ this.service.setCharacteristic(this.platform.Characteristic.InUse, this.platform.Characteristic.InUse.IN_USE);
92
81
  }
93
82
  this.Active = value;
94
83
  this.ActiveCached = this.Active;
@@ -97,17 +86,10 @@ export class WaterHeater {
97
86
 
98
87
  private updateHomeKitCharacteristics() {
99
88
  if (this.Active === undefined) {
100
- this.debugLog(
101
- `Water Heater: ${this.accessory.displayName} Active: ${this.Active}`,
102
- );
89
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Active: ${this.Active}`);
103
90
  } else {
104
- this.service?.updateCharacteristic(
105
- this.platform.Characteristic.Active,
106
- this.Active,
107
- );
108
- this.debugLog(
109
- `Water Heater: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`,
110
- );
91
+ this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
92
+ this.debugLog(`Water Heater: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
111
93
  }
112
94
  }
113
95
 
@@ -124,9 +106,9 @@ export class WaterHeater {
124
106
  async pushWaterHeaterOnChanges() {
125
107
  if (this.Active !== 1) {
126
108
  const payload = {
127
- commandType: "command",
128
- parameter: "default",
129
- command: "turnOn",
109
+ commandType: 'command',
110
+ parameter: 'default',
111
+ command: 'turnOn',
130
112
  } as payload;
131
113
  await this.pushChanges(payload);
132
114
  }
@@ -135,9 +117,9 @@ export class WaterHeater {
135
117
  async pushWaterHeaterOffChanges() {
136
118
  if (this.Active !== 0) {
137
119
  const payload = {
138
- commandType: "command",
139
- parameter: "default",
140
- command: "turnOff",
120
+ commandType: 'command',
121
+ parameter: 'default',
122
+ command: 'turnOff',
141
123
  } as payload;
142
124
  await this.pushChanges(payload);
143
125
  }
@@ -145,85 +127,54 @@ export class WaterHeater {
145
127
 
146
128
  public async pushChanges(payload: payload) {
147
129
  try {
148
- this.infoLog(
149
- `Water Heater: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
150
- ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
151
- );
130
+ this.infoLog(`Water Heater: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
131
+ + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
152
132
 
153
133
  // Make the API request
154
- const push = await this.platform.axios.post(
155
- `${DeviceURL}/${this.device.deviceId}/commands`,
156
- payload,
157
- );
158
- this.debugLog(
159
- `Water Heater: ${this.accessory.displayName} pushChanges: ${push.data}`,
160
- );
134
+ const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
135
+ this.debugLog(`Water Heater: ${this.accessory.displayName} pushChanges: ${push.data}`);
161
136
  this.statusCode(push);
162
137
  this.updateHomeKitCharacteristics();
163
138
  } catch (e: any) {
164
- this.errorLog(
165
- `Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`,
166
- );
167
- if (this.deviceLogging === "debug") {
168
- this.errorLog(
169
- `Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
170
- ` Error Message: ${JSON.stringify(e.message)}`,
171
- );
139
+ this.errorLog(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
140
+ if (this.deviceLogging === 'debug') {
141
+ this.errorLog(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
142
+ + ` Error Message: ${JSON.stringify(e.message)}`);
172
143
  }
173
144
  if (this.platform.debugMode) {
174
- this.errorLog(
175
- `Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
176
- ` Error: ${JSON.stringify(e)}`,
177
- );
145
+ this.errorLog(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
146
+ + ` Error: ${JSON.stringify(e)}`);
178
147
  }
179
148
  this.apiError(e);
180
149
  }
181
150
  }
182
151
 
183
- private statusCode(push: AxiosResponse<{ statusCode: number }>) {
152
+ private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
184
153
  switch (push.data.statusCode) {
185
154
  case 151:
186
- this.errorLog(
187
- `Water Heater: ${this.accessory.displayName} Command not supported by this device type.`,
188
- );
155
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Command not supported by this device type.`);
189
156
  break;
190
157
  case 152:
191
- this.errorLog(
192
- `Water Heater: ${this.accessory.displayName} Device not found.`,
193
- );
158
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Device not found.`);
194
159
  break;
195
160
  case 160:
196
- this.errorLog(
197
- `Water Heater: ${this.accessory.displayName} Command is not supported.`,
198
- );
161
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Command is not supported.`);
199
162
  break;
200
163
  case 161:
201
- this.errorLog(
202
- `Water Heater: ${this.accessory.displayName} Device is offline.`,
203
- );
164
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Device is offline.`);
204
165
  break;
205
166
  case 171:
206
- this.errorLog(
207
- `Water Heater: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
208
- );
167
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
209
168
  break;
210
169
  case 190:
211
- this.errorLog(
212
- `Water Heater: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
213
- ` with server, Or command: ${JSON.stringify(
214
- push.data,
215
- )} format is invalid`,
216
- );
170
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Device internal error due to device states not synchronized`
171
+ + ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
217
172
  break;
218
173
  case 100:
219
- this.debugLog(
220
- `Water Heater: ${this.accessory.displayName} Command successfully sent.`,
221
- );
174
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Command successfully sent.`);
222
175
  break;
223
176
  default:
224
- this.debugLog(
225
- `Water Heater: ${this.accessory.displayName} Unknown statusCode.`,
226
- );
177
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Unknown statusCode.`);
227
178
  }
228
179
  }
229
180
 
@@ -238,45 +189,32 @@ export class WaterHeater {
238
189
  config = device.irwh;
239
190
  }
240
191
  if (device.logging !== undefined) {
241
- config["logging"] = device.logging;
192
+ config['logging'] = device.logging;
242
193
  }
243
194
  if (Object.entries(config).length !== 0) {
244
- this.warnLog(
245
- `Water Heater: ${this.accessory.displayName} Config: ${JSON.stringify(
246
- config,
247
- )}`,
248
- );
195
+ this.warnLog(`Water Heater: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
249
196
  }
250
197
  }
251
198
 
252
199
  logs(device: irdevice & irDevicesConfig) {
253
200
  if (this.platform.debugMode) {
254
- this.deviceLogging = this.accessory.context.logging = "debugMode";
255
- this.debugLog(
256
- `Water Heater: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
257
- );
201
+ this.deviceLogging = this.accessory.context.logging = 'debugMode';
202
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
258
203
  } else if (device.logging) {
259
204
  this.deviceLogging = this.accessory.context.logging = device.logging;
260
- this.debugLog(
261
- `Water Heater: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
262
- );
205
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
263
206
  } else if (this.platform.config.options?.logging) {
264
- this.deviceLogging = this.accessory.context.logging =
265
- this.platform.config.options?.logging;
266
- this.debugLog(
267
- `Water Heater: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
268
- );
207
+ this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
208
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
269
209
  } else {
270
- this.deviceLogging = this.accessory.context.logging = "standard";
271
- this.debugLog(
272
- `Water Heater: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
273
- );
210
+ this.deviceLogging = this.accessory.context.logging = 'standard';
211
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
274
212
  }
275
213
  }
276
214
 
277
215
  /**
278
- * Logging for Device
279
- */
216
+ * Logging for Device
217
+ */
280
218
  infoLog(...log: any[]) {
281
219
  if (this.enablingDeviceLogging()) {
282
220
  this.platform.log.info(String(...log));
@@ -297,8 +235,8 @@ export class WaterHeater {
297
235
 
298
236
  debugLog(...log: any[]) {
299
237
  if (this.enablingDeviceLogging()) {
300
- if (this.deviceLogging === "debug") {
301
- this.platform.log.info("[DEBUG]", String(...log));
238
+ if (this.deviceLogging === 'debug') {
239
+ this.platform.log.info('[DEBUG]', String(...log));
302
240
  } else {
303
241
  this.platform.log.debug(String(...log));
304
242
  }
@@ -306,6 +244,6 @@ export class WaterHeater {
306
244
  }
307
245
 
308
246
  enablingDeviceLogging(): boolean {
309
- return this.deviceLogging.includes("debug") || this.deviceLogging === "standard";
247
+ return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
310
248
  }
311
249
  }