@switchbot/homebridge-switchbot 1.10.2-beta.5 → 1.11.0

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 (52) hide show
  1. package/CHANGELOG.md +3 -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 +29 -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 -145
  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 +41 -41
  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 +20 -22
  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 -14
  30. package/dist/device/meter.js.map +1 -1
  31. package/dist/device/motion.d.ts +16 -16
  32. package/dist/device/motion.d.ts.map +1 -1
  33. package/dist/device/motion.js +16 -17
  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 +22 -21
  38. package/dist/device/plug.js.map +1 -1
  39. package/dist/settings.d.ts +4 -1
  40. package/dist/settings.d.ts.map +1 -1
  41. package/dist/settings.js.map +1 -1
  42. package/package.json +76 -76
  43. package/src/device/bot.ts +53 -50
  44. package/src/device/colorbulb.ts +208 -162
  45. package/src/device/contact.ts +31 -30
  46. package/src/device/curtain.ts +68 -57
  47. package/src/device/humidifier.ts +68 -59
  48. package/src/device/lock.ts +28 -31
  49. package/src/device/meter.ts +25 -31
  50. package/src/device/motion.ts +32 -36
  51. package/src/device/plug.ts +25 -25
  52. 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;
@@ -66,12 +66,6 @@ export class Meter {
66
66
  this.CurrentTemperature = this.accessory.context.CurrentTemperature;
67
67
  }
68
68
 
69
- // Meter Config
70
- this.debugLog(
71
- `Meter: ${this.accessory.displayName} Config: (ble: ${device.ble}, hide_temperature: ${device.meter?.hide_temperature},` +
72
- ` hide_humidity: ${device.meter?.hide_humidity})`,
73
- );
74
-
75
69
  // this is subject we use to track when we need to POST changes to the SwitchBot API
76
70
  this.doMeterUpdate = new Subject();
77
71
  this.meterUpdateInProgress = false;
