@switchbot/homebridge-switchbot 2.8.0-beta.0 → 2.8.0-beta.10

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 (139) hide show
  1. package/.prettierrc +1 -1
  2. package/.vscode/settings.json +1 -1
  3. package/CHANGELOG.md +10 -0
  4. package/config.schema.json +8 -0
  5. package/dist/device/blindtilt.d.ts +1 -0
  6. package/dist/device/blindtilt.d.ts.map +1 -1
  7. package/dist/device/blindtilt.js +58 -65
  8. package/dist/device/blindtilt.js.map +1 -1
  9. package/dist/device/bot.d.ts +1 -0
  10. package/dist/device/bot.d.ts.map +1 -1
  11. package/dist/device/bot.js +52 -55
  12. package/dist/device/bot.js.map +1 -1
  13. package/dist/device/ceilinglight.d.ts +1 -0
  14. package/dist/device/ceilinglight.d.ts.map +1 -1
  15. package/dist/device/ceilinglight.js +68 -68
  16. package/dist/device/ceilinglight.js.map +1 -1
  17. package/dist/device/colorbulb.d.ts +1 -0
  18. package/dist/device/colorbulb.d.ts.map +1 -1
  19. package/dist/device/colorbulb.js +76 -75
  20. package/dist/device/colorbulb.js.map +1 -1
  21. package/dist/device/contact.d.ts +2 -0
  22. package/dist/device/contact.d.ts.map +1 -1
  23. package/dist/device/contact.js +67 -59
  24. package/dist/device/contact.js.map +1 -1
  25. package/dist/device/curtain.d.ts +2 -0
  26. package/dist/device/curtain.d.ts.map +1 -1
  27. package/dist/device/curtain.js +81 -94
  28. package/dist/device/curtain.js.map +1 -1
  29. package/dist/device/hub.d.ts +9 -1
  30. package/dist/device/hub.d.ts.map +1 -1
  31. package/dist/device/hub.js +197 -30
  32. package/dist/device/hub.js.map +1 -1
  33. package/dist/device/humidifier.d.ts.map +1 -1
  34. package/dist/device/humidifier.js +58 -62
  35. package/dist/device/humidifier.js.map +1 -1
  36. package/dist/device/iosensor.d.ts +1 -0
  37. package/dist/device/iosensor.d.ts.map +1 -1
  38. package/dist/device/iosensor.js +28 -26
  39. package/dist/device/iosensor.js.map +1 -1
  40. package/dist/device/lightstrip.d.ts +1 -0
  41. package/dist/device/lightstrip.d.ts.map +1 -1
  42. package/dist/device/lightstrip.js +68 -67
  43. package/dist/device/lightstrip.js.map +1 -1
  44. package/dist/device/lock.d.ts +2 -0
  45. package/dist/device/lock.d.ts.map +1 -1
  46. package/dist/device/lock.js +51 -47
  47. package/dist/device/lock.js.map +1 -1
  48. package/dist/device/meter.d.ts +5 -3
  49. package/dist/device/meter.d.ts.map +1 -1
  50. package/dist/device/meter.js +75 -74
  51. package/dist/device/meter.js.map +1 -1
  52. package/dist/device/meterplus.d.ts +4 -3
  53. package/dist/device/meterplus.d.ts.map +1 -1
  54. package/dist/device/meterplus.js +74 -74
  55. package/dist/device/meterplus.js.map +1 -1
  56. package/dist/device/motion.d.ts +2 -0
  57. package/dist/device/motion.d.ts.map +1 -1
  58. package/dist/device/motion.js +66 -54
  59. package/dist/device/motion.js.map +1 -1
  60. package/dist/device/plug.d.ts +1 -0
  61. package/dist/device/plug.d.ts.map +1 -1
  62. package/dist/device/plug.js +39 -39
  63. package/dist/device/plug.js.map +1 -1
  64. package/dist/device/robotvacuumcleaner.d.ts +1 -0
  65. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  66. package/dist/device/robotvacuumcleaner.js +74 -53
  67. package/dist/device/robotvacuumcleaner.js.map +1 -1
  68. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  69. package/dist/irdevice/airconditioner.js +64 -66
  70. package/dist/irdevice/airconditioner.js.map +1 -1
  71. package/dist/irdevice/airpurifier.d.ts +1 -1
  72. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  73. package/dist/irdevice/airpurifier.js +32 -34
  74. package/dist/irdevice/airpurifier.js.map +1 -1
  75. package/dist/irdevice/camera.d.ts +1 -1
  76. package/dist/irdevice/camera.d.ts.map +1 -1
  77. package/dist/irdevice/camera.js +20 -23
  78. package/dist/irdevice/camera.js.map +1 -1
  79. package/dist/irdevice/fan.d.ts +2 -2
  80. package/dist/irdevice/fan.d.ts.map +1 -1
  81. package/dist/irdevice/fan.js +30 -32
  82. package/dist/irdevice/fan.js.map +1 -1
  83. package/dist/irdevice/light.d.ts +1 -1
  84. package/dist/irdevice/light.d.ts.map +1 -1
  85. package/dist/irdevice/light.js +26 -29
  86. package/dist/irdevice/light.js.map +1 -1
  87. package/dist/irdevice/other.d.ts +1 -1
  88. package/dist/irdevice/other.d.ts.map +1 -1
  89. package/dist/irdevice/other.js +22 -23
  90. package/dist/irdevice/other.js.map +1 -1
  91. package/dist/irdevice/tv.d.ts +2 -2
  92. package/dist/irdevice/tv.d.ts.map +1 -1
  93. package/dist/irdevice/tv.js +47 -50
  94. package/dist/irdevice/tv.js.map +1 -1
  95. package/dist/irdevice/vacuumcleaner.d.ts +1 -1
  96. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  97. package/dist/irdevice/vacuumcleaner.js +20 -23
  98. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  99. package/dist/irdevice/waterheater.d.ts +1 -1
  100. package/dist/irdevice/waterheater.d.ts.map +1 -1
  101. package/dist/irdevice/waterheater.js +22 -23
  102. package/dist/irdevice/waterheater.js.map +1 -1
  103. package/dist/platform.d.ts.map +1 -1
  104. package/dist/platform.js +46 -44
  105. package/dist/platform.js.map +1 -1
  106. package/dist/settings.d.ts +1 -0
  107. package/dist/settings.d.ts.map +1 -1
  108. package/dist/settings.js.map +1 -1
  109. package/dist/utils.js +1 -1
  110. package/dist/utils.js.map +1 -1
  111. package/package.json +3 -3
  112. package/src/device/blindtilt.ts +114 -78
  113. package/src/device/bot.ts +102 -63
  114. package/src/device/ceilinglight.ts +113 -73
  115. package/src/device/colorbulb.ts +144 -87
  116. package/src/device/contact.ts +98 -63
  117. package/src/device/curtain.ts +160 -134
  118. package/src/device/hub.ts +228 -39
  119. package/src/device/humidifier.ts +136 -85
  120. package/src/device/iosensor.ts +52 -32
  121. package/src/device/lightstrip.ts +118 -72
  122. package/src/device/lock.ts +85 -50
  123. package/src/device/meter.ts +104 -80
  124. package/src/device/meterplus.ts +103 -80
  125. package/src/device/motion.ts +95 -59
  126. package/src/device/plug.ts +70 -44
  127. package/src/device/robotvacuumcleaner.ts +107 -56
  128. package/src/irdevice/airconditioner.ts +116 -86
  129. package/src/irdevice/airpurifier.ts +60 -39
  130. package/src/irdevice/camera.ts +40 -28
  131. package/src/irdevice/fan.ts +52 -38
  132. package/src/irdevice/light.ts +48 -34
  133. package/src/irdevice/other.ts +44 -28
  134. package/src/irdevice/tv.ts +70 -56
  135. package/src/irdevice/vacuumcleaner.ts +40 -28
  136. package/src/irdevice/waterheater.ts +48 -32
  137. package/src/platform.ts +87 -56
  138. package/src/settings.ts +41 -40
  139. package/src/utils.ts +1 -1
