@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
@@ -17,33 +17,30 @@ export class Light {
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
45
42
  (this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
46
- `${accessory.displayName} Light Bulb`;
43
+ `${accessory.displayName} ${device.remoteType}`;
47
44
 
48
45
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
49
46
  // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
@@ -55,26 +52,12 @@ export class Light {
55
52
 
56
53
  // handle on / off events using the On characteristic
57
54
  this.lightBulbService.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
58
-
59
- // handle Brightness events using the Brightness characteristic
60
- /* this.service
61
- .getCharacteristic(this.platform.Characteristic.Brightness)
62
- .on(CharacteristicEventTypes.SET, (value: any, callback: CharacteristicGetCallback) => {
63
- this.debugLog(`${this.device.remoteType} ${this.accessory.displayName} Set Brightness: ${value}`);
64
- this.Brightness = value;
65
- if (value > this.Brightness) {
66
- this.pushLightBrightnessUpChanges();
67
- } else {
68
- this.pushLightBrightnessDownChanges();
69
- }
70
- this.service.updateCharacteristic(this.platform.Characteristic.Active, this.Brightness);
71
- callback(null);
72
- });*/
73
55
  }
74
56
 
75
57
  async OnSet(value: CharacteristicValue): Promise<void> {
76
58
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
77
59
  this.On = value;
60
+ this.accessory.context.On = this.On;
78
61
  if (this.On) {
79
62
  await this.pushLightOnChanges();
80
63
  } else {
@@ -82,15 +65,6 @@ export class Light {
82
65
  }
83
66
  }
84
67
 
85
- async updateHomeKitCharacteristics(): Promise<void> {
86
- if (this.On === undefined) {
87
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
88
- } else {
89
- this.lightBulbService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
90
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
91
- }
92
- }
93
-
94
68
  /**
95
69
  * Pushes the requested changes to the SwitchBot API
96
70
  * deviceType commandType Command command parameter Description
@@ -142,7 +116,7 @@ export class Light {
142
116
  }
143
117
 
144
118
  async pushChanges(body): Promise<void> {
145
- if (this.OpenAPI) {
119
+ if (this.device.connectionType === 'OpenAPI') {
146
120
  try {
147
121
  // Make Push On request to the API
148
122
  const t = Date.now();
@@ -181,19 +155,27 @@ export class Light {
181
155
  req.write(body);
182
156
  req.end();
183
157
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
184
- this.OnCached = this.On;
185
- this.accessory.context.On = this.OnCached;
158
+ this.accessory.context.On = this.On;
186
159
  this.updateHomeKitCharacteristics();
187
160
  } catch (e: any) {
188
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
189
- if (this.deviceLogging.includes('debug')) {
190
- this.errorLog(
191
- `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
192
- + ` Error Message: ${superStringify(e.message)}`,
193
- );
194
- }
195
161
  this.apiError(e);
162
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
163
+ + ` Error Message: ${superStringify(e.message)}`,
164
+ );
196
165
  }
166
+ } else {
167
+ this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
168
+ + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
169
+ }
170
+ }
171
+
172
+ async updateHomeKitCharacteristics(): Promise<void> {
173
+ if (this.On === undefined) {
174
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
175
+ } else {
176
+ this.accessory.context.On = this.On;
177
+ this.lightBulbService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
178
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
197
179
  }
198
180
  }
199
181
 
@@ -230,16 +212,30 @@ export class Light {
230
212
 
231
213
  async apiError(e: any): Promise<void> {
232
214
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, e);
233
- //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
234
215
  }
235
216
 
236
- async openAPI() {
237
- if (!this.device.openAPI) {
238
- this.OpenAPI = true;
217
+ FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
218
+ let FirmwareRevision: string;
219
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
220
+ + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
221
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
222
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
223
+ if (accessory.context.FirmwareRevision) {
224
+ FirmwareRevision = accessory.context.FirmwareRevision;
225
+ } else if (device.firmware) {
226
+ FirmwareRevision = device.firmware;
227
+ } else {
228
+ FirmwareRevision = this.platform.version;
229
+ }
230
+ return FirmwareRevision;
231
+ }
232
+
233
+ async context() {
234
+ if (this.On === undefined) {
235
+ this.On = false;
239
236
  } else {
240
- this.OpenAPI = this.device.openAPI;
237
+ this.On = this.accessory.context.On;
241
238
  }
242
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
243
239
  }
244
240
 
245
241
  async config(device: irdevice & irDevicesConfig): Promise<void> {
@@ -250,8 +246,8 @@ export class Light {
250
246
  if (device.logging !== undefined) {
251
247
  config['logging'] = device.logging;
252
248
  }
253
- if (device.openAPI !== undefined) {
254
- config['openAPI'] = device.openAPI;
249
+ if (device.connectionType !== undefined) {
250
+ config['connectionType'] = device.connectionType;
255
251
  }
256
252
  if (Object.entries(config).length !== 0) {
257
253
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
@@ -17,30 +17,27 @@ export class Others {
17
17
 
18
18
  // Characteristic Values
19
19
  Active!: CharacteristicValue;
20
- ActiveCached!: CharacteristicValue;
21
20
 
22
21
  // Config
23
22
  deviceLogging!: string;
24
23
  otherDeviceType?: string;
25
- OpenAPI?: boolean;
26
24
 
27
25
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
28
26
  // default placeholders
29
27
  this.logs(device);
30
28
  this.deviceType(device);
31
29
  this.config(device);
32
- if (this.Active === undefined) {
33
- this.Active = this.platform.Characteristic.Active.INACTIVE;
34
- } else {
35
- this.Active = this.accessory.context.Active;
36
- }
30
+ this.context();
37
31
 
38
32
  // set accessory information
39
33
  accessory
40
34
  .getService(this.platform.Service.AccessoryInformation)!
41
35
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
42
36
  .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
43
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
37
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
38
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
39
+ .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
40
+ .updateValue(this.FirmwareRevision(accessory, device));
44
41
 
45
42
  // get the Television service if it exists, otherwise create a new Television service
46
43
  // you can create multiple services for each accessory
@@ -67,23 +64,13 @@ export class Others {
67
64
 
68
65
  async ActiveSet(value: CharacteristicValue): Promise<void> {
69
66
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
67
+ this.Active = value;
68
+ this.accessory.context.Active = this.Active;
70
69
  if (value) {
71
70
  await this.pushOnChanges();
72
71
  } else {
73
72
  await this.pushOffChanges();
74
73
  }
75
- this.Active = value;
76
- this.ActiveCached = this.Active;
77
- this.accessory.context.Active = this.ActiveCached;
78
- }
79
-
80
- async updateHomeKitCharacteristics(): Promise<void> {
81
- if (this.Active === undefined) {
82
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
83
- } else {
84
- this.fanService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
85
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
86
- }
87
74
  }
88
75
 
89
76
  /**
@@ -143,7 +130,7 @@ export class Others {
143
130
  }
144
131
 
145
132
  async pushChanges(body): Promise<void> {
146
- if (this.OpenAPI) {
133
+ if (this.device.connectionType === 'OpenAPI') {
147
134
  try {
148
135
  // Make Push On request to the API
149
136
  const t = Date.now();
@@ -170,7 +157,7 @@ export class Others {
170
157
  },
171
158
  };
172
159
  const req = https.request(options, res => {
173
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
160
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges statusCode: ${res.statusCode}`);
174
161
  this.statusCode({ res });
175
162
  res.on('data', d => {
176
163
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} d: ${d}`);
@@ -184,15 +171,23 @@ export class Others {
184
171
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
185
172
  this.updateHomeKitCharacteristics();
186
173
  } catch (e: any) {
187
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
188
- if (this.deviceLogging.includes('debug')) {
189
- this.errorLog(
190
- `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
191
- + ` Error Message: ${superStringify(e.message)}`,
192
- );
193
- }
194
174
  this.apiError(e);
175
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
176
+ + ` Error Message: ${superStringify(e.message)}`,
177
+ );
195
178
  }
179
+ } else {
180
+ this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
181
+ + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
182
+ }
183
+ }
184
+
185
+ async updateHomeKitCharacteristics(): Promise<void> {
186
+ if (this.Active === undefined) {
187
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
188
+ } else {
189
+ this.fanService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
190
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
196
191
  }
197
192
  }
198
193
 
@@ -243,13 +238,28 @@ export class Others {
243
238
  }
244
239
  }
245
240
 
246
- async openAPI() {
247
- if (!this.device.openAPI) {
248
- this.OpenAPI = true;
241
+ FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
242
+ let FirmwareRevision: string;
243
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
244
+ + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
245
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
246
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
247
+ if (accessory.context.FirmwareRevision) {
248
+ FirmwareRevision = accessory.context.FirmwareRevision;
249
+ } else if (device.firmware) {
250
+ FirmwareRevision = device.firmware;
249
251
  } else {
250
- this.OpenAPI = this.device.openAPI;
252
+ FirmwareRevision = this.platform.version;
253
+ }
254
+ return FirmwareRevision;
255
+ }
256
+
257
+ async context() {
258
+ if (this.Active === undefined) {
259
+ this.Active = this.platform.Characteristic.Active.INACTIVE;
260
+ } else {
261
+ this.Active = this.accessory.context.Active;
251
262
  }
252
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
253
263
  }
254
264
 
255
265
  async config(device: irdevice & irDevicesConfig): Promise<void> {
@@ -260,8 +270,8 @@ export class Others {
260
270
  if (device.logging !== undefined) {
261
271
  config['logging'] = device.logging;
262
272
  }
263
- if (device.openAPI !== undefined) {
264
- config['openAPI'] = device.openAPI;
273
+ if (device.connectionType !== undefined) {
274
+ config['connectionType'] = device.connectionType;
265
275
  }
266
276
  if (Object.entries(config).length !== 0) {
267
277
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
@@ -18,7 +18,6 @@ export class TV {
18
18
 
19
19
  // Characteristic Values
20
20
  Active!: CharacteristicValue;
21
- ActiveCached!: CharacteristicValue;
22
21
  ActiveIdentifier!: CharacteristicValue;
23
22
 
24
23
  // Others
@@ -26,17 +25,12 @@ export class TV {
26
25
 
27
26
  // Config
28
27
  deviceLogging!: string;
29
- OpenAPI?: boolean;
30
28
 
31
29
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
32
30
  // default placeholders
33
31
  this.logs(device);
34
32
  this.config(device);
35
- if (this.Active === undefined) {
36
- this.Active = this.platform.Characteristic.Active.INACTIVE;
37
- } else {
38
- this.Active = this.accessory.context.Active;
39
- }
33
+ this.context();
40
34
 
41
35
  // set accessory information
42
36
  accessory
@@ -44,7 +38,10 @@ export class TV {
44
38
  .setCharacteristic(this.platform.Characteristic.Name, `${device.deviceName} ${device.remoteType}`)
45
39
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
46
40
  .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
47
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
41
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
42
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
43
+ .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
44
+ .updateValue(this.FirmwareRevision(accessory, device));
48
45
 
49
46
  // set the accessory category
50
47
  switch (device.remoteType) {
@@ -196,46 +193,31 @@ export class TV {
196
193
  async ActiveIdentifierSet(value: CharacteristicValue): Promise<void> {
197
194
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${value}`);
198
195
  this.ActiveIdentifier = value;
196
+ this.accessory.context.ActiveIdentifier = this.ActiveIdentifier;
199
197
  }
200
198
 
201
199
  async ActiveSet(value: CharacteristicValue): Promise<void> {
202
200
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${value}`);
201
+ this.Active = value;
202
+ this.accessory.context.Active = this.Active;
203
203
  if (!this.device.irtv?.disable_power) {
204
204
  if (value === this.platform.Characteristic.Active.INACTIVE) {
205
205
  await this.pushTvOffChanges();
206
206
  } else {
207
207
  await this.pushTvOnChanges();
208
208
  }
209
- this.Active = value;
210
- this.ActiveCached = this.Active;
211
- this.accessory.context.Active = this.ActiveCached;
212
- }
213
- }
214
-
215
- async updateHomeKitCharacteristics(): Promise<void> {
216
- if (this.Active === undefined) {
217
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
218
- } else {
219
- this.tvService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
220
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
221
- }
222
- if (this.ActiveIdentifier === undefined) {
223
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${this.ActiveIdentifier}`);
224
- } else {
225
- this.tvService?.updateCharacteristic(this.platform.Characteristic.ActiveIdentifier, this.ActiveIdentifier);
226
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic ActiveIdentifier: ${this.ActiveIdentifier}`);
227
209
  }
228
210
  }
229
211
 
230
212
  /**
231
213
  * Pushes the requested changes to the SwitchBot API
232
- * deviceType commandType Command command parameter Description
233
- * TV - "command" "turnOff" "default" = set to OFF state
234
- * TV - "command" "turnOn" "default" = set to ON state
235
- * TV - "command" "volumeAdd" "default" = volume up
236
- * TV - "command" "volumeSub" "default" = volume down
237
- * TV - "command" "channelAdd" "default" = next channel
238
- * TV - "command" "channelSub" "default" = previous channel
214
+ * deviceType commandType Command Parameter Description
215
+ * TV "command" "turnOff" "default" set to OFF state
216
+ * TV "command" "turnOn" "default" set to ON state
217
+ * TV "command" "volumeAdd" "default" volume up
218
+ * TV "command" "volumeSub" "default" volume down
219
+ * TV "command" "channelAdd" "default" next channel
220
+ * TV "command" "channelSub" "default" previous channel
239
221
  */
240
222
  async pushTvOnChanges(): Promise<void> {
241
223
  if (this.Active !== 1) {
@@ -339,7 +321,7 @@ export class TV {
339
321
  }
340
322
 
341
323
  async pushTVChanges(body): Promise<void> {
342
- if (this.OpenAPI) {
324
+ if (this.device.connectionType === 'OpenAPI') {
343
325
  {
344
326
  try {
345
327
  // Make Push On request to the API
@@ -367,7 +349,7 @@ export class TV {
367
349
  },
368
350
  };
369
351
  const req = https.request(options, res => {
370
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
352
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges statusCode: ${res.statusCode}`);
371
353
  this.statusCode({ res });
372
354
  res.on('data', d => {
373
355
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} d: ${d}`);
@@ -381,15 +363,32 @@ export class TV {
381
363
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
382
364
  this.updateHomeKitCharacteristics();
383
365
  } catch (e: any) {
384
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
385
- if (this.deviceLogging.includes('debug')) {
386
- this.errorLog(
387
- `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
388
- ` Error Message: ${superStringify(e.message)}`,
389
- );
390
- }
391
366
  this.apiError(e);
392
- }}
367
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
368
+ + ` Error Message: ${superStringify(e.message)}`,
369
+ );
370
+ }
371
+ }
372
+ } else {
373
+ this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
374
+ + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
375
+ }
376
+ }
377
+
378
+ async updateHomeKitCharacteristics(): Promise<void> {
379
+ if (this.Active === undefined) {
380
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
381
+ } else {
382
+ this.accessory.context.Active = this.Active;
383
+ this.tvService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
384
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
385
+ }
386
+ if (this.ActiveIdentifier === undefined) {
387
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${this.ActiveIdentifier}`);
388
+ } else {
389
+ this.accessory.context.ActiveIdentifier = this.ActiveIdentifier;
390
+ this.tvService?.updateCharacteristic(this.platform.Characteristic.ActiveIdentifier, this.ActiveIdentifier);
391
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic ActiveIdentifier: ${this.ActiveIdentifier}`);
393
392
  }
394
393
  }
395
394
 
@@ -428,16 +427,30 @@ export class TV {
428
427
  async apiError(e: any): Promise<void> {
429
428
  this.tvService.updateCharacteristic(this.platform.Characteristic.Active, e);
430
429
  this.tvService.updateCharacteristic(this.platform.Characteristic.ActiveIdentifier, e);
431
- //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
432
430
  }
433
431
 
434
- async openAPI() {
435
- if (!this.device.openAPI) {
436
- this.OpenAPI = true;
432
+ FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
433
+ let FirmwareRevision: string;
434
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
435
+ + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
436
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
437
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
438
+ if (accessory.context.FirmwareRevision) {
439
+ FirmwareRevision = accessory.context.FirmwareRevision;
440
+ } else if (device.firmware) {
441
+ FirmwareRevision = device.firmware;
437
442
  } else {
438
- this.OpenAPI = this.device.openAPI;
443
+ FirmwareRevision = this.platform.version;
444
+ }
445
+ return FirmwareRevision;
446
+ }
447
+
448
+ async context() {
449
+ if (this.Active === undefined) {
450
+ this.Active = this.platform.Characteristic.Active.INACTIVE;
451
+ } else {
452
+ this.Active = this.accessory.context.Active;
439
453
  }
440
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
441
454
  }
442
455
 
443
456
  async config(device: irdevice & irDevicesConfig): Promise<void> {
@@ -448,8 +461,8 @@ export class TV {
448
461
  if (device.logging !== undefined) {
449
462
  config['logging'] = device.logging;
450
463
  }
451
- if (device.openAPI !== undefined) {
452
- config['openAPI'] = device.openAPI;
464
+ if (device.connectionType !== undefined) {
465
+ config['connectionType'] = device.connectionType;
453
466
  }
454
467
  if (Object.entries(config).length !== 0) {
455
468
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);