@switchbot/homebridge-switchbot 2.0.0-beta.19 → 2.0.0-beta.20

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 (112) hide show
  1. package/CHANGELOG.md +6 -1
  2. package/README.md +1 -2
  3. package/config.schema.json +51 -32
  4. package/dist/device/bot.d.ts +32 -29
  5. package/dist/device/bot.d.ts.map +1 -1
  6. package/dist/device/bot.js +549 -575
  7. package/dist/device/bot.js.map +1 -1
  8. package/dist/device/colorbulb.d.ts +33 -15
  9. package/dist/device/colorbulb.d.ts.map +1 -1
  10. package/dist/device/colorbulb.js +426 -341
  11. package/dist/device/colorbulb.js.map +1 -1
  12. package/dist/device/contact.d.ts +16 -9
  13. package/dist/device/contact.d.ts.map +1 -1
  14. package/dist/device/contact.js +246 -208
  15. package/dist/device/contact.js.map +1 -1
  16. package/dist/device/curtain.d.ts +21 -18
  17. package/dist/device/curtain.d.ts.map +1 -1
  18. package/dist/device/curtain.js +449 -449
  19. package/dist/device/curtain.js.map +1 -1
  20. package/dist/device/humidifier.d.ts +22 -20
  21. package/dist/device/humidifier.d.ts.map +1 -1
  22. package/dist/device/humidifier.js +346 -324
  23. package/dist/device/humidifier.js.map +1 -1
  24. package/dist/device/lock.d.ts +22 -10
  25. package/dist/device/lock.d.ts.map +1 -1
  26. package/dist/device/lock.js +257 -178
  27. package/dist/device/lock.js.map +1 -1
  28. package/dist/device/meter.d.ts +21 -14
  29. package/dist/device/meter.d.ts.map +1 -1
  30. package/dist/device/meter.js +287 -239
  31. package/dist/device/meter.js.map +1 -1
  32. package/dist/device/meterplus.d.ts +23 -10
  33. package/dist/device/meterplus.d.ts.map +1 -1
  34. package/dist/device/meterplus.js +308 -190
  35. package/dist/device/meterplus.js.map +1 -1
  36. package/dist/device/motion.d.ts +17 -10
  37. package/dist/device/motion.d.ts.map +1 -1
  38. package/dist/device/motion.js +225 -193
  39. package/dist/device/motion.js.map +1 -1
  40. package/dist/device/plug.d.ts +24 -17
  41. package/dist/device/plug.d.ts.map +1 -1
  42. package/dist/device/plug.js +270 -267
  43. package/dist/device/plug.js.map +1 -1
  44. package/dist/device/striplight.d.ts +36 -14
  45. package/dist/device/striplight.d.ts.map +1 -1
  46. package/dist/device/striplight.js +447 -299
  47. package/dist/device/striplight.js.map +1 -1
  48. package/dist/irdevice/airconditioner.d.ts +7 -14
  49. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  50. package/dist/irdevice/airconditioner.js +177 -169
  51. package/dist/irdevice/airconditioner.js.map +1 -1
  52. package/dist/irdevice/airpurifier.d.ts +3 -5
  53. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  54. package/dist/irdevice/airpurifier.js +72 -57
  55. package/dist/irdevice/airpurifier.js.map +1 -1
  56. package/dist/irdevice/camera.d.ts +3 -4
  57. package/dist/irdevice/camera.d.ts.map +1 -1
  58. package/dist/irdevice/camera.js +47 -33
  59. package/dist/irdevice/camera.js.map +1 -1
  60. package/dist/irdevice/fan.d.ts +3 -4
  61. package/dist/irdevice/fan.d.ts.map +1 -1
  62. package/dist/irdevice/fan.js +66 -48
  63. package/dist/irdevice/fan.js.map +1 -1
  64. package/dist/irdevice/light.d.ts +3 -4
  65. package/dist/irdevice/light.d.ts.map +1 -1
  66. package/dist/irdevice/light.js +48 -47
  67. package/dist/irdevice/light.js.map +1 -1
  68. package/dist/irdevice/other.d.ts +3 -4
  69. package/dist/irdevice/other.d.ts.map +1 -1
  70. package/dist/irdevice/other.js +47 -33
  71. package/dist/irdevice/other.js.map +1 -1
  72. package/dist/irdevice/tv.d.ts +10 -11
  73. package/dist/irdevice/tv.d.ts.map +1 -1
  74. package/dist/irdevice/tv.js +64 -48
  75. package/dist/irdevice/tv.js.map +1 -1
  76. package/dist/irdevice/vacuumcleaner.d.ts +7 -12
  77. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  78. package/dist/irdevice/vacuumcleaner.js +52 -41
  79. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  80. package/dist/irdevice/waterheater.d.ts +6 -11
  81. package/dist/irdevice/waterheater.d.ts.map +1 -1
  82. package/dist/irdevice/waterheater.js +52 -42
  83. package/dist/irdevice/waterheater.js.map +1 -1
  84. package/dist/platform.d.ts +0 -4
  85. package/dist/platform.d.ts.map +1 -1
  86. package/dist/platform.js +44 -66
  87. package/dist/platform.js.map +1 -1
  88. package/dist/settings.d.ts +3 -3
  89. package/dist/settings.d.ts.map +1 -1
  90. package/package.json +7 -6
  91. package/src/device/bot.ts +551 -589
  92. package/src/device/colorbulb.ts +441 -375
  93. package/src/device/contact.ts +249 -213
  94. package/src/device/curtain.ts +452 -461
  95. package/src/device/humidifier.ts +358 -365
  96. package/src/device/lock.ts +263 -179
  97. package/src/device/meter.ts +302 -253
  98. package/src/device/meterplus.ts +319 -194
  99. package/src/device/motion.ts +230 -199
  100. package/src/device/plug.ts +273 -274
  101. package/src/device/striplight.ts +460 -316
  102. package/src/irdevice/airconditioner.ts +181 -183
  103. package/src/irdevice/airpurifier.ts +70 -60
  104. package/src/irdevice/camera.ts +46 -36
  105. package/src/irdevice/fan.ts +64 -49
  106. package/src/irdevice/light.ts +47 -51
  107. package/src/irdevice/other.ts +46 -36
  108. package/src/irdevice/tv.ts +64 -51
  109. package/src/irdevice/vacuumcleaner.ts +52 -45
  110. package/src/irdevice/waterheater.ts +50 -45
  111. package/src/platform.ts +44 -68
  112. package/src/settings.ts +3 -3
