@switchbot/homebridge-switchbot 2.8.0-beta.0 → 2.8.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/.prettierrc +1 -1
  2. package/.vscode/settings.json +1 -1
  3. package/CHANGELOG.md +10 -0
  4. package/config.schema.json +8 -0
  5. package/dist/device/blindtilt.d.ts.map +1 -1
  6. package/dist/device/blindtilt.js +49 -59
  7. package/dist/device/blindtilt.js.map +1 -1
  8. package/dist/device/bot.d.ts.map +1 -1
  9. package/dist/device/bot.js +44 -50
  10. package/dist/device/bot.js.map +1 -1
  11. package/dist/device/ceilinglight.d.ts.map +1 -1
  12. package/dist/device/ceilinglight.js +60 -63
  13. package/dist/device/ceilinglight.js.map +1 -1
  14. package/dist/device/colorbulb.d.ts.map +1 -1
  15. package/dist/device/colorbulb.js +68 -70
  16. package/dist/device/colorbulb.js.map +1 -1
  17. package/dist/device/contact.d.ts.map +1 -1
  18. package/dist/device/contact.js +22 -25
  19. package/dist/device/contact.js.map +1 -1
  20. package/dist/device/curtain.d.ts.map +1 -1
  21. package/dist/device/curtain.js +50 -58
  22. package/dist/device/curtain.js.map +1 -1
  23. package/dist/device/hub.d.ts +6 -0
  24. package/dist/device/hub.d.ts.map +1 -1
  25. package/dist/device/hub.js +168 -26
  26. package/dist/device/hub.js.map +1 -1
  27. package/dist/device/humidifier.d.ts.map +1 -1
  28. package/dist/device/humidifier.js +49 -56
  29. package/dist/device/humidifier.js.map +1 -1
  30. package/dist/device/iosensor.d.ts.map +1 -1
  31. package/dist/device/iosensor.js +18 -20
  32. package/dist/device/iosensor.js.map +1 -1
  33. package/dist/device/lightstrip.d.ts.map +1 -1
  34. package/dist/device/lightstrip.js +59 -61
  35. package/dist/device/lightstrip.js.map +1 -1
  36. package/dist/device/lock.d.ts.map +1 -1
  37. package/dist/device/lock.js +40 -41
  38. package/dist/device/lock.js.map +1 -1
  39. package/dist/device/meter.d.ts +3 -3
  40. package/dist/device/meter.d.ts.map +1 -1
  41. package/dist/device/meter.js +65 -68
  42. package/dist/device/meter.js.map +1 -1
  43. package/dist/device/meterplus.d.ts.map +1 -1
  44. package/dist/device/meterplus.js +18 -20
  45. package/dist/device/meterplus.js.map +1 -1
  46. package/dist/device/motion.d.ts.map +1 -1
  47. package/dist/device/motion.js +20 -23
  48. package/dist/device/motion.js.map +1 -1
  49. package/dist/device/plug.d.ts.map +1 -1
  50. package/dist/device/plug.js +30 -33
  51. package/dist/device/plug.js.map +1 -1
  52. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  53. package/dist/device/robotvacuumcleaner.js +48 -51
  54. package/dist/device/robotvacuumcleaner.js.map +1 -1
  55. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  56. package/dist/irdevice/airconditioner.js +58 -62
  57. package/dist/irdevice/airconditioner.js.map +1 -1
  58. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  59. package/dist/irdevice/airpurifier.js +29 -31
  60. package/dist/irdevice/airpurifier.js.map +1 -1
  61. package/dist/irdevice/camera.d.ts.map +1 -1
  62. package/dist/irdevice/camera.js +17 -20
  63. package/dist/irdevice/camera.js.map +1 -1
  64. package/dist/irdevice/fan.d.ts.map +1 -1
  65. package/dist/irdevice/fan.js +27 -29
  66. package/dist/irdevice/fan.js.map +1 -1
  67. package/dist/irdevice/light.d.ts.map +1 -1
  68. package/dist/irdevice/light.js +23 -26
  69. package/dist/irdevice/light.js.map +1 -1
  70. package/dist/irdevice/other.d.ts.map +1 -1
  71. package/dist/irdevice/other.js +19 -20
  72. package/dist/irdevice/other.js.map +1 -1
  73. package/dist/irdevice/tv.d.ts.map +1 -1
  74. package/dist/irdevice/tv.js +44 -47
  75. package/dist/irdevice/tv.js.map +1 -1
  76. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  77. package/dist/irdevice/vacuumcleaner.js +17 -20
  78. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  79. package/dist/irdevice/waterheater.d.ts.map +1 -1
  80. package/dist/irdevice/waterheater.js +19 -20
  81. package/dist/irdevice/waterheater.js.map +1 -1
  82. package/dist/platform.d.ts.map +1 -1
  83. package/dist/platform.js +44 -43
  84. package/dist/platform.js.map +1 -1
  85. package/dist/settings.d.ts +1 -0
  86. package/dist/settings.d.ts.map +1 -1
  87. package/dist/settings.js.map +1 -1
  88. package/dist/utils.js +1 -1
  89. package/dist/utils.js.map +1 -1
  90. package/package.json +1 -1
  91. package/src/device/blindtilt.ts +106 -72
  92. package/src/device/bot.ts +94 -58
  93. package/src/device/ceilinglight.ts +102 -68
  94. package/src/device/colorbulb.ts +134 -82
  95. package/src/device/contact.ts +54 -33
  96. package/src/device/curtain.ts +130 -101
  97. package/src/device/hub.ts +198 -35
  98. package/src/device/humidifier.ts +128 -80
  99. package/src/device/iosensor.ts +43 -27
  100. package/src/device/lightstrip.ts +108 -67
  101. package/src/device/lock.ts +73 -45
  102. package/src/device/meter.ts +94 -75
  103. package/src/device/meterplus.ts +43 -27
  104. package/src/device/motion.ts +50 -32
  105. package/src/device/plug.ts +62 -39
  106. package/src/device/robotvacuumcleaner.ts +78 -54
  107. package/src/irdevice/airconditioner.ts +112 -84
  108. package/src/irdevice/airpurifier.ts +55 -34
  109. package/src/irdevice/camera.ts +35 -23
  110. package/src/irdevice/fan.ts +47 -33
  111. package/src/irdevice/light.ts +43 -29
  112. package/src/irdevice/other.ts +39 -23
  113. package/src/irdevice/tv.ts +65 -51
  114. package/src/irdevice/vacuumcleaner.ts +35 -23
  115. package/src/irdevice/waterheater.ts +43 -27
  116. package/src/platform.ts +85 -55
  117. package/src/settings.ts +41 -40
  118. package/src/utils.ts +1 -1
