@switchbot/homebridge-switchbot 1.12.9-beta.2 → 1.12.9-beta.22

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 (72) hide show
  1. package/.github/workflows/dependabot.yml +12 -0
  2. package/.github/workflows/nodejs-beta.yml +0 -3
  3. package/.github/workflows/nodejs.yml +0 -3
  4. package/CHANGELOG.md +3 -0
  5. package/config.schema.json +18 -0
  6. package/dist/device/bot.d.ts +3 -0
  7. package/dist/device/bot.d.ts.map +1 -1
  8. package/dist/device/bot.js +19 -1
  9. package/dist/device/bot.js.map +1 -1
  10. package/dist/device/colorbulb.d.ts +3 -0
  11. package/dist/device/colorbulb.d.ts.map +1 -1
  12. package/dist/device/colorbulb.js +19 -1
  13. package/dist/device/colorbulb.js.map +1 -1
  14. package/dist/device/contact.d.ts +3 -0
  15. package/dist/device/contact.d.ts.map +1 -1
  16. package/dist/device/contact.js +19 -1
  17. package/dist/device/contact.js.map +1 -1
  18. package/dist/device/curtain.d.ts +3 -0
  19. package/dist/device/curtain.d.ts.map +1 -1
  20. package/dist/device/curtain.js +39 -2
  21. package/dist/device/curtain.js.map +1 -1
  22. package/dist/device/humidifier.d.ts +3 -0
  23. package/dist/device/humidifier.d.ts.map +1 -1
  24. package/dist/device/humidifier.js +19 -2
  25. package/dist/device/humidifier.js.map +1 -1
  26. package/dist/device/lock.d.ts +4 -0
  27. package/dist/device/lock.d.ts.map +1 -1
  28. package/dist/device/lock.js +60 -6
  29. package/dist/device/lock.js.map +1 -1
  30. package/dist/device/meter.d.ts +3 -0
  31. package/dist/device/meter.d.ts.map +1 -1
  32. package/dist/device/meter.js +19 -1
  33. package/dist/device/meter.js.map +1 -1
  34. package/dist/device/meterplus.d.ts +3 -0
  35. package/dist/device/meterplus.d.ts.map +1 -1
  36. package/dist/device/meterplus.js +19 -1
  37. package/dist/device/meterplus.js.map +1 -1
  38. package/dist/device/motion.d.ts +3 -0
  39. package/dist/device/motion.d.ts.map +1 -1
  40. package/dist/device/motion.js +19 -1
  41. package/dist/device/motion.js.map +1 -1
  42. package/dist/device/plug.d.ts +3 -0
  43. package/dist/device/plug.d.ts.map +1 -1
  44. package/dist/device/plug.js +19 -1
  45. package/dist/device/plug.js.map +1 -1
  46. package/dist/device/striplight.d.ts +3 -0
  47. package/dist/device/striplight.d.ts.map +1 -1
  48. package/dist/device/striplight.js +19 -1
  49. package/dist/device/striplight.js.map +1 -1
  50. package/dist/irdevice/other.js +4 -4
  51. package/dist/irdevice/other.js.map +1 -1
  52. package/dist/platform.d.ts.map +1 -1
  53. package/dist/platform.js +41 -41
  54. package/dist/platform.js.map +1 -1
  55. package/dist/settings.d.ts +1 -0
  56. package/dist/settings.d.ts.map +1 -1
  57. package/dist/settings.js.map +1 -1
  58. package/package.json +3 -3
  59. package/src/device/bot.ts +19 -1
  60. package/src/device/colorbulb.ts +19 -1
  61. package/src/device/contact.ts +19 -1
  62. package/src/device/curtain.ts +38 -2
  63. package/src/device/humidifier.ts +19 -2
  64. package/src/device/lock.ts +61 -6
  65. package/src/device/meter.ts +19 -1
  66. package/src/device/meterplus.ts +19 -1
  67. package/src/device/motion.ts +19 -1
  68. package/src/device/plug.ts +19 -1
  69. package/src/device/striplight.ts +19 -1
  70. package/src/irdevice/other.ts +4 -4
  71. package/src/platform.ts +41 -41
  72. package/src/settings.ts +1 -0
@@ -4,6 +4,7 @@ import { SwitchBotPlatform } from '../platform';
4
4
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
5
5
  import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
6
6
  import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse, payload, deviceStatus, ad } from '../settings';
7
+ import { Context } from 'vm';
7
8
 