@@ -18,13 +18,11 @@ export class AirPurifier {
18
18
  // Characteristic Values
19
19
  Active!: CharacteristicValue;
20
20
  APActive!: CharacteristicValue;
21
- ActiveCached!: CharacteristicValue;
22
21
  CurrentAPTemp!: CharacteristicValue;
23
22
  CurrentAPMode!: CharacteristicValue;
24
23
  RotationSpeed!: CharacteristicValue;
25
24
  CurrentAPFanSpeed!: CharacteristicValue;
26
25
  CurrentTemperature!: CharacteristicValue;
27
- CurrentTemperatureCached!: CharacteristicValue;
28
26
  CurrentAirPurifierState!: CharacteristicValue;
29
27
  CurrentHeaterCoolerState!: CharacteristicValue;
30
28
 
@@ -40,29 +38,22 @@ export class AirPurifier {
40
38
 
41
39
  // Config
42
40
  deviceLogging!: string;
43
- OpenAPI?: boolean;
44
41
 
45
42
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
46
43
  // default placeholders
47
44
  this.logs(device);
48
45
  this.config(device);
49
- if (this.Active === undefined) {
50
- this.Active = this.platform.Characteristic.Active.INACTIVE;
51
- } else {
52
- this.Active = this.accessory.context.Active;
53
- }
54
- if (this.CurrentTemperature === undefined) {
55
- this.CurrentTemperature = 24;
56
- } else {
57
- this.CurrentTemperature = this.accessory.context.CurrentTemperature;
58
- }
46
+ this.context();
59
47
 
60
48
  // set accessory information
61
49
  accessory
62
50
  .getService(this.platform.Service.AccessoryInformation)!
63
51
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
64
52
  .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
65
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
53
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
54
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
55
+ .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
56
+ .updateValue(this.FirmwareRevision(accessory, device));
66
57
 
67
58
  // get the Television service if it exists, otherwise create a new Television service
68
59
  // you can create multiple services for each accessory
@@ -89,39 +80,13 @@ export class AirPurifier {
89
80
 
90
81
  async ActiveSet(value: CharacteristicValue): Promise<void> {
91
82
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
83
+ this.Active = value;
84
+ this.accessory.context.Active = this.Active;
92
85
  if (value === this.platform.Characteristic.Active.INACTIVE) {
93
86
  this.pushAirPurifierOffChanges();
94
87
  } else {
95
88
  this.pushAirPurifierOnChanges();
96
89
  }
97
- this.Active = value;
98
- this.ActiveCached = this.Active;
99
- this.accessory.context.Active = this.ActiveCached;
100
- }
101
-
102
- async updateHomeKitCharacteristics(): Promise<void> {
103
- if (this.Active === undefined) {
104
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
105
- } else {
106
- this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
107
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
108
- }
109
- if (this.CurrentAirPurifierState === undefined) {
110
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
111
- } else {
112
- this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, this.CurrentAirPurifierState);
113
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
114
- + ` updateCharacteristic CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
115
- }
116
- if (this.CurrentHeaterCoolerState === undefined) {
117
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
118
- } else {
119
- this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
120
- this.debugLog(
121
- `${this.device.remoteType}: ${this.accessory.displayName}`
122
- + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
123
- );
124
- }
125
90
  }
126
91
 
127
92
  async TargetAirPurifierStateSet(value: CharacteristicValue): Promise<void> {
@@ -217,7 +182,7 @@ export class AirPurifier {
217
182
  }
218
183
 
219
184
  async pushChanges(body): Promise<void> {
220
- if (this.OpenAPI) {
185
+ if (this.device.connectionType === 'OpenAPI') {
221
186
  try {
222
187
  // Make Push On request to the API
223
188
  const t = Date.now();
@@ -257,18 +222,44 @@ export class AirPurifier {
257
222
  req.end();
258
223
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
259
224
  this.updateHomeKitCharacteristics();
260
- this.CurrentTemperatureCached = this.CurrentTemperature;
261
- this.accessory.context.CurrentTemperature = this.CurrentTemperatureCached;
225
+ this.accessory.context.CurrentTemperature = this.CurrentTemperature;
262
226
  } catch (e: any) {
263
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
264
- if (this.deviceLogging.includes('debug')) {
265
- this.errorLog(
266
- `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
267
- + ` Error Message: ${superStringify(e.message)}`,
268
- );
269
- }
270
227
  this.apiError(e);
228
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
229
+ + ` Error Message: ${superStringify(e.message)}`,
230
+ );
271
231
  }