package/src/device/hub.ts CHANGED
@@ -10,13 +10,17 @@ export class Hub {
10
10
  // Services
11
11
  hubTemperatureSensor: Service;
12
12
  hubHumiditySensor: Service;
13
+ hubLightSensor: Service;
13
14
 
14
15
  // Characteristic Values
15
16
  CurrentRelativeHumidity!: number;
16
17
  CurrentTemperature!: number;
18
+ CurrentAmbientLightLevel!: number;
17
19
 
18
20
  // OpenAPI Others
19
21
  deviceStatus!: any; //deviceStatusResponse;
22
+ lightLevel!: number;
23
+ spaceBetweenLevels!: number;
20
24
 
21
25
  // Config
22
26
  set_minStep!: number;
@@ -31,7 +35,11 @@ export class Hub {
31
35
  private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
32
36
  private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
33
37
 
34
- constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
38
+ constructor(
39
+ private readonly platform: SwitchBotPlatform,
40
+ private accessory: PlatformAccessory,
41
+ public device: device & devicesConfig,
42
+ ) {
35
43
  // default placeholders
36
44
  this.logs(device);
37
45
  this.refreshRate(device);
@@ -56,11 +64,14 @@ export class Hub {
56
64
  // you can create multiple services for each accessory
57
65
  (this.hubTemperatureSensor =
58
66
  accessory.getService(this.platform.Service.TemperatureSensor) || accessory.addService(this.platform.Service.TemperatureSensor)),
59
- `${device.deviceName} ${device.deviceType}`;
67
+ `${device.deviceName} ${device.deviceType}`;
60
68
 
61
69
  (this.hubHumiditySensor =
62
70
  accessory.getService(this.platform.Service.HumiditySensor) || accessory.addService(this.platform.Service.HumiditySensor)),
63
- `${device.deviceName} ${device.deviceType}`;
71
+ `${device.deviceName} ${device.deviceType}`;
72
+
73
+ (this.hubLightSensor = accessory.getService(this.platform.Service.LightSensor) || accessory.addService(this.platform.Service.LightSensor)),
74
+ `${device.deviceName} ${device.deviceType}`;
64
75
 
65
76
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
66
77
  // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
@@ -78,10 +89,30 @@ export class Hub {
78
89
  this.hubHumiditySensor.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
79
90
  }
80
91
 
92
+ this.hubLightSensor.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
93
+ if (!this.hubLightSensor.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
94
+ this.hubLightSensor.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
95
+ }
96
+
81
97
  // each service must implement at-minimum the "required characteristics" for the given service type
82
98
  // see https://developers.homebridge.io/#/service/WindowCovering
83
99
 
84
- // console.log(this.hubHumiditySensor);
100
+ // Temperature Sensor Service
101
+ if (device.hub?.hide_temperature) {
102
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
103
+ this.hubTemperatureSensor = this.hubTemperatureSensor.setCharacteristic(this.platform.Characteristic.CurrentTemperature, false);
104
+ accessory.removeService(this.hubTemperatureSensor!);
105
+ } else if (!this.hubTemperatureSensor) {
106
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
107
+ (this.hubTemperatureSensor =
108
+ accessory.getService(this.platform.Service.TemperatureSensor) || accessory.addService(this.platform.Service.TemperatureSensor)),
109
+ `${device.deviceName} ${device.deviceType}`;
110
+
111
+ this.hubTemperatureSensor.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Temperature Sensor`);
112
+ this.hubTemperatureSensor.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Temperature Sensor`);
113
+ } else {
114
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
115
+ }
85
116
 
86
117
  // Humidity Sensor Service
87
118
  if (device.hub?.hide_humidity) {
@@ -92,7 +123,7 @@ export class Hub {
92
123
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Humidity Sensor Service`);
93
124
  (this.hubHumiditySensor =
94
125
  accessory.getService(this.platform.Service.HumiditySensor) || accessory.addService(this.platform.Service.HumiditySensor)),
95
- `${device.deviceName} ${device.deviceType}`;
126
+ `${device.deviceName} ${device.deviceType}`;
96
127
 
97
128
  this.hubHumiditySensor.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Humidity Sensor`);
98
129
  this.hubHumiditySensor.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Humidity Sensor`);
@@ -100,21 +131,20 @@ export class Hub {
100
131
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Humidity Sensor Service Not Added`);
101
132
  }
102
133
 
103
- // Temperature Sensor Service
104
- if (device.hub?.hide_temperature) {
105
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
106
- this.hubTemperatureSensor = this.hubTemperatureSensor.setCharacteristic(this.platform.Characteristic.CurrentTemperature, false);
107
- accessory.removeService(this.hubTemperatureSensor!);
108
- } else if (!this.hubTemperatureSensor) {
109
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
110
- (this.hubTemperatureSensor =
111
- accessory.getService(this.platform.Service.TemperatureSensor) || accessory.addService(this.platform.Service.TemperatureSensor)),
112
- `${device.deviceName} ${device.deviceType}`;
134
+ // Humidity Sensor Service
135
+ if (device.hub?.hide_lightsensor) {
136
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
137
+ this.hubLightSensor = this.hubLightSensor.setCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, false);
138
+ accessory.removeService(this.hubLightSensor!);
139
+ } else if (!this.hubLightSensor) {
140
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
141
+ (this.hubLightSensor = accessory.getService(this.platform.Service.LightSensor) || accessory.addService(this.platform.Service.LightSensor)),
142
+ `${device.deviceName} ${device.deviceType}`;
113
143
 
114
- this.hubTemperatureSensor.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Temperature Sensor`);
115
- this.hubTemperatureSensor.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Temperature Sensor`);
144
+ this.hubLightSensor.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
145
+ this.hubLightSensor.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Light Sensor`);
116
146
  } else {
117
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
147
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Light Sensor Service Not Added`);
118
148
  }
