@switchbot/homebridge-switchbot 1.4.1-beta.2 → 1.4.1-beta.6

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 (88) hide show
  1. package/CHANGELOG.md +13 -7
  2. package/config.schema.json +1 -1
  3. package/dist/devices/bots.d.ts +1 -1
  4. package/dist/devices/bots.d.ts.map +1 -1
  5. package/dist/devices/bots.js +32 -17
  6. package/dist/devices/bots.js.map +1 -1
  7. package/dist/devices/colorbulb.d.ts +1 -1
  8. package/dist/devices/colorbulb.d.ts.map +1 -1
  9. package/dist/devices/colorbulb.js +28 -8
  10. package/dist/devices/colorbulb.js.map +1 -1
  11. package/dist/devices/contact.d.ts +1 -1
  12. package/dist/devices/contact.d.ts.map +1 -1
  13. package/dist/devices/contact.js +30 -4
  14. package/dist/devices/contact.js.map +1 -1
  15. package/dist/devices/curtains.d.ts +1 -1
  16. package/dist/devices/curtains.d.ts.map +1 -1
  17. package/dist/devices/curtains.js +35 -7
  18. package/dist/devices/curtains.js.map +1 -1
  19. package/dist/devices/humidifiers.d.ts +1 -1
  20. package/dist/devices/humidifiers.d.ts.map +1 -1
  21. package/dist/devices/humidifiers.js +35 -9
  22. package/dist/devices/humidifiers.js.map +1 -1
  23. package/dist/devices/meters.d.ts +1 -1
  24. package/dist/devices/meters.d.ts.map +1 -1
  25. package/dist/devices/meters.js +27 -4
  26. package/dist/devices/meters.js.map +1 -1
  27. package/dist/devices/motion.d.ts +1 -1
  28. package/dist/devices/motion.d.ts.map +1 -1
  29. package/dist/devices/motion.js +25 -4
  30. package/dist/devices/motion.js.map +1 -1
  31. package/dist/devices/plugs.d.ts +1 -1
  32. package/dist/devices/plugs.d.ts.map +1 -1
  33. package/dist/devices/plugs.js +20 -4
  34. package/dist/devices/plugs.js.map +1 -1
  35. package/dist/irdevices/airconditioners.d.ts +30 -14
  36. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  37. package/dist/irdevices/airconditioners.js +292 -152
  38. package/dist/irdevices/airconditioners.js.map +1 -1
  39. package/dist/irdevices/airpurifiers.d.ts +1 -1
  40. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  41. package/dist/irdevices/airpurifiers.js +7 -3
  42. package/dist/irdevices/airpurifiers.js.map +1 -1
  43. package/dist/irdevices/cameras.d.ts +1 -1
  44. package/dist/irdevices/cameras.d.ts.map +1 -1
  45. package/dist/irdevices/cameras.js +4 -3
  46. package/dist/irdevices/cameras.js.map +1 -1
  47. package/dist/irdevices/fans.d.ts +1 -1
  48. package/dist/irdevices/fans.d.ts.map +1 -1
  49. package/dist/irdevices/fans.js +6 -3
  50. package/dist/irdevices/fans.js.map +1 -1
  51. package/dist/irdevices/lights.d.ts +1 -1
  52. package/dist/irdevices/lights.d.ts.map +1 -1
  53. package/dist/irdevices/lights.js +4 -3
  54. package/dist/irdevices/lights.js.map +1 -1
  55. package/dist/irdevices/others.d.ts +1 -1
  56. package/dist/irdevices/others.d.ts.map +1 -1
  57. package/dist/irdevices/others.js +4 -3
  58. package/dist/irdevices/others.js.map +1 -1
  59. package/dist/irdevices/tvs.d.ts +1 -1
  60. package/dist/irdevices/tvs.d.ts.map +1 -1
  61. package/dist/irdevices/tvs.js +5 -3
  62. package/dist/irdevices/tvs.js.map +1 -1
  63. package/dist/irdevices/vacuumcleaners.d.ts +1 -1
  64. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  65. package/dist/irdevices/vacuumcleaners.js +4 -3
  66. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  67. package/dist/irdevices/waterheaters.d.ts +1 -1
  68. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  69. package/dist/irdevices/waterheaters.js +4 -3
  70. package/dist/irdevices/waterheaters.js.map +1 -1
  71. package/package.json +10 -6
  72. package/src/devices/bots.ts +32 -18
  73. package/src/devices/colorbulb.ts +29 -9
  74. package/src/devices/contact.ts +31 -5
  75. package/src/devices/curtains.ts +35 -7
  76. package/src/devices/humidifiers.ts +36 -10
  77. package/src/devices/meters.ts +28 -5
  78. package/src/devices/motion.ts +26 -5
  79. package/src/devices/plugs.ts +21 -5
  80. package/src/irdevices/airconditioners.ts +301 -160
  81. package/src/irdevices/airpurifiers.ts +8 -4
  82. package/src/irdevices/cameras.ts +5 -4
  83. package/src/irdevices/fans.ts +7 -4
  84. package/src/irdevices/lights.ts +5 -4
  85. package/src/irdevices/others.ts +4 -3
  86. package/src/irdevices/tvs.ts +6 -4
  87. package/src/irdevices/vacuumcleaners.ts +5 -4
  88. package/src/irdevices/waterheaters.ts +5 -4
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { SwitchBotPlatform } from '../platform';
3
3
  import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
