@switchbot/homebridge-switchbot 1.10.2-beta.7 → 1.11.2

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 (99) hide show
  1. package/CHANGELOG.md +20 -3
  2. package/config.schema.json +49 -0
  3. package/dist/device/bot.d.ts +43 -40
  4. package/dist/device/bot.d.ts.map +1 -1
  5. package/dist/device/bot.js +26 -26
  6. package/dist/device/bot.js.map +1 -1
  7. package/dist/device/colorbulb.d.ts +25 -21
  8. package/dist/device/colorbulb.d.ts.map +1 -1
  9. package/dist/device/colorbulb.js +176 -140
  10. package/dist/device/colorbulb.js.map +1 -1
  11. package/dist/device/contact.d.ts +15 -15
  12. package/dist/device/contact.d.ts.map +1 -1
  13. package/dist/device/contact.js +14 -13
  14. package/dist/device/contact.js.map +1 -1
  15. package/dist/device/curtain.d.ts +25 -22
  16. package/dist/device/curtain.d.ts.map +1 -1
  17. package/dist/device/curtain.js +50 -37
  18. package/dist/device/curtain.js.map +1 -1
  19. package/dist/device/humidifier.d.ts +23 -20
  20. package/dist/device/humidifier.d.ts.map +1 -1
  21. package/dist/device/humidifier.js +38 -38
  22. package/dist/device/humidifier.js.map +1 -1
  23. package/dist/device/lock.d.ts +16 -13
  24. package/dist/device/lock.d.ts.map +1 -1
  25. package/dist/device/lock.js +17 -17
  26. package/dist/device/lock.js.map +1 -1
  27. package/dist/device/meter.d.ts +15 -15
  28. package/dist/device/meter.d.ts.map +1 -1
  29. package/dist/device/meter.js +11 -11
  30. package/dist/device/meter.js.map +1 -1
  31. package/dist/device/motion.d.ts +14 -14
  32. package/dist/device/motion.d.ts.map +1 -1
  33. package/dist/device/motion.js +13 -13
  34. package/dist/device/motion.js.map +1 -1
  35. package/dist/device/plug.d.ts +10 -7
  36. package/dist/device/plug.d.ts.map +1 -1
  37. package/dist/device/plug.js +19 -19
  38. package/dist/device/plug.js.map +1 -1
  39. package/dist/irdevice/airconditioner.d.ts +22 -22
  40. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  41. package/dist/irdevice/airconditioner.js +44 -44
  42. package/dist/irdevice/airconditioner.js.map +1 -1
  43. package/dist/irdevice/airpurifier.d.ts +12 -9
  44. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  45. package/dist/irdevice/airpurifier.js +20 -20
  46. package/dist/irdevice/airpurifier.js.map +1 -1
  47. package/dist/irdevice/camera.d.ts +10 -7
  48. package/dist/irdevice/camera.d.ts.map +1 -1
  49. package/dist/irdevice/camera.js +11 -11
  50. package/dist/irdevice/camera.js.map +1 -1
  51. package/dist/irdevice/fan.d.ts +12 -9
  52. package/dist/irdevice/fan.d.ts.map +1 -1
  53. package/dist/irdevice/fan.js +29 -29
  54. package/dist/irdevice/fan.js.map +1 -1
  55. package/dist/irdevice/light.d.ts +10 -7
  56. package/dist/irdevice/light.d.ts.map +1 -1
  57. package/dist/irdevice/light.js +13 -13
  58. package/dist/irdevice/light.js.map +1 -1
  59. package/dist/irdevice/other.d.ts +12 -9
  60. package/dist/irdevice/other.d.ts.map +1 -1
  61. package/dist/irdevice/other.js +17 -17
  62. package/dist/irdevice/other.js.map +1 -1
  63. package/dist/irdevice/tv.d.ts +13 -10
  64. package/dist/irdevice/tv.d.ts.map +1 -1
  65. package/dist/irdevice/tv.js +25 -25
  66. package/dist/irdevice/tv.js.map +1 -1
  67. package/dist/irdevice/vacuumcleaner.d.ts +10 -7
  68. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  69. package/dist/irdevice/vacuumcleaner.js +13 -13
  70. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  71. package/dist/irdevice/waterheater.d.ts +10 -7
  72. package/dist/irdevice/waterheater.d.ts.map +1 -1
  73. package/dist/irdevice/waterheater.js +16 -16
  74. package/dist/irdevice/waterheater.js.map +1 -1
  75. package/dist/platform.d.ts.map +1 -1
  76. package/dist/settings.d.ts +4 -1
  77. package/dist/settings.d.ts.map +1 -1
  78. package/dist/settings.js.map +1 -1
  79. package/package.json +76 -76
  80. package/src/device/bot.ts +50 -50
  81. package/src/device/colorbulb.ts +206 -157
  82. package/src/device/contact.ts +31 -30
  83. package/src/device/curtain.ts +68 -57
  84. package/src/device/humidifier.ts +65 -53
  85. package/src/device/lock.ts +25 -25
  86. package/src/device/meter.ts +25 -25
  87. package/src/device/motion.ts +27 -27
  88. package/src/device/plug.ts +22 -22
  89. package/src/irdevice/airconditioner.ts +54 -54
  90. package/src/irdevice/airpurifier.ts +30 -30
  91. package/src/irdevice/camera.ts +19 -19
  92. package/src/irdevice/fan.ts +40 -40
  93. package/src/irdevice/light.ts +23 -23
  94. package/src/irdevice/other.ts +25 -25
  95. package/src/irdevice/tv.ts +42 -42
  96. package/src/irdevice/vacuumcleaner.ts +21 -21
  97. package/src/irdevice/waterheater.ts +24 -24
  98. package/src/platform.ts +4 -4
  99. package/src/settings.ts +5 -1