119
149
 
120
150
  // Update Homekit
@@ -146,6 +176,105 @@ export class Hub {
146
176
  // this.infoLog(`temp: ${this.CurrentTemperature}, humidity: ${this.CurrentRelativeHumidity}`);
147
177
  this.hubTemperatureSensor.setCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
148
178
  this.hubHumiditySensor.setCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
179
+
180
+ if (!this.device.curtain?.hide_lightsensor) {
181
+ this.set_minLux = this.minLux();
182
+ this.set_maxLux = this.maxLux();
183
+ this.spaceBetweenLevels = 19;
184
+
185
+ // Brightness
186
+ switch (this.lightLevel) {
187
+ case 1:
188
+ this.CurrentAmbientLightLevel = this.set_minLux;
189
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
190
+ break;
191
+ case 2:
192
+ this.CurrentAmbientLightLevel = (this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels;
193
+ this.debugLog(
194
+ `${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
195
+ ` Calculation: ${(this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels}`,
196
+ );
197
+ break;
198
+ case 3:
199
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 2;
200
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
201
+ break;
202
+ case 4:
203
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 3;
204
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
205
+ break;
206
+ case 5:
207
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 4;
208
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
209
+ break;
210
+ case 6:
211
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 5;
212
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
213
+ break;
214
+ case 7:
215
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 6;
216
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
217
+ break;
218
+ case 8:
219
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 7;
220
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
221
+ break;
222
+ case 9:
223
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 8;
224
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
225
+ break;
226
+ case 10:
227
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 9;
228
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
229
+ break;
230
+ case 11:
231
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 10;
232
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
233
+ break;
234
+ case 12:
235
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 11;
236
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
237
+ break;
238
+ case 13:
239
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 12;
240
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
241
+ break;
242
+ case 14:
243
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 13;
244
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
245
+ break;
246
+ case 15:
247
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 14;
248
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
249
+ break;
250
+ case 16:
251
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 15;
252
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
253
+ break;
254
+ case 17:
255
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 16;
256
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
257
+ break;
258
+ case 18:
259
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 17;
260
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
261
+ break;
262
+ case 19:
263
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 18;
264
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
265
+ break;
266
+ case 20:
267
+ default:
268
+ this.CurrentAmbientLightLevel = this.set_maxLux;
269
+ this.debugLog();
270
+ }
271
+ this.debugLog(
272
+ `${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
273
+ ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
274
+ );
275
+ }
276
+
277
+ this.hubLightSensor.setCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
149
278
  }
150
279
 
151
280
  async refreshStatus(): Promise<void> {
@@ -167,18 +296,18 @@ export class Hub {
167
296
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
168
297
  this.statusCode(statusCode);
169
298
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
170
- this.debugLog(
171
- `${this.device.deviceType}: ${this.accessory.displayName
172
- } refreshStatus: ${JSON.stringify(deviceStatus)}`,
173
- );
299
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
174
300
  this.CurrentTemperature = deviceStatus.body.temperature;
175
301
  this.CurrentRelativeHumidity = deviceStatus.body.humidity;
302
+ this.lightLevel = deviceStatus.body.lightLevel;
176
303
  this.openAPIparseStatus();
177
304
  this.updateHomeKitCharacteristics();
178
305
  } catch (e: any) {
179
306
  this.apiError(e);
180
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
181
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
307
+ this.errorLog(
308
+ `${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
309
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
310
+ );
182
311
  }
183
312
  }
184
313
 
@@ -207,20 +336,31 @@ export class Hub {
207
336
  */
208
337
 
209
338
  async updateHomeKitCharacteristics(): Promise<void> {
339
+ if (this.CurrentTemperature === undefined) {
340
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
341
+ } else {
342
+ this.accessory.context.CurrentTemperature = this.CurrentTemperature;
343
+ this.hubTemperatureSensor?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
344
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
345
+ }
210
346
  if (this.CurrentRelativeHumidity === undefined) {
211
347
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
212
348
  } else {
213
349
  this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
214
350
  this.hubHumiditySensor?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
215
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
351
+ this.debugLog(
352
+ `${this.device.deviceType}: ${this.accessory.displayName} ` + `updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
353
+ );
216
354
  }
217
-
218
- if (this.CurrentTemperature === undefined) {
219
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
355
+ if (this.CurrentAmbientLightLevel === undefined) {
356
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
220
357
  } else {
221
- this.accessory.context.CurrentTemperature = this.CurrentTemperature;
222
- this.hubTemperatureSensor?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
223
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
358
+ this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
359
+ this.hubHumiditySensor?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
360
+ this.debugLog(
361
+ `${this.device.deviceType}: ${this.accessory.displayName} ` +
362
+ `updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
363
+ );
224
364
  }
225
365
  }
226
366
 
@@ -240,8 +380,10 @@ export class Hub {
240
380
  this.offlineOff();
241
381
  break;
242
382
  case 171:
243
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
244
- + `Hub: ${this.device.hubDeviceId}`);
383
+ this.errorLog(
384
+ `${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
385
+ `Hub: ${this.device.hubDeviceId}`,
386
+ );
245
387
  this.offlineOff();
246
388
  break;
247
389
  case 190:
@@ -257,8 +399,10 @@ export class Hub {
257
399
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
258
400
  break;
259
401
  default:
260
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: `
261
- + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
402
+ this.infoLog(
403
+ `${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
404
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
405
+ );
262
406
  }
263
407
  }
264
408
 
@@ -271,6 +415,25 @@ export class Hub {
271
415
  async apiError(e: any): Promise<void> {
272
416
  this.hubTemperatureSensor?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
273
417
  this.hubHumiditySensor?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, e);
418
+ this.hubLightSensor?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
419
+ }
420
+
421
+ minLux(): number {
422
+ if (this.device.curtain?.set_minLux) {
423
+ this.set_minLux = this.device.curtain?.set_minLux;
424
+ } else {
425
+ this.set_minLux = 1;
426
+ }
427
+ return this.set_minLux;
428
+ }
429
+
430
+ maxLux(): number {
431
+ if (this.device.curtain?.set_maxLux) {
432
+ this.set_maxLux = this.device.curtain?.set_maxLux;
433
+ } else {
434
+ this.set_maxLux = 6001;
435
+ }
436
+ return this.set_maxLux;
274
437
  }
275
438
 
276
439
  FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {