@switchbot/homebridge-switchbot 3.5.0-beta.57 → 3.5.0-beta.59

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 (164) hide show
  1. package/.vscode/settings.json +4 -1
  2. package/dist/device/blindtilt.d.ts +5 -5
  3. package/dist/device/blindtilt.d.ts.map +1 -1
  4. package/dist/device/blindtilt.js +103 -69
  5. package/dist/device/blindtilt.js.map +1 -1
  6. package/dist/device/bot.d.ts +4 -4
  7. package/dist/device/bot.d.ts.map +1 -1
  8. package/dist/device/bot.js +201 -154
  9. package/dist/device/bot.js.map +1 -1
  10. package/dist/device/ceilinglight.d.ts +3 -3
  11. package/dist/device/ceilinglight.d.ts.map +1 -1
  12. package/dist/device/ceilinglight.js +41 -36
  13. package/dist/device/ceilinglight.js.map +1 -1
  14. package/dist/device/colorbulb.d.ts +3 -3
  15. package/dist/device/colorbulb.d.ts.map +1 -1
  16. package/dist/device/colorbulb.js +36 -37
  17. package/dist/device/colorbulb.js.map +1 -1
  18. package/dist/device/contact.d.ts +4 -4
  19. package/dist/device/contact.d.ts.map +1 -1
  20. package/dist/device/contact.js +76 -55
  21. package/dist/device/contact.js.map +1 -1
  22. package/dist/device/curtain.d.ts +4 -4
  23. package/dist/device/curtain.d.ts.map +1 -1
  24. package/dist/device/curtain.js +99 -55
  25. package/dist/device/curtain.js.map +1 -1
  26. package/dist/device/device.d.ts +4 -4
  27. package/dist/device/device.d.ts.map +1 -1
  28. package/dist/device/device.js +11 -9
  29. package/dist/device/device.js.map +1 -1
  30. package/dist/device/fan.d.ts +3 -3
  31. package/dist/device/fan.d.ts.map +1 -1
  32. package/dist/device/fan.js +54 -24
  33. package/dist/device/fan.js.map +1 -1
  34. package/dist/device/hub.d.ts +4 -4
  35. package/dist/device/hub.d.ts.map +1 -1
  36. package/dist/device/hub.js +40 -57
  37. package/dist/device/hub.js.map +1 -1
  38. package/dist/device/humidifier.d.ts +3 -3
  39. package/dist/device/humidifier.d.ts.map +1 -1
  40. package/dist/device/humidifier.js +39 -39
  41. package/dist/device/humidifier.js.map +1 -1
  42. package/dist/device/iosensor.d.ts +3 -3
  43. package/dist/device/iosensor.d.ts.map +1 -1
  44. package/dist/device/iosensor.js +41 -50
  45. package/dist/device/iosensor.js.map +1 -1
  46. package/dist/device/lightstrip.d.ts +4 -4
  47. package/dist/device/lightstrip.d.ts.map +1 -1
  48. package/dist/device/lightstrip.js +36 -33
  49. package/dist/device/lightstrip.js.map +1 -1
  50. package/dist/device/lock.d.ts +3 -3
  51. package/dist/device/lock.d.ts.map +1 -1
  52. package/dist/device/lock.js +68 -59
  53. package/dist/device/lock.js.map +1 -1
  54. package/dist/device/meter.d.ts +3 -3
  55. package/dist/device/meter.d.ts.map +1 -1
  56. package/dist/device/meter.js +42 -51
  57. package/dist/device/meter.js.map +1 -1
  58. package/dist/device/meterplus.d.ts +3 -3
  59. package/dist/device/meterplus.d.ts.map +1 -1
  60. package/dist/device/meterplus.js +42 -51
  61. package/dist/device/meterplus.js.map +1 -1
  62. package/dist/device/motion.d.ts +3 -3
  63. package/dist/device/motion.d.ts.map +1 -1
  64. package/dist/device/motion.js +52 -40
  65. package/dist/device/motion.js.map +1 -1
  66. package/dist/device/plug.d.ts +3 -3
  67. package/dist/device/plug.d.ts.map +1 -1
  68. package/dist/device/plug.js +13 -13
  69. package/dist/device/plug.js.map +1 -1
  70. package/dist/device/robotvacuumcleaner.d.ts +4 -4
  71. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  72. package/dist/device/robotvacuumcleaner.js +81 -98
  73. package/dist/device/robotvacuumcleaner.js.map +1 -1
  74. package/dist/device/waterdetector.d.ts +3 -3
  75. package/dist/device/waterdetector.d.ts.map +1 -1
  76. package/dist/device/waterdetector.js +39 -31
  77. package/dist/device/waterdetector.js.map +1 -1
  78. package/dist/homebridge-ui/public/index.html +20 -14
  79. package/dist/index.d.ts +1 -1
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +1 -1
  82. package/dist/index.js.map +1 -1
  83. package/dist/irdevice/airconditioner.d.ts +3 -3
  84. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  85. package/dist/irdevice/airconditioner.js +9 -9
  86. package/dist/irdevice/airconditioner.js.map +1 -1
  87. package/dist/irdevice/airpurifier.d.ts +3 -3
  88. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  89. package/dist/irdevice/airpurifier.js +1 -1
  90. package/dist/irdevice/airpurifier.js.map +1 -1
  91. package/dist/irdevice/camera.d.ts +3 -3
  92. package/dist/irdevice/camera.d.ts.map +1 -1
  93. package/dist/irdevice/camera.js +2 -2
  94. package/dist/irdevice/camera.js.map +1 -1
  95. package/dist/irdevice/fan.d.ts +6 -6
  96. package/dist/irdevice/fan.d.ts.map +1 -1
  97. package/dist/irdevice/fan.js +37 -29
  98. package/dist/irdevice/fan.js.map +1 -1
  99. package/dist/irdevice/irdevice.d.ts +3 -3
  100. package/dist/irdevice/irdevice.d.ts.map +1 -1
  101. package/dist/irdevice/irdevice.js.map +1 -1
  102. package/dist/irdevice/light.d.ts +9 -14
  103. package/dist/irdevice/light.d.ts.map +1 -1
  104. package/dist/irdevice/light.js +67 -88
  105. package/dist/irdevice/light.js.map +1 -1
  106. package/dist/irdevice/other.d.ts +3 -3
  107. package/dist/irdevice/other.d.ts.map +1 -1
  108. package/dist/irdevice/other.js +1 -1
  109. package/dist/irdevice/other.js.map +1 -1
  110. package/dist/irdevice/tv.d.ts +3 -3
  111. package/dist/irdevice/tv.d.ts.map +1 -1
  112. package/dist/irdevice/tv.js +3 -3
  113. package/dist/irdevice/tv.js.map +1 -1
  114. package/dist/irdevice/vacuumcleaner.d.ts +3 -3
  115. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  116. package/dist/irdevice/vacuumcleaner.js +2 -2
  117. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  118. package/dist/irdevice/waterheater.d.ts +3 -3
  119. package/dist/irdevice/waterheater.d.ts.map +1 -1
  120. package/dist/irdevice/waterheater.js +2 -2
  121. package/dist/irdevice/waterheater.js.map +1 -1
  122. package/dist/platform.d.ts +7 -7
  123. package/dist/platform.d.ts.map +1 -1
  124. package/dist/platform.js +20 -23
  125. package/dist/platform.js.map +1 -1
  126. package/dist/settings.d.ts +24 -10
  127. package/dist/settings.d.ts.map +1 -1
  128. package/dist/settings.js +16 -0
  129. package/dist/settings.js.map +1 -1
  130. package/eslint.config.js +89 -78
  131. package/package.json +3 -3
  132. package/src/device/blindtilt.ts +120 -87
  133. package/src/device/bot.ts +238 -175
  134. package/src/device/ceilinglight.ts +49 -46
  135. package/src/device/colorbulb.ts +40 -43
  136. package/src/device/contact.ts +91 -65
  137. package/src/device/curtain.ts +113 -66
  138. package/src/device/device.ts +12 -13
  139. package/src/device/fan.ts +66 -29
  140. package/src/device/hub.ts +53 -60
  141. package/src/device/humidifier.ts +54 -56
  142. package/src/device/iosensor.ts +57 -56
  143. package/src/device/lightstrip.ts +43 -39
  144. package/src/device/lock.ts +79 -68
  145. package/src/device/meter.ts +54 -54
  146. package/src/device/meterplus.ts +54 -54
  147. package/src/device/motion.ts +62 -46
  148. package/src/device/plug.ts +19 -18
  149. package/src/device/robotvacuumcleaner.ts +89 -104
  150. package/src/device/waterdetector.ts +46 -34
  151. package/src/homebridge-ui/public/index.html +20 -14
  152. package/src/index.ts +3 -2
  153. package/src/irdevice/airconditioner.ts +13 -11
  154. package/src/irdevice/airpurifier.ts +5 -3
  155. package/src/irdevice/camera.ts +6 -4
  156. package/src/irdevice/fan.ts +42 -29
  157. package/src/irdevice/irdevice.ts +4 -5
  158. package/src/irdevice/light.ts +83 -103
  159. package/src/irdevice/other.ts +5 -3
  160. package/src/irdevice/tv.ts +7 -5
  161. package/src/irdevice/vacuumcleaner.ts +6 -4
  162. package/src/irdevice/waterheater.ts +6 -4
  163. package/src/platform.ts +59 -66
  164. package/src/settings.ts +73 -58
