@switchbot/homebridge-switchbot 2.8.1-beta.8 → 2.8.1
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/.github/dependabot.yml +2 -2
- package/CHANGELOG.md +9 -0
- package/config.schema.json +4 -4
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +37 -23
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +26 -10
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +78 -29
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +78 -29
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +22 -19
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +36 -20
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +3 -3
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +205 -172
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +66 -28
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +21 -11
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +63 -25
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +35 -19
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +2 -2
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +41 -31
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +21 -11
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +21 -16
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +32 -16
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +48 -21
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +15 -9
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +15 -9
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +15 -9
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +15 -9
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +16 -10
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +15 -4
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +15 -9
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +15 -9
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +15 -9
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +28 -11
- package/dist/platform.js.map +1 -1
- package/package.json +3 -3
- package/src/device/blindtilt.ts +35 -25
- package/src/device/bot.ts +25 -10
- package/src/device/ceilinglight.ts +73 -30
- package/src/device/colorbulb.ts +73 -30
- package/src/device/contact.ts +21 -20
- package/src/device/curtain.ts +34 -21
- package/src/device/hub.ts +211 -188
- package/src/device/humidifier.ts +62 -29
- package/src/device/iosensor.ts +20 -11
- package/src/device/lightstrip.ts +59 -26
- package/src/device/lock.ts +33 -20
- package/src/device/meter.ts +42 -34
- package/src/device/meterplus.ts +20 -11
- package/src/device/motion.ts +20 -17
- package/src/device/plug.ts +30 -17
- package/src/device/robotvacuumcleaner.ts +45 -22
- package/src/irdevice/airconditioner.ts +14 -10
- package/src/irdevice/airpurifier.ts +14 -10
- package/src/irdevice/camera.ts +14 -10
- package/src/irdevice/fan.ts +14 -10
- package/src/irdevice/light.ts +15 -11
- package/src/irdevice/other.ts +14 -4
- package/src/irdevice/tv.ts +14 -10
- package/src/irdevice/vacuumcleaner.ts +14 -10
- package/src/irdevice/waterheater.ts +14 -10
- package/src/platform.ts +25 -11
- package/.github/npm-version-script.js +0 -81
package/src/device/hub.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
1
|
+
import { CharacteristicValue, PlatformAccessory, Service, Units } from 'homebridge';
|
|
2
2
|
import { interval } from 'rxjs';
|
|
3
3
|
import { request } from 'undici';
|
|
4
4
|
import { Context } from 'vm';
|
|
@@ -8,9 +8,9 @@ import { sleep } from '../utils';
|
|
|
8
8
|
|
|
9
9
|
export class Hub {
|
|
10
10
|
// Services
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
lightSensorService?: Service;
|
|
12
|
+
humidityService?: Service;
|
|
13
|
+
temperatureService?: Service;
|
|
14
14
|
|
|
15
15
|
// Characteristic Values
|
|
16
16
|
CurrentTemperature!: CharacteristicValue;
|
|
@@ -65,44 +65,33 @@ export class Hub {
|
|
|
65
65
|
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
66
66
|
.updateValue(this.FirmwareRevision(accessory, device));
|
|
67
67
|
|
|
68
|
-
// get the WindowCovering service if it exists, otherwise create a new WindowCovering service
|
|
69
|
-
// you can create multiple services for each accessory
|
|
70
|
-
(this.hubTemperatureSensor =
|
|
71
|
-
accessory.getService(this.platform.Service.TemperatureSensor) || accessory.addService(this.platform.Service.TemperatureSensor)),
|
|
72
|
-
`${device.deviceName} ${device.deviceType}`;
|
|
73
|
-
|
|
74
|
-
(this.hubHumiditySensor =
|
|
75
|
-
accessory.getService(this.platform.Service.HumiditySensor) || accessory.addService(this.platform.Service.HumiditySensor)),
|
|
76
|
-
`${device.deviceName} ${device.deviceType}`;
|
|
77
|
-
|
|
78
|
-
(this.hubLightSensor = accessory.getService(this.platform.Service.LightSensor) || accessory.addService(this.platform.Service.LightSensor)),
|
|
79
|
-
`${device.deviceName} ${device.deviceType}`;
|
|
80
|
-
|
|
81
|
-
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
82
|
-
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
83
|
-
// accessory.getService('NAME') ?? accessory.addService(this.platform.Service.WindowCovering, 'NAME', 'USER_DEFINED_SUBTYPE');
|
|
84
|
-
|
|
85
|
-
// set the service name, this is what is displayed as the default name on the Home app
|
|
86
|
-
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method
|
|
87
|
-
|
|
88
|
-
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
89
|
-
// see https://developers.homebridge.io/#/service/WindowCovering
|
|
90
|
-
|
|
91
68
|
// Temperature Sensor Service
|
|
92
69
|
if (device.hub?.hide_temperature) {
|
|
93
70
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
94
|
-
this.
|
|
95
|
-
accessory.removeService(this.
|
|
96
|
-
} else if (!this.
|
|
71
|
+
this.temperatureService = this.accessory.getService(this.platform.Service.TemperatureSensor);
|
|
72
|
+
accessory.removeService(this.temperatureService!);
|
|
73
|
+
} else if (!this.temperatureService) {
|
|
97
74
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
98
|
-
(this.
|
|
99
|
-
accessory.getService(this.platform.Service.TemperatureSensor) || accessory.addService(this.platform.Service.TemperatureSensor)),
|
|
100
|
-
`${
|
|
75
|
+
(this.temperatureService =
|
|
76
|
+
this.accessory.getService(this.platform.Service.TemperatureSensor) || this.accessory.addService(this.platform.Service.TemperatureSensor)),
|
|
77
|
+
`${accessory.displayName} Temperature Sensor`;
|
|
101
78
|
|
|
102
|
-
this.
|
|
103
|
-
if (!this.
|
|
104
|
-
this.
|
|
79
|
+
this.temperatureService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Temperature Sensor`);
|
|
80
|
+
if (!this.temperatureService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
81
|
+
this.temperatureService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Temperature Sensor`);
|
|
105
82
|
}
|
|
83
|
+
this.temperatureService
|
|
84
|
+
.getCharacteristic(this.platform.Characteristic.CurrentTemperature)
|
|
85
|
+
.setProps({
|
|
86
|
+
unit: Units['CELSIUS'],
|
|
87
|
+
validValueRanges: [-273.15, 100],
|
|
88
|
+
minValue: -273.15,
|
|
89
|
+
maxValue: 100,
|
|
90
|
+
minStep: 0.1,
|
|
91
|
+
})
|
|
92
|
+
.onGet(() => {
|
|
93
|
+
return this.CurrentTemperature!;
|
|
94
|
+
});
|
|
106
95
|
} else {
|
|
107
96
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
108
97
|
}
|
|
@@ -110,18 +99,26 @@ export class Hub {
|
|
|
110
99
|
// Humidity Sensor Service
|
|
111
100
|
if (device.hub?.hide_humidity) {
|
|
112
101
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Humidity Sensor Service`);
|
|
113
|
-
this.
|
|
114
|
-
accessory.removeService(this.
|
|
115
|
-
} else if (!this.
|
|
102
|
+
this.humidityService = this.accessory.getService(this.platform.Service.HumiditySensor);
|
|
103
|
+
accessory.removeService(this.humidityService!);
|
|
104
|
+
} else if (!this.humidityService) {
|
|
116
105
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Humidity Sensor Service`);
|
|
117
|
-
(this.
|
|
118
|
-
accessory.getService(this.platform.Service.HumiditySensor) || accessory.addService(this.platform.Service.HumiditySensor)),
|
|
119
|
-
`${
|
|
106
|
+
(this.humidityService =
|
|
107
|
+
this.accessory.getService(this.platform.Service.HumiditySensor) || this.accessory.addService(this.platform.Service.HumiditySensor)),
|
|
108
|
+
`${accessory.displayName} Humidity Sensor`;
|
|
120
109
|
|
|
121
|
-
this.
|
|
122
|
-
if (!this.
|
|
123
|
-
this.
|
|
110
|
+
this.humidityService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Humidity Sensor`);
|
|
111
|
+
if (!this.humidityService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
112
|
+
this.humidityService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Humidity Sensor`);
|
|
124
113
|
}
|
|
114
|
+
this.humidityService
|
|
115
|
+
.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity)
|
|
116
|
+
.setProps({
|
|
117
|
+
minStep: 0.1,
|
|
118
|
+
})
|
|
119
|
+
.onGet(() => {
|
|
120
|
+
return this.CurrentRelativeHumidity;
|
|
121
|
+
});
|
|
125
122
|
} else {
|
|
126
123
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Humidity Sensor Service Not Added`);
|
|
127
124
|
}
|
|
@@ -129,17 +126,16 @@ export class Hub {
|
|
|
129
126
|
// Humidity Sensor Service
|
|
130
127
|
if (device.hub?.hide_lightsensor) {
|
|
131
128
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
|
|
132
|
-
this.
|
|
133
|
-
accessory.removeService(this.
|
|
134
|
-
} else if (!this.
|
|
129
|
+
this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor);
|
|
130
|
+
accessory.removeService(this.lightSensorService!);
|
|
131
|
+
} else if (!this.lightSensorService) {
|
|
135
132
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
|
|
136
|
-
(this.
|
|
137
|
-
|
|
133
|
+
(this.lightSensorService =
|
|
134
|
+
this.accessory.getService(this.platform.Service.LightSensor) || this.accessory.addService(this.platform.Service.LightSensor)),
|
|
135
|
+
`${accessory.displayName} Light Sensor`;
|
|
138
136
|
|
|
139
|
-
this.
|
|
140
|
-
|
|
141
|
-
this.hubLightSensor.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
|
|
142
|
-
}
|
|
137
|
+
this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
|
|
138
|
+
this.lightSensorService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Light Sensor`);
|
|
143
139
|
} else {
|
|
144
140
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Light Sensor Service Not Added`);
|
|
145
141
|
}
|
|
@@ -170,109 +166,115 @@ export class Hub {
|
|
|
170
166
|
async openAPIparseStatus(): Promise<void> {
|
|
171
167
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
172
168
|
// Temperature
|
|
173
|
-
|
|
169
|
+
if (!this.device.hub?.hide_temperature) {
|
|
170
|
+
this.CurrentTemperature = Number(this.OpenAPI_CurrentTemperature);
|
|
171
|
+
}
|
|
174
172
|
|
|
175
173
|
// Humidity
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
174
|
+
if (!this.device.hub?.hide_humidity) {
|
|
175
|
+
this.CurrentRelativeHumidity = Number(this.OpenAPI_CurrentRelativeHumidity);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Brightness
|
|
179
|
+
if (!this.device.hub?.hide_lightsensor) {
|
|
180
|
+
if (!this.device.curtain?.hide_lightsensor) {
|
|
181
|
+
this.set_minLux = this.minLux();
|
|
182
|
+
this.set_maxLux = this.maxLux();
|
|
183
|
+
this.spaceBetweenLevels = 19;
|
|
184
|
+
switch (this.OpenAPI_CurrentAmbientLightLevel) {
|
|
185
|
+
case 1:
|
|
186
|
+
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
187
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
188
|
+
break;
|
|
189
|
+
case 2:
|
|
190
|
+
this.CurrentAmbientLightLevel = (this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels;
|
|
191
|
+
this.debugLog(
|
|
192
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel},` +
|
|
193
193
|
` Calculation: ${(this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels}`,
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
194
|
+
);
|
|
195
|
+
break;
|
|
196
|
+
case 3:
|
|
197
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 2;
|
|
198
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
199
|
+
break;
|
|
200
|
+
case 4:
|
|
201
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 3;
|
|
202
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
203
|
+
break;
|
|
204
|
+
case 5:
|
|
205
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 4;
|
|
206
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
207
|
+
break;
|
|
208
|
+
case 6:
|
|
209
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 5;
|
|
210
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
211
|
+
break;
|
|
212
|
+
case 7:
|
|
213
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 6;
|
|
214
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
215
|
+
break;
|
|
216
|
+
case 8:
|
|
217
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 7;
|
|
218
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
219
|
+
break;
|
|
220
|
+
case 9:
|
|
221
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 8;
|
|
222
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
223
|
+
break;
|
|
224
|
+
case 10:
|
|
225
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 9;
|
|
226
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
227
|
+
break;
|
|
228
|
+
case 11:
|
|
229
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 10;
|
|
230
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
231
|
+
break;
|
|
232
|
+
case 12:
|
|
233
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 11;
|
|
234
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
235
|
+
break;
|
|
236
|
+
case 13:
|
|
237
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 12;
|
|
238
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
239
|
+
break;
|
|
240
|
+
case 14:
|
|
241
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 13;
|
|
242
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
243
|
+
break;
|
|
244
|
+
case 15:
|
|
245
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 14;
|
|
246
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
247
|
+
break;
|
|
248
|
+
case 16:
|
|
249
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 15;
|
|
250
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
251
|
+
break;
|
|
252
|
+
case 17:
|
|
253
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 16;
|
|
254
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
255
|
+
break;
|
|
256
|
+
case 18:
|
|
257
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 17;
|
|
258
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
259
|
+
break;
|
|
260
|
+
case 19:
|
|
261
|
+
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 18;
|
|
262
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
263
|
+
break;
|
|
264
|
+
case 20:
|
|
265
|
+
default:
|
|
266
|
+
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
267
|
+
this.debugLog();
|
|
268
|
+
}
|
|
269
|
+
this.debugLog(
|
|
270
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel},` +
|
|
271
271
|
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
272
|
-
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
if (!this.device.hub?.hide_lightsensor) {
|
|
275
|
+
this.lightSensorService?.setCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
|
|
276
|
+
}
|
|
273
277
|
}
|
|
274
|
-
|
|
275
|
-
this.hubLightSensor.setCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
|
|
276
278
|
}
|
|
277
279
|
|
|
278
280
|
async refreshStatus(): Promise<void> {
|
|
@@ -290,17 +292,26 @@ export class Hub {
|
|
|
290
292
|
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
291
293
|
headers: this.platform.generateHeaders(),
|
|
292
294
|
});
|
|
295
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
296
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
297
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
293
298
|
const deviceStatus: any = await body.json();
|
|
294
|
-
this.
|
|
295
|
-
this.
|
|
296
|
-
this.
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
299
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
300
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
301
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
302
|
+
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
303
|
+
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
304
|
+
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
305
|
+
this.OpenAPI_CurrentTemperature = deviceStatus.body.temperature;
|
|
306
|
+
this.OpenAPI_CurrentRelativeHumidity = deviceStatus.body.humidity;
|
|
307
|
+
this.OpenAPI_CurrentAmbientLightLevel = deviceStatus.body.lightLevel;
|
|
308
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
309
|
+
this.openAPIparseStatus();
|
|
310
|
+
this.updateHomeKitCharacteristics();
|
|
311
|
+
} else {
|
|
312
|
+
this.statusCode(statusCode);
|
|
313
|
+
this.statusCode(deviceStatus.statusCode);
|
|
314
|
+
}
|
|
304
315
|
} catch (e: any) {
|
|
305
316
|
this.apiError(e);
|
|
306
317
|
this.errorLog(
|
|
@@ -335,31 +346,37 @@ export class Hub {
|
|
|
335
346
|
*/
|
|
336
347
|
|
|
337
348
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
338
|
-
if (this.
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
349
|
+
if (!this.device.hub?.hide_temperature) {
|
|
350
|
+
if (this.CurrentTemperature === undefined) {
|
|
351
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
352
|
+
} else {
|
|
353
|
+
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
354
|
+
this.temperatureService?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
355
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
356
|
+
}
|
|
344
357
|
}
|
|
345
|
-
if (this.
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
352
|
-
|
|
358
|
+
if (!this.device.hub?.hide_humidity) {
|
|
359
|
+
if (this.CurrentRelativeHumidity === undefined) {
|
|
360
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
361
|
+
} else {
|
|
362
|
+
this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
|
|
363
|
+
this.humidityService?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
364
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
365
|
+
+ `updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
|
|
366
|
+
);
|
|
367
|
+
}
|
|
353
368
|
}
|
|
354
|
-
if (this.
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
369
|
+
if (!this.device.hub?.hide_lightsensor) {
|
|
370
|
+
if (this.CurrentAmbientLightLevel === undefined) {
|
|
371
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
372
|
+
} else {
|
|
373
|
+
this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
|
|
374
|
+
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
|
|
375
|
+
this.debugLog(
|
|
376
|
+
`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
361
377
|
+ `updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
362
|
-
|
|
378
|
+
);
|
|
379
|
+
}
|
|
363
380
|
}
|
|
364
381
|
// FirmwareRevision
|
|
365
382
|
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
@@ -369,7 +386,7 @@ export class Hub {
|
|
|
369
386
|
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
370
387
|
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
371
388
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
372
|
-
+ `updateCharacteristic
|
|
389
|
+
+ `updateCharacteristic FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
373
390
|
}
|
|
374
391
|
}
|
|
375
392
|
|
|
@@ -422,9 +439,15 @@ export class Hub {
|
|
|
422
439
|
}
|
|
423
440
|
|
|
424
441
|
async apiError(e: any): Promise<void> {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
442
|
+
if (!this.device.hub?.hide_temperature) {
|
|
443
|
+
this.temperatureService?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
|
|
444
|
+
}
|
|
445
|
+
if (!this.device.hub?.hide_humidity) {
|
|
446
|
+
this.humidityService?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, e);
|
|
447
|
+
}
|
|
448
|
+
if (!this.device.hub?.hide_lightsensor) {
|
|
449
|
+
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
|
|
450
|
+
}
|
|
428
451
|
}
|
|
429
452
|
|
|
430
453
|
minLux(): number {
|
package/src/device/humidifier.ts
CHANGED
|
@@ -91,12 +91,6 @@ export class Humidifier {
|
|
|
91
91
|
accessory.getService(this.platform.Service.HumidifierDehumidifier) || accessory.addService(this.platform.Service.HumidifierDehumidifier)),
|
|
92
92
|
`${accessory.displayName} Humidifier`;
|
|
93
93
|
|
|
94
|
-
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
95
|
-
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
96
|
-
// accessory.getService('NAME') ?? accessory.addService(this.platform.Service.HumidifierDehumidifier, 'NAME', 'USER_DEFINED_SUBTYPE');
|
|
97
|
-
|
|
98
|
-
// set the service name, this is what is displayed as the default name on the Home app
|
|
99
|
-
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
100
94
|
this.humidifierService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
101
95
|
if (!this.humidifierService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
102
96
|
this.humidifierService.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
|
|
@@ -375,20 +369,29 @@ export class Humidifier {
|
|
|
375
369
|
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
376
370
|
headers: this.platform.generateHeaders(),
|
|
377
371
|
});
|
|
372
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
373
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
374
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
378
375
|
const deviceStatus: any = await body.json();
|
|
379
|
-
this.
|
|
380
|
-
this.
|
|
381
|
-
this.
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
376
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
377
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
378
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
379
|
+
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
380
|
+
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
381
|
+
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
382
|
+
this.OpenAPI_CurrentHumidifierDehumidifierState = deviceStatus.body.auto;
|
|
383
|
+
this.OpenAPI_Active = deviceStatus.body.power;
|
|
384
|
+
this.OpenAPI_WaterLevel = deviceStatus.body.lackWater;
|
|
385
|
+
this.OpenAPI_CurrentRelativeHumidity = deviceStatus.body.humidity;
|
|
386
|
+
this.OpenAPI_CurrentTemperature = deviceStatus.body.temperature;
|
|
387
|
+
this.OpenAPI_RelativeHumidityHumidifierThreshold = deviceStatus.body.nebulizationEfficiency;
|
|
388
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
389
|
+
this.openAPIparseStatus();
|
|
390
|
+
this.updateHomeKitCharacteristics();
|
|
391
|
+
} else {
|
|
392
|
+
this.statusCode(statusCode);
|
|
393
|
+
this.statusCode(deviceStatus.statusCode);
|
|
394
|
+
}
|
|
392
395
|
} catch (e: any) {
|
|
393
396
|
this.apiError(e);
|
|
394
397
|
this.errorLog(
|
|
@@ -472,10 +475,20 @@ export class Humidifier {
|
|
|
472
475
|
method: 'POST',
|
|
473
476
|
headers: this.platform.generateHeaders(),
|
|
474
477
|
});
|
|
478
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
479
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
480
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
475
481
|
const deviceStatus: any = await body.json();
|
|
476
|
-
this.
|
|
477
|
-
this.
|
|
478
|
-
this.
|
|
482
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
483
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
484
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
485
|
+
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
486
|
+
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
487
|
+
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
488
|
+
} else {
|
|
489
|
+
this.statusCode(statusCode);
|
|
490
|
+
this.statusCode(deviceStatus.statusCode);
|
|
491
|
+
}
|
|
479
492
|
} catch (e: any) {
|
|
480
493
|
this.apiError(e);
|
|
481
494
|
this.errorLog(
|
|
@@ -515,10 +528,20 @@ export class Humidifier {
|
|
|
515
528
|
method: 'POST',
|
|
516
529
|
headers: this.platform.generateHeaders(),
|
|
517
530
|
});
|
|
531
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
532
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
533
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
518
534
|
const deviceStatus: any = await body.json();
|
|
519
|
-
this.
|
|
520
|
-
this.
|
|
521
|
-
this.
|
|
535
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
536
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
537
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
538
|
+
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
539
|
+
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
540
|
+
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
541
|
+
} else {
|
|
542
|
+
this.statusCode(statusCode);
|
|
543
|
+
this.statusCode(deviceStatus.statusCode);
|
|
544
|
+
}
|
|
522
545
|
} catch (e: any) {
|
|
523
546
|
this.apiError(e);
|
|
524
547
|
this.errorLog(
|
|
@@ -553,10 +576,20 @@ export class Humidifier {
|
|
|
553
576
|
method: 'POST',
|
|
554
577
|
headers: this.platform.generateHeaders(),
|
|
555
578
|
});
|
|
579
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
580
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
581
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
556
582
|
const deviceStatus: any = await body.json();
|
|
557
|
-
this.
|
|
558
|
-
this.
|
|
559
|
-
this.
|
|
583
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
584
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
585
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
586
|
+
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
587
|
+
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
588
|
+
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
589
|
+
} else {
|
|
590
|
+
this.statusCode(statusCode);
|
|
591
|
+
this.statusCode(deviceStatus.statusCode);
|
|
592
|
+
}
|
|
560
593
|
} catch (e: any) {
|
|
561
594
|
this.apiError(e);
|
|
562
595
|
this.errorLog(
|
|
@@ -708,7 +741,7 @@ export class Humidifier {
|
|
|
708
741
|
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
709
742
|
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
710
743
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
711
|
-
+ `updateCharacteristic
|
|
744
|
+
+ `updateCharacteristic FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
712
745
|
}
|
|
713
746
|
}
|
|
714
747
|
|