@switchbot/homebridge-switchbot 2.8.0-beta.0 → 2.8.0-beta.10
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.
- package/.prettierrc +1 -1
- package/.vscode/settings.json +1 -1
- package/CHANGELOG.md +10 -0
- package/config.schema.json +8 -0
- package/dist/device/blindtilt.d.ts +1 -0
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +58 -65
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +1 -0
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +52 -55
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +1 -0
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +68 -68
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +1 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +76 -75
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +2 -0
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +67 -59
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +2 -0
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +81 -94
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +9 -1
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +197 -30
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +58 -62
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +1 -0
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +28 -26
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +1 -0
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +68 -67
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +2 -0
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +51 -47
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +5 -3
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +75 -74
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +4 -3
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +74 -74
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +2 -0
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +66 -54
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +1 -0
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +39 -39
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +1 -0
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +74 -53
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +64 -66
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +32 -34
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +20 -23
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +2 -2
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +30 -32
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +26 -29
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +22 -23
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +2 -2
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +47 -50
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +20 -23
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +22 -23
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +46 -44
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/device/blindtilt.ts +114 -78
- package/src/device/bot.ts +102 -63
- package/src/device/ceilinglight.ts +113 -73
- package/src/device/colorbulb.ts +144 -87
- package/src/device/contact.ts +98 -63
- package/src/device/curtain.ts +160 -134
- package/src/device/hub.ts +228 -39
- package/src/device/humidifier.ts +136 -85
- package/src/device/iosensor.ts +52 -32
- package/src/device/lightstrip.ts +118 -72
- package/src/device/lock.ts +85 -50
- package/src/device/meter.ts +104 -80
- package/src/device/meterplus.ts +103 -80
- package/src/device/motion.ts +95 -59
- package/src/device/plug.ts +70 -44
- package/src/device/robotvacuumcleaner.ts +107 -56
- package/src/irdevice/airconditioner.ts +116 -86
- package/src/irdevice/airpurifier.ts +60 -39
- package/src/irdevice/camera.ts +40 -28
- package/src/irdevice/fan.ts +52 -38
- package/src/irdevice/light.ts +48 -34
- package/src/irdevice/other.ts +44 -28
- package/src/irdevice/tv.ts +70 -56
- package/src/irdevice/vacuumcleaner.ts +40 -28
- package/src/irdevice/waterheater.ts +48 -32
- package/src/platform.ts +87 -56
- package/src/settings.ts +41 -40
- package/src/utils.ts +1 -1
package/src/device/hub.ts
CHANGED
|
@@ -3,20 +3,25 @@ import { interval } from 'rxjs';
|
|
|
3
3
|
import { request } from 'undici';
|
|
4
4
|
import { Context } from 'vm';
|
|
5
5
|
import { SwitchBotPlatform } from '../platform';
|
|
6
|
-
import { Devices, device, devicesConfig } from '../settings';
|
|
6
|
+
import { Devices, device, deviceStatus, devicesConfig } from '../settings';
|
|
7
7
|
import { sleep } from '../utils';
|
|
8
8
|
|
|
9
9
|
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
|
|
21
|
+
Version: deviceStatus['version'];
|
|
19
22
|
deviceStatus!: any; //deviceStatusResponse;
|
|
23
|
+
lightLevel!: number;
|
|
24
|
+
spaceBetweenLevels!: number;
|
|
20
25
|
|
|
21
26
|
// Config
|
|
22
27
|
set_minStep!: number;
|
|
@@ -31,10 +36,15 @@ export class Hub {
|
|
|
31
36
|
private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
32
37
|
private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
33
38
|
|
|
34
|
-
constructor(
|
|
39
|
+
constructor(
|
|
40
|
+
private readonly platform: SwitchBotPlatform,
|
|
41
|
+
private accessory: PlatformAccessory,
|
|
42
|
+
public device: device & devicesConfig,
|
|
43
|
+
) {
|
|
35
44
|
// default placeholders
|
|
36
45
|
this.logs(device);
|
|
37
46
|
this.refreshRate(device);
|
|
47
|
+
this.config(device);
|
|
38
48
|
|
|
39
49
|
this.CurrentRelativeHumidity = accessory.context.CurrentRelativeHumidity;
|
|
40
50
|
this.CurrentTemperature = accessory.context.CurrentTemperature;
|
|
@@ -56,11 +66,14 @@ export class Hub {
|
|
|
56
66
|
// you can create multiple services for each accessory
|
|
57
67
|
(this.hubTemperatureSensor =
|
|
58
68
|
accessory.getService(this.platform.Service.TemperatureSensor) || accessory.addService(this.platform.Service.TemperatureSensor)),
|
|
59
|
-
|
|
69
|
+
`${device.deviceName} ${device.deviceType}`;
|
|
60
70
|
|
|
61
71
|
(this.hubHumiditySensor =
|
|
62
72
|
accessory.getService(this.platform.Service.HumiditySensor) || accessory.addService(this.platform.Service.HumiditySensor)),
|
|
63
|
-
|
|
73
|
+
`${device.deviceName} ${device.deviceType}`;
|
|
74
|
+
|
|
75
|
+
(this.hubLightSensor = accessory.getService(this.platform.Service.LightSensor) || accessory.addService(this.platform.Service.LightSensor)),
|
|
76
|
+
`${device.deviceName} ${device.deviceType}`;
|
|
64
77
|
|
|
65
78
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
66
79
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
@@ -78,10 +91,30 @@ export class Hub {
|
|
|
78
91
|
this.hubHumiditySensor.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
|
|
79
92
|
}
|
|
80
93
|
|
|
94
|
+
this.hubLightSensor.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
95
|
+
if (!this.hubLightSensor.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
96
|
+
this.hubLightSensor.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
|
|
97
|
+
}
|
|
98
|
+
|
|
81
99
|
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
82
100
|
// see https://developers.homebridge.io/#/service/WindowCovering
|
|
83
101
|
|
|
84
|
-
//
|
|
102
|
+
// Temperature Sensor Service
|
|
103
|
+
if (device.hub?.hide_temperature) {
|
|
104
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
105
|
+
this.hubTemperatureSensor = this.hubTemperatureSensor.setCharacteristic(this.platform.Characteristic.CurrentTemperature, false);
|
|
106
|
+
accessory.removeService(this.hubTemperatureSensor!);
|
|
107
|
+
} else if (!this.hubTemperatureSensor) {
|
|
108
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
109
|
+
(this.hubTemperatureSensor =
|
|
110
|
+
accessory.getService(this.platform.Service.TemperatureSensor) || accessory.addService(this.platform.Service.TemperatureSensor)),
|
|
111
|
+
`${device.deviceName} ${device.deviceType}`;
|
|
112
|
+
|
|
113
|
+
this.hubTemperatureSensor.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Temperature Sensor`);
|
|
114
|
+
this.hubTemperatureSensor.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Temperature Sensor`);
|
|
115
|
+
} else {
|
|
116
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
117
|
+
}
|
|
85
118
|
|
|
86
119
|
// Humidity Sensor Service
|
|
87
120
|
if (device.hub?.hide_humidity) {
|
|
@@ -92,7 +125,7 @@ export class Hub {
|
|
|
92
125
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Humidity Sensor Service`);
|
|
93
126
|
(this.hubHumiditySensor =
|
|
94
127
|
accessory.getService(this.platform.Service.HumiditySensor) || accessory.addService(this.platform.Service.HumiditySensor)),
|
|
95
|
-
|
|
128
|
+
`${device.deviceName} ${device.deviceType}`;
|
|
96
129
|
|
|
97
130
|
this.hubHumiditySensor.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Humidity Sensor`);
|
|
98
131
|
this.hubHumiditySensor.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Humidity Sensor`);
|
|
@@ -100,21 +133,20 @@ export class Hub {
|
|
|
100
133
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Humidity Sensor Service Not Added`);
|
|
101
134
|
}
|
|
102
135
|
|
|
103
|
-
//
|
|
104
|
-
if (device.hub?.
|
|
105
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing
|
|
106
|
-
this.
|
|
107
|
-
accessory.removeService(this.
|
|
108
|
-
} else if (!this.
|
|
109
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add
|
|
110
|
-
(this.
|
|
111
|
-
|
|
112
|
-
`${device.deviceName} ${device.deviceType}`;
|
|
136
|
+
// Humidity Sensor Service
|
|
137
|
+
if (device.hub?.hide_lightsensor) {
|
|
138
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
|
|
139
|
+
this.hubLightSensor = this.hubLightSensor.setCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, false);
|
|
140
|
+
accessory.removeService(this.hubLightSensor!);
|
|
141
|
+
} else if (!this.hubLightSensor) {
|
|
142
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
|
|
143
|
+
(this.hubLightSensor = accessory.getService(this.platform.Service.LightSensor) || accessory.addService(this.platform.Service.LightSensor)),
|
|
144
|
+
`${device.deviceName} ${device.deviceType}`;
|
|
113
145
|
|
|
114
|
-
this.
|
|
115
|
-
this.
|
|
146
|
+
this.hubLightSensor.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
|
|
147
|
+
this.hubLightSensor.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Light Sensor`);
|
|
116
148
|
} else {
|
|
117
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName}
|
|
149
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Light Sensor Service Not Added`);
|
|
118
150
|
}
|
|
119
151
|
|
|
120
152
|
// Update Homekit
|
|
@@ -146,6 +178,105 @@ export class Hub {
|
|
|
146
178
|
// this.infoLog(`temp: ${this.CurrentTemperature}, humidity: ${this.CurrentRelativeHumidity}`);
|
|
147
179
|
this.hubTemperatureSensor.setCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
148
180
|
this.hubHumiditySensor.setCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
181
|
+
|
|
182
|
+
if (!this.device.curtain?.hide_lightsensor) {
|
|
183
|
+
this.set_minLux = this.minLux();
|
|
184
|
+
this.set_maxLux = this.maxLux();
|
|
185
|
+
this.spaceBetweenLevels = 19;
|
|
186
|
+
|
|
187
|
+
// Brightness
|
|
188
|
+
switch (this.lightLevel) {
|
|
189
|
+
case 1:
|
|
190
|
+
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
191
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
192
|
+
break;
|
|
193
|
+
case 2:
|
|
194
|
+
this.CurrentAmbientLightLevel = (this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels;
|
|
195
|
+
this.debugLog(
|
|
196
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
|
|
197
|
+
` Calculation: ${(this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels}`,
|
|
198
|
+
);
|
|
199
|
+
break;
|
|
200
|
+
case 3:
|
|
201
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 2;
|
|
202
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
203
|
+
break;
|
|
204
|
+
case 4:
|
|
205
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 3;
|
|
206
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
207
|
+
break;
|
|
208
|
+
case 5:
|
|
209
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 4;
|
|
210
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
211
|
+
break;
|
|
212
|
+
case 6:
|
|
213
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 5;
|
|
214
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
215
|
+
break;
|
|
216
|
+
case 7:
|
|
217
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 6;
|
|
218
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
219
|
+
break;
|
|
220
|
+
case 8:
|
|
221
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 7;
|
|
222
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
223
|
+
break;
|
|
224
|
+
case 9:
|
|
225
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 8;
|
|
226
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
227
|
+
break;
|
|
228
|
+
case 10:
|
|
229
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 9;
|
|
230
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
231
|
+
break;
|
|
232
|
+
case 11:
|
|
233
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 10;
|
|
234
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
235
|
+
break;
|
|
236
|
+
case 12:
|
|
237
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 11;
|
|
238
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
239
|
+
break;
|
|
240
|
+
case 13:
|
|
241
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 12;
|
|
242
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
243
|
+
break;
|
|
244
|
+
case 14:
|
|
245
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 13;
|
|
246
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
247
|
+
break;
|
|
248
|
+
case 15:
|
|
249
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 14;
|
|
250
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
251
|
+
break;
|
|
252
|
+
case 16:
|
|
253
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 15;
|
|
254
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
255
|
+
break;
|
|
256
|
+
case 17:
|
|
257
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 16;
|
|
258
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
259
|
+
break;
|
|
260
|
+
case 18:
|
|
261
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 17;
|
|
262
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
263
|
+
break;
|
|
264
|
+
case 19:
|
|
265
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 18;
|
|
266
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
|
|
267
|
+
break;
|
|
268
|
+
case 20:
|
|
269
|
+
default:
|
|
270
|
+
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
271
|
+
this.debugLog();
|
|
272
|
+
}
|
|
273
|
+
this.debugLog(
|
|
274
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
|
|
275
|
+
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
this.hubLightSensor.setCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
|
|
149
280
|
}
|
|
150
281
|
|
|
151
282
|
async refreshStatus(): Promise<void> {
|
|
@@ -167,18 +298,18 @@ export class Hub {
|
|
|
167
298
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
168
299
|
this.statusCode(statusCode);
|
|
169
300
|
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
|
-
);
|
|
301
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
174
302
|
this.CurrentTemperature = deviceStatus.body.temperature;
|
|
175
303
|
this.CurrentRelativeHumidity = deviceStatus.body.humidity;
|
|
304
|
+
this.lightLevel = deviceStatus.body.lightLevel;
|
|
176
305
|
this.openAPIparseStatus();
|
|
177
306
|
this.updateHomeKitCharacteristics();
|
|
178
307
|
} catch (e: any) {
|
|
179
308
|
this.apiError(e);
|
|
180
|
-
this.errorLog(
|
|
181
|
-
|
|
309
|
+
this.errorLog(
|
|
310
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
|
|
311
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
312
|
+
);
|
|
182
313
|
}
|
|
183
314
|
}
|
|
184
315
|
|
|
@@ -207,20 +338,31 @@ export class Hub {
|
|
|
207
338
|
*/
|
|
208
339
|
|
|
209
340
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
341
|
+
if (this.CurrentTemperature === undefined) {
|
|
342
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
343
|
+
} else {
|
|
344
|
+
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
345
|
+
this.hubTemperatureSensor?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
346
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
347
|
+
}
|
|
210
348
|
if (this.CurrentRelativeHumidity === undefined) {
|
|
211
349
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
212
350
|
} else {
|
|
213
351
|
this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
|
|
214
352
|
this.hubHumiditySensor?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
215
|
-
this.debugLog(
|
|
353
|
+
this.debugLog(
|
|
354
|
+
`${this.device.deviceType}: ${this.accessory.displayName} ` + `updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
|
|
355
|
+
);
|
|
216
356
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
357
|
+
if (this.CurrentAmbientLightLevel === undefined) {
|
|
358
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
220
359
|
} else {
|
|
221
|
-
this.accessory.context.
|
|
222
|
-
this.
|
|
223
|
-
this.debugLog(
|
|
360
|
+
this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
|
|
361
|
+
this.hubHumiditySensor?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
|
|
362
|
+
this.debugLog(
|
|
363
|
+
`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
364
|
+
`updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
365
|
+
);
|
|
224
366
|
}
|
|
225
367
|
}
|
|
226
368
|
|
|
@@ -240,8 +382,10 @@ export class Hub {
|
|
|
240
382
|
this.offlineOff();
|
|
241
383
|
break;
|
|
242
384
|
case 171:
|
|
243
|
-
this.errorLog(
|
|
244
|
-
|
|
385
|
+
this.errorLog(
|
|
386
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
387
|
+
`Hub: ${this.device.hubDeviceId}`,
|
|
388
|
+
);
|
|
245
389
|
this.offlineOff();
|
|
246
390
|
break;
|
|
247
391
|
case 190:
|
|
@@ -257,8 +401,10 @@ export class Hub {
|
|
|
257
401
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
258
402
|
break;
|
|
259
403
|
default:
|
|
260
|
-
this.infoLog(
|
|
261
|
-
|
|
404
|
+
this.infoLog(
|
|
405
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
406
|
+
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
407
|
+
);
|
|
262
408
|
}
|
|
263
409
|
}
|
|
264
410
|
|
|
@@ -271,6 +417,25 @@ export class Hub {
|
|
|
271
417
|
async apiError(e: any): Promise<void> {
|
|
272
418
|
this.hubTemperatureSensor?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
|
|
273
419
|
this.hubHumiditySensor?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, e);
|
|
420
|
+
this.hubLightSensor?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
minLux(): number {
|
|
424
|
+
if (this.device.curtain?.set_minLux) {
|
|
425
|
+
this.set_minLux = this.device.curtain?.set_minLux;
|
|
426
|
+
} else {
|
|
427
|
+
this.set_minLux = 1;
|
|
428
|
+
}
|
|
429
|
+
return this.set_minLux;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
maxLux(): number {
|
|
433
|
+
if (this.device.curtain?.set_maxLux) {
|
|
434
|
+
this.set_maxLux = this.device.curtain?.set_maxLux;
|
|
435
|
+
} else {
|
|
436
|
+
this.set_maxLux = 6001;
|
|
437
|
+
}
|
|
438
|
+
return this.set_maxLux;
|
|
274
439
|
}
|
|
275
440
|
|
|
276
441
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
@@ -280,10 +445,12 @@ export class Hub {
|
|
|
280
445
|
);
|
|
281
446
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
282
447
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
283
|
-
if (
|
|
284
|
-
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
285
|
-
} else if (device.firmware) {
|
|
448
|
+
if (device.firmware) {
|
|
286
449
|
FirmwareRevision = device.firmware;
|
|
450
|
+
} else if (device.version) {
|
|
451
|
+
FirmwareRevision = JSON.stringify(device.version);
|
|
452
|
+
} else if (accessory.context.FirmwareRevision) {
|
|
453
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
287
454
|
} else {
|
|
288
455
|
FirmwareRevision = this.platform.version;
|
|
289
456
|
}
|
|
@@ -309,6 +476,28 @@ export class Hub {
|
|
|
309
476
|
}
|
|
310
477
|
}
|
|
311
478
|
|
|
479
|
+
async config(device: device & devicesConfig): Promise<void> {
|
|
480
|
+
let config = {};
|
|
481
|
+
if (device.hub) {
|
|
482
|
+
config = device.hub;
|
|
483
|
+
}
|
|
484
|
+
if (device.connectionType !== undefined) {
|
|
485
|
+
config['connectionType'] = device.connectionType;
|
|
486
|
+
}
|
|
487
|
+
if (device.external !== undefined) {
|
|
488
|
+
config['external'] = device.external;
|
|
489
|
+
}
|
|
490
|
+
if (device.logging !== undefined) {
|
|
491
|
+
config['logging'] = device.logging;
|
|
492
|
+
}
|
|
493
|
+
if (device.refreshRate !== undefined) {
|
|
494
|
+
config['refreshRate'] = device.refreshRate;
|
|
495
|
+
}
|
|
496
|
+
if (Object.entries(config).length !== 0) {
|
|
497
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
312
501
|
async logs(device: device & devicesConfig): Promise<void> {
|
|
313
502
|
if (this.platform.debugMode) {
|
|
314
503
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|