@switchbot/homebridge-switchbot 1.2.1 → 1.2.4

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 (70) hide show
  1. package/.github/workflows/nodejs.yml +1 -1
  2. package/CHANGELOG.md +23 -1
  3. package/config.schema.json +1 -1
  4. package/dist/devices/bots.d.ts +1 -0
  5. package/dist/devices/bots.d.ts.map +1 -1
  6. package/dist/devices/bots.js +28 -11
  7. package/dist/devices/bots.js.map +1 -1
  8. package/dist/devices/contact.d.ts +1 -0
  9. package/dist/devices/contact.d.ts.map +1 -1
  10. package/dist/devices/contact.js +26 -9
  11. package/dist/devices/contact.js.map +1 -1
  12. package/dist/devices/curtains.d.ts +1 -0
  13. package/dist/devices/curtains.d.ts.map +1 -1
  14. package/dist/devices/curtains.js +25 -8
  15. package/dist/devices/curtains.js.map +1 -1
  16. package/dist/devices/humidifiers.d.ts +1 -0
  17. package/dist/devices/humidifiers.d.ts.map +1 -1
  18. package/dist/devices/humidifiers.js +22 -5
  19. package/dist/devices/humidifiers.js.map +1 -1
  20. package/dist/devices/meters.d.ts +1 -0
  21. package/dist/devices/meters.d.ts.map +1 -1
  22. package/dist/devices/meters.js +24 -13
  23. package/dist/devices/meters.js.map +1 -1
  24. package/dist/devices/motion.d.ts +1 -0
  25. package/dist/devices/motion.d.ts.map +1 -1
  26. package/dist/devices/motion.js +20 -3
  27. package/dist/devices/motion.js.map +1 -1
  28. package/dist/devices/plugs.d.ts +0 -1
  29. package/dist/devices/plugs.d.ts.map +1 -1
  30. package/dist/devices/plugs.js +0 -10
  31. package/dist/devices/plugs.js.map +1 -1
  32. package/dist/irdevices/airconditioners.js +6 -6
  33. package/dist/irdevices/airconditioners.js.map +1 -1
  34. package/dist/irdevices/airpurifiers.js +3 -3
  35. package/dist/irdevices/airpurifiers.js.map +1 -1
  36. package/dist/irdevices/cameras.js +1 -1
  37. package/dist/irdevices/cameras.js.map +1 -1
  38. package/dist/irdevices/fans.js +3 -3
  39. package/dist/irdevices/fans.js.map +1 -1
  40. package/dist/irdevices/lights.js +1 -1
  41. package/dist/irdevices/lights.js.map +1 -1
  42. package/dist/irdevices/others.js +2 -2
  43. package/dist/irdevices/others.js.map +1 -1
  44. package/dist/irdevices/tvs.js +2 -2
  45. package/dist/irdevices/tvs.js.map +1 -1
  46. package/dist/irdevices/vacuumcleaners.js +1 -1
  47. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  48. package/dist/irdevices/waterheaters.js +1 -1
  49. package/dist/irdevices/waterheaters.js.map +1 -1
  50. package/dist/platform.d.ts.map +1 -1
  51. package/dist/platform.js +6 -0
  52. package/dist/platform.js.map +1 -1
  53. package/package.json +1 -1
  54. package/src/devices/bots.ts +28 -11
  55. package/src/devices/contact.ts +26 -9
  56. package/src/devices/curtains.ts +25 -8
  57. package/src/devices/humidifiers.ts +22 -5
  58. package/src/devices/meters.ts +24 -13
  59. package/src/devices/motion.ts +20 -3
  60. package/src/devices/plugs.ts +0 -11
  61. package/src/irdevices/airconditioners.ts +6 -6
  62. package/src/irdevices/airpurifiers.ts +3 -3
  63. package/src/irdevices/cameras.ts +1 -1
  64. package/src/irdevices/fans.ts +3 -3
  65. package/src/irdevices/lights.ts +1 -1
  66. package/src/irdevices/others.ts +2 -2
  67. package/src/irdevices/tvs.ts +2 -2
  68. package/src/irdevices/vacuumcleaners.ts +1 -1
  69. package/src/irdevices/waterheaters.ts +1 -1
  70. package/src/platform.ts +6 -0
