@switchbot/homebridge-switchbot 1.8.3-beta.0 → 1.10.1-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 (122) hide show
  1. package/.eslintrc +14 -45
  2. package/.github/ISSUE_TEMPLATE/bug-report.yml +3 -3
  3. package/.github/ISSUE_TEMPLATE/feature-request.yml +2 -2
  4. package/.github/ISSUE_TEMPLATE/support-request.yml +3 -3
  5. package/.github/labeler.yml +1 -1
  6. package/.github/workflows/codeql-analysis.yml +29 -29
  7. package/.github/workflows/nodejs-beta.yml +1 -1
  8. package/.github/workflows/prerelease-beta.js +1 -1
  9. package/.github/workflows/stale.yml +1 -1
  10. package/.prettierrc +9 -0
  11. package/.vscode/extensions.json +2 -4
  12. package/.vscode/settings.json +14 -2
  13. package/CHANGELOG.md +16 -0
  14. package/README.md +100 -99
  15. package/SECURITY.md +2 -2
  16. package/config.schema.json +17 -0
  17. package/dist/devices/bots.d.ts +35 -32
  18. package/dist/devices/bots.d.ts.map +1 -1
  19. package/dist/devices/bots.js +168 -210
  20. package/dist/devices/bots.js.map +1 -1
  21. package/dist/devices/colorbulb.d.ts +35 -35
  22. package/dist/devices/colorbulb.d.ts.map +1 -1
  23. package/dist/devices/colorbulb.js +83 -108
  24. package/dist/devices/colorbulb.js.map +1 -1
  25. package/dist/devices/contact.d.ts +27 -25
  26. package/dist/devices/contact.d.ts.map +1 -1
  27. package/dist/devices/contact.js +110 -131
  28. package/dist/devices/contact.js.map +1 -1
  29. package/dist/devices/curtains.d.ts +29 -27
  30. package/dist/devices/curtains.d.ts.map +1 -1
  31. package/dist/devices/curtains.js +147 -182
  32. package/dist/devices/curtains.js.map +1 -1
  33. package/dist/devices/humidifiers.d.ts +31 -31
  34. package/dist/devices/humidifiers.d.ts.map +1 -1
  35. package/dist/devices/humidifiers.js +154 -181
  36. package/dist/devices/humidifiers.js.map +1 -1
  37. package/dist/devices/meters.d.ts +29 -28
  38. package/dist/devices/meters.d.ts.map +1 -1
  39. package/dist/devices/meters.js +98 -120
  40. package/dist/devices/meters.js.map +1 -1
  41. package/dist/devices/motion.d.ts +24 -23
  42. package/dist/devices/motion.d.ts.map +1 -1
  43. package/dist/devices/motion.js +97 -113
  44. package/dist/devices/motion.js.map +1 -1
  45. package/dist/devices/plugs.d.ts +16 -16
  46. package/dist/devices/plugs.d.ts.map +1 -1
  47. package/dist/devices/plugs.js +48 -71
  48. package/dist/devices/plugs.js.map +1 -1
  49. package/dist/index.d.ts +2 -2
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +3 -22
  52. package/dist/index.js.map +1 -1
  53. package/dist/irdevices/airconditioners.d.ts +7 -4
  54. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  55. package/dist/irdevices/airconditioners.js +72 -93
  56. package/dist/irdevices/airconditioners.js.map +1 -1
  57. package/dist/irdevices/airpurifiers.d.ts +3 -3
  58. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  59. package/dist/irdevices/airpurifiers.js +32 -51
  60. package/dist/irdevices/airpurifiers.js.map +1 -1
  61. package/dist/irdevices/cameras.d.ts +3 -3
  62. package/dist/irdevices/cameras.d.ts.map +1 -1
  63. package/dist/irdevices/cameras.js +19 -26
  64. package/dist/irdevices/cameras.js.map +1 -1
  65. package/dist/irdevices/fans.d.ts +3 -3
  66. package/dist/irdevices/fans.d.ts.map +1 -1
  67. package/dist/irdevices/fans.js +35 -44
  68. package/dist/irdevices/fans.js.map +1 -1
  69. package/dist/irdevices/lights.d.ts +3 -3
  70. package/dist/irdevices/lights.d.ts.map +1 -1
  71. package/dist/irdevices/lights.js +25 -32
  72. package/dist/irdevices/lights.js.map +1 -1
  73. package/dist/irdevices/others.d.ts +3 -3
  74. package/dist/irdevices/others.d.ts.map +1 -1
  75. package/dist/irdevices/others.js +21 -29
  76. package/dist/irdevices/others.js.map +1 -1
  77. package/dist/irdevices/tvs.d.ts +3 -3
  78. package/dist/irdevices/tvs.d.ts.map +1 -1
  79. package/dist/irdevices/tvs.js +66 -89
  80. package/dist/irdevices/tvs.js.map +1 -1
  81. package/dist/irdevices/vacuumcleaners.d.ts +3 -3
  82. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  83. package/dist/irdevices/vacuumcleaners.js +18 -24
  84. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  85. package/dist/irdevices/waterheaters.d.ts +3 -3
  86. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  87. package/dist/irdevices/waterheaters.js +19 -26
  88. package/dist/irdevices/waterheaters.js.map +1 -1
  89. package/dist/platform.d.ts +10 -10
  90. package/dist/platform.d.ts.map +1 -1
  91. package/dist/platform.js +163 -233
  92. package/dist/platform.js.map +1 -1
  93. package/dist/settings.d.ts +3 -1
  94. package/dist/settings.d.ts.map +1 -1
  95. package/dist/settings.js +4 -4
  96. package/dist/settings.js.map +1 -1
  97. package/homebridge-ui/public/index.html +231 -245
  98. package/homebridge-ui/server.js +2 -4
  99. package/nodemon.json +2 -4
  100. package/package.json +17 -12
  101. package/src/devices/bots.ts +411 -854
  102. package/src/devices/colorbulb.ts +187 -408
  103. package/src/devices/contact.ts +210 -376
  104. package/src/devices/curtains.ts +288 -563
  105. package/src/devices/humidifiers.ts +291 -537
  106. package/src/devices/meters.ts +189 -331
  107. package/src/devices/motion.ts +188 -322
  108. package/src/devices/plugs.ts +88 -160
  109. package/src/index.ts +5 -5
  110. package/src/irdevices/airconditioners.ts +139 -318
  111. package/src/irdevices/airpurifiers.ts +71 -170
  112. package/src/irdevices/cameras.ts +44 -103
  113. package/src/irdevices/fans.ts +70 -165
  114. package/src/irdevices/lights.ts +49 -104
  115. package/src/irdevices/others.ts +55 -131
  116. package/src/irdevices/tvs.ts +114 -247
  117. package/src/irdevices/vacuumcleaners.ts +44 -104
  118. package/src/irdevices/waterheaters.ts +49 -121
  119. package/src/platform.ts +341 -753
  120. package/src/settings.ts +8 -11
  121. package/tsconfig.json +5 -14
  122. package/.github/PULL_REQUEST_TEMPLATE/pull_requests.md +0 -27