- import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
4
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -16,12 +16,17 @@ export class AirConditioner {
16
16
  Active!: CharacteristicValue;
17
17
  ActiveCached!: CharacteristicValue;
18
18
  RotationSpeed!: CharacteristicValue;
19
- LastTemperature!: CharacteristicValue;
19
+ RotationSpeedCached!: CharacteristicValue;
20
20
  CurrentTemperature!: CharacteristicValue;
21
21
  CurrentTemperatureCached!: CharacteristicValue;
22
- TargetHeaterCoolerState?: CharacteristicValue;
22
+ TargetHeaterCoolerState!: CharacteristicValue;
23
+ TargetHeaterCoolerStateCached!: CharacteristicValue;
23
24
  CurrentHeaterCoolerState!: CharacteristicValue;
24
- HeatingThresholdTemperature?: CharacteristicValue;
25
+ CurrentHeaterCoolerStateCached!: CharacteristicValue;
26
+ HeatingThresholdTemperature!: CharacteristicValue;
27
+ HeatingThresholdTemperatureCached!: CharacteristicValue;
28
+ CoolingThresholdTemperature!: CharacteristicValue;
29
+ CoolingThresholdTemperatureCached!: CharacteristicValue;
25
30
 
26
31
  // Others
27
32
  state!: string;
@@ -36,6 +41,7 @@ export class AirConditioner {
36
41
 
37
42
  // Config
38
43
  deviceLogging!: string;
44
+ hide_automode?: boolean;
39
45
 
40
46
  constructor(
41
47
  private readonly platform: SwitchBotPlatform,
@@ -54,6 +60,13 @@ export class AirConditioner {
54
60
  } else {
55
61
  this.CurrentTemperature = this.accessory.context.CurrentTemperature;
56
62
  }
63
+ if (device.irair?.hide_automode) {
64
+ this.hide_automode = device.irair?.hide_automode;
65
+ this.accessory.context.hide_automode = this.hide_automode;
66
+ } else {
67
+ this.hide_automode = device.irair?.hide_automode;
68
+ this.accessory.context.hide_automode = this.hide_automode;
69
+ }
57
70
 
58
71
  // set accessory information
59
72
  accessory
@@ -86,25 +99,35 @@ export class AirConditioner {
86
99
  maxValue: 100,
87
100
  minStep: 0.01,
88
101
  })
89
- .onGet((value: CharacteristicValue) => {
90
- return this.CurrentTemperatureGet(value);
102
+ .onGet(() => {
103
+ return this.CurrentTemperatureGet();
91
104
  });
92
105
 
93
- if (device.irair?.hide_automode) {
106
+ if (this.hide_automode) {
107
+ this.TargetHeaterCoolerState = 1 || 2;
94
108
  this.ValidValues = [1, 2];
109
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} ValidValues: ${JSON.stringify(this.ValidValues)},`
110
+ + ` hide_automode: ${this.hide_automode}, TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
95
111
  } else {
112
+ this.TargetHeaterCoolerState = 0 || 1 || 2;
96
113
  this.ValidValues = [0, 1, 2];
114
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} ValidValues: ${JSON.stringify(this.ValidValues)},`
115
+ + ` hide_automode: ${this.hide_automode}, TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
97
116
  }
98
117
  this.service
99
118
  .getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState)
100
119
  .setProps({
101
120
  validValues: this.ValidValues,
102
121
  })
122
+ .onGet(async () => {
123
+ return this.TargetHeaterCoolerStateGet();
124
+ })
103
125
  .onSet(this.TargetHeaterCoolerStateSet.bind(this));
104
126
 
105
- this.service.getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState).onGet(async () => {
106
- return this.CurrentHeaterCoolerStateGet();
107
- });
127
+ this.service.getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState)
128
+ .onGet(async () => {
129
+ return this.CurrentHeaterCoolerStateGet();
130
+ });
108
131
 