@@ -29,6 +29,7 @@ export class Humidifier {
29
29
  deviceStatus!: deviceStatusResponse;
30
30
 
31
31
  // BLE Others
32
+ connected?: boolean;
32
33
  serviceData!: serviceData;
33
34
  onState!: serviceData['onState'];
34
35
  autoMode!: serviceData['autoMode'];
@@ -315,14 +316,30 @@ export class Humidifier {
315
316
  this.platform.device(`Humidifier: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
316
317
  this.platform.device(`Humidifier: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},`
317
318
  + `autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`);
319
+
320
+ if (this.serviceData) {
321
+ this.connected = true;
322
+ this.platform.device(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
323
+ } else {
324
+ this.connected = false;
325
+ this.platform.device(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
326
+ }
318
327
  };
319
328
  // Wait 10 seconds
320
329
  return switchbot.wait(10000);
321
- }).then(() => {
330
+ }).then(async () => {
322
331
  // Stop to monitor
323
332
  switchbot.stopScan();
324
- this.parseStatus();
325
- this.updateHomeKitCharacteristics();
333
+ if (this.connected) {
334
+ this.parseStatus();
335
+ this.updateHomeKitCharacteristics();
336
+ } else {
337
+ this.platform.log.error(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
338
+ if (this.platform.config.credentials?.openToken) {
339
+ this.platform.log.warn(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
340
+ await this.openAPIRefreshStatus();
341
+ }
342
+ }
326
343
  }).catch(async (e: any) => {
327
344
  this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
328
345
  if (this.deviceDebug) {
@@ -578,7 +595,7 @@ export class Humidifier {
578
595
  if (this.CurrentTemperature === undefined) {
579
596
  this.platform.debug(`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
580
597
  } else {
581
- this.temperatureservice!.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
598
+ this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
582
599
  this.platform.device(`Humidifier: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
583
600
  }
584
601
  }
@@ -594,7 +611,7 @@ export class Humidifier {
594
611
  this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
595
612
  this.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, e);
596
613
  if (!this.device.humidifier?.hide_temperature && !this.device.ble) {
597
- this.temperatureservice!.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
614
+ this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
598
615
  }
599
616
  }
600
617
 
@@ -29,6 +29,7 @@ export class Meter {
29
29
  deviceStatus!: deviceStatusResponse;
30
30
 
31
31
  // BLE Others
32
+ connected?: boolean;
32
33
  switchbot!: switchbot;
33
34
  serviceData!: serviceData;
34
35
  battery!: serviceData['battery'];
@@ -191,19 +192,13 @@ export class Meter {
191
192
  // Current Temperature
192
193
  if (!this.device.meter?.hide_temperature) {
193
194
  if (this.device.meter?.unit === 1) {
194
- this.CurrentTemperature = Number(this.temperature?.f);
195
+ this.CurrentTemperature = this.toFahrenheit(this.temperature!.c);
195
196
  } else if (this.device.meter?.unit === 0) {
196
- this.CurrentTemperature = Number(this.temperature?.c);
197
+ this.CurrentTemperature = this.toCelsius(this.temperature!.c);
197
198
  } else {
198
- if (this.fahrenheit) {
199
- this.CurrentTemperature = Number(this.temperature?.f);
200
- } else {
201
- this.CurrentTemperature = Number(this.temperature?.c);
202
- }
199
+ this.CurrentTemperature = Number(this.temperature?.c);
203
200
  }
204
-
205
- this.CurrentTemperature = Number();
206
- this.platform.debug(`Meter: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c, fahrenheit: ${this.fahrenheit}`);
201
+ this.platform.debug(`Meter: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
207
202
  }
208
203
  }
209
204
 
@@ -278,14 +273,30 @@ export class Meter {
278
273
  this.platform.device(`Meter: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, `
279
274
  + `temperature: ${JSON.stringify(ad.serviceData.temperature)}, fahrenheit: ${ad.serviceData.fahrenheit}, `
280
275
  + `humidity: ${ad.serviceData.humidity}, battery: ${ad.serviceData.battery}`);
276
+
277
+ if (this.serviceData) {
278
+ this.connected = true;
279
+ this.platform.device(`Meter: ${this.accessory.displayName} connected: ${this.connected}`);
280
+ } else {
281
+ this.connected = false;
282
+ this.platform.device(`Meter: ${this.accessory.displayName} connected: ${this.connected}`);
283
+ }
281
284
  };
282
285
  // Wait 10 seconds
283
286
  return switchbot.wait(10000);
284
- }).then(() => {
287
+ }).then(async () => {
285
288
  // Stop to monitor
286
289
  switchbot.stopScan();
287
- this.parseStatus();
288
- this.updateHomeKitCharacteristics();
290
+ if (this.connected) {
291
+ this.parseStatus();
292
+ this.updateHomeKitCharacteristics();
293
+ } else {
294
+ this.platform.log.error(`Meter: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
295
+ if (this.platform.config.credentials?.openToken) {
296
+ this.platform.log.warn(`Meter: ${this.accessory.displayName} Using OpenAPI Connection`);
297
+ await this.openAPIRefreshStatus();
298
+ }
299
+ }
289
300
  }).catch(async (e: any) => {
290
301
  this.platform.log.error(`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
291
302
  if (this.deviceDebug) {
@@ -26,6 +26,7 @@ export class Motion {
26
26
  deviceStatus!: deviceStatusResponse;
27
27
 
28
28
  // BLE Others
29
+ connected?: boolean;
29
30
  switchbot!: switchbot;
30
31
  serviceData!: serviceData;
31
32
  battery!: serviceData['battery'];
@@ -185,14 +186,30 @@ export class Motion {
185
186
  this.platform.device(`Motion Sensor: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
186
187
  this.platform.device(`Motion Sensor: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, lightLevel: `
187
188
  + `${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`);
189
+
190
+ if (this.serviceData) {
191
+ this.connected = true;
192
+ this.platform.device(`Motion Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
193
+ } else {
194
+ this.connected = false;
195
+ this.platform.device(`Motion Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
196
+ }
188
197
  };
189
198
  // Wait 10 seconds
190
199
  return switchbot.wait(10000);
191
- }).then(() => {
200
+ }).then(async () => {
192
201
  // Stop to monitor
193
202
  switchbot.stopScan();
194
- this.parseStatus();
195
- this.updateHomeKitCharacteristics();
203
+ if (this.connected) {
204
+ this.parseStatus();
205
+ this.updateHomeKitCharacteristics();
206
+ } else {
207
+ this.platform.log.error(`Motion Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
208
+ if (this.platform.config.credentials?.openToken) {
209
+ this.platform.log.warn(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
210
+ await this.openAPIRefreshStatus();
211
+ }
212
+ }
196
213
  }).catch(async (e: any) => {
197
214
  this.platform.log.error(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
198
215
  if (this.deviceDebug) {
@@ -12,7 +12,6 @@ export class Plug {
12
12
 
13
13
  // Characteristic Values
14
14
  On!: CharacteristicValue;
15
- OutletInUse!: CharacteristicValue;
16
15
 
17
16
  // OpenAPI Others
18
17
  deviceStatus!: deviceStatusResponse;
@@ -32,7 +31,6 @@ export class Plug {
32
31
  ) {
33
32
  // default placeholders
34
33
  this.On = false;
35
- this.OutletInUse = true;
36
34
 
37
35
  // this is subject we use to track when we need to POST changes to the SwitchBot API
38
36
  this.doPlugUpdate = new Subject();
@@ -68,8 +66,6 @@ export class Plug {
68
66
  // create handlers for required characteristics
69
67
  this.service.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
70
68
 
71
- this.service.setCharacteristic(this.platform.Characteristic.OutletInUse, this.OutletInUse || true);
72
-
73
69
  // Update Homekit
74
70
  this.updateHomeKitCharacteristics();
75
71
 
@@ -173,17 +169,10 @@ export class Plug {
173
169
  this.service.updateCharacteristic(this.platform.Characteristic.On, this.On);
174
170
  this.platform.device(`Plug: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
175
171
  }
176
- if (this.OutletInUse === undefined) {
177
- this.platform.debug(`Plug: ${this.accessory.displayName} OutletInUse: ${this.OutletInUse}`);
178
- } else {
179
- this.service.updateCharacteristic(this.platform.Characteristic.OutletInUse, this.OutletInUse);
180
- this.platform.device(`Plug: ${this.accessory.displayName} updateCharacteristic OutletInUse: ${this.OutletInUse}`);
181
- }
182
172
  }
183
173
 
184
174
  public apiError(e: any) {
185
175
  this.service.updateCharacteristic(this.platform.Characteristic.On, e);
186
- this.service.updateCharacteristic(this.platform.Characteristic.OutletInUse, e);
187
176
  }
188
177
 
189
178
  private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
@@ -168,39 +168,39 @@ export class AirConditioner {
168
168
  if (this.Active === undefined) {
169
169
  this.platform.debug(`Air Conditioner: ${this.accessory.displayName} Active: ${this.Active}`);
170
170
  } else {
171
- this.service!.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
171
+ this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
172
172
  this.platform.device(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
173
173
  }
174
174
  if (this.RotationSpeed === undefined) {
175
175
  this.platform.debug(`Air Conditioner: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
176
176
  } else {
177
- this.service!.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
177
+ this.service?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
178
178
  this.platform.device(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
179
179
  }
180
180
  if (this.CurrentTemperature === undefined) {
181
181
  this.platform.debug(`Air Conditioner: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
182
182
  } else {
183
- this.service!.updateCharacteristic(this.platform.Characteristic.Active, this.CurrentTemperature);
183
+ this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.CurrentTemperature);
184
184
  this.platform.device(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
185
185
  }
186
186
  if (this.TargetHeaterCoolerState === undefined) {
187
187
  this.platform.debug(`Air Conditioner: ${this.accessory.displayName} TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
188
188
  } else {
189
- this.service!.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.TargetHeaterCoolerState);
189
+ this.service?.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.TargetHeaterCoolerState);
190
190
  this.platform.device(`Air Conditioner: ${this.accessory.displayName}`
191
191
  + ` updateCharacteristic TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
192
192
  }
193
193
  if (this.CurrentHeaterCoolerState === undefined) {
194
194
  this.platform.debug(`Air Conditioner: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
195
195
  } else {
196
- this.service!.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
196
+ this.service?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
197
197
  this.platform.device(`Air Conditioner: ${this.accessory.displayName}`
198
198
  + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
199
199
  }
200
200
  if (this.HeatingThresholdTemperature === undefined) {
201
201
  this.platform.debug(`Air Conditioner: ${this.accessory.displayName} HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
202
202
  } else {
203
- this.service!.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, this.HeatingThresholdTemperature);
203
+ this.service?.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, this.HeatingThresholdTemperature);
204
204
  this.platform.device(`Air Conditioner: ${this.accessory.displayName}`
205
205
  + ` updateCharacteristic HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
206
206
  }
@@ -87,20 +87,20 @@ export class AirPurifier {
87
87
  if (this.Active === undefined) {
88
88
  this.platform.debug(`Air Purifier: ${this.accessory.displayName} Active: ${this.Active}`);
89
89
  } else {
90
- this.service!.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
90
+ this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
91
91
  this.platform.device(`Air Purifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
92
92
  }
93
93
  if (this.CurrentAirPurifierState === undefined) {
94
94
  this.platform.debug(`Air Purifier: ${this.accessory.displayName} CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
95
95
  } else {
96
- this.service!.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, this.CurrentAirPurifierState);
96
+ this.service?.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, this.CurrentAirPurifierState);
97
97
  this.platform.device(`Air Purifier: ${this.accessory.displayName}`
98
98
  + ` updateCharacteristic CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
99
99
  }
100
100
  if (this.CurrentHeaterCoolerState === undefined) {
101
101
  this.platform.debug(`Air Purifier: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
102
102
  } else {
103
- this.service!.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
103
+ this.service?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
104
104
  this.platform.device(`Air Purifier: ${this.accessory.displayName}`
105
105
  + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
106
106
  }
@@ -63,7 +63,7 @@ export class Camera {
63
63
  if (this.On === undefined) {
64
64
  this.platform.debug(`Camera: ${this.accessory.displayName} On: ${this.On}`);
65
65
  } else {
66
- this.service!.updateCharacteristic(this.platform.Characteristic.On, this.On);
66
+ this.service?.updateCharacteristic(this.platform.Characteristic.On, this.On);
67
67
  this.platform.device(`Camera: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
68
68
  }
69
69
  }
@@ -126,19 +126,19 @@ export class Fan {
126
126
  if (this.Active === undefined) {
127
127
  this.platform.debug(`Fan: ${this.accessory.displayName} Active: ${this.Active}`);
128
128
  } else {
129
- this.service!.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
129
+ this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
130
130
  this.platform.device(`Fan: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
131
131
  }
132
132
  if (this.SwingMode === undefined) {
133
133
  this.platform.debug(`Fan: ${this.accessory.displayName} SwingMode: ${this.SwingMode}`);
134
134
  } else {
135
- this.service!.updateCharacteristic(this.platform.Characteristic.SwingMode, this.SwingMode);
135
+ this.service?.updateCharacteristic(this.platform.Characteristic.SwingMode, this.SwingMode);
136
136
  this.platform.device(`Fan: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.SwingMode}`);
137
137
  }
138
138
  if (this.RotationSpeed === undefined) {
139
139
  this.platform.debug(`Fan: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
140
140
  } else {
141
- this.service!.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
141
+ this.service?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
142
142
  this.platform.device(`Fan: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
143
143
  }
144
144
  }
@@ -78,7 +78,7 @@ export class Light {
78
78
  if (this.On === undefined) {
79
79
  this.platform.debug(`Light: ${this.accessory.displayName} On: ${this.On}`);
80
80
  } else {
81
- this.service!.updateCharacteristic(this.platform.Characteristic.On, this.On);
81
+ this.service?.updateCharacteristic(this.platform.Characteristic.On, this.On);
82
82
  this.platform.device(`Light: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
83
83
  }
84
84
  }
@@ -60,7 +60,7 @@ export class Others {
60
60
  if (this.Active === undefined) {
61
61
  this.platform.debug(`Other: ${this.accessory.displayName} Active: ${this.Active}`);
62
62
  } else {
63
- this.service!.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
63
+ this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
64
64
  this.platform.device(`Other: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
65
65
  }
66
66
  }
@@ -175,6 +175,6 @@ export class Others {
175
175
  }
176
176
 
177
177
  public apiError(e: any) {
178
- this.service!.updateCharacteristic(this.platform.Characteristic.Active, e);
178
+ this.service?.updateCharacteristic(this.platform.Characteristic.Active, e);
179
179
  }
180
180
  }
@@ -214,13 +214,13 @@ export class TV {
214
214
  if (this.Active === undefined) {
215
215
  this.platform.debug(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
216
216
  } else {
217
- this.service!.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
217
+ this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
218
218
  this.platform.device(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
219
219
  }
220
220
  if (this.ActiveIdentifier === undefined) {
221
221
  this.platform.debug(`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${this.ActiveIdentifier}`);
222
222
  } else {
223
- this.service!.updateCharacteristic(this.platform.Characteristic.ActiveIdentifier, this.ActiveIdentifier);
223
+ this.service?.updateCharacteristic(this.platform.Characteristic.ActiveIdentifier, this.ActiveIdentifier);
224
224
  this.platform.device(`${this.device.remoteType}: ${this.accessory.displayName}`
225
225
  + ` updateCharacteristic ActiveIdentifier: ${this.ActiveIdentifier}`);
226
226
  }
@@ -63,7 +63,7 @@ export class VacuumCleaner {
63
63
  if (this.On === undefined) {
64
64
  this.platform.debug(`Vacuum Cleaner: ${this.accessory.displayName} On: ${this.On}`);
65
65
  } else {
66
- this.service!.updateCharacteristic(this.platform.Characteristic.On, this.On);
66
+ this.service?.updateCharacteristic(this.platform.Characteristic.On, this.On);
67
67
  this.platform.device(`Vacuum Cleaner: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
68
68
  }
69
69
  }
@@ -77,7 +77,7 @@ export class WaterHeater {
77
77
  if (this.Active === undefined) {
78
78
  this.platform.debug(`Water Heater: ${this.accessory.displayName} Active: ${this.Active}`);
79
79
  } else {
80
- this.service!.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
80
+ this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
81
81
  this.platform.device(`Water Heater: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
82
82
  }
83
83
  }
package/src/platform.ts CHANGED
@@ -192,6 +192,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
192
192
  const devices = deviceLists.map((v: any) => v);
193
193
  for (const device of devices) {
194
194
  if (device.deviceType) {
195
+ if (device.configDeviceName) {
196
+ device.deviceName = device.configDeviceName;
197
+ }
195
198
  this.createDevice(device);
196
199
  }
197
200
  }
@@ -209,6 +212,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
209
212
  this.debug(`SwitchBot Devices: ${JSON.stringify(devices)}`);
210
213
  for (const device of devices) {
211
214
  if (device.deviceType) {
215
+ if (device.configDeviceName) {
216
+ device.deviceName = device.configDeviceName;
217
+ }
212
218
  this.createDevice(device);
213
219
  }
214
220
  }