232
+ } else {
233
+ this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
234
+ + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
235
+ }
236
+ }
237
+
238
+ async updateHomeKitCharacteristics(): Promise<void> {
239
+ if (this.Active === undefined) {
240
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
241
+ } else {
242
+ this.accessory.context.Active = this.Active;
243
+ this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
244
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
245
+ }
246
+ if (this.CurrentAirPurifierState === undefined) {
247
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
248
+ } else {
249
+ this.accessory.context.CurrentAirPurifierState = this.CurrentAirPurifierState;
250
+ this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, this.CurrentAirPurifierState);
251
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
252
+ + ` updateCharacteristic CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
253
+ }
254
+ if (this.CurrentHeaterCoolerState === undefined) {
255
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
256
+ } else {
257
+ this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerState;
258
+ this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
259
+ this.debugLog(
260
+ `${this.device.remoteType}: ${this.accessory.displayName}`
261
+ + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
262
+ );
272
263
  }
273
264
  }
274
265
 
@@ -308,16 +299,35 @@ export class AirPurifier {
308
299
  this.airPurifierService.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, e);
309
300
  this.airPurifierService.updateCharacteristic(this.platform.Characteristic.TargetAirPurifierState, e);
310
301
  this.airPurifierService.updateCharacteristic(this.platform.Characteristic.Active, e);
311
- //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
312
302
  }
313
303
 
314
- async openAPI() {
315
- if (!this.device.openAPI) {
316
- this.OpenAPI = true;
304
+ FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
305
+ let FirmwareRevision: string;
306
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
307
+ + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
308
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
309
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
310
+ if (accessory.context.FirmwareRevision) {
311
+ FirmwareRevision = accessory.context.FirmwareRevision;
312
+ } else if (device.firmware) {
313
+ FirmwareRevision = device.firmware;
317
314
  } else {
318
- this.OpenAPI = this.device.openAPI;
315
+ FirmwareRevision = this.platform.version;
316
+ }
317
+ return FirmwareRevision;
318
+ }
319
+
320
+ private context() {
321
+ if (this.Active === undefined) {
322
+ this.Active = this.platform.Characteristic.Active.INACTIVE;
323
+ } else {
324
+ this.Active = this.accessory.context.Active;
325
+ }
326
+ if (this.CurrentTemperature === undefined) {
327
+ this.CurrentTemperature = 24;
328
+ } else {
329
+ this.CurrentTemperature = this.accessory.context.CurrentTemperature;
319
330
  }
320
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
321
331
  }
322
332
 
323
333
  async config(device: irdevice & irDevicesConfig): Promise<void> {
@@ -328,8 +338,8 @@ export class AirPurifier {
328
338
  if (device.logging !== undefined) {
329
339
  config['logging'] = device.logging;
330
340
  }
331
- if (device.openAPI !== undefined) {
332
- config['openAPI'] = device.openAPI;
341
+ if (device.connectionType !== undefined) {
342
+ config['connectionType'] = device.connectionType;
333
343
  }
334
344
  if (Object.entries(config).length !== 0) {
335
345
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
@@ -17,28 +17,25 @@ export class Camera {
17
17
 
18
18
  // Characteristic Values
19
19
  On!: CharacteristicValue;
20
- OnCached!: CharacteristicValue;
21
20
 
22
21
  // Config
23
22
  deviceLogging!: string;
24
- OpenAPI?: boolean;
25
23
 
26
24
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
27
25
  // default placeholders
28
26
  this.logs(device);
29
27
  this.config(device);
30
- if (this.On === undefined) {
31
- this.On = false;
32
- } else {
33
- this.On = this.accessory.context.On;
34
- }
28
+ this.context();
35
29
 
36
30
  // set accessory information
37
31
  accessory
38
32
  .getService(this.platform.Service.AccessoryInformation)!
39
33
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
40
34
  .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
41
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
35
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
36
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
37
+ .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
38
+ .updateValue(this.FirmwareRevision(accessory, device));
42
39
 
43
40
  // get the Television service if it exists, otherwise create a new Television service
44
41
  // you can create multiple services for each accessory
@@ -60,6 +57,7 @@ export class Camera {
60
57
  async OnSet(value: CharacteristicValue): Promise<void> {
61
58
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
62
59
  this.On = value;
60
+ this.accessory.context.On = this.On;
63
61
  if (this.On) {
64
62
  this.pushOnChanges();
65
63
  } else {
@@ -67,15 +65,6 @@ export class Camera {
67
65
  }
68
66
  }
69
67
 
70
- async updateHomeKitCharacteristics(): Promise<void> {
71
- if (this.On === undefined) {
72
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
73
- } else {
74
- this.switchService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
75
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
76
- }
77
- }
78
-
79
68
  /**
80
69
  * Pushes the requested changes to the SwitchBot API
81
70
  * deviceType commandType Command command parameter Description
@@ -109,7 +98,7 @@ export class Camera {
109
98
  }
110
99
 
111
100
  async pushChanges(body): Promise<void> {
112
- if (this.OpenAPI) {
101
+ if (this.device.connectionType === 'OpenAPI') {
113
102
  try {
114
103
  // Make Push On request to the API
115
104
  const t = Date.now();
@@ -136,7 +125,7 @@ export class Camera {
136
125
  },
137
126
  };
138
127
  const req = https.request(options, res => {
139
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
128
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges statusCode: ${res.statusCode}`);
140
129
  this.statusCode({ res });