@@ -163,15 +157,15 @@ export class Meter {
163
157
  // Start an update interval
164
158
  interval(this.deviceRefreshRate * 1000)
165
159
  .pipe(skipWhile(() => this.meterUpdateInProgress))
166
- .subscribe(() => {
167
- this.refreshStatus();
160
+ .subscribe(async () => {
161
+ await this.refreshStatus();
168
162
  });
169
163
  }
170
164
 
171
165
  /**
172
166
  * Parse the device status from the SwitchBot api
173
167
  */
174
- async parseStatus() {
168
+ async parseStatus(): Promise<void> {
175
169
  if (this.SwitchToOpenAPI || !this.device.ble) {
176
170
  await this.openAPIparseStatus();
177
171
  } else {
@@ -179,7 +173,7 @@ export class Meter {
179
173
  }
180
174
  }
181
175
 
182
- private async BLEparseStatus() {
176
+ async BLEparseStatus(): Promise<void> {
183
177
  this.debugLog(`Meter: ${this.accessory.displayName} BLE parseStatus`);
184
178
 
185
179
  // Battery
@@ -205,7 +199,7 @@ export class Meter {
205
199
  }
206
200
  }
207
201
 
208
- private async openAPIparseStatus() {
202
+ async openAPIparseStatus(): Promise<void> {
209
203
  if (this.device.ble) {
210
204
  this.SwitchToOpenAPI = false;
211
205
  }
@@ -228,7 +222,7 @@ export class Meter {
228
222
  /**
229
223
  * Asks the SwitchBot API for the latest device information
230
224
  */
231
- async refreshStatus() {
225
+ async refreshStatus(): Promise<void> {
232
226
  if (this.device.ble) {
233
227
  this.BLErefreshStatus();
234
228
  } else {
@@ -236,7 +230,7 @@ export class Meter {
236
230
  }
237
231
  }
238
232
 
239
- private async BLErefreshStatus() {
233
+ async BLErefreshStatus(): Promise<void> {
240
234
  this.debugLog(`Meter: ${this.accessory.displayName} BLE RefreshStatus`);
241
235
  const switchbot = await this.platform.connectBLE();
242
236
  // Convert to BLE Address
@@ -309,7 +303,7 @@ export class Meter {
309
303
  }
310
304
  }
311
305
 
312
- private async BLEconnection(switchbot: any) {
306
+ async BLEconnection(switchbot: any): Promise<void> {
313
307
  this.errorLog(`Meter: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
314
308
  if (this.platform.config.credentials?.openToken) {
315
309
  this.warnLog(`Meter: ${this.accessory.displayName} Using OpenAPI Connection`);
@@ -318,7 +312,7 @@ export class Meter {
318
312
  }
319
313
  }
320
314
 
321
- private async openAPIRefreshStatus() {
315
+ async openAPIRefreshStatus(): Promise<void> {
322
316
  if (this.platform.config.credentials?.openToken) {
323
317
  this.debugLog(`Meter: ${this.accessory.displayName} OpenAPI RefreshStatus`);
324
318
  try {
@@ -346,7 +340,7 @@ export class Meter {
346
340
  /**
347
341
  * Updates the status for each of the HomeKit Characteristics
348
342
  */
349
- updateHomeKitCharacteristics() {
343
+ async updateHomeKitCharacteristics(): Promise<void> {
350
344
  if (!this.device.meter?.hide_humidity) {
351
345
  if (this.CurrentRelativeHumidity === undefined) {
352
346
  this.debugLog(`Meter: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
@@ -379,7 +373,7 @@ export class Meter {
379
373
  }
380
374
  }
381
375
 
382
- public apiError(e: any) {
376
+ async apiError(e: any): Promise<void> {
383
377
  if (!this.device.meter?.hide_humidity) {
384
378
  this.humidityservice?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, e);
385
379
  }
@@ -396,16 +390,16 @@ export class Meter {
396
390
  model(device: device & devicesConfig): CharacteristicValue {
397
391
  let model: string;
398
392
  if (device.deviceType === 'Meter Plus (US)') {
399
- model = 'SWITCHBOT-METERTH-W2301500';
393
+ model = 'W2301500';
400
394
  } else if (device.deviceType === 'Meter Plus (JP)') {
401
- model = 'SWITCHBOT-METERTH-W2201500';
395
+ model = 'W2201500';
402
396
  } else {
403
- model = 'SWITCHBOT-METERTH-S1';
397
+ model = 'S1';
404
398
  }
405
399
  return model;
406
400
  }
407
401
 
408
- config(device: device & devicesConfig) {
402
+ async config(device: device & devicesConfig): Promise<void> {
409
403
  let config = {};
410
404
  if (device.meter) {
411
405
  config = device.meter;
@@ -427,7 +421,7 @@ export class Meter {
427
421
  }
428
422
  }
429
423
 
430
- refreshRate(device: device & devicesConfig) {
424
+ async refreshRate(device: device & devicesConfig): Promise<void> {
431
425
  if (device.refreshRate) {
432
426
  this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
433
427
  this.debugLog(`Meter: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
@@ -437,7 +431,7 @@ export class Meter {
437
431
  }
438
432
  }
439
433
 
440
- scan(device: device & devicesConfig) {
434
+ async scan(device: device & devicesConfig): Promise<void> {
441
435
  if (device.scanDuration) {
442
436
  this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
443
437
  if (device.ble) {
@@ -451,7 +445,7 @@ export class Meter {
451
445
  }
452
446
  }
453
447
 
454
- logs(device: device & devicesConfig) {
448
+ async logs(device: device & devicesConfig): Promise<void> {
455
449
  if (this.platform.debugMode) {
456
450
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
457
451
  this.debugLog(`Meter: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
@@ -470,25 +464,25 @@ export class Meter {
470
464
  /**
471
465
  * Logging for Device
472
466
  */
473
- infoLog(...log: any[]) {
467
+ infoLog(...log: any[]): void {
474
468
  if (this.enablingDeviceLogging()) {
475
469
  this.platform.log.info(String(...log));
476
470
  }
477
471
  }
478
472
 
479
- warnLog(...log: any[]) {
473
+ warnLog(...log: any[]): void {
480
474
  if (this.enablingDeviceLogging()) {
481
475
  this.platform.log.warn(String(...log));
482
476
  }
483
477
  }
484
478
 
485
- errorLog(...log: any[]) {
479
+ errorLog(...log: any[]): void {
486
480
  if (this.enablingDeviceLogging()) {
487
481
  this.platform.log.error(String(...log));
488
482
  }
489
483
  }
490
484
 
491
- debugLog(...log: any[]) {
485
+ debugLog(...log: any[]): void {
492
486
  if (this.enablingDeviceLogging()) {
493
487
  if (this.deviceLogging === 'debug') {
494
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;
@@ -54,13 +54,6 @@ export class Motion {
54
54
  this.config(device);
55
55
  this.MotionDetected = false;
56
56
 
57
- // Motion Config
58
- this.debugLog(
59
- `Motion Sensor: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline},` +
60
- ` hide_lightsensor: ${device.motion?.hide_lightsensor},` +
61
- ` set_minLux: ${this.device.motion?.set_minLux}, set_maxLux: ${this.device.motion?.set_maxLux})`,
62
- );
63
-
64
57
  // this is subject we use to track when we need to POST changes to the SwitchBot API
65
58
  this.doMotionUpdate = new Subject();
66
59
  this.motionUbpdateInProgress = false;
@@ -72,12 +65,12 @@ export class Motion {
72
65
  accessory
73
66
  .getService(this.platform.Service.AccessoryInformation)!
74
67
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
75
- .setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-WOMOTION-W1101500')
68
+ .setCharacteristic(this.platform.Characteristic.Model, 'W1101500')
76
69
  .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
77
70
 
78
71
  // get the Battery service if it exists, otherwise create a new Motion service
79
72
  // you can create multiple services for each accessory
80
- (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)),
81
74
  `${accessory.displayName} Motion Sensor`;
82
75
 
83
76
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
@@ -86,7 +79,7 @@ export class Motion {
86
79
 
87
80
  // set the service name, this is what is displayed as the default name on the Home app
88
81
  // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
89
- this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
82
+ this.motionSensorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
90
83
 
91
84
  // each service must implement at-minimum the "required characteristics" for the given service type
92
85
  // see https://developers.homebridge.io/#/service/MotionSensor
@@ -128,15 +121,15 @@ export class Motion {
128
121
  // Start an update interval
129
122
  interval(this.deviceRefreshRate * 1000)
130
123
  .pipe(skipWhile(() => this.motionUbpdateInProgress))
131
- .subscribe(() => {
132
- this.refreshStatus();
124
+ .subscribe(async () => {
125
+ await this.refreshStatus();
133
126
  });
134
127
  }
135
128
 
136
129
  /**
137
130
  * Parse the device status from the SwitchBot api
138
131
  */
139
- async parseStatus() {
132
+ async parseStatus(): Promise<void> {
140
133
  if (this.SwitchToOpenAPI || !this.device.ble) {
141
134
  await this.openAPIparseStatus();
142
135
  } else {
@@ -144,7 +137,7 @@ export class Motion {
144
137
  }
145
138
  }
146
139
 
147
- private async BLEparseStatus() {
140
+ async BLEparseStatus(): Promise<void> {
148
141
  this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE parseStatus`);
149
142
  // Movement
150
143
  this.MotionDetected = this.movement!;
@@ -179,7 +172,7 @@ export class Motion {
179
172
  this.debugLog(`Motion Sensor: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
180
173
  }
181
174
 
182
- private async openAPIparseStatus() {
175
+ async openAPIparseStatus(): Promise<void> {
183
176
  if (this.device.ble) {
184
177
  this.SwitchToOpenAPI = false;
185
178
  }
@@ -208,7 +201,7 @@ export class Motion {
208
201
  /**
209
202
  * Asks the SwitchBot API for the latest device information
210
203
  */
211
- async refreshStatus() {
204
+ async refreshStatus(): Promise<void> {
212
205
  if (this.device.ble) {
213
206
  await this.BLERefreshStatus();
214
207
  } else {
@@ -216,7 +209,7 @@ export class Motion {
216
209
  }
217
210
  }
218
211
 
219
- private async BLERefreshStatus() {
212
+ async BLERefreshStatus(): Promise<void> {
220
213
  this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE RefreshStatus`);
221
214
  const switchbot = await this.platform.connectBLE();
222
215
  // Convert to BLE Address
@@ -289,7 +282,7 @@ export class Motion {
289
282
  }
290
283
  }
291
284
 
292
- public async BLEconnection(switchbot: any) {
285
+ async BLEconnection(switchbot: any): Promise<void> {
293
286
  this.errorLog(`Motion Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
294
287
  if (this.platform.config.credentials?.openToken) {
295
288
  this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
@@ -298,7 +291,7 @@ export class Motion {
298
291
  }
299
292
  }
300
293
 
301
- private async openAPIRefreshStatus() {
294
+ async openAPIRefreshStatus(): Promise<void> {
302
295
  if (this.platform.config.credentials?.openToken) {
303
296
  this.debugLog(`Motion Sensor: ${this.accessory.displayName} OpenAPI RefreshStatus`);
304
297
  try {
@@ -332,11 +325,11 @@ export class Motion {
332
325
  /**
333
326
  * Updates the status for each of the HomeKit Characteristics
334
327
  */
335
- updateHomeKitCharacteristics() {
328
+ async updateHomeKitCharacteristics(): Promise<void> {
336
329
  if (this.MotionDetected === undefined) {
337
330
  this.debugLog(`Motion Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
338
331
  } else {
339
- this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected);
332
+ this.motionSensorService.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected);
340
333
  this.debugLog(`Motion Sensor: ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`);
341
334
  }
342
335
  if (this.device.ble) {
@@ -363,8 +356,8 @@ export class Motion {
363
356
  }
364
357
  }
365
358
 
366
- public apiError(e: any) {
367
- this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, e);
359
+ async apiError(e: any): Promise<void> {
360
+ this.motionSensorService.updateCharacteristic(this.platform.Characteristic.MotionDetected, e);
368
361
  if (this.device.ble) {
369
362
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
370
363
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
@@ -373,7 +366,7 @@ export class Motion {
373
366
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
374
367
  }
375
368
 
376
- config(device: device & devicesConfig) {
369
+ async config(device: device & devicesConfig): Promise<void> {
377
370
  let config = {};
378
371
  if (device.motion) {
379
372
  config = device.motion;
@@ -390,12 +383,15 @@ export class Motion {
390
383
  if (device.scanDuration !== undefined) {
391
384
  config['scanDuration'] = device.scanDuration;
392
385
  }
386
+ if (device.offline !== undefined) {
387
+ config['offline'] = device.offline;
388
+ }
393
389
  if (Object.entries(config).length !== 0) {
394
390
  this.warnLog(`Motion Sensor: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
395
391
  }
396
392
  }
397
393
 
398
- refreshRate(device: device & devicesConfig) {
394
+ async refreshRate(device: device & devicesConfig): Promise<void> {
399
395
  if (device.refreshRate) {
400
396
  this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
401
397
  this.debugLog(`Motion Sensor: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
@@ -405,7 +401,7 @@ export class Motion {
405
401
  }
406
402
  }
407
403
 
408
- scan(device: device & devicesConfig) {
404
+ async scan(device: device & devicesConfig): Promise<void> {
409
405
  if (device.scanDuration) {
410
406
  this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
411
407
  if (device.ble) {
@@ -419,7 +415,7 @@ export class Motion {
419
415
  }
420
416
  }
421
417
 
422
- logs(device: device & devicesConfig) {
418
+ async logs(device: device & devicesConfig): Promise<void> {
423
419
  if (this.platform.debugMode) {
424
420
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
425
421
  this.debugLog(`Motion Sensor: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
@@ -435,7 +431,7 @@ export class Motion {
435
431
  }
436
432
  }
437
433
 
438
- private minLux(): number {
434
+ minLux(): number {
439
435
  if (this.device.motion?.set_minLux) {
440
436
  this.set_minLux = this.device.motion!.set_minLux!;
441
437
  } else {
@@ -444,7 +440,7 @@ export class Motion {
444
440
  return this.set_minLux;
445
441
  }
446
442
 
447
- private maxLux(): number {
443
+ maxLux(): number {
448
444
  if (this.device.motion?.set_maxLux) {
449
445
  this.set_maxLux = this.device.motion!.set_maxLux!;
450
446
  } else {
@@ -456,25 +452,25 @@ export class Motion {
456
452
  /**
457
453
  * Logging for Device
458
454
  */
459
- infoLog(...log: any[]) {
455
+ infoLog(...log: any[]): void {
460
456
  if (this.enablingDeviceLogging()) {
461
457
  this.platform.log.info(String(...log));
462
458
  }
463
459
  }
464
460
 
465
- warnLog(...log: any[]) {
461
+ warnLog(...log: any[]): void {
466
462
  if (this.enablingDeviceLogging()) {
467
463
  this.platform.log.warn(String(...log));
468
464
  }
469
465
  }
470
466
 
471
- errorLog(...log: any[]) {
467
+ errorLog(...log: any[]): void {
472
468
  if (this.enablingDeviceLogging()) {
473
469
  this.platform.log.error(String(...log));
474
470
  }
475
471
  }
476
472
 
477
- debugLog(...log: any[]) {
473
+ debugLog(...log: any[]): void {
478
474
  if (this.enablingDeviceLogging()) {
479
475
  if (this.deviceLogging === 'debug') {
480
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;
@@ -38,9 +38,6 @@ export class Plug {
38
38
  this.On = this.accessory.context.On;
39
39
  }
40
40
 
41
- // Plug Config
42
- this.debugLog(`Plug: ${this.accessory.displayName} Config: (offline: ${device.offline})`);
43
-
44
41
  // this is subject we use to track when we need to POST changes to the SwitchBot API
45
42
  this.doPlugUpdate = new Subject();
46
43
  this.plugUpdateInProgress = false;
@@ -55,9 +52,9 @@ export class Plug {
55
52
  .setCharacteristic(this.platform.Characteristic.Model, this.model(device))
56
53
  .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
57
54
 
58
- // 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
59
56
  // you can create multiple services for each accessory
60
- (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)),
61
58
  `${device.deviceName} ${device.deviceType}`;
62
59
 
63
60
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
@@ -66,13 +63,13 @@ export class Plug {
66
63
 
67
64
  // set the service name, this is what is displayed as the default name on the Home app
68
65
  // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
69
- this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
66
+ this.outletService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
70
67
 
71
68
  // each service must implement at-minimum the "required characteristics" for the given service type
72
- // see https://developers.homebridge.io/#/service/WindowCovering
69
+ // see https://developers.homebridge.io/#/service/Outlet
73
70
 
74
71
  // create handlers for required characteristics
75
- 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));
76
73
 
77
74
  // Update Homekit
78
75
  this.updateHomeKitCharacteristics();
@@ -80,8 +77,8 @@ export class Plug {
80
77
  // Start an update interval
81
78
  interval(this.deviceRefreshRate * 1000)
82
79
  .pipe(skipWhile(() => this.plugUpdateInProgress))
83
- .subscribe(() => {
84
- this.refreshStatus();
80
+ .subscribe(async () => {
81
+ await this.refreshStatus();
85
82
  });
86
83
 
87
84
  // Watch for Plug change events
@@ -110,7 +107,7 @@ export class Plug {
110
107
  });
111
108
  }
112
109
 
113
- parseStatus() {
110
+ async parseStatus(): Promise<void> {
114
111
  switch (this.power) {
115
112
  case 'on':
116
113
  this.On = true;
@@ -121,7 +118,7 @@ export class Plug {
121
118
  this.debugLog(`Plug ${this.accessory.displayName} On: ${this.On}`);
122
119
  }
123
120
 
124
- private async refreshStatus() {
121
+ async refreshStatus(): Promise<void> {
125
122
  try {
126
123
  this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
127
124
  this.debugLog(`Plug: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
@@ -151,7 +148,7 @@ export class Plug {
151
148
  * Plug Mini (US/JP) - "command" turnOff default = set to OFF state
152
149
  * Plug Mini (US/JP) - "command" toggle default = toggle state
153
150
  */
154
- async pushChanges() {
151
+ async pushChanges(): Promise<void> {
155
152
  if (this.On !== this.OnCached) {
156
153
  const payload = {
157
154
  commandType: 'command',
@@ -179,26 +176,26 @@ export class Plug {
179
176
  interval(5000)
180
177
  .pipe(skipWhile(() => this.plugUpdateInProgress))
181
178
  .pipe(take(1))
182
- .subscribe(() => {
183
- this.refreshStatus();
179
+ .subscribe(async () => {
180
+ await this.refreshStatus();
184
181
  });
185
182
  }
186
183
 
187
- updateHomeKitCharacteristics() {
184
+ async updateHomeKitCharacteristics(): Promise<void> {
188
185
  if (this.On === undefined) {
189
186
  this.debugLog(`Plug: ${this.accessory.displayName} On: ${this.On}`);
190
187
  } else {
191
- this.service.updateCharacteristic(this.platform.Characteristic.On, this.On);
188
+ this.outletService.updateCharacteristic(this.platform.Characteristic.On, this.On);
192
189
  this.debugLog(`Plug: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
193
190
  }
194
191
  }
195
192
 
196
- public apiError(e: any) {
197
- this.service.updateCharacteristic(this.platform.Characteristic.On, e);
193
+ async apiError(e: any): Promise<void> {
194
+ this.outletService.updateCharacteristic(this.platform.Characteristic.On, e);
198
195
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
199
196
  }
200
197
 
201
- private statusCode(push: AxiosResponse<{ statusCode: number }>) {
198
+ async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void> {
202
199
  switch (push.data.statusCode) {
203
200
  case 151:
204
201
  this.errorLog(`Plug: ${this.accessory.displayName} Command not supported by this device type.`);
@@ -234,7 +231,7 @@ export class Plug {
234
231
  async offlineOff(): Promise<void> {
235
232
  if (this.device.offline) {
236
233
  this.On = false;
237
- this.service.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
234
+ this.outletService.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
238
235
  }
239
236
  }
240
237
 
@@ -251,11 +248,11 @@ export class Plug {
251
248
  model(device: device & devicesConfig): string {
252
249
  let model: string;
253
250
  if (device.deviceType === 'Plug Mini (US)') {
254
- model = 'SWITCHBOT-PLUG-W1901400';
251
+ model = 'W1901400';
255
252
  } else if (device.deviceType === 'Plug Mini (JP)') {
256
- model = 'SWITCHBOT-PLUG-W2001400';
253
+ model = 'W2001400';
257
254
  } else {
258
- model = 'SWITCHBOT-PLUG-SP11';
255
+ model = 'SP11';
259
256
  }
260
257
  return model;
261
258
  }
@@ -277,6 +274,9 @@ export class Plug {
277
274
  if (device.scanDuration !== undefined) {
278
275
  config['scanDuration'] = device.scanDuration;
279
276
  }
277
+ if (device.offline !== undefined) {
278
+ config['offline'] = device.offline;
279
+ }
280
280
  if (Object.entries(config).length !== 0) {
281
281
  this.warnLog(`Plug: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
282
282
  }
package/src/settings.ts CHANGED
@@ -51,7 +51,7 @@ export interface devicesConfig extends device {
51
51
  motion?: motion;
52
52
  colorbulb?: colorbulb;
53
53
  plug?: Record<any, any>;
54
- lock?: Record<any, any>;
54
+ lock?: lock;
55
55
  ble?: boolean;
56
56
  scanDuration?: number;
57
57
  hide_device?: boolean;
@@ -104,6 +104,10 @@ export type colorbulb = {
104
104
  adaptiveLightingShift?: number;
105
105
  };
106
106
 
107
+ export type lock = {
108
+ hide_contactsensor?: boolean;
109
+ };
110
+
107
111
  export interface irDevicesConfig extends irdevice {
108
112
  configRemoteType?: string;
109
113
  deviceId: string;