@@ -4,12 +4,14 @@
4
4
  */
5
5
  import { request } from 'undici';
6
6
  import { deviceBase } from './device.js';
7
- import { hs2rgb, rgb2hs, m2hs } from '../utils.js';
8
7
  import { interval, Subject } from 'rxjs';
9
- import { SwitchBotPlatform } from '../platform.js';
8
+ import { Devices } from '../settings.js';
9
+ import { hs2rgb, rgb2hs, m2hs } from '../utils.js';
10
10
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
11
- import { device, devicesConfig, serviceData, deviceStatus, Devices } from '../settings.js';
12
- import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
11
+
12
+ import type { SwitchBotPlatform } from '../platform.js';
13
+ import type { device, devicesConfig, serviceData, deviceStatus} from '../settings.js';
14
+ import type { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
13
15
 
14
16
  /**
15
17
  * Platform Accessory
@@ -19,6 +21,7 @@ import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor,
19
21
  export class CeilingLight extends deviceBase {
20
22
  // Services
21
23
  private LightBulb: {
24
+ Name: CharacteristicValue;
22
25
  Service: Service;
23
26
  On: CharacteristicValue;
24
27
  Hue: CharacteristicValue;
@@ -50,35 +53,44 @@ export class CeilingLight extends deviceBase {
50
53
 
51
54
  // Initialize LightBulb property
52
55
  this.LightBulb = {
53
- Service: accessory.getService(this.hap.Service.Lightbulb) as Service,
54
- On: accessory.context.On || false,
55
- Hue: accessory.context.Hue || 0,
56
- Saturation: accessory.context.Saturation || 0,
57
- Brightness: accessory.context.Brightness || 0,
58
- ColorTemperature: accessory.context.ColorTemperature || 140,
56
+ Name: accessory.context.LightBulb.Name ?? accessory.displayName,
57
+ Service: accessory.getService(this.hap.Service.Lightbulb) ?? accessory.addService(this.hap.Service.Lightbulb) as Service,
58
+ On: accessory.context.On ?? false,
59
+ Hue: accessory.context.Hue ?? 0,
60
+ Saturation: accessory.context.Saturation ?? 0,
61
+ Brightness: accessory.context.Brightness ?? 0,
62
+ ColorTemperature: accessory.context.ColorTemperature ?? 140,
59
63
  };
60
64
 
61
- // Retrieve initial values and updateHomekit
62
- this.refreshStatus();
63
-
64
- const LightBulbService = `${accessory.displayName} ${device.deviceType}`;
65
- (this.LightBulb!.Service = accessory.getService(this.hap.Service.Lightbulb)
66
- || accessory.addService(this.hap.Service.Lightbulb)), LightBulbService;
67
-
68
-
69
- if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
70
- this.accessory.removeService(this.LightBulb!.Service);
71
- this.LightBulb!.Service = this.accessory.addService(this.hap.Service.Lightbulb);
72
- this.accessory.context.adaptiveLighting = false;
73
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
65
+ // Adaptive Lighting
66
+ if (this.adaptiveLightingShift === -1 && accessory.context.adaptiveLighting) {
67
+ accessory.removeService(this.LightBulb.Service);
68
+ this.LightBulb.Service = accessory.addService(this.hap.Service.Lightbulb);
69
+ accessory.context.adaptiveLighting = false;
70
+ this.debugLog(`${device.deviceType}: ${accessory.displayName} adaptiveLighting: ${accessory.context.adaptiveLighting}`);
71
+ }
72
+ if (this.adaptiveLightingShift !== -1) {
73
+ this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.LightBulb.Service, {
74
+ customTemperatureAdjustment: this.adaptiveLightingShift,
75
+ });
76
+ this.accessory.configureController(this.AdaptiveLightingController);
77
+ this.accessory.context.adaptiveLighting = true;
78
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},`
79
+ + ` adaptiveLightingShift: ${this.adaptiveLightingShift}`);
74
80
  }
81
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
75
82
 
76
- this.LightBulb!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
77
- // handle on / off events using the On characteristic
78
- this.LightBulb!.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
83
+ // Initialize LightBulb Characteristics
84
+ this.LightBulb.Service
85
+ .setCharacteristic(this.hap.Characteristic.Name, this.LightBulb.Name)
86
+ .getCharacteristic(this.hap.Characteristic.On)
87
+ .onGet(() => {
88
+ return this.LightBulb.On;
89
+ })
90
+ .onSet(this.OnSet.bind(this));
79
91
 
80
- // handle Brightness events using the Brightness characteristic
81
- this.LightBulb!.Service
92
+ // Initialize LightBulb Brightness
93
+ this.LightBulb.Service
82
94
  .getCharacteristic(this.hap.Characteristic.Brightness)
83
95
  .setProps({
84
96
  minStep: this.minStep(device),
@@ -91,8 +103,8 @@ export class CeilingLight extends deviceBase {
91
103
  })
92
104
  .onSet(this.BrightnessSet.bind(this));
93
105
 
94
- // handle ColorTemperature events using the ColorTemperature characteristic
95
- this.LightBulb!.Service
106
+ // Initialize LightBulb ColorTemperature
107
+ this.LightBulb.Service
96
108
  .getCharacteristic(this.hap.Characteristic.ColorTemperature)
97
109
  .setProps({
98
110
  minValue: 140,
@@ -104,8 +116,8 @@ export class CeilingLight extends deviceBase {
104
116
  })
105
117
  .onSet(this.ColorTemperatureSet.bind(this));
106
118
 
107
- // handle Hue events using the Hue characteristic
108
- this.LightBulb!.Service
119
+ // Initialize LightBulb Hue
120
+ this.LightBulb.Service
109
121
  .getCharacteristic(this.hap.Characteristic.Hue)
110
122
  .setProps({
111
123
  minValue: 0,
@@ -117,8 +129,8 @@ export class CeilingLight extends deviceBase {
117
129
  })
118
130
  .onSet(this.HueSet.bind(this));
119
131
 
120
- // handle Hue events using the Hue characteristic
121
- this.LightBulb!.Service
132
+ // Initialize LightBulb Saturation
133
+ this.LightBulb.Service
122
134
  .getCharacteristic(this.hap.Characteristic.Saturation)
123
135
  .setProps({
124
136
  minValue: 0,
@@ -129,19 +141,10 @@ export class CeilingLight extends deviceBase {
129
141
  return this.LightBulb.Saturation;
130
142
  })
131
143
  .onSet(this.SaturationSet.bind(this));
144
+ accessory.context.LightBulb.Name = this.LightBulb.Name;
132
145
 
133
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
134
- if (this.adaptiveLightingShift !== -1) {
135
- this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.LightBulb!.Service, {
136
- customTemperatureAdjustment: this.adaptiveLightingShift,
137
- });
138
- this.accessory.configureController(this.AdaptiveLightingController);
139
- this.accessory.context.adaptiveLighting = true;
140
- this.debugLog(
141
- `${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
142
- ` adaptiveLightingShift: ${this.adaptiveLightingShift}`,
143
- );
144
- }
146
+ // Retrieve initial values and updateHomekit
147
+ this.refreshStatus();
145
148
 
146
149
  // Update Homekit
147
150
  this.updateHomeKitCharacteristics();
@@ -5,11 +5,13 @@
5
5
  import { request } from 'undici';
6
6
  import { deviceBase } from './device.js';
7
7
  import { interval, Subject } from 'rxjs';
8
- import { SwitchBotPlatform } from '../platform.js';
8
+ import { Devices } from '../settings.js';
9
9
  import { hs2rgb, rgb2hs, m2hs } from '../utils.js';
10
10
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
11
- import { device, devicesConfig, deviceStatus, serviceData, Devices } from '../settings.js';
12
- import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
11
+
12
+ import type { SwitchBotPlatform } from '../platform.js';
13
+ import type { device, devicesConfig, deviceStatus, serviceData} from '../settings.js';
14
+ import type { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
13
15
 
14
16
  /**
15
17
  * Platform Accessory
@@ -19,6 +21,7 @@ import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor,
19
21
  export class ColorBulb extends deviceBase {
20
22
  // Services
21
23
  private LightBulb: {
24
+ Name: CharacteristicValue;
22
25
  Service: Service;
23
26
  On: CharacteristicValue;
24
27
  Hue: CharacteristicValue;
@@ -51,36 +54,42 @@ export class ColorBulb extends deviceBase {
51
54
 
52
55
  // Initialize LightBulb property
53
56
  this.LightBulb = {
54
- Service: accessory.getService(this.hap.Service.Lightbulb) as Service,
55
- On: accessory.context.On || false,
56
- Hue: accessory.context.Hue || 0,
57
- Saturation: accessory.context.Saturation || 0,
58
- Brightness: accessory.context.Brightness || 0,
59
- ColorTemperature: accessory.context.ColorTemperature || 140,
57
+ Name: accessory.context.LightBulb.Name ?? accessory.displayName,
58
+ Service: accessory.getService(this.hap.Service.Lightbulb) ?? accessory.addService(this.hap.Service.Lightbulb) as Service,
59
+ On: accessory.context.On ?? false,
60
+ Hue: accessory.context.Hue ?? 0,
61
+ Saturation: accessory.context.Saturation ?? 0,
62
+ Brightness: accessory.context.Brightness ?? 0,
63
+ ColorTemperature: accessory.context.ColorTemperature ?? 140,
60
64
  };
61
65
 
62
- // Retrieve initial values and updateHomekit
63
- this.refreshStatus();
64
-
65
- // get the Lightbulb service if it exists, otherwise create a new Lightbulb service
66
- // you can create multiple services for each accessory
67
- const lightBulbService = `${accessory.displayName} ${device.deviceType}`;
68
- (this.LightBulb.Service = accessory.getService(this.hap.Service.Lightbulb)
69
- || accessory.addService(this.hap.Service.Lightbulb)), lightBulbService;
70
-
71
- if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
72
- this.accessory.removeService(this.LightBulb.Service);
73
- this.LightBulb.Service = this.accessory.addService(this.hap.Service.Lightbulb);
74
- this.accessory.context.adaptiveLighting = false;
75
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
66
+ // Adaptive Lighting
67
+ if (this.adaptiveLightingShift === -1 && accessory.context.adaptiveLighting) {
68
+ accessory.removeService(this.LightBulb.Service);
69
+ this.LightBulb.Service = accessory.addService(this.hap.Service.Lightbulb);
70
+ accessory.context.adaptiveLighting = false;
71
+ this.debugLog(`${device.deviceType}: ${accessory.displayName} adaptiveLighting: ${accessory.context.adaptiveLighting}`);
76
72
  }
73
+ if (this.adaptiveLightingShift !== -1) {
74
+ this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.LightBulb.Service, {
75
+ customTemperatureAdjustment: this.adaptiveLightingShift,
76
+ });
77
+ accessory.configureController(this.AdaptiveLightingController);
78
+ accessory.context.adaptiveLighting = true;
79
+ this.debugLog(`${device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${accessory.context.adaptiveLighting},`
80
+ + ` adaptiveLightingShift: ${this.adaptiveLightingShift}`);
81
+ }
82
+ this.debugLog(`${device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
77
83
 
78
- this.LightBulb.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
79
-
80
- // handle on / off events using the On characteristic
81
- this.LightBulb.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
84
+ // Initialize LightBulb Characteristics
85
+ this.LightBulb.Service
86
+ .setCharacteristic(this.hap.Characteristic.Name, this.LightBulb.Name)
87
+ .getCharacteristic(this.hap.Characteristic.On)
88
+ .onGet(() => {
89
+ return this.LightBulb.On;
90
+ })
91
+ .onSet(this.OnSet.bind(this));
82
92
 
83
- // handle Brightness events using the Brightness characteristic
84
93
  this.LightBulb.Service
85
94
  .getCharacteristic(this.hap.Characteristic.Brightness)
86
95
  .setProps({
@@ -94,7 +103,6 @@ export class ColorBulb extends deviceBase {
94
103
  })
95
104
  .onSet(this.BrightnessSet.bind(this));
96
105
 
97
- // handle ColorTemperature events using the ColorTemperature characteristic
98
106
  this.LightBulb.Service
99
107
  .getCharacteristic(this.hap.Characteristic.ColorTemperature)
100
108
  .setProps({
@@ -107,7 +115,6 @@ export class ColorBulb extends deviceBase {
107
115
  })
108
116
  .onSet(this.ColorTemperatureSet.bind(this));
109
117
 
110
- // handle Hue events using the Hue characteristic
111
118
  this.LightBulb.Service
112
119
  .getCharacteristic(this.hap.Characteristic.Hue)
113
120
  .setProps({
@@ -120,7 +127,6 @@ export class ColorBulb extends deviceBase {
120
127
  })
121
128
  .onSet(this.HueSet.bind(this));
122
129
 
123
- // handle Hue events using the Hue characteristic
124
130
  this.LightBulb.Service
125
131
  .getCharacteristic(this.hap.Characteristic.Saturation)
126
132
  .setProps({
@@ -132,19 +138,10 @@ export class ColorBulb extends deviceBase {
132
138
  return this.LightBulb.Saturation;
133
139
  })
134
140
  .onSet(this.SaturationSet.bind(this));
141
+ accessory.context.LightBulb.Name = this.LightBulb.Name;
135
142
 
136
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
137
- if (this.adaptiveLightingShift !== -1) {
138
- this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.LightBulb.Service, {
139
- customTemperatureAdjustment: this.adaptiveLightingShift,
140
- });
141
- this.accessory.configureController(this.AdaptiveLightingController);
142
- this.accessory.context.adaptiveLighting = true;
143
- this.debugLog(
144
- `${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
145
- ` adaptiveLightingShift: ${this.adaptiveLightingShift}`,
146
- );
147
- }
143
+ // Retrieve initial values and updateHomekit
144
+ this.refreshStatus();
148
145
 
149
146
  // Update Homekit
150
147
  this.updateHomeKitCharacteristics();
@@ -4,10 +4,12 @@
4
4
  */
5
5
  import { deviceBase } from './device.js';
6
6
  import { interval, Subject } from 'rxjs';
7
+ import { Devices } from '../settings.js';
7
8
  import { skipWhile } from 'rxjs/operators';
8
- import { SwitchBotPlatform } from '../platform.js';
9
- import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
10
- import { device, devicesConfig, serviceData, deviceStatus, Devices } from '../settings.js';
9
+
10
+ import type { SwitchBotPlatform } from '../platform.js';
11
+ import type { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
12
+ import type { device, devicesConfig, serviceData, deviceStatus } from '../settings.js';
11
13
 
12
14
  /**
13
15
  * Platform Accessory
@@ -16,27 +18,31 @@ import { device, devicesConfig, serviceData, deviceStatus, Devices } from '../se
16
18
  */
17
19
  export class Contact extends deviceBase {
18
20
  // Services
19
- private ContactSensor!: {
21
+ private ContactSensor: {
22
+ Name: CharacteristicValue;
20
23
  Service: Service;
21
24
  ContactSensorState: CharacteristicValue;
22
25
  };
23
26
 
27
+ private Battery: {
28
+ Name: CharacteristicValue;
29
+ Service: Service;
30
+ BatteryLevel: CharacteristicValue;
31
+ StatusLowBattery: CharacteristicValue;
32
+ };
33
+
24
34
  private MotionSensor?: {
35
+ Name: CharacteristicValue;
25
36
  Service: Service;
26
37
  MotionDetected: CharacteristicValue;
27
38
  };
28
39
 
29
40
  private LightSensor?: {
41
+ Name: CharacteristicValue;
30
42
  Service: Service;
31
43
  CurrentAmbientLightLevel: CharacteristicValue;
32
44
  };
33
45
 
34
- private Battery!: {
35
- Service: Service;
36
- BatteryLevel: CharacteristicValue;
37
- StatusLowBattery: CharacteristicValue;
38
- };
39
-
40
46
  // Updates
41
47
  contactUpdateInProgress!: boolean;
42
48
  doContactUpdate!: Subject<void>;
@@ -53,77 +59,94 @@ export class Contact extends deviceBase {
53
59
 
54
60
  // Initialize Contact Sensor property
55
61
  this.ContactSensor = {
56
- Service: accessory.getService(this.hap.Service.ContactSensor) as Service,
57
- ContactSensorState: this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED,
62
+ Name: accessory.context.ContactSensor.Name ?? accessory.displayName,
63
+ Service: accessory.getService(this.hap.Service.ContactSensor) ?? accessory.addService(this.hap.Service.ContactSensor) as Service,
64
+ ContactSensorState: accessory.context.ContactSensorState ?? this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED,
58
65
  };
59
66
 
60
- // Initialize Motion Sensor property
61
- if (!this.device.contact?.hide_motionsensor) {
62
- this.MotionSensor = {
63
- Service: accessory.getService(this.hap.Service.MotionSensor) as Service,
64
- MotionDetected: false,
65
- };
66
- }
67
-
68
- // Initialize Light Sensor property
69
- if (!this.device.contact?.hide_lightsensor) {
70
- this.LightSensor = {
71
- Service: accessory.getService(this.hap.Service.LightSensor) as Service,
72
- CurrentAmbientLightLevel: 0,
73
- };
74
- }
75
-
76
- // Retrieve initial values and updateHomekit
77
- this.refreshStatus();
67
+ // Initialize ContactSensor Characteristics
68
+ this.ContactSensor.Service
69
+ .setCharacteristic(this.hap.Characteristic.Name, this.ContactSensor.Name)
70
+ .setCharacteristic(this.hap.Characteristic.StatusActive, true)
71
+ .getCharacteristic(this.hap.Characteristic.ContactSensorState)
72
+ .onGet(() => {
73
+ return this.ContactSensor.ContactSensorState;
74
+ });
75
+ accessory.context.ContactSensor.Name = this.ContactSensor.Name;
76
+
77
+ // Initialize Battery property
78
+ this.Battery = {
79
+ Name: accessory.context.Battery.Name ?? `${accessory.displayName} Battery`,
80
+ Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
81
+ BatteryLevel: accessory.context.BatteryLevel ?? 100,
82
+ StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
83
+ };
78
84
 
79
- // get the Contact service if it exists, otherwise create a new Contact service
80
- // you can create multiple services for each accessory
81
- const ContactSensorService = `${accessory.displayName} Contact Sensor`;
82
- (this.ContactSensor.Service = accessory.getService(this.hap.Service.ContactSensor)
83
- || accessory.addService(this.hap.Service.ContactSensor)), ContactSensorService;
85
+ // Initialize Battery Characteristics
86
+ this.Battery.Service
87
+ .setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name)
88
+ .setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE)
89
+ .getCharacteristic(this.hap.Characteristic.BatteryLevel)
90
+ .onGet(() => {
91
+ return this.Battery.BatteryLevel;
92
+ });
84
93
 
85
- this.ContactSensor.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
94
+ this.Battery.Service
95
+ .setCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery)
96
+ .getCharacteristic(this.hap.Characteristic.StatusLowBattery)
97
+ .onGet(() => {
98
+ return this.Battery.StatusLowBattery;
99
+ });
100
+ accessory.context.Battery.Name = this.Battery.Name;
86
101
 
87
- // Motion Sensor Service
88
- if (device.contact?.hide_motionsensor) {
102
+ // Initialize Motion Sensor Service
103
+ if (this.device.contact?.hide_motionsensor) {
89
104
  this.debugLog(`${device.deviceType}: ${accessory.displayName} Removing Motion Sensor Service`);
90
105
  this.MotionSensor!.Service = accessory.getService(this.hap.Service.MotionSensor) as Service;
91
106
  accessory.removeService(this.MotionSensor!.Service);
92
- } else if (!this.MotionSensor?.Service && !device.contact?.hide_motionsensor) {
93
- this.debugLog(`${device.deviceType}: ${accessory.displayName} Add Motion Sensor Service`);
94
- const MotionService = `${accessory.displayName} Motion Sensor`;
95
- (this.MotionSensor!.Service = accessory.getService(this.hap.Service.MotionSensor)
96
- || accessory.addService(this.hap.Service.MotionSensor)), MotionService;
97
-
98
- this.MotionSensor!.Service.setCharacteristic(this.hap.Characteristic.Name, MotionService);
99
107
  } else {
100
- this.debugLog(`${device.deviceType}: ${accessory.displayName} Motion Sensor Service Not Added`);
108
+ this.MotionSensor = {
109
+ Name: accessory.context.MotionSensor.Name ?? `${accessory.displayName} Motion Sensor`,
110
+ Service: accessory.getService(this.hap.Service.MotionSensor) ?? accessory.addService(this.hap.Service.MotionSensor) as Service,
111
+ MotionDetected: accessory.context.MotionDetected ?? false,
112
+ };
113
+
114
+ // Motion Sensor Characteristics
115
+ this.MotionSensor.Service
116
+ .setCharacteristic(this.hap.Characteristic.Name, this.MotionSensor.Name)
117
+ .setCharacteristic(this.hap.Characteristic.StatusActive, true)
118
+ .getCharacteristic(this.hap.Characteristic.MotionDetected)
119
+ .onGet(() => {
120
+ return this.MotionSensor!.MotionDetected;
121
+ });
122
+ accessory.context.MotionSensor.Name = this.MotionSensor.Name;
101
123
  }
102
124
 
103
- // Light Sensor Service
125
+ // Initialize Light Sensor Service
104
126
  if (device.contact?.hide_lightsensor) {
105
127
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
106
128
  this.LightSensor!.Service = accessory.getService(this.hap.Service.LightSensor) as Service;
107
129
  accessory.removeService(this.LightSensor!.Service);
108
- } else if (!this.LightSensor?.Service && !device.contact?.hide_lightsensor) {
109
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
110
-
111
- const LightSensorService = `${accessory.displayName} Light Sensor`;
112
- (this.LightSensor!.Service = this.accessory.getService(this.hap.Service.LightSensor)
113
- || this.accessory.addService(this.hap.Service.LightSensor)), LightSensorService;
114
-
115
- this.LightSensor!.Service.setCharacteristic(this.hap.Characteristic.Name, LightSensorService);
116
130
  } else {
117
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Light Sensor Service Not Added`);
118
- }
131
+ this.LightSensor = {
132
+ Name: accessory.context.LightSensor.Name ?? `${accessory.displayName} Light Sensor`,
133
+ Service: accessory.getService(this.hap.Service.LightSensor) ?? accessory.addService(this.hap.Service.LightSensor) as Service,
134
+ CurrentAmbientLightLevel: accessory.context.CurrentAmbientLightLevel ?? 0.0001,
135
+ };
119
136
 
120
- // Battery Service
121
- const BatteryService = `${accessory.displayName} Battery`;
122
- (this.Battery.Service = this.accessory.getService(this.hap.Service.Battery)
123
- || accessory.addService(this.hap.Service.Battery)), BatteryService;
137
+ // Light Sensor Characteristics
138
+ this.LightSensor.Service
139
+ .setCharacteristic(this.hap.Characteristic.Name, this.LightSensor.Name)
140
+ .setCharacteristic(this.hap.Characteristic.StatusActive, true)
141
+ .getCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel)
142
+ .onGet(() => {
143
+ return this.LightSensor!.CurrentAmbientLightLevel;
144
+ });
145
+ accessory.context.LightSensor.Name = this.LightSensor.Name;
146
+ }
124
147
 
125
- this.Battery.Service.setCharacteristic(this.hap.Characteristic.Name, BatteryService);
126
- this.Battery.Service.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
148
+ // Retrieve initial values and updateHomekit
149
+ this.refreshStatus();
127
150
 
128
151
  // Retrieve initial values and updateHomekit
129
152
  this.updateHomeKitCharacteristics();
@@ -143,8 +166,8 @@ export class Contact extends deviceBase {
143
166
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
144
167
  const { detectionState, brightness, openState } = context;
145
168
  const { ContactSensorState } = this.ContactSensor;
146
- const { CurrentAmbientLightLevel } = this.LightSensor || {};
147
- const { MotionDetected } = this.MotionSensor || {};
169
+ const { CurrentAmbientLightLevel } = this.LightSensor ?? {};
170
+ const { MotionDetected } = this.MotionSensor ?? {};
148
171
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
149
172
  '(detectionState, brightness, openState) = ' +
150
173
  `Webhook:(${detectionState}, ${brightness}, ${openState}), ` +
@@ -473,11 +496,14 @@ export class Contact extends deviceBase {
473
496
 
474
497
  async apiError(e: any): Promise<void> {
475
498
  this.ContactSensor.Service.updateCharacteristic(this.hap.Characteristic.ContactSensorState, e);
499
+ this.ContactSensor.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e);
476
500
  if (!this.device.contact?.hide_motionsensor) {
477
501
  this.MotionSensor!.Service.updateCharacteristic(this.hap.Characteristic.MotionDetected, e);
502
+ this.MotionSensor!.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e);
478
503
  }
479
504
  if (!this.device.contact?.hide_lightsensor) {
480
505
  this.LightSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e);
506
+ this.LightSensor!.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e);
481
507
  }
482
508
  this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
483
509
  this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);