@@ -43,14 +43,18 @@ export class AirConditioner {
43
43
  private readonly valid12 = [1, 2];
44
44
  private readonly valid012 = [0, 1, 2];
45
45
 
46
- constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
46
+ constructor(
47
+ private readonly platform: SwitchBotPlatform,
48
+ private accessory: PlatformAccessory,
49
+ public device: irdevice & irDevicesConfig,
50
+ ) {
47
51
  // default placeholders
48
52
  this.logs({ device });
49
- this.config({ device });
50
53
  this.context();
51
54
  this.disablePushOnChanges({ device });
52
55
  this.disablePushOffChanges({ device });
53
56
  this.disablePushDetailChanges({ device });
57
+ this.config({ device });
54
58
 
55
59
  // set accessory information
56
60
  accessory
@@ -65,7 +69,7 @@ export class AirConditioner {
65
69
  // get the Television service if it exists, otherwise create a new Television service
66
70
  // you can create multiple services for each accessory
67
71
  (this.coolerService = accessory.getService(this.platform.Service.HeaterCooler) || accessory.addService(this.platform.Service.HeaterCooler)),
68
- `${accessory.displayName} ${device.remoteType}`;
72
+ `${accessory.displayName} ${device.remoteType}`;
69
73
 
70
74
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
71
75
  // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
@@ -79,11 +83,9 @@ export class AirConditioner {
79
83
  }
80
84
 
81
85
  // handle on / off events using the Active characteristic
82
- this.coolerService.getCharacteristic(this.platform.Characteristic.Active)
83
- .onSet(this.ActiveSet.bind(this));
86
+ this.coolerService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
84
87
 
85
- this.coolerService.getCharacteristic(this.platform.Characteristic.CurrentTemperature)
86
- .onGet(this.CurrentTemperatureGet.bind(this));
88
+ this.coolerService.getCharacteristic(this.platform.Characteristic.CurrentTemperature).onGet(this.CurrentTemperatureGet.bind(this));
87
89
 
88
90
  if (this.hide_automode) {
89
91
  this.TargetHeaterCoolerState = 1 || 2;
@@ -102,39 +104,39 @@ export class AirConditioner {
102
104
  }
103
105
 
104
106
  if (this.meter) {
105
- this.coolerService
106
- .getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity)
107
- .onGet(this.CurrentRelativeHumidityGet.bind(this));
107
+ this.coolerService.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).onGet(this.CurrentRelativeHumidityGet.bind(this));
108
108
  }
109
109
 
110
- this.coolerService.getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState)
110
+ this.coolerService
111
+ .getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState)
111
112
  .setProps({
112
113
  validValues: this.ValidValues,
113
114
  })