@@ -11,9 +11,9 @@ import { DeviceURL, device, devicesConfig, serviceData, ad, switchbot, deviceSta
11
11
  */
12
12
  export class Meter {
13
13
  // Services
14
- private batteryService?: Service;
15
- private temperatureservice?: Service;
16
- private humidityservice?: Service;
14
+ batteryService?: Service;
15
+ temperatureservice?: Service;
16
+ humidityservice?: Service;
17
17
 
18
18
  // Characteristic Values
19
19
  CurrentRelativeHumidity!: CharacteristicValue;
@@ -157,15 +157,15 @@ export class Meter {
157
157
  // Start an update interval
158
158
  interval(this.deviceRefreshRate * 1000)
159
159
  .pipe(skipWhile(() => this.meterUpdateInProgress))
160
- .subscribe(() => {
161
- this.refreshStatus();
160
+ .subscribe(async () => {
161
+ await this.refreshStatus();
162
162
  });
163
163
  }
164
164
 
165
165
  /**
166
166
  * Parse the device status from the SwitchBot api
167
167
  */
168
- async parseStatus() {
168
+ async parseStatus(): Promise<void> {
169
169
  if (this.SwitchToOpenAPI || !this.device.ble) {
170
170
  await this.openAPIparseStatus();
171
171
  } else {
@@ -173,7 +173,7 @@ export class Meter {
173
173
  }
174
174
  }
175
175
 
176
- private async BLEparseStatus() {
176
+ async BLEparseStatus(): Promise<void> {
177
177
  this.debugLog(`Meter: ${this.accessory.displayName} BLE parseStatus`);
178
178
 
179
179
  // Battery
@@ -199,7 +199,7 @@ export class Meter {
199
199
  }
200
200
  }
201
201
 
202
- private async openAPIparseStatus() {
202
+ async openAPIparseStatus(): Promise<void> {
203
203
  if (this.device.ble) {
204
204
  this.SwitchToOpenAPI = false;
205
205
  }
@@ -222,7 +222,7 @@ export class Meter {
222
222
  /**
223
223
  * Asks the SwitchBot API for the latest device information
224
224
  */
225
- async refreshStatus() {
225
+ async refreshStatus(): Promise<void> {
226
226
  if (this.device.ble) {
227
227
  this.BLErefreshStatus();
228
228
  } else {
@@ -230,7 +230,7 @@ export class Meter {
230
230
  }
231
231
  }
232
232
 
233
- private async BLErefreshStatus() {
233
+ async BLErefreshStatus(): Promise<void> {
234
234
  this.debugLog(`Meter: ${this.accessory.displayName} BLE RefreshStatus`);
235
235
  const switchbot = await this.platform.connectBLE();
236
236
  // Convert to BLE Address
@@ -303,7 +303,7 @@ export class Meter {
303
303
  }
304
304
  }
305
305
 
306
- private async BLEconnection(switchbot: any) {
306
+ async BLEconnection(switchbot: any): Promise<void> {
307
307
  this.errorLog(`Meter: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
308
308
  if (this.platform.config.credentials?.openToken) {
309
309
  this.warnLog(`Meter: ${this.accessory.displayName} Using OpenAPI Connection`);
@@ -312,7 +312,7 @@ export class Meter {
312
312
  }
313
313
  }
314
314
 
315
- private async openAPIRefreshStatus() {
315
+ async openAPIRefreshStatus(): Promise<void> {
316
316
  if (this.platform.config.credentials?.openToken) {
317
317
  this.debugLog(`Meter: ${this.accessory.displayName} OpenAPI RefreshStatus`);
318
318
  try {
@@ -340,7 +340,7 @@ export class Meter {
340
340
  /**
341
341
  * Updates the status for each of the HomeKit Characteristics
342
342
  */
343
- updateHomeKitCharacteristics() {
343
+ async updateHomeKitCharacteristics(): Promise<void> {
344
344
  if (!this.device.meter?.hide_humidity) {
345
345
  if (this.CurrentRelativeHumidity === undefined) {
346
346
  this.debugLog(`Meter: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
@@ -373,7 +373,7 @@ export class Meter {
373
373
  }
374
374
  }
375
375
 
376
- public apiError(e: any) {
376
+ async apiError(e: any): Promise<void> {
377
377
  if (!this.device.meter?.hide_humidity) {
378
378
  this.humidityservice?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, e);
379
379
  }
@@ -390,16 +390,16 @@ export class Meter {
390
390
  model(device: device & devicesConfig): CharacteristicValue {
391
391
  let model: string;
392
392
  if (device.deviceType === 'Meter Plus (US)') {
393
- model = 'SWITCHBOT-METERTH-W2301500';
393
+ model = 'W2301500';
394
394
  } else if (device.deviceType === 'Meter Plus (JP)') {
395
- model = 'SWITCHBOT-METERTH-W2201500';
395
+ model = 'W2201500';
396
396
  } else {
397
- model = 'SWITCHBOT-METERTH-S1';
397
+ model = 'S1';
398
398
  }
399
399
  return model;
400
400
  }
401
401
 
402
- config(device: device & devicesConfig) {
402
+ async config(device: device & devicesConfig): Promise<void> {
403
403
  let config = {};
404
404
  if (device.meter) {
405
405
  config = device.meter;
@@ -421,7 +421,7 @@ export class Meter {
421
421
  }
422
422
  }
423
423
 
424
- refreshRate(device: device & devicesConfig) {
424
+ async refreshRate(device: device & devicesConfig): Promise<void> {
425
425
  if (device.refreshRate) {
426
426
  this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
427
427
  this.debugLog(`Meter: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
@@ -431,7 +431,7 @@ export class Meter {
431
431
  }
432
432
  }
433
433
 
434
- scan(device: device & devicesConfig) {
434
+ async scan(device: device & devicesConfig): Promise<void> {
435
435
  if (device.scanDuration) {
436
436
  this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
437
437
  if (device.ble) {
@@ -445,7 +445,7 @@ export class Meter {
445
445
  }
446
446
  }
447
447
 
448
- logs(device: device & devicesConfig) {
448
+ async logs(device: device & devicesConfig): Promise<void> {
449
449
  if (this.platform.debugMode) {
450
450
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
451
451
  this.debugLog(`Meter: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
@@ -464,25 +464,25 @@ export class Meter {
464
464
  /**
465
465
  * Logging for Device
466
466
  */
467
- infoLog(...log: any[]) {
467
+ infoLog(...log: any[]): void {
468
468
  if (this.enablingDeviceLogging()) {
469
469
  this.platform.log.info(String(...log));
470
470
  }
471
471
  }
472
472
 
473
- warnLog(...log: any[]) {
473
+ warnLog(...log: any[]): void {
474
474
  if (this.enablingDeviceLogging()) {
475
475
  this.platform.log.warn(String(...log));
476
476
  }
477
477
  }
478
478
 
479
- errorLog(...log: any[]) {
479
+ errorLog(...log: any[]): void {
480
480
  if (this.enablingDeviceLogging()) {
481
481
  this.platform.log.error(String(...log));
482
482
  }
483
483
  }
484
484
 
485
- debugLog(...log: any[]) {
485
+ debugLog(...log: any[]): void {
486
486
  if (this.enablingDeviceLogging()) {
487
487
  if (this.deviceLogging === 'debug') {
488
488
  this.platform.log.info('[DEBUG]', String(...log));
@@ -11,9 +11,9 @@ import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusR
11
11
  */
12
12
  export class Motion {
13
13
  // Services
14
- private service: Service;
15
- private lightSensorService?: Service;
16
- private batteryService?: Service;
14
+ motionSensorService: Service;
15
+ lightSensorService?: Service;
16
+ batteryService?: Service;
17
17
 
18
18
  // Characteristic Values
19
19
  MotionDetected!: CharacteristicValue;
@@ -65,12 +65,12 @@ export class Motion {
65
65
  accessory
66
66
  .getService(this.platform.Service.AccessoryInformation)!
67
67
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
68
- .setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-WOMOTION-W1101500')
68
+ .setCharacteristic(this.platform.Characteristic.Model, 'W1101500')
69
69
  .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
70
70
 
71
71
  // get the Battery service if it exists, otherwise create a new Motion service
72
72
  // you can create multiple services for each accessory
73
- (this.service = accessory.getService(this.platform.Service.MotionSensor) || accessory.addService(this.platform.Service.MotionSensor)),
73
+ (this.motionSensorService = accessory.getService(this.platform.Service.MotionSensor) || accessory.addService(this.platform.Service.MotionSensor)),
74
74
  `${accessory.displayName} Motion Sensor`;
75
75
 
76
76
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
@@ -79,7 +79,7 @@ export class Motion {
79
79
 
80
80
  // set the service name, this is what is displayed as the default name on the Home app
81
81
  // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
82
- this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
82
+ this.motionSensorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
83
83
 
84
84
  // each service must implement at-minimum the "required characteristics" for the given service type
85
85
  // see https://developers.homebridge.io/#/service/MotionSensor
@@ -121,15 +121,15 @@ export class Motion {
121
121
  // Start an update interval
122
122
  interval(this.deviceRefreshRate * 1000)
123
123
  .pipe(skipWhile(() => this.motionUbpdateInProgress))
124
- .subscribe(() => {
125
- this.refreshStatus();
124
+ .subscribe(async () => {
125
+ await this.refreshStatus();
126
126
  });
127
127
  }
128
128
 
129
129
  /**
130
130
  * Parse the device status from the SwitchBot api
131
131
  */
132
- async parseStatus() {
132
+ async parseStatus(): Promise<void> {
133
133
  if (this.SwitchToOpenAPI || !this.device.ble) {
134
134
  await this.openAPIparseStatus();
135
135
  } else {
@@ -137,7 +137,7 @@ export class Motion {
137
137
  }
138
138
  }
139
139
 
140
- private async BLEparseStatus() {
140
+ async BLEparseStatus(): Promise<void> {
141
141
  this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE parseStatus`);
142
142
  // Movement
143
143
  this.MotionDetected = this.movement!;
@@ -172,7 +172,7 @@ export class Motion {
172
172
  this.debugLog(`Motion Sensor: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
173
173
  }
174
174
 
175
- private async openAPIparseStatus() {
175
+ async openAPIparseStatus(): Promise<void> {
176
176
  if (this.device.ble) {
177
177
  this.SwitchToOpenAPI = false;
178
178
  }
@@ -201,7 +201,7 @@ export class Motion {
201
201
  /**
202
202
  * Asks the SwitchBot API for the latest device information
203
203
  */
204
- async refreshStatus() {
204
+ async refreshStatus(): Promise<void> {
205
205
  if (this.device.ble) {
206
206
  await this.BLERefreshStatus();
207
207
  } else {
@@ -209,7 +209,7 @@ export class Motion {
209
209
  }
210
210
  }
211
211
 
212
- private async BLERefreshStatus() {
212
+ async BLERefreshStatus(): Promise<void> {
213
213
  this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE RefreshStatus`);
214
214
  const switchbot = await this.platform.connectBLE();
215
215
  // Convert to BLE Address
@@ -282,7 +282,7 @@ export class Motion {
282
282
  }
283
283
  }
284
284
 
285
- public async BLEconnection(switchbot: any) {
285
+ async BLEconnection(switchbot: any): Promise<void> {
286
286
  this.errorLog(`Motion Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
287
287
  if (this.platform.config.credentials?.openToken) {
288
288
  this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
@@ -291,7 +291,7 @@ export class Motion {
291
291
  }
292
292
  }
293
293
 
294
- private async openAPIRefreshStatus() {
294
+ async openAPIRefreshStatus(): Promise<void> {
295
295
  if (this.platform.config.credentials?.openToken) {
296
296
  this.debugLog(`Motion Sensor: ${this.accessory.displayName} OpenAPI RefreshStatus`);
297
297
  try {
@@ -325,11 +325,11 @@ export class Motion {
325
325
  /**
326
326
  * Updates the status for each of the HomeKit Characteristics
327
327
  */
328
- updateHomeKitCharacteristics() {
328
+ async updateHomeKitCharacteristics(): Promise<void> {
329
329
  if (this.MotionDetected === undefined) {
330
330
  this.debugLog(`Motion Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
331
331
  } else {
332
- this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected);
332
+ this.motionSensorService.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected);
333
333
  this.debugLog(`Motion Sensor: ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`);
334
334
  }
335
335
  if (this.device.ble) {
@@ -356,8 +356,8 @@ export class Motion {
356
356
  }
357
357
  }
358
358
 
359
- public apiError(e: any) {
360
- this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, e);
359
+ async apiError(e: any): Promise<void> {
360
+ this.motionSensorService.updateCharacteristic(this.platform.Characteristic.MotionDetected, e);
361
361
  if (this.device.ble) {
362
362
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
363
363
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
@@ -366,7 +366,7 @@ export class Motion {
366
366
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
367
367
  }
368
368
 
369
- config(device: device & devicesConfig) {
369
+ async config(device: device & devicesConfig): Promise<void> {
370
370
  let config = {};
371
371
  if (device.motion) {
372
372
  config = device.motion;
@@ -391,7 +391,7 @@ export class Motion {
391
391
  }
392
392
  }
393
393
 
394
- refreshRate(device: device & devicesConfig) {
394
+ async refreshRate(device: device & devicesConfig): Promise<void> {
395
395
  if (device.refreshRate) {
396
396
  this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
397
397
  this.debugLog(`Motion Sensor: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
@@ -401,7 +401,7 @@ export class Motion {
401
401
  }
402
402
  }
403
403
 
404
- scan(device: device & devicesConfig) {
404
+ async scan(device: device & devicesConfig): Promise<void> {
405
405
  if (device.scanDuration) {
406
406
  this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
407
407
  if (device.ble) {
@@ -415,7 +415,7 @@ export class Motion {
415
415
  }
416
416
  }
417
417
 
418
- logs(device: device & devicesConfig) {
418
+ async logs(device: device & devicesConfig): Promise<void> {
419
419
  if (this.platform.debugMode) {
420
420
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
421
421
  this.debugLog(`Motion Sensor: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
@@ -452,25 +452,25 @@ export class Motion {
452
452
  /**
453
453
  * Logging for Device
454
454
  */
455
- infoLog(...log: any[]) {
455
+ infoLog(...log: any[]): void {
456
456
  if (this.enablingDeviceLogging()) {
457
457
  this.platform.log.info(String(...log));
458
458
  }
459
459
  }
460
460
 
461
- warnLog(...log: any[]) {
461
+ warnLog(...log: any[]): void {
462
462
  if (this.enablingDeviceLogging()) {
463
463
  this.platform.log.warn(String(...log));
464
464
  }
465
465
  }
466
466
 
467
- errorLog(...log: any[]) {
467
+ errorLog(...log: any[]): void {
468
468
  if (this.enablingDeviceLogging()) {
469
469
  this.platform.log.error(String(...log));
470
470
  }
471
471
  }
472
472
 
473
- debugLog(...log: any[]) {
473
+ debugLog(...log: any[]): void {
474
474
  if (this.enablingDeviceLogging()) {
475
475
  if (this.deviceLogging === 'debug') {
476
476
  this.platform.log.info('[DEBUG]', String(...log));
@@ -7,7 +7,7 @@ import { DeviceURL, device, devicesConfig, deviceStatusResponse, payload, device
7
7
 
8
8
  export class Plug {
9
9
  // Services
10
- private service: Service;
10
+ outletService: Service;
11
11
 
12
12
  // Characteristic Values
13
13
  On!: CharacteristicValue;
@@ -52,9 +52,9 @@ export class Plug {
52
52
  .setCharacteristic(this.platform.Characteristic.Model, this.model(device))
53
53
  .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
54
54
 
55
- // get the WindowCovering service if it exists, otherwise create a new WindowCovering service
55
+ // get the Outlet service if it exists, otherwise create a new Outlet service
56
56
  // you can create multiple services for each accessory
57
- (this.service = accessory.getService(this.platform.Service.Outlet) || accessory.addService(this.platform.Service.Outlet)),
57
+ (this.outletService = accessory.getService(this.platform.Service.Outlet) || accessory.addService(this.platform.Service.Outlet)),
58
58
  `${device.deviceName} ${device.deviceType}`;
59
59
 
60
60
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
@@ -63,13 +63,13 @@ export class Plug {
63
63
 
64
64
  // set the service name, this is what is displayed as the default name on the Home app
65
65
  // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
66
- this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
66
+ this.outletService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
67
67
 
68
68
  // each service must implement at-minimum the "required characteristics" for the given service type
69
- // see https://developers.homebridge.io/#/service/WindowCovering
69
+ // see https://developers.homebridge.io/#/service/Outlet
70
70
 
71
71
  // create handlers for required characteristics
72
- this.service.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
72
+ this.outletService.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
73
73
 
74
74
  // Update Homekit
75
75
  this.updateHomeKitCharacteristics();
@@ -77,8 +77,8 @@ export class Plug {
77
77
  // Start an update interval
78
78
  interval(this.deviceRefreshRate * 1000)
79
79
  .pipe(skipWhile(() => this.plugUpdateInProgress))
80
- .subscribe(() => {
81
- this.refreshStatus();
80
+ .subscribe(async () => {
81
+ await this.refreshStatus();
82
82
  });
83
83
 
84
84
  // Watch for Plug change events
@@ -107,7 +107,7 @@ export class Plug {
107
107
  });
108
108
  }
109
109
 
110
- parseStatus() {
110
+ async parseStatus(): Promise<void> {
111
111
  switch (this.power) {
112
112
  case 'on':
113
113
  this.On = true;
@@ -118,7 +118,7 @@ export class Plug {
118
118
  this.debugLog(`Plug ${this.accessory.displayName} On: ${this.On}`);
119
119
  }
120
120
 
121
- private async refreshStatus() {
121
+ async refreshStatus(): Promise<void> {
122
122
  try {
123
123
  this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
124
124
  this.debugLog(`Plug: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
@@ -148,7 +148,7 @@ export class Plug {
148
148
  * Plug Mini (US/JP) - "command" turnOff default = set to OFF state
149
149
  * Plug Mini (US/JP) - "command" toggle default = toggle state
150
150
  */
151
- async pushChanges() {
151
+ async pushChanges(): Promise<void> {
152
152
  if (this.On !== this.OnCached) {
153
153
  const payload = {
154
154
  commandType: 'command',
@@ -176,26 +176,26 @@ export class Plug {
176
176
  interval(5000)
177
177
  .pipe(skipWhile(() => this.plugUpdateInProgress))
178
178
  .pipe(take(1))
179
- .subscribe(() => {
180
- this.refreshStatus();
179
+ .subscribe(async () => {
180
+ await this.refreshStatus();
181
181
  });
182
182
  }
183
183
 
184
- updateHomeKitCharacteristics() {
184
+ async updateHomeKitCharacteristics(): Promise<void> {
185
185
  if (this.On === undefined) {
186
186
  this.debugLog(`Plug: ${this.accessory.displayName} On: ${this.On}`);
187
187
  } else {
188
- this.service.updateCharacteristic(this.platform.Characteristic.On, this.On);
188
+ this.outletService.updateCharacteristic(this.platform.Characteristic.On, this.On);
189
189
  this.debugLog(`Plug: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
190
190
  }
191
191
  }
192
192
 
193
- public apiError(e: any) {
194
- this.service.updateCharacteristic(this.platform.Characteristic.On, e);
193
+ async apiError(e: any): Promise<void> {
194
+ this.outletService.updateCharacteristic(this.platform.Characteristic.On, e);
195
195
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
196
196
  }
197
197
 
198
- private statusCode(push: AxiosResponse<{ statusCode: number }>) {
198
+ async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void> {
199
199
  switch (push.data.statusCode) {
200
200
  case 151:
201
201
  this.errorLog(`Plug: ${this.accessory.displayName} Command not supported by this device type.`);
@@ -231,7 +231,7 @@ export class Plug {
231
231
  async offlineOff(): Promise<void> {
232
232
  if (this.device.offline) {
233
233
  this.On = false;
234
- this.service.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
234
+ this.outletService.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
235
235
  }
236
236
  }
237
237
 
@@ -248,11 +248,11 @@ export class Plug {
248
248
  model(device: device & devicesConfig): string {
249
249
  let model: string;
250
250
  if (device.deviceType === 'Plug Mini (US)') {
251
- model = 'SWITCHBOT-PLUG-W1901400';
251
+ model = 'W1901400';
252
252
  } else if (device.deviceType === 'Plug Mini (JP)') {
253
- model = 'SWITCHBOT-PLUG-W2001400';
253
+ model = 'W2001400';
254
254
  } else {
255
- model = 'SWITCHBOT-PLUG-SP11';
255
+ model = 'SP11';
256
256
  }
257
257
  return model;
258
258
  }