109
132
  this.service
110
133
  .getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature)
@@ -126,9 +149,9 @@ export class AirConditioner {
126
149
  minStep: 1,
127
150
  })
128
151
  .onGet(() => {
129
- return this.HeatingThresholdTemperatureGet();
152
+ return this.CoolingThresholdTemperatureGet();
130
153
  })
131
- .onSet(this.HeatingThresholdTemperatureSet.bind(this));
154
+ .onSet(this.CoolingThresholdTemperatureSet.bind(this));
132
155
 
133
156
  this.service
134
157
  .getCharacteristic(this.platform.Characteristic.RotationSpeed)
@@ -153,138 +176,6 @@ export class AirConditioner {
153
176
  }
154
177
  }
155
178
 
156
- private RotationSpeedSet(value: CharacteristicValue) {
157
- if (value === 4) {
158
- this.CurrentFanSpeed = 1;
159
- } else {
160
- this.CurrentFanSpeed = Number(value) + 1;
161
- }
162
- this.pushAirConditionerStatusChanges();
163
- this.RotationSpeed = this.CurrentFanSpeed || 1;
164
- }
165
-
166
- private RotationSpeedGet() {
167
- if (!this.CurrentFanSpeed || this.CurrentFanSpeed === 1) {
168
- this.RotationSpeed = 4;
169
- } else {
170
- this.RotationSpeed = this.CurrentFanSpeed - 1;
171
- }
172
- return this.RotationSpeed;
173
- }
174
-
175
- private ActiveSet(value: CharacteristicValue) {
176
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set Active: ${value}`);
177
-
178
- if (value === this.platform.Characteristic.Active.INACTIVE) {
179
- this.pushAirConditionerOffChanges();
180
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
181
- } else {
182
- this.pushAirConditionerOnChanges();
183
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
184
- }
185
- this.Active = value;
186
- this.ActiveCached = this.Active;
187
- this.accessory.context.Active = this.ActiveCached;
188
- }
189
-
190
- private updateHomeKitCharacteristics() {
191
- if (this.Active === undefined) {
192
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Active: ${this.Active}`);
193
- } else {
194
- this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
195
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
196
- }
197
- if (this.RotationSpeed === undefined) {
198
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
199
- } else {
200
- this.service?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
201
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
202
- }
203
- if (this.CurrentTemperature === undefined) {
204
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
205
- } else {
206
- this.service?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
207
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
208
- }
209
- if (this.TargetHeaterCoolerState === undefined) {
210
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
211
- } else {
212
- this.service?.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.TargetHeaterCoolerState);
213
- this.debugLog(`Air Conditioner: ${this.accessory.displayName}`
214
- + ` updateCharacteristic TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
215
- }
216
- if (this.CurrentHeaterCoolerState === undefined) {
217
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
218
- } else {
219
- this.service?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
220
- this.debugLog(`Air Conditioner: ${this.accessory.displayName}`
221
- + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
222
- }
223
- if (this.HeatingThresholdTemperature === undefined) {
224
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
225
- } else {
226
- this.service?.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, this.HeatingThresholdTemperature);
227
- this.debugLog(`Air Conditioner: ${this.accessory.displayName}`
228
- + ` updateCharacteristic HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
229
- }
230
- }
231
-
232
- private CurrentTemperatureGet(value: CharacteristicValue) {
233
- value = Number(this.CurrentTemperature) || 24;
234
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Trigger Get CurrentTemperature: ${value}`);
235
-
236
- this.service
237
- .getCharacteristic(this.platform.Characteristic.CurrentTemperature)
238
- .updateValue(value);
239
-
240
- return value;
241
- }
242
-
243
- private TargetHeaterCoolerStateSet(value: CharacteristicValue) {
244
- switch (value) {
245
- case this.platform.Characteristic.TargetHeaterCoolerState.AUTO:
246
- this.CurrentMode = AirConditioner.MODE_AUTO;
247
- break;
248
- case this.platform.Characteristic.TargetHeaterCoolerState.COOL:
249
- this.CurrentMode = AirConditioner.MODE_COOL;
250
- break;
251
- case this.platform.Characteristic.TargetHeaterCoolerState.HEAT:
252
- this.CurrentMode = AirConditioner.MODE_HEAT;
253
- break;
254
- default:
255
- break;
256
- }
257
- this.pushAirConditionerStatusChanges();
258
- }
259
-
260
- private CurrentHeaterCoolerStateGet() {
261
- if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
262
- if ((this.CurrentTemperature || 24) < (this.LastTemperature || 30)) {
263
- this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
264
- } else {
265
- this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
266
- }
267
- } else {
268
- this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
269
- }
270
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
271
- return this.CurrentHeaterCoolerState;
272
- }
273
-
274
- private HeatingThresholdTemperatureGet() {
275
- this.CurrentTemperature = this.CurrentTemperature || 24;
276
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
277
- return this.CurrentTemperature;
278
- }
279
-
280
- private HeatingThresholdTemperatureSet(value: CharacteristicValue) {
281
- this.pushAirConditionerStatusChanges();
282
- this.LastTemperature = Number(this.CurrentTemperature);
283
- this.CurrentTemperature = Number(value);
284
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature},`
285
- + ` LastTemperature: ${this.LastTemperature}`);
286
- }
287
-
288
179
  /**
289
180
  * Pushes the requested changes to the SwitchBot API
290
181
  * deviceType commandType Command command parameter Description
@@ -306,14 +197,12 @@ export class AirConditioner {
306
197
  }
307
198
 
308
199
  async pushAirConditionerOffChanges() {
309
- if (this.Active !== this.platform.Characteristic.Active.INACTIVE) {
310
- const payload = {
311
- commandType: 'command',
312
- parameter: 'default',
313
- command: 'turnOff',
314
- } as any;
315
- await this.pushChanges(payload);
316
- }
200
+ const payload = {
201
+ commandType: 'command',
202
+ parameter: 'default',
203
+ command: 'turnOff',
204
+ } as any;
205
+ await this.pushChanges(payload);
317
206
  }
318
207
 
319
208
  async pushAirConditionerStatusChanges() {
@@ -342,7 +231,6 @@ export class AirConditioner {
342
231
  if (this.CurrentFanSpeed === undefined) {
343
232
  this.CurrentFanSpeed = 1;
344
233
  }
345
- this.Active = this.platform.Characteristic.Active.ACTIVE;
346
234
  if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
347
235
  this.state = 'on';
348
236
  } else {
@@ -352,9 +240,10 @@ export class AirConditioner {
352
240
 
353
241
 
354
242
  if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
355
- if ((this.CurrentTemperature || 24) < (this.LastTemperature || 30)) {
243
+ this.CurrentTemperatureUndefined();
244
+ if (this.CurrentTemperature < this.CurrentTemperatureCached) {
356
245
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
357
- } else {
246
+ } else if (this.CurrentTemperature > this.CurrentTemperatureCached) {
358
247
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
359
248
  }
360
249
  } else {
@@ -371,10 +260,16 @@ export class AirConditioner {
371
260
 
372
261
  // Make the API request
373
262
  const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
374
- this.errorLog(`Air Conditioner: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
263
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
375
264
  this.statusCode(push);
376
265
  this.CurrentTemperatureCached = this.CurrentTemperature;
377
266
  this.accessory.context.CurrentTemperature = this.CurrentTemperatureCached;
267
+ this.HeatingThresholdTemperature = this.CurrentTemperatureCached;
268
+ this.HeatingThresholdTemperatureCached = this.CurrentTemperatureCached;
269
+ this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperatureCached;
270
+ this.CoolingThresholdTemperature = this.CurrentTemperatureCached;
271
+ this.CoolingThresholdTemperatureCached = this.CurrentTemperatureCached;
272
+ this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperatureCached;
378
273
  this.updateHomeKitCharacteristics();
379
274
  } catch (e: any) {
380
275
  this.errorLog(`Air Conditioner: ${this.accessory.displayName} failed pushChanges`);
@@ -386,11 +281,11 @@ export class AirConditioner {
386
281
  this.errorLog(`Air Conditioner: ${this.accessory.displayName} failed pushChanges,`
387
282
  + ` Error: ${JSON.stringify(e)}`);
388
283
  }
389
- this.apiError();
284
+ this.apiError(e);
390
285
  }
391
286
  }
392
287
 
393
- private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
288
+ statusCode(push: AxiosResponse<{ statusCode: number; }>) {
394
289
  switch (push.data.statusCode) {
395
290
  case 151:
396
291
  this.errorLog(`Air Conditioner: ${this.accessory.displayName} Command not supported by this device type.`);
@@ -419,8 +314,254 @@ export class AirConditioner {
419
314
  }
420
315
  }
421
316
 
422
- public apiError() {
423
- throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
317
+ updateHomeKitCharacteristics() {
318
+ if (this.Active === undefined) {
319
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Active: ${this.Active}`);
320
+ } else {
321
+ this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
322
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
323
+ }
324
+ if (this.RotationSpeed === undefined) {
325
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
326
+ } else {
327
+ this.service?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
328
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
329
+ }
330
+ if (this.CurrentTemperature === undefined) {
331
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
332
+ } else {
333
+ this.service?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
334
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
335
+ }
336
+ if (this.TargetHeaterCoolerState === undefined) {
337
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
338
+ } else {
339
+ this.service?.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.TargetHeaterCoolerState);
340
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName}`
341
+ + ` updateCharacteristic TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
342
+ }
343
+ if (this.CurrentHeaterCoolerState === undefined) {
344
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
345
+ } else {
346
+ this.service?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
347
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName}`
348
+ + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
349
+ }
350
+ if (this.HeatingThresholdTemperature === undefined) {
351
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
352
+ } else {
353
+ this.service?.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, this.HeatingThresholdTemperature);
354
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName}`
355
+ + ` updateCharacteristic HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
356
+ }
357
+ if (this.CoolingThresholdTemperature === undefined) {
358
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`);
359
+ } else {
360
+ this.service?.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, this.CoolingThresholdTemperature);
361
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName}`
362
+ + ` updateCharacteristic CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`);
363
+ }
364
+ }
365
+
366
+ public apiError(e: any) {
367
+ this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
368
+ this.service.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
369
+ this.service.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
370
+ this.service.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, e);
371
+ this.service.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, e);
372
+ this.service.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, e);
373
+ this.service.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, e);
374
+ //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
375
+ }
376
+
377
+ CurrentTemperatureGet() {
378
+ if (this.CurrentTemperature === undefined) {
379
+ this.CurrentTemperature = 24;
380
+ this.CurrentTemperatureCached = this.CurrentTemperature;
381
+ } else {
382
+ this.CurrentTemperatureCached = this.CurrentTemperature;
383
+ }
384
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get CurrentTemperature: ${this.CurrentTemperature}`);
385
+ this.accessory.context.CurrentTemperature = this.CurrentTemperatureCached;
386
+ return this.CurrentTemperature;
387
+ }
388
+
389
+ RotationSpeedGet() {
390
+ if (!this.CurrentFanSpeed) {
391
+ this.RotationSpeed = 4;
392
+ } else if (this.CurrentFanSpeed === 1) {
393
+ this.RotationSpeed = 4;
394
+ } else {
395
+ this.RotationSpeed = this.CurrentFanSpeed - 1;
396
+ }
397
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get RotationSpeed: ${this.RotationSpeed}`);
398
+ this.RotationSpeedCached = this.RotationSpeed;
399
+ this.accessory.context.RotationSpeed = this.RotationSpeedCached;
400
+ return this.RotationSpeed;
401
+ }
402
+
403
+ RotationSpeedSet(value: CharacteristicValue) {
404
+ if (value === 4) {
405
+ this.CurrentFanSpeed = 1;
406
+ } else {
407
+ this.CurrentFanSpeed = Number(value) + 1;
408
+ }
409
+ this.RotationSpeed = this.CurrentFanSpeed;
410
+ this.RotationSpeedCached = this.RotationSpeed;
411
+ this.accessory.context.RotationSpeed = this.RotationSpeedCached;
412
+ this.pushAirConditionerStatusChanges();
413
+ }
414
+
415
+ ActiveSet(value: CharacteristicValue) {
416
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set Active: ${value}`);
417
+
418
+ this.Active = value;
419
+ this.ActiveCached = this.Active;
420
+ this.accessory.context.Active = this.ActiveCached;
421
+
422
+ if (value === this.platform.Characteristic.Active.INACTIVE) {
423
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
424
+ this.pushAirConditionerOffChanges();
425
+ } else {
426
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} pushAirConditionerOnChanges, Active: ${this.Active}`);
427
+ this.pushAirConditionerStatusChanges();
428
+ }
429
+ }
430
+
431
+ TargetHeaterCoolerStateGet() {
432
+ if (this.ValidValues === [0, 1, 2]) {
433
+ this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
434
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get (AUTO) TargetHeaterCoolerState: ${this.CurrentHeaterCoolerState},`
435
+ + ` ValidValues: ${this.ValidValues}`);
436
+ } else if (this.ValidValues === [1, 2]) {
437
+ this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.COOL
438
+ || this.platform.Characteristic.TargetHeaterCoolerState.HEAT;
439
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get (COOL/HEAT) TargetHeaterCoolerState: ${this.CurrentHeaterCoolerState},`
440
+ + ` ValidValues: ${this.ValidValues}`);
441
+ } else {
442
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get TargetHeaterCoolerState: ${this.CurrentHeaterCoolerState},`
443
+ + ` ValidValues: ${this.ValidValues}`);
444
+ }
445
+ this.TargetHeaterCoolerStateCached = this.TargetHeaterCoolerState;
446
+ this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerStateCached;
447
+ return this.TargetHeaterCoolerState;
448
+ }
449
+
450
+ TargetHeaterCoolerStateSet(value: CharacteristicValue) {
451
+ if (this.hide_automode) {
452
+ if (value === this.platform.Characteristic.TargetHeaterCoolerState.HEAT) {
453
+ this.TargetHeaterCoolerStateHEAT();
454
+ } else if (value === this.platform.Characteristic.TargetHeaterCoolerState.COOL) {
455
+ this.TargetHeaterCoolerStateCOOL();
456
+ } else {
457
+ this.errorLog(`Air Conditioner: ${this.accessory.displayName} Set TargetHeaterCoolerState: ${this.TargetHeaterCoolerState},`
458
+ + ` hide_automode: ${this.hide_automode} `);
459
+ }
460
+ } else {
461
+ if (value === this.platform.Characteristic.TargetHeaterCoolerState.AUTO) {
462
+ this.TargetHeaterCoolerStateAUTO();
463
+ } else if (value === this.platform.Characteristic.TargetHeaterCoolerState.HEAT) {
464
+ this.TargetHeaterCoolerStateHEAT();
465
+ } else if (value === this.platform.Characteristic.TargetHeaterCoolerState.COOL) {
466
+ this.TargetHeaterCoolerStateCOOL();
467
+ } else {
468
+ this.errorLog(`Air Conditioner: ${this.accessory.displayName} Set TargetHeaterCoolerState: ${this.TargetHeaterCoolerState},`
469
+ + ` hide_automode: ${this.hide_automode} `);
470
+ }
471
+ }
472
+ this.TargetHeaterCoolerStateCached = this.TargetHeaterCoolerState;
473
+ this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerStateCached;
474
+ this.pushAirConditionerStatusChanges();
475
+ }
476
+
477
+ private TargetHeaterCoolerStateAUTO() {
478
+ this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
479
+ this.CurrentMode = 1;
480
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set (AUTO) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
481
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
482
+ }
483
+
484
+ private TargetHeaterCoolerStateCOOL() {
485
+ this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.COOL;
486
+ this.CurrentMode = 2;
487
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set (COOL) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
488
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
489
+ }
490
+
491
+ private TargetHeaterCoolerStateHEAT() {
492
+ this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.HEAT;
493
+ this.CurrentMode = 5;
494
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set (HEAT) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
495
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
496
+ }
497
+
498
+ CurrentHeaterCoolerStateGet() {
499
+ if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
500
+ this.CurrentTemperatureUndefined();
501
+ if (this.CurrentTemperature < this.CurrentTemperatureCached) {
502
+ this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
503
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get (COOLLING) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
504
+ } else if (this.CurrentTemperature > this.CurrentTemperatureCached) {
505
+ this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
506
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get (HEATING) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
507
+ }
508
+ } else {
509
+ this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
510
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get (INACTIVE) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
511
+ }
512
+ this.CurrentHeaterCoolerStateCached = this.CurrentHeaterCoolerState;
513
+ this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerStateCached;
514
+ return this.CurrentHeaterCoolerState;
515
+ }
516
+
517
+ private HeatingThresholdTemperatureGet() {
518
+ this.CurrentTemperatureUndefined;
519
+ this.CurrentTemperature = this.CurrentTemperatureCached;
520
+ this.HeatingThresholdTemperature = this.CurrentTemperatureCached;
521
+ this.HeatingThresholdTemperatureCached = this.HeatingThresholdTemperature;
522
+ this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperatureCached;
523
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
524
+ return this.HeatingThresholdTemperature;
525
+ }
526
+
527
+ private HeatingThresholdTemperatureSet(value: CharacteristicValue) {
528
+ this.CurrentTemperatureCached = this.CurrentTemperature;
529
+ this.CurrentTemperature = value;
530
+ this.HeatingThresholdTemperatureCached = this.HeatingThresholdTemperature;
531
+ this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperatureCached;
532
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set HeatingThresholdTemperature: ${this.HeatingThresholdTemperature},`
533
+ + ` CurrentTemperatureCached: ${this.CurrentTemperatureCached}`);
534
+ this.pushAirConditionerStatusChanges();
535
+ }
536
+
537
+
538
+ private CoolingThresholdTemperatureGet() {
539
+ this.CurrentTemperatureUndefined;
540
+ this.CurrentTemperature = this.CurrentTemperatureCached;
541
+ this.CoolingThresholdTemperature = this.CurrentTemperatureCached;
542
+ this.CoolingThresholdTemperatureCached = this.CoolingThresholdTemperature;
543
+ this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperatureCached;
544
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`);
545
+ return this.CoolingThresholdTemperature;
546
+ }
547
+
548
+ private CoolingThresholdTemperatureSet(value: CharacteristicValue) {
549
+ this.CurrentTemperatureCached = this.CurrentTemperature;
550
+ this.CurrentTemperature = value;
551
+ this.CoolingThresholdTemperatureCached = this.CoolingThresholdTemperature;
552
+ this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperatureCached;
553
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set CoolingThresholdTemperature: ${this.CoolingThresholdTemperature},`
554
+ + ` CurrentTemperatureCached: ${this.CurrentTemperatureCached}`);
555
+ this.pushAirConditionerStatusChanges();
556
+ }
557
+
558
+ private CurrentTemperatureUndefined() {
559
+ if (this.CurrentTemperature === undefined) {
560
+ this.CurrentTemperature = 24;
561
+ }
562
+ if (this.CurrentTemperatureCached === undefined) {
563
+ this.CurrentTemperature = 30;
564
+ }
424
565
  }
425
566
 
426
567
  /**
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { SwitchBotPlatform } from '../platform';
3
3
  import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
- import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
4
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -248,7 +248,7 @@ export class AirPurifier {
248
248
  this.errorLog(`Air Purifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
249
249
  + ` Error: ${JSON.stringify(e)}`);
250
250
  }
251
- this.apiError();
251
+ this.apiError(e);
252
252
  }
253
253
  }
254
254
 
@@ -281,8 +281,12 @@ export class AirPurifier {
281
281
  }
282
282
  }
283
283
 
284
- public apiError() {
285
- throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
284
+ public apiError(e: any) {
285
+ this.service.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, e);
286
+ this.service.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, e);
287
+ this.service.updateCharacteristic(this.platform.Characteristic.TargetAirPurifierState, e);
288
+ this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
289
+ //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
286
290
  }
287
291
 
288
292
  /**
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { SwitchBotPlatform } from '../platform';
3
3
  import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
- import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
4
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -140,7 +140,7 @@ export class Camera {
140
140
  this.errorLog(`Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
141
141
  + ` Error: ${JSON.stringify(e)}`);
142
142
  }
143
- this.apiError();
143
+ this.apiError(e);
144
144
  }
145
145
  }
146
146
 
@@ -173,8 +173,9 @@ export class Camera {
173
173
  }
174
174
  }
175
175
 
176
- public apiError() {
177
- throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
176
+ public apiError(e: any) {
177
+ this.service.updateCharacteristic(this.platform.Characteristic.On, e);
178
+ //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
178
179
  }
179
180
 
180
181
  /**
@@ -1,6 +1,6 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { SwitchBotPlatform } from '../platform';
3
- import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
3
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
4
  import { DeviceURL, irdevice, deviceStatusResponse, irDevicesConfig, payload } from '../settings';
5
5
 
6
6
  /**
@@ -262,7 +262,7 @@ export class Fan {
262
262
  this.errorLog(`Fan: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
263
263
  + ` Error: ${JSON.stringify(e)}`);
264
264
  }
265
- this.apiError();
265
+ this.apiError(e);
266
266
  }
267
267
  }
268
268
 
@@ -295,8 +295,11 @@ export class Fan {
295
295
  }
296
296
  }
297
297
 
298
- public apiError() {
299
- throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
298
+ public apiError(e: any) {
299
+ this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
300
+ this.service.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
301
+ this.service.updateCharacteristic(this.platform.Characteristic.SwingMode, e);
302
+ //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
300
303
  }
301
304
 
302
305
  /**