141
130
  res.on('data', d => {
142
131
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} d: ${d}`);
@@ -149,18 +138,25 @@ export class Camera {
149
138
  req.end();
150
139
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
151
140
  this.updateHomeKitCharacteristics();
152
- this.OnCached = this.On;
153
- this.accessory.context.On = this.OnCached;
154
141
  } catch (e: any) {
155
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
156
- if (this.deviceLogging.includes('debug')) {
157
- this.errorLog(
158
- `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
159
- + ` Error Message: ${superStringify(e.message)}`,
160
- );
161
- }
162
142
  this.apiError(e);
143
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
144
+ + ` Error Message: ${superStringify(e.message)}`,
145
+ );
163
146
  }
147
+ } else {
148
+ this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
149
+ + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
150
+ }
151
+ }
152
+
153
+ async updateHomeKitCharacteristics(): Promise<void> {
154
+ if (this.On === undefined) {
155
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
156
+ } else {
157
+ this.accessory.context.On = this.On;
158
+ this.switchService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
159
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
164
160
  }
165
161
  }
166
162
 
@@ -197,16 +193,30 @@ export class Camera {
197
193
 
198
194
  async apiError(e: any): Promise<void> {
199
195
  this.switchService.updateCharacteristic(this.platform.Characteristic.On, e);
200
- //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
201
196
  }
202
197
 
203
- async openAPI() {
204
- if (!this.device.openAPI) {
205
- this.OpenAPI = true;
198
+ FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
199
+ let FirmwareRevision: string;
200
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
201
+ + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
202
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
203
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
204
+ if (accessory.context.FirmwareRevision) {
205
+ FirmwareRevision = accessory.context.FirmwareRevision;
206
+ } else if (device.firmware) {
207
+ FirmwareRevision = device.firmware;
208
+ } else {
209
+ FirmwareRevision = this.platform.version;
210
+ }
211
+ return FirmwareRevision;
212
+ }
213
+
214
+ async context() {
215
+ if (this.On === undefined) {
216
+ this.On = false;
206
217
  } else {
207
- this.OpenAPI = this.device.openAPI;
218
+ this.On = this.accessory.context.On;
208
219
  }
209
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
210
220
  }
211
221
 
212
222
  async config(device: irdevice & irDevicesConfig): Promise<void> {
@@ -217,8 +227,8 @@ export class Camera {
217
227
  if (device.logging !== undefined) {
218
228
  config['logging'] = device.logging;
219
229
  }
220
- if (device.openAPI !== undefined) {
221
- config['openAPI'] = device.openAPI;
230
+ if (device.connectionType !== undefined) {
231
+ config['connectionType'] = device.connectionType;
222
232
  }
223
233
  if (Object.entries(config).length !== 0) {
224
234
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
@@ -17,7 +17,6 @@ export class Fan {
17
17
 
18
18
  // Characteristic Values
19
19
  Active!: CharacteristicValue;
20
- ActiveCached!: CharacteristicValue;
21
20
  ActiveIdentifier!: CharacteristicValue;
22
21
  RotationSpeed!: CharacteristicValue;
23
22
  SwingMode!: CharacteristicValue;
@@ -31,24 +30,22 @@ export class Fan {
31
30
  minValue?: number;
32
31
  maxValue?: number;
33
32
  deviceLogging!: string;
34
- OpenAPI?: boolean;
35
33
 
36
34
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
37
35
  // default placeholders
38
36
  this.logs(device);
39
37
  this.config(device);
40
- if (this.Active === undefined) {
41
- this.Active = this.platform.Characteristic.Active.INACTIVE;
42
- } else {
43
- this.Active = this.accessory.context.Active;
44
- }
38
+ this.context();
45
39
 
46
40
  // set accessory information
47
41
  accessory
48
42
  .getService(this.platform.Service.AccessoryInformation)!
49
43
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
50
44
  .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
51
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
45
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
46
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
47
+ .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
48
+ .updateValue(this.FirmwareRevision(accessory, device));
52
49
 
53
50
  // get the Television service if it exists, otherwise create a new Television service
54
51
  // you can create multiple services for each accessory
@@ -131,27 +128,7 @@ export class Fan {
131
128
  await this.pushFanSwingChanges();
132
129
  }
133
130
  this.SwingMode = value;
134
- }
135
-
136
- async updateHomeKitCharacteristics(): Promise<void> {
137
- if (this.Active === undefined) {
138
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
139
- } else {
140
- this.fanService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
141
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
142
- }
143
- if (this.SwingMode === undefined) {
144
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} SwingMode: ${this.SwingMode}`);
145
- } else {
146
- this.fanService?.updateCharacteristic(this.platform.Characteristic.SwingMode, this.SwingMode);
147
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.SwingMode}`);
148
- }
149
- if (this.RotationSpeed === undefined) {
150
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
151
- } else {
152
- this.fanService?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
153
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
154
- }
131
+ this.accessory.context.SwingMode = this.SwingMode;
155
132
  }
156
133
 
157
134
  async RotationSpeedSet(value: CharacteristicValue): Promise<void> {
@@ -165,18 +142,18 @@ export class Fan {
165
142
  this.pushFanSpeedDownChanges();
166
143
  }
167
144
  this.RotationSpeed = value;
145
+ this.accessory.context.RotationSpeed = this.RotationSpeed;
168
146
  }
169
147
 
170
148
  async ActiveSet(value: CharacteristicValue): Promise<void> {
171
149
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${value}`);
150
+ this.Active = value;
151
+ this.accessory.context.Active = this.Active;
172
152
  if (value === this.platform.Characteristic.Active.INACTIVE) {
173
153
  this.pushFanOffChanges();
174
154
  } else {
175
155
  this.pushFanOnChanges();
176
156
  }
177
- this.Active = value;
178
- this.ActiveCached = this.Active;
179
- this.accessory.context.Active = this.ActiveCached;
180
157
  }
181
158
 
182
159
  /**
@@ -236,7 +213,7 @@ export class Fan {
236
213
  }
237
214
 
238
215
  async pushTVChanges(body): Promise<void> {
239
- if (this.OpenAPI) {
216
+ if (this.device.connectionType === 'OpenAPI') {
240
217
  try {
241
218
  // Make Push On request to the API
242
219
  const t = Date.now();
@@ -263,7 +240,7 @@ export class Fan {
263
240
  },
264
241
  };
265
242
  const req = https.request(options, res => {
266
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
243
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges statusCode: ${res.statusCode}`);
267
244
  this.statusCode({ res });
268
245
  res.on('data', d => {
269
246
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} d: ${d}`);
@@ -277,15 +254,38 @@ export class Fan {
277
254
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
278
255
  this.updateHomeKitCharacteristics();
279
256
  } catch (e: any) {
280
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
281
- if (this.deviceLogging.includes('debug')) {
282
- this.errorLog(
283
- `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
284
- + ` Error Message: ${superStringify(e.message)}`,
285
- );
286
- }
287
257
  this.apiError(e);
258
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
259
+ + ` Error Message: ${superStringify(e.message)}`,
260
+ );
288
261
  }
262
+ } else {
263
+ this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
264
+ + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
265
+ }
266
+ }
267
+
268
+ async updateHomeKitCharacteristics(): Promise<void> {
269
+ if (this.Active === undefined) {
270
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
271
+ } else {
272
+ this.accessory.context.Active = this.Active;
273
+ this.fanService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
274
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
275
+ }
276
+ if (this.SwingMode === undefined) {
277
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} SwingMode: ${this.SwingMode}`);
278
+ } else {
279
+ this.accessory.context.SwingMode = this.SwingMode;
280
+ this.fanService?.updateCharacteristic(this.platform.Characteristic.SwingMode, this.SwingMode);
281
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.SwingMode}`);
282
+ }
283
+ if (this.RotationSpeed === undefined) {
284
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
285
+ } else {
286
+ this.accessory.context.RotationSpeed = this.RotationSpeed;
287
+ this.fanService?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
288
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
289
289
  }