@@ -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
@@ -19,11 +19,7 @@ export class VacuumCleaner {
19
19
  // Config
20
20
  deviceLogging!: string;
21
21
 
22
- constructor(
23
- private readonly platform: SwitchBotPlatform,
24
- private accessory: PlatformAccessory,
25
- public device: irdevice & irDevicesConfig,
26
- ) {
22
+ constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
27
23
  // default placeholders
28
24
  this.logs(device);
29
25
  this.config(device);
@@ -36,18 +32,13 @@ export class VacuumCleaner {
36
32
  // set accessory information
37
33
  accessory
38
34
  .getService(this.platform.Service.AccessoryInformation)!
39
- .setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
35
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
40
36
  .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
41
- .setCharacteristic(
42
- this.platform.Characteristic.SerialNumber,
43
- device.deviceId!,
44
- );
37
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
45
38
 
46
39
  // get the Television service if it exists, otherwise create a new Television service
47
40
  // you can create multiple services for each accessory
48
- (this.service =
49
- accessory.getService(this.platform.Service.Switch) ||
50
- accessory.addService(this.platform.Service.Switch)),
41
+ (this.service = accessory.getService(this.platform.Service.Switch) || accessory.addService(this.platform.Service.Switch)),
51
42
  `${accessory.displayName} Vacuum`;
52
43
 
53
44
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
@@ -56,15 +47,10 @@ export class VacuumCleaner {
56
47
 
57
48
  // set the service name, this is what is displayed as the default name on the Home app
58
49
  // 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
- );
50
+ this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
63
51
 
64
52
  // handle on / off events using the On characteristic
65
- this.service
66
- .getCharacteristic(this.platform.Characteristic.On)
67
- .onSet(this.OnSet.bind(this));
53
+ this.service.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
68
54
  }
69
55
 
70
56
  private OnSet(value: CharacteristicValue) {
@@ -79,17 +65,10 @@ export class VacuumCleaner {
79
65
 
80
66
  private updateHomeKitCharacteristics() {
81
67
  if (this.On === undefined) {
82
- this.debugLog(
83
- `Vacuum Cleaner: ${this.accessory.displayName} On: ${this.On}`,
84
- );
68
+ this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} On: ${this.On}`);
85
69
  } 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
- );
70
+ this.service?.updateCharacteristic(this.platform.Characteristic.On, this.On);
71
+ this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
93
72
  }
94
73
  }
95
74
 
@@ -106,9 +85,9 @@ export class VacuumCleaner {
106
85
  async pushOnChanges() {
107
86
  if (this.On) {
108
87
  const payload = {
109
- commandType: "command",
110
- parameter: "default",
111
- command: "turnOn",
88
+ commandType: 'command',
89
+ parameter: 'default',
90
+ command: 'turnOn',
112
91
  } as payload;
113
92
  await this.pushChanges(payload);
114
93
  }
@@ -117,9 +96,9 @@ export class VacuumCleaner {
117
96
  async pushOffChanges() {
118
97
  if (!this.On) {
119
98
  const payload = {
120
- commandType: "command",
121
- parameter: "default",
122
- command: "turnOff",
99
+ commandType: 'command',
100
+ parameter: 'default',
101
+ command: 'turnOff',
123
102
  } as payload;
124
103
  await this.pushChanges(payload);
125
104
  }
@@ -133,32 +112,22 @@ export class VacuumCleaner {
133
112
  );
134
113
 
135
114
  // 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
- );
115
+ const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
116
+ this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} pushChanges: ${push.data}`);
143
117
  this.statusCode(push);
144
118
  this.OnCached = this.On;
145
119
  this.accessory.context.On = this.OnCached;
146
120
  this.updateHomeKitCharacteristics();
147
121
  } catch (e: any) {
148
- this.errorLog(
149
- `Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`,
150
- );
151
- if (this.deviceLogging === "debug") {
122
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
123
+ if (this.deviceLogging === 'debug') {
152
124
  this.errorLog(
153
125
  `Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
154
126
  ` Error Message: ${JSON.stringify(e.message)}`,
155
127
  );
156
128
  }
157
129
  if (this.platform.debugMode) {
158
- this.errorLog(
159
- `Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
160
- ` Error: ${JSON.stringify(e)}`,
161
- );
130
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
162
131
  }
163
132
  this.apiError(e);
164
133
  }
@@ -167,47 +136,31 @@ export class VacuumCleaner {
167
136
  private statusCode(push: AxiosResponse<{ statusCode: number }>) {
168
137
  switch (push.data.statusCode) {
169
138
  case 151:
170
- this.errorLog(
171
- `Vacuum Cleaner: ${this.accessory.displayName} Command not supported by this device type.`,
172
- );
139
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Command not supported by this device type.`);
173
140
  break;
174
141
  case 152:
175
- this.errorLog(
176
- `Vacuum Cleaner: ${this.accessory.displayName} Device not found.`,
177
- );
142
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Device not found.`);
178
143
  break;
179
144
  case 160:
180
- this.errorLog(
181
- `Vacuum Cleaner: ${this.accessory.displayName} Command is not supported.`,
182
- );
145
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Command is not supported.`);
183
146
  break;
184
147
  case 161:
185
- this.errorLog(
186
- `Vacuum Cleaner: ${this.accessory.displayName} Device is offline.`,
187
- );
148
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Device is offline.`);
188
149
  break;
189
150
  case 171:
190
- this.errorLog(
191
- `Vacuum Cleaner: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
192
- );
151
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
193
152
  break;
194
153
  case 190:
195
154
  this.errorLog(
196
155
  `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`,
156
+ ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`,
200
157
  );
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,39 +175,26 @@ 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
 
@@ -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
@@ -19,11 +19,7 @@ export class WaterHeater {
19
19
  // Config
20
20
  deviceLogging!: string;
21
21
 
22
- constructor(
23
- private readonly platform: SwitchBotPlatform,
24
- private accessory: PlatformAccessory,
25
- public device: irdevice & irDevicesConfig,
26
- ) {
22
+ constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
27
23
  // default placeholders
28
24
  this.logs(device);
29
25
  this.config(device);
@@ -36,18 +32,13 @@ export class WaterHeater {
36
32
  // set accessory information
37
33
  accessory
38
34
  .getService(this.platform.Service.AccessoryInformation)!
39
- .setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
35
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
40
36
  .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
41
- .setCharacteristic(
42
- this.platform.Characteristic.SerialNumber,
43
- device.deviceId!,
44
- );
37
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
45
38
 
46
39
  // get the Television service if it exists, otherwise create a new Television service
47
40
  // you can create multiple services for each accessory
48
- (this.service =
49
- accessory.getService(this.platform.Service.Valve) ||
50
- accessory.addService(this.platform.Service.Valve)),
41
+ (this.service = accessory.getService(this.platform.Service.Valve) || accessory.addService(this.platform.Service.Valve)),
51
42
  `${accessory.displayName} Water Heater`;
52
43
 
53
44
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
@@ -56,39 +47,23 @@ export class WaterHeater {
56
47
 
57
48
  // set the service name, this is what is displayed as the default name on the Home app
58
49
  // 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
- `${device.deviceName} ${device.remoteType}`,
62
- );
50
+ this.service.setCharacteristic(this.platform.Characteristic.Name, `${device.deviceName} ${device.remoteType}`);
63
51
 
64
52
  // set sleep discovery characteristic
65
- this.service.setCharacteristic(
66
- this.platform.Characteristic.ValveType,
67
- this.platform.Characteristic.ValveType.GENERIC_VALVE,
68
- );
53
+ this.service.setCharacteristic(this.platform.Characteristic.ValveType, this.platform.Characteristic.ValveType.GENERIC_VALVE);
69
54
 
70
55
  // handle on / off events using the Active characteristic
71
- this.service
72
- .getCharacteristic(this.platform.Characteristic.Active)
73
- .onSet(this.ActiveSet.bind(this));
56
+ this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
74
57
  }
75
58
 
76
59
  private ActiveSet(value: CharacteristicValue) {
77
- this.debugLog(
78
- `Water Heater: ${this.accessory.displayName} Active: ${value}`,
79
- );
60
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Active: ${value}`);
80
61
  if (value === this.platform.Characteristic.Active.INACTIVE) {
81
62
  this.pushWaterHeaterOffChanges();
82
- this.service.setCharacteristic(
83
- this.platform.Characteristic.InUse,
84
- this.platform.Characteristic.InUse.NOT_IN_USE,
85
- );
63
+ this.service.setCharacteristic(this.platform.Characteristic.InUse, this.platform.Characteristic.InUse.NOT_IN_USE);
86
64
  } else {
87
65
  this.pushWaterHeaterOnChanges();
88
- this.service.setCharacteristic(
89
- this.platform.Characteristic.InUse,
90
- this.platform.Characteristic.InUse.IN_USE,
91
- );
66
+ this.service.setCharacteristic(this.platform.Characteristic.InUse, this.platform.Characteristic.InUse.IN_USE);
92
67
  }
93
68
  this.Active = value;
94
69
  this.ActiveCached = this.Active;
@@ -97,17 +72,10 @@ export class WaterHeater {
97
72
 
98
73
  private updateHomeKitCharacteristics() {
99
74
  if (this.Active === undefined) {
100
- this.debugLog(
101
- `Water Heater: ${this.accessory.displayName} Active: ${this.Active}`,
102
- );
75
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Active: ${this.Active}`);
103
76
  } 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
- );
77
+ this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
78
+ this.debugLog(`Water Heater: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
111
79
  }
112
80
  }
113
81
 
@@ -124,9 +92,9 @@ export class WaterHeater {
124
92
  async pushWaterHeaterOnChanges() {
125
93
  if (this.Active !== 1) {
126
94
  const payload = {
127
- commandType: "command",
128
- parameter: "default",
129
- command: "turnOn",
95
+ commandType: 'command',
96
+ parameter: 'default',
97
+ command: 'turnOn',
130
98
  } as payload;
131
99
  await this.pushChanges(payload);
132
100
  }
@@ -135,9 +103,9 @@ export class WaterHeater {
135
103
  async pushWaterHeaterOffChanges() {
136
104
  if (this.Active !== 0) {
137
105
  const payload = {
138
- commandType: "command",
139
- parameter: "default",
140
- command: "turnOff",
106
+ commandType: 'command',
107
+ parameter: 'default',
108
+ command: 'turnOff',
141
109
  } as payload;
142
110
  await this.pushChanges(payload);
143
111
  }
@@ -151,30 +119,19 @@ export class WaterHeater {
151
119
  );
152
120
 
153
121
  // 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
- );
122
+ const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
123
+ this.debugLog(`Water Heater: ${this.accessory.displayName} pushChanges: ${push.data}`);
161
124
  this.statusCode(push);
162
125
  this.updateHomeKitCharacteristics();
163
126
  } catch (e: any) {
164
- this.errorLog(
165
- `Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`,
166
- );
167
- if (this.deviceLogging === "debug") {
127
+ this.errorLog(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
128
+ if (this.deviceLogging === 'debug') {
168
129
  this.errorLog(
169
- `Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
170
- ` Error Message: ${JSON.stringify(e.message)}`,
130
+ `Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
171
131
  );
172
132
  }
173
133
  if (this.platform.debugMode) {
174
- this.errorLog(
175
- `Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
176
- ` Error: ${JSON.stringify(e)}`,
177
- );
134
+ this.errorLog(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
178
135
  }
179
136
  this.apiError(e);
180
137
  }
@@ -183,47 +140,31 @@ export class WaterHeater {
183
140
  private statusCode(push: AxiosResponse<{ statusCode: number }>) {
184
141
  switch (push.data.statusCode) {
185
142
  case 151:
186
- this.errorLog(
187
- `Water Heater: ${this.accessory.displayName} Command not supported by this device type.`,
188
- );
143
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Command not supported by this device type.`);
189
144
  break;
190
145
  case 152:
191
- this.errorLog(
192
- `Water Heater: ${this.accessory.displayName} Device not found.`,
193
- );
146
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Device not found.`);
194
147
  break;
195
148
  case 160:
196
- this.errorLog(
197
- `Water Heater: ${this.accessory.displayName} Command is not supported.`,
198
- );
149
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Command is not supported.`);
199
150
  break;
200
151
  case 161:
201
- this.errorLog(
202
- `Water Heater: ${this.accessory.displayName} Device is offline.`,
203
- );
152
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Device is offline.`);
204
153
  break;
205
154
  case 171:
206
- this.errorLog(
207
- `Water Heater: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
208
- );
155
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
209
156
  break;
210
157
  case 190:
211
158
  this.errorLog(
212
159
  `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`,
160
+ ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`,
216
161
  );
217
162
  break;
218
163
  case 100:
219
- this.debugLog(
220
- `Water Heater: ${this.accessory.displayName} Command successfully sent.`,
221
- );
164
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Command successfully sent.`);
222
165
  break;
223
166
  default:
224
- this.debugLog(
225
- `Water Heater: ${this.accessory.displayName} Unknown statusCode.`,
226
- );
167
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Unknown statusCode.`);
227
168
  }
228
169
  }
229
170
 
@@ -238,39 +179,26 @@ export class WaterHeater {
238
179
  config = device.irwh;
239
180
  }
240
181
  if (device.logging !== undefined) {
241
- config["logging"] = device.logging;
182
+ config['logging'] = device.logging;
242
183
  }
243
184
  if (Object.entries(config).length !== 0) {
244
- this.warnLog(
245
- `Water Heater: ${this.accessory.displayName} Config: ${JSON.stringify(
246
- config,
247
- )}`,
248
- );
185
+ this.warnLog(`Water Heater: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
249
186
  }
250
187
  }
251
188
 
252
189
  logs(device: irdevice & irDevicesConfig) {
253
190
  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
- );
191
+ this.deviceLogging = this.accessory.context.logging = 'debugMode';
192
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
258
193
  } else if (device.logging) {
259
194
  this.deviceLogging = this.accessory.context.logging = device.logging;
260
- this.debugLog(
261
- `Water Heater: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
262
- );
195
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
263
196
  } 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
- );
197
+ this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
198
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
269
199
  } 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
- );
200
+ this.deviceLogging = this.accessory.context.logging = 'standard';
201
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
274
202
  }
275
203
  }
276
204
 
@@ -297,8 +225,8 @@ export class WaterHeater {
297
225
 
298
226
  debugLog(...log: any[]) {
299
227
  if (this.enablingDeviceLogging()) {
300
- if (this.deviceLogging === "debug") {
301
- this.platform.log.info("[DEBUG]", String(...log));
228
+ if (this.deviceLogging === 'debug') {
229
+ this.platform.log.info('[DEBUG]', String(...log));
302
230
  } else {
303
231
  this.platform.log.debug(String(...log));
304
232
  }
@@ -306,6 +234,6 @@ export class WaterHeater {
306
234
  }
307
235
 
308
236
  enablingDeviceLogging(): boolean {
309
- return this.deviceLogging.includes("debug") || this.deviceLogging === "standard";
237
+ return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
310
238
  }
311
239
  }