114
115
  .onGet(this.TargetHeaterCoolerStateGet.bind(this))
115
116
  .onSet(this.TargetHeaterCoolerStateSet.bind(this));
116
117
 
117
- this.coolerService.getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState)
118
- .onGet(this.CurrentHeaterCoolerStateGet.bind(this));
118
+ this.coolerService.getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState).onGet(this.CurrentHeaterCoolerStateGet.bind(this));
119
119
 
120
-
121
- this.coolerService.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature)
120
+ this.coolerService
121
+ .getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature)
122
122
  .setProps({
123
123
  minStep: 0.5,
124
124
  })
125
125
  .onGet(this.ThresholdTemperatureGet.bind(this))
126
126
  .onSet(this.ThresholdTemperatureSet.bind(this));
127
127
 
128
- this.coolerService.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature)
128
+ this.coolerService
129
+ .getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature)
129
130
  .setProps({
130
131
  minStep: 0.5,
131
132
  })
132
133
  .onGet(this.ThresholdTemperatureGet.bind(this))
133
134
  .onSet(this.ThresholdTemperatureSet.bind(this));
134
135
 
135
- this.coolerService.getCharacteristic(this.platform.Characteristic.RotationSpeed)
136
+ this.coolerService
137
+ .getCharacteristic(this.platform.Characteristic.RotationSpeed)
136
138
  .setProps({
137
- format: "int",
139
+ format: 'int',
138
140
  minStep: 1,
139
141
  minValue: 1,
140
142
  maxValue: 4,
@@ -153,38 +155,44 @@ export class AirConditioner {
153
155
  * AirConditioner: "command" "highSpeed" "default" = fan speed to high
154
156
  */
155
157
  async pushAirConditionerOnChanges(): Promise<void> {
156
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOnChanges Active: ${this.Active},`
157
- + ` disablePushOn: ${this.disablePushOn}`);
158
+ this.debugLog(
159
+ `${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOnChanges Active: ${this.Active},` +
160
+ ` disablePushOn: ${this.disablePushOn}`,
161
+ );
158
162
  if (this.Active === this.platform.Characteristic.Active.ACTIVE && !this.disablePushOn) {
159
163
  const commandType: string = await this.commandType();
160
164
  const command: string = await this.commandOn();
161
165
  const bodyChange = JSON.stringify({
162
- 'command': command,
163
- 'parameter': 'default',
164
- 'commandType': commandType,
166
+ command: command,
167
+ parameter: 'default',
168
+ commandType: commandType,
165
169
  });
166
170
  await this.pushChanges(bodyChange);
167
171
  }
168
172
  }
169
173
 
170
174
  async pushAirConditionerOffChanges(): Promise<void> {
171
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOffChanges Active: ${this.Active},`
172
- + ` disablePushOff: ${this.disablePushOff}`);
175
+ this.debugLog(
176
+ `${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOffChanges Active: ${this.Active},` +
177
+ ` disablePushOff: ${this.disablePushOff}`,
178
+ );
173
179
  if (this.Active === this.platform.Characteristic.Active.INACTIVE && !this.disablePushOff) {
174
180
  const commandType: string = await this.commandType();
175
181
  const command: string = await this.commandOff();
176
182
  const bodyChange = JSON.stringify({
177
- 'command': command,
178
- 'parameter': 'default',
179
- 'commandType': commandType,
183
+ command: command,
184
+ parameter: 'default',
185
+ commandType: commandType,
180
186
  });
181
187
  await this.pushChanges(bodyChange);
182
188
  }
183
189
  }
184
190
 
185
191
  async pushAirConditionerStatusChanges(): Promise<void> {
186
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerStatusChanges Active: ${this.Active},`
187
- + ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
192
+ this.debugLog(
193
+ `${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerStatusChanges Active: ${this.Active},` +
194
+ ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`,
195
+ );
188
196
  if (!this.Busy) {
189
197
  this.Busy = true;
190
198
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
@@ -196,8 +204,10 @@ export class AirConditioner {
196
204
  }
197
205
 
198
206
  async pushAirConditionerDetailsChanges(): Promise<void> {
199
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerDetailsChanges Active: ${this.Active},`
200
- + ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
207
+ this.debugLog(
208
+ `${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerDetailsChanges Active: ${this.Active},` +
209
+ ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`,
210
+ );
201
211
  //await this.context();
202
212
  if (this.CurrentMode === undefined) {
203
213
  this.CurrentMode = 1;
@@ -214,8 +224,8 @@ export class AirConditioner {
214
224
  // Remove or make configurable?
215
225
  this.ThresholdTemperature = 25;
216
226
  this.debugLog(
217
- `${this.device.remoteType}: ${this.accessory.displayName} CurrentMode: ${this.CurrentMode},`
218
- + ` ThresholdTemperature: ${this.ThresholdTemperature}`,
227
+ `${this.device.remoteType}: ${this.accessory.displayName} CurrentMode: ${this.CurrentMode},` +
228
+ ` ThresholdTemperature: ${this.ThresholdTemperature}`,
219
229
  );
220
230
  }
221
231
  const parameter = `${this.ThresholdTemperature},${this.CurrentMode},${this.CurrentFanSpeed},${this.state}`;
@@ -231,9 +241,9 @@ export class AirConditioner {
231
241
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
232
242
  }
233
243
  const bodyChange = JSON.stringify({
234
- 'command': 'setAll',
235
- 'parameter': `${parameter}`,
236
- 'commandType': 'command',
244
+ command: 'setAll',
245
+ parameter: `${parameter}`,
246
+ commandType: 'command',
237
247
  });
238
248
 
239
249
  await this.pushChanges(bodyChange);
@@ -242,7 +252,7 @@ export class AirConditioner {
242
252
  async pushChanges(bodyChange: any): Promise<void> {
243
253
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
244
254
  if (this.device.connectionType === 'OpenAPI' && !this.disablePushDetail) {
245
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
255
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
246
256
  try {
247
257
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
248
258
  body: bodyChange,
@@ -256,25 +266,34 @@ export class AirConditioner {
256
266
  this.updateHomeKitCharacteristics();
257
267
  } catch (e: any) {
258
268
  this.apiError(e);
259
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}`
260
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
269
+ this.errorLog(
270
+ `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}` +
271
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
261
272
  );
262
273
  }
263
274
  } else {
264
- this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
265
- + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
266
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
267
- + ` Connection Type: ${this.device.connectionType}, disablePushDetails: ${this.disablePushDetail}`);
275
+ this.warnLog(
276
+ `${this.device.remoteType}: ${this.accessory.displayName}` +
277
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
278
+ );
279
+ this.debugLog(
280
+ `${this.device.remoteType}: ${this.accessory.displayName}` +
281
+ ` Connection Type: ${this.device.connectionType}, disablePushDetails: ${this.disablePushDetail}`,
282
+ );
268
283
  this.updateHomeKitCharacteristics();
269
284
  }
270
285
  }
271
286
 
272
287
  async CurrentTemperatureGet(): Promise<CharacteristicValue> {
273
288
  if (this.meter) {
274
- this.CurrentTemperature = this.meter.context?.CurrentTemperature
275
- || this.meter.getService(this.platform.Service.TemperatureSensor)?.getCharacteristic(this.platform.Characteristic.CurrentTemperature).value
276
- || 24;
277
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using CurrentTemperature from ${this.meter.context?.deviceType} (${this.meter.context?.deviceID})`)
289
+ this.CurrentTemperature =
290
+ this.meter.context?.CurrentTemperature ||
291
+ this.meter.getService(this.platform.Service.TemperatureSensor)?.getCharacteristic(this.platform.Characteristic.CurrentTemperature).value ||
292
+ 24;
293
+ this.debugLog(
294
+ `${this.device.remoteType}: ${this.accessory.displayName} `
295
+ + `Using CurrentTemperature from ${this.meter.context?.deviceType} (${this.meter.context?.deviceID})`,
296
+ );
278
297
  } else if (this.CurrentTemperature === undefined) {
279
298
  this.CurrentTemperature = 24;
280
299
  } else {
@@ -286,15 +305,17 @@ export class AirConditioner {
286
305
 
287
306
  async CurrentRelativeHumidityGet(): Promise<CharacteristicValue> {
288
307
  if (this.meter) {
289
- this.CurrentRelativeHumidity = this.meter.context?.CurrentRelativeHumidity
290
- || this.meter.getService(this.platform.Service.HumiditySensor)?.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value
291
- || 0;
292
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using CurrentRelativeHumidity from ${this.meter.context?.deviceType} (${this.meter.context?.deviceID})`)
293
- }
294
- else if (this.CurrentRelativeHumidity === undefined) {
308
+ this.CurrentRelativeHumidity =
309
+ this.meter.context?.CurrentRelativeHumidity ||
310
+ this.meter.getService(this.platform.Service.HumiditySensor)?.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value ||
311
+ 0;
312
+ this.debugLog(
313
+ `${this.device.remoteType}: ${this.accessory.displayName} `
314
+ + `Using CurrentRelativeHumidity from ${this.meter.context?.deviceType} (${this.meter.context?.deviceID})`,
315
+ );
316
+ } else if (this.CurrentRelativeHumidity === undefined) {
295
317
  this.CurrentRelativeHumidity = 0;
296
- }
297
- else {
318
+ } else {
298
319
  this.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity;
299
320
  }
300
321
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
@@ -402,17 +423,20 @@ export class AirConditioner {
402
423
  if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
403
424
  if (this.ThresholdTemperature < this.accessory.context.CurrentTemperature) {
404
425
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
405
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
406
- + ` Get (COOLING) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
426
+ this.debugLog(
427
+ `${this.device.remoteType}: ${this.accessory.displayName}` + ` Get (COOLING) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
428
+ );
407
429
  } else if (this.ThresholdTemperature > this.accessory.context.CurrentTemperature) {
408
430
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
409
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
410
- + ` Get (HEATING) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
431
+ this.debugLog(
432
+ `${this.device.remoteType}: ${this.accessory.displayName}` + ` Get (HEATING) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
433
+ );
411
434
  }
412
435
  } else {
413
436
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
414
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
415
- + ` Get (INACTIVE) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
437
+ this.debugLog(
438
+ `${this.device.remoteType}: ${this.accessory.displayName}` + ` Get (INACTIVE) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
439
+ );
416
440
  }
417
441
  return this.CurrentHeaterCoolerState;
418
442
  }
@@ -425,8 +449,10 @@ export class AirConditioner {
425
449
 
426
450
  async ThresholdTemperatureSet(value: CharacteristicValue): Promise<void> {
427
451
  this.ThresholdTemperature = value;
428
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set ThresholdTemperature: ${this.ThresholdTemperature},` +
429
- ` ThresholdTemperatureCached: ${this.accessory.context.ThresholdTemperature}`);
452
+ this.debugLog(
453
+ `${this.device.remoteType}: ${this.accessory.displayName} Set ThresholdTemperature: ${this.ThresholdTemperature},` +
454
+ ` ThresholdTemperatureCached: ${this.accessory.context.ThresholdTemperature}`,
455
+ );
430
456
  this.pushAirConditionerStatusChanges();
431
457
  }
432
458
 
@@ -455,11 +481,12 @@ export class AirConditioner {
455
481
  if (this.meter) {
456
482
  if (this.CurrentRelativeHumidity === undefined) {
457
483
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
458
- }
459
- else {
484
+ } else {
460
485
  this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
461
486
  this.coolerService?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
462
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
487
+ this.debugLog(
488
+ `${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
489
+ );
463
490
  }
464
491
  }
465
492
  if (this.TargetHeaterCoolerState === undefined) {
@@ -477,8 +504,8 @@ export class AirConditioner {
477
504
  this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerState;
478
505
  this.coolerService?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
479
506
  this.debugLog(
480
- `${this.device.remoteType}: ${this.accessory.displayName}`
481
- + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
507
+ `${this.device.remoteType}: ${this.accessory.displayName}` +
508
+ ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
482
509
  );
483
510
  }
484
511
  if (this.ThresholdTemperature === undefined) {
@@ -488,13 +515,12 @@ export class AirConditioner {
488
515
  this.coolerService?.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, this.ThresholdTemperature);
489
516
  this.coolerService?.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, this.ThresholdTemperature);
490
517
  this.debugLog(
491
- `${this.device.remoteType}: ${this.accessory.displayName}`
492
- + ` updateCharacteristic ThresholdTemperature: ${this.ThresholdTemperature}`,
518
+ `${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic ThresholdTemperature: ${this.ThresholdTemperature}`,
493
519
  );
494
520
  }
495
521
  }
496
522
 
497
- async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
523
+ async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
498
524
  if (device.disablePushOn === undefined) {
499
525
  this.disablePushOn = false;
500
526
  } else {
@@ -502,7 +528,7 @@ export class AirConditioner {
502
528
  }
503
529
  }
504
530
 
505
- async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
531
+ async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
506
532
  if (device.disablePushOff === undefined) {
507
533
  this.disablePushOff = false;
508
534
  } else {
@@ -510,7 +536,7 @@ export class AirConditioner {
510
536
  }
511
537
  }
512
538
 
513
- async disablePushDetailChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
539
+ async disablePushDetailChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
514
540
  if (device.disablePushDetail === undefined) {
515
541
  this.disablePushDetail = false;
516
542
  } else {
@@ -563,8 +589,10 @@ export class AirConditioner {
563
589
  this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
564
590
  break;
565
591
  case 171:
566
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
567
- + `Hub: ${this.device.hubDeviceId}`);
592
+ this.errorLog(
593
+ `${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
594
+ `Hub: ${this.device.hubDeviceId}`,
595
+ );
568
596
  break;
569
597
  case 190:
570
598
  this.errorLog(
@@ -579,12 +607,14 @@ export class AirConditioner {
579
607
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
580
608
  break;
581
609
  default:
582
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: `
583
- + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
610
+ this.infoLog(
611
+ `${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
612
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
613
+ );
584
614
  }
585
615
  }
586
616
 
587
- async apiError({ e }: { e: any; }): Promise<void> {
617
+ async apiError({ e }: { e: any }): Promise<void> {
588
618
  this.coolerService.updateCharacteristic(this.platform.Characteristic.Active, e);
589
619
  this.coolerService.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
590
620
  this.coolerService.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
@@ -595,10 +625,11 @@ export class AirConditioner {
595
625
  this.coolerService.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, e);
596
626
  }
597
627
 
598
- FirmwareRevision({ accessory, device }: { accessory: PlatformAccessory; device: irdevice & irDevicesConfig; }): string {
628
+ FirmwareRevision({ accessory, device }: { accessory: PlatformAccessory; device: irdevice & irDevicesConfig }): string {
599
629
  let FirmwareRevision: string;
600
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
601
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
630
+ this.debugLog(
631
+ `${this.device.remoteType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
632
+ );
602
633
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
603
634
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
604
635
  if (accessory.context.FirmwareRevision) {
@@ -653,7 +684,7 @@ export class AirConditioner {
653
684
  }
654
685
  }
655
686
 
656
- async config({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
687
+ async config({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
657
688
  let config = {};
658
689
  if (device.irair) {
659
690
  config = device.irair;
@@ -686,11 +717,11 @@ export class AirConditioner {
686
717
  config['disablePushDetail'] = device.disablePushDetail;
687
718
  }
688
719
  if (Object.entries(config).length !== 0) {
689
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
720
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
690
721
  }
691
722
  }
692
723
 
693
- async logs({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
724
+ async logs({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
694
725
  if (this.platform.debugMode) {
695
726
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
696
727
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
@@ -753,4 +784,3 @@ export class AirConditioner {
753
784
  return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
754
785
  }
755
786
  }
756
-
@@ -1,7 +1,7 @@
1
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
1
2
  import { request } from 'undici';
2
3
  import { SwitchBotPlatform } from '../platform';
3
- import { irDevicesConfig, irdevice, Devices } from '../settings';
4
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
+ import { Devices, irDevicesConfig, irdevice } from '../settings';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -38,13 +38,17 @@ export class AirPurifier {
38
38
  disablePushOff?: boolean;
39
39
  deviceLogging!: string;
40
40
 
41
- constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
41
+ constructor(
42
+ private readonly platform: SwitchBotPlatform,
43
+ private accessory: PlatformAccessory,
44
+ public device: irdevice & irDevicesConfig,
45
+ ) {
42
46
  // default placeholders
43
47
  this.logs(device);
44
- this.config(device);
45
48
  this.context();
46
49
  this.disablePushOnChanges({ device });
47
50
  this.disablePushOffChanges({ device });
51
+ this.config(device);
48
52
 
49
53
  // set accessory information
50
54
  accessory
@@ -129,38 +133,44 @@ export class AirPurifier {
129
133
  * AirPurifier: "command" "highSpeed" "default" = fan speed to high
130
134
  */
131
135
  async pushAirPurifierOnChanges(): Promise<void> {
132
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierOnChanges Active: ${this.Active},`
133
- + ` disablePushOn: ${this.disablePushOn}`);
136
+ this.debugLog(
137
+ `${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierOnChanges Active: ${this.Active},` +
138
+ ` disablePushOn: ${this.disablePushOn}`,
139
+ );
134
140
  if (this.Active === this.platform.Characteristic.Active.ACTIVE && !this.disablePushOn) {
135
141
  const commandType: string = await this.commandType();
136
142
  const command: string = await this.commandOn();
137
143
  const bodyChange = JSON.stringify({
138
- 'command': command,
139
- 'parameter': 'default',
140
- 'commandType': commandType,
144
+ command: command,
145
+ parameter: 'default',
146
+ commandType: commandType,
141
147
  });
142
148
  await this.pushChanges(bodyChange);
143
149
  }
144
150
  }
145
151
 
146
152
  async pushAirPurifierOffChanges(): Promise<void> {
147
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierOffChanges Active: ${this.Active},`
148
- + ` disablePushOff: ${this.disablePushOff}`);
153
+ this.debugLog(
154
+ `${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierOffChanges Active: ${this.Active},` +
155
+ ` disablePushOff: ${this.disablePushOff}`,
156
+ );
149
157
  if (this.Active === this.platform.Characteristic.Active.INACTIVE && !this.disablePushOn) {
150
158
  const commandType: string = await this.commandType();
151
159
  const command: string = await this.commandOff();
152
160
  const bodyChange = JSON.stringify({
153
- 'command': command,
154
- 'parameter': 'default',
155
- 'commandType': commandType,
161
+ command: command,
162
+ parameter: 'default',
163
+ commandType: commandType,
156
164
  });
157
165
  await this.pushChanges(bodyChange);
158
166
  }
159
167
  }
160
168
 
161
169
  async pushAirPurifierStatusChanges(): Promise<void> {
162
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierStatusChanges Active: ${this.Active},`
163
- + ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
170
+ this.debugLog(
171
+ `${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierStatusChanges Active: ${this.Active},` +
172
+ ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`,
173
+ );
164
174
  if (!this.Busy) {
165
175
  this.Busy = true;
166
176
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
@@ -172,17 +182,19 @@ export class AirPurifier {
172
182
  }
173
183
 
174
184
  async pushAirPurifierDetailsChanges(): Promise<void> {
175
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierDetailsChanges Active: ${this.Active},`
176
- + ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
185
+ this.debugLog(
186
+ `${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierDetailsChanges Active: ${this.Active},` +
187
+ ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`,
188
+ );
177
189
  this.CurrentAPTemp = this.CurrentTemperature || 24;
178
190
  this.CurrentAPMode = this.CurrentMode || 1;
179
191
  this.CurrentAPFanSpeed = this.CurrentFanSpeed || 1;
180
192
  this.APActive = this.Active === 1 ? 'on' : 'off';
181
193
  const parameter = `${this.CurrentAPTemp},${this.CurrentAPMode},${this.CurrentAPFanSpeed},${this.APActive}`;
182
194
  const bodyChange = JSON.stringify({
183
- 'command': 'setAll',
184
- 'parameter': `${parameter}`,
185
- 'commandType': 'command',
195
+ command: 'setAll',
196
+ parameter: `${parameter}`,
197
+ commandType: 'command',
186
198
  });
187
199
  if (this.Active === 1) {
188
200
  if ((Number(this.CurrentTemperature) || 24) < (this.LastTemperature || 30)) {
@@ -199,7 +211,7 @@ export class AirPurifier {
199
211
  async pushChanges(bodyChange: any): Promise<void> {
200
212
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
201
213
  if (this.device.connectionType === 'OpenAPI') {
202
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
214
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
203
215
  try {
204
216
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
205
217
  body: bodyChange,
@@ -213,13 +225,16 @@ export class AirPurifier {
213
225
  this.updateHomeKitCharacteristics();
214
226
  } catch (e: any) {
215
227
  this.apiError(e);
216
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}`
217
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
228
+ this.errorLog(
229
+ `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}` +
230
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
218
231
  );
219
232
  }
220
233
  } else {
221
- this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
222
- + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
234
+ this.warnLog(
235
+ `${this.device.remoteType}: ${this.accessory.displayName}` +
236
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
237
+ );
223
238
  }
224
239
  }
225
240
 
@@ -236,8 +251,9 @@ export class AirPurifier {
236
251
  } else {
237
252
  this.accessory.context.CurrentAirPurifierState = this.CurrentAirPurifierState;
238
253
  this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, this.CurrentAirPurifierState);
239
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
240
- + ` updateCharacteristic CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
254
+ this.debugLog(
255
+ `${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic CurrentAirPurifierState: ${this.CurrentAirPurifierState}`,
256
+ );
241
257
  }
242
258
  if (this.CurrentHeaterCoolerState === undefined) {
243
259
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
@@ -245,13 +261,13 @@ export class AirPurifier {
245
261
  this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerState;
246
262
  this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
247
263
  this.debugLog(
248
- `${this.device.remoteType}: ${this.accessory.displayName}`
249
- + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
264
+ `${this.device.remoteType}: ${this.accessory.displayName}` +
265
+ ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
250
266
  );
251
267
  }
252
268
  }
253
269
 
254
- async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
270
+ async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
255
271
  if (device.disablePushOn === undefined) {
256
272
  this.disablePushOn = false;
257
273
  } else {
@@ -259,7 +275,7 @@ export class AirPurifier {
259
275
  }
260
276
  }
261
277
 
262
- async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
278
+ async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
263
279
  if (device.disablePushOff === undefined) {
264
280
  this.disablePushOff = false;
265
281
  } else {
@@ -312,8 +328,10 @@ export class AirPurifier {
312
328
  this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
313
329
  break;
314
330
  case 171:
315
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
316
- + `Hub: ${this.device.hubDeviceId}`);
331
+ this.errorLog(
332
+ `${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
333
+ `Hub: ${this.device.hubDeviceId}`,
334
+ );
317
335
  break;
318
336
  case 190:
319
337
  this.errorLog(
@@ -328,8 +346,10 @@ export class AirPurifier {
328
346
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
329
347
  break;
330
348
  default:
331
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: `
332
- + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
349
+ this.infoLog(
350
+ `${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
351
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
352
+ );
333
353
  }
334
354
  }
335
355
 
@@ -342,8 +362,9 @@ export class AirPurifier {
342
362
 
343
363
  FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
344
364
  let FirmwareRevision: string;
345
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
346
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
365
+ this.debugLog(
366
+ `${this.device.remoteType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
367
+ );
347
368
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
348
369
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
349
370
  if (accessory.context.FirmwareRevision) {
@@ -399,7 +420,7 @@ export class AirPurifier {
399
420
  config['disablePushOff'] = device.disablePushOff;
400
421
  }
401
422
  if (Object.entries(config).length !== 0) {
402
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
423
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
403
424
  }
404
425
  }
405
426