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