290
290
  }
291
291
 
@@ -324,18 +324,33 @@ export class Fan {
324
324
  this.fanService.updateCharacteristic(this.platform.Characteristic.Active, e);
325
325
  this.fanService.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
326
326
  this.fanService.updateCharacteristic(this.platform.Characteristic.SwingMode, e);
327
- //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
328
327
  }
329
328
 
330
- async openAPI() {
331
- if (!this.device.openAPI) {
332
- this.OpenAPI = true;
329
+ FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
330
+ let FirmwareRevision: string;
331
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
332
+ + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
333
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
334
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
335
+ if (accessory.context.FirmwareRevision) {
336
+ FirmwareRevision = accessory.context.FirmwareRevision;
337
+ } else if (device.firmware) {
338
+ FirmwareRevision = device.firmware;
339
+ } else {
340
+ FirmwareRevision = this.platform.version;
341
+ }
342
+ return FirmwareRevision;
343
+ }
344
+
345
+ async context() {
346
+ if (this.Active === undefined) {
347
+ this.Active = this.platform.Characteristic.Active.INACTIVE;
333
348
  } else {
334
- this.OpenAPI = this.device.openAPI;
349
+ this.Active = this.accessory.context.Active;
335
350
  }
336
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
337
351
  }
338
352
 
353
+
339
354
  async config(device: irdevice & irDevicesConfig): Promise<void> {
340
355
  let config = {};
341
356
  if (device.irfan) {
@@ -344,8 +359,8 @@ export class Fan {
344
359
  if (device.logging !== undefined) {
345
360
  config['logging'] = device.logging;
346
361
  }
347
- if (device.openAPI !== undefined) {
348
- config['openAPI'] = device.openAPI;
362
+ if (device.connectionType !== undefined) {
363
+ config['connectionType'] = device.connectionType;
349
364
  }
350
365
  if (Object.entries(config).length !== 0) {
351
366
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);