8
9
  export class Curtain {
9
10
  // Services
@@ -25,6 +26,7 @@ export class Curtain {
25
26
  moving: deviceStatus['moving'];
26
27
  brightness: deviceStatus['brightness'];
27
28
  setPositionMode?: string | number;
29
+ Mode!: string;
28
30
 
29
31
  // BLE Others
30
32
  connected?: boolean;
@@ -80,7 +82,9 @@ export class Curtain {
80
82
  .getService(this.platform.Service.AccessoryInformation)!
81
83
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
82
84
  .setCharacteristic(this.platform.Characteristic.Model, 'W0701600')
83
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId);
85
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
86
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
87
+ .getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(this.FirmwareRevision(accessory, device));
84
88
 
85
89
  // get the WindowCovering service if it exists, otherwise create a new WindowCovering service
86
90
  // you can create multiple services for each accessory
@@ -534,22 +538,31 @@ export class Curtain {
534
538
  if (this.TargetPosition > 50) {
535
539
  if (this.device.curtain?.setOpenMode === '1') {
536
540
  this.setPositionMode = 1;
541
+ this.Mode = 'Silent Mode';
537
542
  } else {
538
543
  this.setPositionMode = 0;
544
+ this.Mode = 'Performance Mode';
539
545
  }
540
546
  } else {
541
547
  if (this.device.curtain?.setCloseMode === '1') {
542
548
  this.setPositionMode = 1;
549
+ this.Mode = 'Silent Mode';
543
550
  } else {
544
551
  this.setPositionMode = 0;
552
+ this.Mode = 'Performance Mode';
545
553
  }
546
554
  }
555
+ const adjustedMode = this.setPositionMode || null;
556
+ if (adjustedMode === null) {
557
+ this.Mode = 'Default Mode';
558
+ }
559
+ this.debugLog(`${this.accessory.displayName} Mode: ${this.Mode}`);
547
560
  if (switchbot !== false) {
548
561
  switchbot
549
562
  .discover({ model: 'c', quick: true, id: this.device.bleMac })
550
563
  .then((device_list) => {
551
564
  this.infoLog(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`);
552
- return device_list[0].runToPos(100 - Number(this.TargetPosition), this.setPositionMode);
565
+ return device_list[0].runToPos(100 - Number(this.TargetPosition), adjustedMode);
553
566
  })
554
567
  .then(() => {
555
568
  this.debugLog(`Curtain: ${this.accessory.displayName} Done.`);
@@ -594,6 +607,14 @@ export class Curtain {
594
607
  } else {
595
608
  this.setPositionMode = this.device.curtain?.setCloseMode;
596
609
  }
610
+ if (this.setPositionMode === '1') {
611
+ this.Mode = 'Silent Mode';
612
+ } else if (this.setPositionMode === '0') {
613
+ this.Mode = 'Performance Mode';
614
+ } else {
615
+ this.Mode = 'Default Mode';
616
+ }
617
+ this.debugLog(`${this.accessory.displayName} Mode: ${this.Mode}`);
597
618
  const adjustedMode = this.setPositionMode || 'ff';
598
619
  const payload = {
599
620
  commandType: 'command',
@@ -851,6 +872,21 @@ export class Curtain {
851
872
  }
852
873
  }
853
874
 
875
+ FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
876
+ let FirmwareRevision: string;
877
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
878
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
879
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
880
+ if (accessory.context.FirmwareRevision) {
881
+ FirmwareRevision = accessory.context.FirmwareRevision;
882
+ } else if (device.firmware) {
883
+ FirmwareRevision = device.firmware;
884
+ } else {
885
+ FirmwareRevision = this.platform.version;
886
+ }
887
+ return FirmwareRevision;
888
+ }
889
+
854
890
  minStep(device: device & devicesConfig): number {
855
891
  if (device.curtain?.set_minStep) {
856
892
  this.set_minStep = device.curtain?.set_minStep;
@@ -4,6 +4,7 @@ import { SwitchBotPlatform } from '../platform';
4
4
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
5
5
  import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
6
6
  import { DeviceURL, device, devicesConfig, serviceData, ad, deviceStatusResponse, payload, deviceStatus } from '../settings';
7
+ import { Context } from 'vm';
7
8
 
8
9
  /**
9
10
  * Platform Accessory
@@ -77,7 +78,9 @@ export class Humidifier {
77
78
  .getService(this.platform.Service.AccessoryInformation)!
78
79
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
79
80
  .setCharacteristic(this.platform.Characteristic.Model, 'W0801800')
80
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
81
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
82
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
83
+ .getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(this.FirmwareRevision(accessory, device));
81
84
 
82
85
  // get the service if it exists, otherwise create a new service
83
86
  // you can create multiple services for each accessory
@@ -124,7 +127,6 @@ export class Humidifier {
124
127
  })
125
128
  .onSet(this.handleRelativeHumidityHumidifierThresholdSet.bind(this));
126
129
 
127
- // create a new Temperature Sensor service
128
130
  // Temperature Sensor Service
129
131
  if (device.humidifier?.hide_temperature || device.ble) {
130
132
  this.debugLog(`Humidifier: ${accessory.displayName} Removing Temperature Sensor Service`);
@@ -812,6 +814,21 @@ export class Humidifier {
812
814
  }
813
815
  }
814
816
 
817
+ FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
818
+ let FirmwareRevision: string;
819
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
820
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
821
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
822
+ if (accessory.context.FirmwareRevision) {
823
+ FirmwareRevision = accessory.context.FirmwareRevision;
824
+ } else if (device.firmware) {
825
+ FirmwareRevision = device.firmware;
826
+ } else {
827
+ FirmwareRevision = this.platform.version;
828
+ }
829
+ return FirmwareRevision;
830
+ }
831
+
815
832
  minStep(): number {
816
833
  if (this.device.humidifier?.set_minStep) {
817
834
  this.set_minStep = this.device.humidifier?.set_minStep;
@@ -4,6 +4,7 @@ import { SwitchBotPlatform } from '../platform';
4
4
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
5
5
  import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
6
6
  import { DeviceURL, device, devicesConfig, deviceStatusResponse, payload, deviceStatus } from '../settings';
7
+ import { Context } from 'vm';
7
8
 
8
9
  export class Lock {
9
10
  // Services
@@ -11,6 +12,7 @@ export class Lock {
11
12
  contactSensorService?: Service;
12
13
 
13
14
  // Characteristic Values
15
+ ContactSensorState!: CharacteristicValue;
14
16
  LockCurrentState!: CharacteristicValue;
15
17
  LockTargetState!: CharacteristicValue;
16
18
  LockTargetStateCached!: CharacteristicValue;
@@ -53,7 +55,9 @@ export class Lock {
53
55
  .getService(this.platform.Service.AccessoryInformation)!
54
56
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
55
57
  .setCharacteristic(this.platform.Characteristic.Model, 'W1601700')
56
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
58
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
59
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
60
+ .getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(this.FirmwareRevision(accessory, device));
57
61
 
58
62
  // get the LockMechanism service if it exists, otherwise create a new LockMechanism service
59
63
  // you can create multiple services for each accessory
@@ -74,6 +78,22 @@ export class Lock {
74
78
  // create handlers for required characteristics
75
79
  this.lockService.getCharacteristic(this.platform.Characteristic.LockCurrentState).onSet(this.LockTargetStateSet.bind(this));
76
80
 
81
+ // Contact Sensor Service
82
+ if (device.lock?.hide_contactsensor) {
83
+ this.debugLog(`Lock: ${accessory.displayName} Removing Contact Sensor Service`);
84
+ this.contactSensorService = this.accessory.getService(this.platform.Service.ContactSensor);
85
+ accessory.removeService(this.contactSensorService!);
86
+ } else if (!this.contactSensorService) {
87
+ this.debugLog(`Lock: ${accessory.displayName} Add Contact Sensor Service`);
88
+ (this.contactSensorService =
89
+ this.accessory.getService(this.platform.Service.ContactSensor) || this.accessory.addService(this.platform.Service.ContactSensor)),
90
+ `${accessory.displayName} Contact Sensor`;
91
+
92
+ this.contactSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Contact Sensor`);
93
+ } else {
94
+ this.debugLog(`Lock: ${accessory.displayName} Contact Sensor Service Not Added`);
95
+ }
96
+
77
97
  // Update Homekit
78
98
  this.updateHomeKitCharacteristics();
79
99
 
@@ -107,13 +127,24 @@ export class Lock {
107
127
  });
108
128
  }
109
129
 
130
+ //{"deviceId":"DBDC23B53139","deviceType":"Smart Lock","hubDeviceId":"E68B14109DA2","lockState":"locked","doorState":"opened","calibrate":true}
131
+
110
132
  async parseStatus(): Promise<void> {
111
133
  switch (this.lockState) {
112
- case 'on':
134
+ case 'locked':
135
+ this.LockCurrentState = this.platform.Characteristic.LockCurrentState.SECURED;
136
+ this.LockTargetState = this.platform.Characteristic.LockTargetState.SECURED;
137
+ break;
138
+ default:
113
139
  this.LockCurrentState = this.platform.Characteristic.LockCurrentState.UNSECURED;
140
+ this.LockTargetState = this.platform.Characteristic.LockTargetState.UNSECURED;
141
+ }
142
+ switch (this.doorState) {
143
+ case 'opened':
144
+ this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
114
145
  break;
115
146
  default:
116
- this.LockCurrentState = this.platform.Characteristic.LockCurrentState.SECURED;
147
+ this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
117
148
  }
118
149
  this.debugLog(`Lock: ${this.accessory.displayName} On: ${this.LockTargetState}`);
119
150
  }
@@ -123,9 +154,7 @@ export class Lock {
123
154
  this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
124
155
  this.debugLog(`Lock: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
125
156
  this.lockState = this.deviceStatus.body.lockState;
126
- this.warnLog(`Lock: ${this.accessory.displayName} lockState: ${JSON.stringify(this.lockState)} (COPY THIS LOG)`);
127
157
  this.doorState = this.deviceStatus.body.doorState;
128
- this.debugLog(`Lock: ${this.accessory.displayName} doorState: ${JSON.stringify(this.doorState)} (COPY THIS LOG)`);
129
158
  this.parseStatus();
130
159
  this.updateHomeKitCharacteristics();
131
160
  } catch (e: any) {
@@ -178,6 +207,14 @@ export class Lock {
178
207
  }
179
208
 
180
209
  async updateHomeKitCharacteristics(): Promise<void> {
210
+ if (!this.device.lock?.hide_contactsensor) {
211
+ if (this.ContactSensorState === undefined) {
212
+ this.debugLog(`Lock: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
213
+ } else {
214
+ this.contactSensorService?.updateCharacteristic(this.platform.Characteristic.ContactSensorState, this.ContactSensorState);
215
+ this.debugLog(`Lock: ${this.accessory.displayName} updateCharacteristic ContactSensorState: ${this.ContactSensorState}`);
216
+ }
217
+ }
181
218
  if (this.LockTargetState === undefined) {
182
219
  this.debugLog(`Lock: ${this.accessory.displayName} LockTargetState: ${this.LockTargetState}`);
183
220
  } else {
@@ -188,11 +225,14 @@ export class Lock {
188
225
  this.debugLog(`Lock: ${this.accessory.displayName} LockCurrentState: ${this.LockCurrentState}`);
189
226
  } else {
190
227
  this.lockService.updateCharacteristic(this.platform.Characteristic.LockCurrentState, this.LockCurrentState);
191
- this.debugLog(`Lock: ${this.accessory.displayName} updateCharacteristic LockTargetState: ${this.LockCurrentState}`);
228
+ this.debugLog(`Lock: ${this.accessory.displayName} updateCharacteristic LockCurrentState: ${this.LockCurrentState}`);
192
229
  }
193
230
  }
194
231
 
195
232
  async apiError(e: any): Promise<void> {
233
+ if (!this.device.lock?.hide_contactsensor) {
234
+ this.contactSensorService?.updateCharacteristic(this.platform.Characteristic.ContactSensorState, e);
235
+ }
196
236
  this.lockService.updateCharacteristic(this.platform.Characteristic.LockTargetState, e);
197
237
  this.lockService.updateCharacteristic(this.platform.Characteristic.LockCurrentState, e);
198
238
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
@@ -301,6 +341,21 @@ export class Lock {
301
341
  }
302
342
  }
303
343
 
344
+ FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
345
+ let FirmwareRevision: string;
346
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
347
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
348
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
349
+ if (accessory.context.FirmwareRevision) {
350
+ FirmwareRevision = accessory.context.FirmwareRevision;
351
+ } else if (device.firmware) {
352
+ FirmwareRevision = device.firmware;
353
+ } else {
354
+ FirmwareRevision = this.platform.version;
355
+ }
356
+ return FirmwareRevision;
357
+ }
358
+
304
359
  /**
305
360
  * Logging for Device
306
361
  */
@@ -3,6 +3,7 @@ import { skipWhile } from 'rxjs/operators';
3
3
  import { SwitchBotPlatform } from '../platform';
4
4
  import { Service, PlatformAccessory, Units, CharacteristicValue } from 'homebridge';
5
5
  import { DeviceURL, device, devicesConfig, serviceData, ad, switchbot, deviceStatusResponse, temperature, deviceStatus } from '../settings';
6
+ import { Context } from 'vm';
6
7
 
7
8
  /**
8
9
  * Platform Accessory
@@ -79,7 +80,9 @@ export class Meter {
79
80
  .getService(this.platform.Service.AccessoryInformation)!
80
81
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
81
82
  .setCharacteristic(this.platform.Characteristic.Model, 'METERTH-S1')
82
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
83
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
84
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
85
+ .getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(this.FirmwareRevision(accessory, device));
83
86
 
84
87
  // Temperature Sensor Service
85
88
  if (device.meter?.hide_temperature) {
@@ -470,6 +473,21 @@ export class Meter {
470
473
  }
471
474
  }
472
475
 
476
+ FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
477
+ let FirmwareRevision: string;
478
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
479
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
480
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
481
+ if (accessory.context.FirmwareRevision) {
482
+ FirmwareRevision = accessory.context.FirmwareRevision;
483
+ } else if (device.firmware) {
484
+ FirmwareRevision = device.firmware;
485
+ } else {
486
+ FirmwareRevision = this.platform.version;
487
+ }
488
+ return FirmwareRevision;
489
+ }
490
+
473
491
  /**
474
492
  * Logging for Device
475
493
  */
@@ -3,6 +3,7 @@ import { skipWhile } from 'rxjs/operators';
3
3
  import { SwitchBotPlatform } from '../platform';
4
4
  import { Service, PlatformAccessory, Units, CharacteristicValue } from 'homebridge';
5
5
  import { DeviceURL, device, devicesConfig, serviceData, ad, switchbot, deviceStatusResponse, temperature, deviceStatus } from '../settings';
6
+ import { Context } from 'vm';
6
7
 
7
8
  /**
8
9
  * Platform Accessory
@@ -79,7 +80,9 @@ export class MeterPlus {
79
80
  .getService(this.platform.Service.AccessoryInformation)!
80
81
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
81
82
  .setCharacteristic(this.platform.Characteristic.Model, this.model(device))
82
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
83
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
84
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
85
+ .getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(this.FirmwareRevision(accessory, device));
83
86
 
84
87
  // Temperature Sensor Service
85
88
  if (device.meter?.hide_temperature) {
@@ -481,6 +484,21 @@ export class MeterPlus {
481
484
  }
482
485
  }
483
486
 
487
+ FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
488
+ let FirmwareRevision: string;
489
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
490
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
491
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
492
+ if (accessory.context.FirmwareRevision) {
493
+ FirmwareRevision = accessory.context.FirmwareRevision;
494
+ } else if (device.firmware) {
495
+ FirmwareRevision = device.firmware;
496
+ } else {
497
+ FirmwareRevision = this.platform.version;
498
+ }
499
+ return FirmwareRevision;
500
+ }
501
+
484
502
  /**
485
503
  * Logging for Device
486
504
  */
@@ -3,6 +3,7 @@ import { skipWhile } from 'rxjs/operators';
3
3
  import { SwitchBotPlatform } from '../platform';
4
4
  import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
5
5
  import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse, deviceStatus, ad } from '../settings';
6
+ import { Context } from 'vm';
6
7
 
7
8
  /**
8
9
  * Platform Accessory
@@ -67,7 +68,9 @@ export class Motion {
67
68
  .getService(this.platform.Service.AccessoryInformation)!
68
69
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
69
70
  .setCharacteristic(this.platform.Characteristic.Model, 'W1101500')
70
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
71
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
72
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
73
+ .getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(this.FirmwareRevision(accessory, device));
71
74
 
72
75
  // get the Battery service if it exists, otherwise create a new Motion service
73
76
  // you can create multiple services for each accessory
@@ -453,6 +456,21 @@ export class Motion {
453
456
  }
454
457
  }
455
458
 
459
+ FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
460
+ let FirmwareRevision: string;
461
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
462
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
463
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
464
+ if (accessory.context.FirmwareRevision) {
465
+ FirmwareRevision = accessory.context.FirmwareRevision;
466
+ } else if (device.firmware) {
467
+ FirmwareRevision = device.firmware;
468
+ } else {
469
+ FirmwareRevision = this.platform.version;
470
+ }
471
+ return FirmwareRevision;
472
+ }
473
+
456
474
  minLux(): number {
457
475
  if (this.device.motion?.set_minLux) {
458
476
  this.set_minLux = this.device.motion!.set_minLux!;
@@ -4,6 +4,7 @@ import { SwitchBotPlatform } from '../platform';
4
4
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
5
5
  import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
6
6
  import { DeviceURL, device, devicesConfig, deviceStatusResponse, payload, deviceStatus } from '../settings';
7
+ import { Context } from 'vm';
7
8
 
8
9
  export class Plug {
9
10
  // Services
@@ -50,7 +51,9 @@ export class Plug {
50
51
  .getService(this.platform.Service.AccessoryInformation)!
51
52
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
52
53
  .setCharacteristic(this.platform.Characteristic.Model, this.model(device))
53
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
54
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
55
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
56
+ .getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(this.FirmwareRevision(accessory, device));
54
57
 
55
58
  // get the Outlet service if it exists, otherwise create a new Outlet service
56
59
  // you can create multiple services for each accessory
@@ -315,6 +318,21 @@ export class Plug {
315
318
  }
316
319
  }
317
320
 
321
+ FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
322
+ let FirmwareRevision: string;
323
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
324
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
325
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
326
+ if (accessory.context.FirmwareRevision) {
327
+ FirmwareRevision = accessory.context.FirmwareRevision;
328
+ } else if (device.firmware) {
329
+ FirmwareRevision = device.firmware;
330
+ } else {
331
+ FirmwareRevision = this.platform.version;
332
+ }
333
+ return FirmwareRevision;
334
+ }
335
+
318
336
  /**
319
337
  * Logging for Device
320
338
  */
@@ -4,6 +4,7 @@ import { SwitchBotPlatform } from '../platform';
4
4
  import { debounceTime, skipWhile, tap } from 'rxjs/operators';
5
5
  import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
6
6
  import { DeviceURL, device, devicesConfig, switchbot, deviceStatusResponse, payload, hs2rgb, rgb2hs, deviceStatus } from '../settings';
7
+ import { Context } from 'vm';
7
8
 
8
9
  /**
9
10
  * Platform Accessory
@@ -78,7 +79,9 @@ export class StripLight {
78
79
  .getService(this.platform.Service.AccessoryInformation)!
79
80
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
80
81
  .setCharacteristic(this.platform.Characteristic.Model, 'W1701100')
81
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
82
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
83
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
84
+ .getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(this.FirmwareRevision(accessory, device));
82
85
 
83
86
  // get the Lightbulb service if it exists, otherwise create a new Lightbulb service
84
87
  // you can create multiple services for each accessory
@@ -537,6 +540,21 @@ export class StripLight {
537
540
  }
538
541
  }
539
542
 
543
+ FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
544
+ let FirmwareRevision: string;
545
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
546
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
547
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
548
+ if (accessory.context.FirmwareRevision) {
549
+ FirmwareRevision = accessory.context.FirmwareRevision;
550
+ } else if (device.firmware) {
551
+ FirmwareRevision = device.firmware;
552
+ } else {
553
+ FirmwareRevision = this.platform.version;
554
+ }
555
+ return FirmwareRevision;
556
+ }
557
+
540
558
  minStep(device: device & devicesConfig): number {
541
559
  if (device.colorbulb?.set_minStep) {
542
560
  this.set_minStep = device.colorbulb?.set_minStep;
@@ -64,9 +64,9 @@ export class Others {
64
64
  async ActiveSet(value: CharacteristicValue): Promise<void> {
65
65
  this.debugLog(`Other: ${this.accessory.displayName} On: ${value}`);
66
66
  if (this.Active) {
67
- await this.pushOnChanges();
68
- } else {
69
67
  await this.pushOffChanges();
68
+ } else {
69
+ await this.pushOnChanges();
70
70
  }
71
71
  this.Active = value;
72
72
  this.ActiveCached = this.Active;
@@ -96,7 +96,7 @@ export class Others {
96
96
  if (this.platform.config.options) {
97
97
  if (this.device.other) {
98
98
  if (this.device.other.commandOn) {
99
- if (this.Active) {
99
+ if (!this.Active) {
100
100
  const payload = {
101
101
  commandType: 'customize',
102
102
  parameter: 'default',
@@ -119,7 +119,7 @@ export class Others {
119
119
  if (this.platform.config.options) {
120
120
  if (this.device.other) {
121
121
  if (this.device.other.commandOff) {
122
- if (!this.Active) {
122
+ if (this.Active) {
123
123
  const payload = {
124
124
  commandType: 'customize',
125
125
  parameter: 'default',