@switchbot/homebridge-switchbot 3.5.0-beta.9 → 3.5.1-beta.0
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/.vscode/settings.json +4 -1
- package/CHANGELOG.md +4 -1
- package/config.schema.json +164 -22
- package/dist/device/blindtilt.d.ts +21 -96
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +457 -866
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +27 -72
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +851 -913
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +15 -69
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +316 -742
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +15 -76
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +380 -833
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +14 -66
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +267 -602
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +18 -89
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +469 -897
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +76 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +846 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/fan.d.ts +63 -0
- package/dist/device/fan.d.ts.map +1 -0
- package/dist/device/fan.js +645 -0
- package/dist/device/fan.js.map +1 -0
- package/dist/device/hub.d.ts +19 -58
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +304 -640
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +11 -66
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +300 -710
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +12 -64
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +225 -643
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +12 -70
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +371 -742
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +17 -63
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +309 -642
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +15 -64
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +223 -638
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +15 -65
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +216 -644
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +12 -69
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +209 -588
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +10 -57
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +141 -532
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +13 -63
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +252 -609
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +11 -63
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +179 -521
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +22 -16
- package/dist/homebridge-ui/server.js +1 -1
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +10 -50
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +337 -482
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +8 -39
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +108 -333
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +7 -36
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +47 -299
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +7 -43
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +95 -364
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +46 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +393 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +12 -45
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +121 -376
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +19 -48
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +441 -584
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -40
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +94 -353
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +7 -36
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +48 -299
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +7 -36
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +50 -305
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +22 -8
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +342 -191
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +66 -18
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +16 -552
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +95 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +657 -1
- package/dist/utils.js.map +1 -1
- package/eslint.config.js +96 -0
- package/package.json +20 -16
- package/src/custom.d.ts +2 -1
- package/src/device/blindtilt.ts +488 -937
- package/src/device/bot.ts +907 -1016
- package/src/device/ceilinglight.ts +330 -798
- package/src/device/colorbulb.ts +394 -904
- package/src/device/contact.ts +298 -637
- package/src/device/curtain.ts +496 -954
- package/src/device/device.ts +872 -0
- package/src/device/fan.ts +692 -0
- package/src/device/hub.ts +338 -671
- package/src/device/humidifier.ts +330 -777
- package/src/device/iosensor.ts +258 -671
- package/src/device/lightstrip.ts +394 -809
- package/src/device/lock.ts +345 -700
- package/src/device/meter.ts +256 -666
- package/src/device/meterplus.ts +248 -672
- package/src/device/motion.ts +234 -622
- package/src/device/plug.ts +152 -572
- package/src/device/robotvacuumcleaner.ts +273 -653
- package/src/device/waterdetector.ts +198 -549
- package/src/homebridge-ui/public/index.html +22 -16
- package/src/homebridge-ui/server.ts +1 -1
- package/src/index.ts +4 -3
- package/src/irdevice/airconditioner.ts +368 -540
- package/src/irdevice/airpurifier.ts +134 -369
- package/src/irdevice/camera.ts +60 -324
- package/src/irdevice/fan.ts +111 -392
- package/src/irdevice/irdevice.ts +406 -0
- package/src/irdevice/light.ts +159 -425
- package/src/irdevice/other.ts +509 -661
- package/src/irdevice/tv.ts +123 -388
- package/src/irdevice/vacuumcleaner.ts +61 -324
- package/src/irdevice/waterheater.ts +63 -333
- package/src/platform.ts +395 -259
- package/src/settings.ts +120 -610
- package/src/utils.ts +661 -1
- package/src/device/waterdetector.json +0 -11
package/dist/device/hub.js
CHANGED
|
@@ -1,92 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { interval } from 'rxjs';
|
|
4
|
-
|
|
5
|
-
import { Devices } from '../settings.js';
|
|
6
|
-
export class Hub {
|
|
1
|
+
import { deviceBase } from './device.js';
|
|
2
|
+
import { convertUnits } from '../utils.js';
|
|
3
|
+
import { Subject, interval, skipWhile } from 'rxjs';
|
|
4
|
+
export class Hub extends deviceBase {
|
|
7
5
|
platform;
|
|
8
|
-
accessory;
|
|
9
|
-
device;
|
|
10
|
-
api;
|
|
11
|
-
log;
|
|
12
|
-
config;
|
|
13
|
-
hap;
|
|
14
6
|
// Services
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
CurrentRelativeHumidity;
|
|
22
|
-
CurrentAmbientLightLevel;
|
|
23
|
-
// OpenAPI Status
|
|
24
|
-
OpenAPI_FirmwareRevision;
|
|
25
|
-
OpenAPI_CurrentTemperature;
|
|
26
|
-
OpenAPI_CurrentRelativeHumidity;
|
|
27
|
-
OpenAPI_CurrentAmbientLightLevel;
|
|
28
|
-
// OpenAPI Others
|
|
29
|
-
spaceBetweenLevels;
|
|
30
|
-
//MQTT stuff
|
|
31
|
-
mqttClient = null;
|
|
32
|
-
// EVE history service handler
|
|
33
|
-
historyService;
|
|
34
|
-
// Config
|
|
35
|
-
set_minStep;
|
|
36
|
-
updateRate;
|
|
37
|
-
set_minLux;
|
|
38
|
-
set_maxLux;
|
|
39
|
-
scanDuration;
|
|
40
|
-
deviceLogging;
|
|
41
|
-
deviceRefreshRate;
|
|
42
|
-
// Connection
|
|
43
|
-
OpenAPI;
|
|
44
|
-
BLE;
|
|
7
|
+
LightSensor;
|
|
8
|
+
HumiditySensor;
|
|
9
|
+
TemperatureSensor;
|
|
10
|
+
// Updates
|
|
11
|
+
hubUpdateInProgress;
|
|
12
|
+
doHubUpdate;
|
|
45
13
|
constructor(platform, accessory, device) {
|
|
14
|
+
super(platform, accessory, device);
|
|
46
15
|
this.platform = platform;
|
|
47
|
-
this
|
|
48
|
-
this.
|
|
49
|
-
this.
|
|
50
|
-
|
|
51
|
-
this.config = this.platform.config;
|
|
52
|
-
this.hap = this.api.hap;
|
|
53
|
-
// Connection
|
|
54
|
-
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
55
|
-
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
56
|
-
// default placeholders
|
|
57
|
-
this.deviceLogs(device);
|
|
58
|
-
this.refreshRate(device);
|
|
59
|
-
this.deviceContext();
|
|
60
|
-
this.setupHistoryService(device);
|
|
61
|
-
this.setupMqtt(device);
|
|
62
|
-
this.deviceConfig(device);
|
|
63
|
-
this.CurrentRelativeHumidity = accessory.context.CurrentRelativeHumidity;
|
|
64
|
-
this.CurrentTemperature = accessory.context.CurrentTemperature;
|
|
65
|
-
// Retrieve initial values and updateHomekit
|
|
66
|
-
this.refreshStatus();
|
|
67
|
-
// set accessory information
|
|
68
|
-
accessory
|
|
69
|
-
.getService(this.hap.Service.AccessoryInformation)
|
|
70
|
-
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
71
|
-
.setCharacteristic(this.hap.Characteristic.Model, accessory.context.model)
|
|
72
|
-
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
73
|
-
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
74
|
-
// Temperature Sensor Service
|
|
16
|
+
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
17
|
+
this.doHubUpdate = new Subject();
|
|
18
|
+
this.hubUpdateInProgress = false;
|
|
19
|
+
// Initialize Temperature Sensor Service
|
|
75
20
|
if (device.hub?.hide_temperature) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
else if (!this.temperatureService) {
|
|
81
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
82
|
-
const temperatureService = `${accessory.displayName} Temperature Sensor`;
|
|
83
|
-
(this.temperatureService = this.accessory.getService(this.hap.Service.TemperatureSensor)
|
|
84
|
-
|| this.accessory.addService(this.hap.Service.TemperatureSensor)), temperatureService;
|
|
85
|
-
this.temperatureService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Temperature Sensor`);
|
|
86
|
-
if (!this.temperatureService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
87
|
-
this.temperatureService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Temperature Sensor`);
|
|
21
|
+
if (this.TemperatureSensor) {
|
|
22
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
23
|
+
this.TemperatureSensor.Service = this.accessory.getService(this.hap.Service.TemperatureSensor);
|
|
24
|
+
accessory.removeService(this.TemperatureSensor.Service);
|
|
88
25
|
}
|
|
89
|
-
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
accessory.context.TemperatureSensor = accessory.context.TemperatureSensor ?? {};
|
|
29
|
+
this.TemperatureSensor = {
|
|
30
|
+
Name: accessory.context.TemperatureSensor.Name ?? `${accessory.displayName} Temperature Sensor`,
|
|
31
|
+
Service: accessory.getService(this.hap.Service.TemperatureSensor) ?? this.accessory.addService(this.hap.Service.TemperatureSensor),
|
|
32
|
+
CurrentTemperature: accessory.context.CurrentTemperature ?? 0,
|
|
33
|
+
};
|
|
34
|
+
accessory.context.TemperatureSensor = this.TemperatureSensor;
|
|
35
|
+
// Initialize Temperature Sensor Characteristic
|
|
36
|
+
this.TemperatureSensor.Service
|
|
37
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.TemperatureSensor.Name)
|
|
90
38
|
.getCharacteristic(this.hap.Characteristic.CurrentTemperature)
|
|
91
39
|
.setProps({
|
|
92
40
|
unit: "celsius" /* Units['CELSIUS'] */,
|
|
@@ -96,342 +44,223 @@ export class Hub {
|
|
|
96
44
|
minStep: 0.1,
|
|
97
45
|
})
|
|
98
46
|
.onGet(() => {
|
|
99
|
-
return this.CurrentTemperature;
|
|
47
|
+
return this.TemperatureSensor.CurrentTemperature;
|
|
100
48
|
});
|
|
101
49
|
}
|
|
102
|
-
|
|
103
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
104
|
-
}
|
|
105
|
-
// Humidity Sensor Service
|
|
50
|
+
// Initialize Humidity Sensor Service
|
|
106
51
|
if (device.hub?.hide_humidity) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
else if (!this.humidityService) {
|
|
112
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Humidity Sensor Service`);
|
|
113
|
-
const humidityService = `${accessory.displayName} Humidity Sensor`;
|
|
114
|
-
(this.humidityService = this.accessory.getService(this.hap.Service.HumiditySensor)
|
|
115
|
-
|| this.accessory.addService(this.hap.Service.HumiditySensor)), humidityService;
|
|
116
|
-
this.humidityService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Humidity Sensor`);
|
|
117
|
-
if (!this.humidityService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
118
|
-
this.humidityService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Humidity Sensor`);
|
|
52
|
+
if (this.HumiditySensor) {
|
|
53
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Humidity Sensor Service`);
|
|
54
|
+
this.HumiditySensor.Service = this.accessory.getService(this.hap.Service.HumiditySensor);
|
|
55
|
+
accessory.removeService(this.HumiditySensor.Service);
|
|
119
56
|
}
|
|
120
|
-
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
accessory.context.HumiditySensor = accessory.context.HumiditySensor ?? {};
|
|
60
|
+
this.HumiditySensor = {
|
|
61
|
+
Name: accessory.context.HumiditySensor.Name ?? `${accessory.displayName} Humidity Sensor`,
|
|
62
|
+
Service: accessory.getService(this.hap.Service.HumiditySensor) ?? this.accessory.addService(this.hap.Service.HumiditySensor),
|
|
63
|
+
CurrentRelativeHumidity: accessory.context.CurrentRelativeHumidity ?? 0,
|
|
64
|
+
};
|
|
65
|
+
accessory.context.HumiditySensor = this.HumiditySensor;
|
|
66
|
+
// Initialize Humidity Sensor Characteristics
|
|
67
|
+
this.HumiditySensor.Service
|
|
68
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.HumiditySensor.Name)
|
|
121
69
|
.getCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity)
|
|
122
70
|
.setProps({
|
|
123
71
|
minStep: 0.1,
|
|
124
72
|
})
|
|
125
73
|
.onGet(() => {
|
|
126
|
-
return this.CurrentRelativeHumidity;
|
|
74
|
+
return this.HumiditySensor.CurrentRelativeHumidity;
|
|
127
75
|
});
|
|
128
76
|
}
|
|
129
|
-
|
|
130
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Humidity Sensor Service Not Added`);
|
|
131
|
-
}
|
|
132
|
-
// Light Sensor Service
|
|
77
|
+
// Initialize Light Sensor Service
|
|
133
78
|
if (device.hub?.hide_lightsensor) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
|
|
140
|
-
const lightSensorService = `${accessory.displayName} Light Sensor`;
|
|
141
|
-
(this.lightSensorService = this.accessory.getService(this.hap.Service.LightSensor)
|
|
142
|
-
|| this.accessory.addService(this.hap.Service.LightSensor)), lightSensorService;
|
|
143
|
-
this.lightSensorService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Light Sensor`);
|
|
144
|
-
this.lightSensorService.setCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Light Sensor`);
|
|
79
|
+
if (this.LightSensor) {
|
|
80
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
|
|
81
|
+
this.LightSensor.Service = this.accessory.getService(this.hap.Service.LightSensor);
|
|
82
|
+
accessory.removeService(this.LightSensor.Service);
|
|
83
|
+
}
|
|
145
84
|
}
|
|
146
85
|
else {
|
|
147
|
-
|
|
86
|
+
accessory.context.LightSensor = accessory.context.LightSensor ?? {};
|
|
87
|
+
this.LightSensor = {
|
|
88
|
+
Name: accessory.context.LightSensor.Name ?? `${accessory.displayName} Light Sensor`,
|
|
89
|
+
Service: accessory.getService(this.hap.Service.LightSensor) ?? this.accessory.addService(this.hap.Service.LightSensor),
|
|
90
|
+
CurrentAmbientLightLevel: accessory.context.CurrentAmbientLightLevel ?? 0.0001,
|
|
91
|
+
};
|
|
92
|
+
accessory.context.LightSensor = this.LightSensor;
|
|
93
|
+
// Initialize Light Sensor Characteristics
|
|
94
|
+
this.LightSensor.Service
|
|
95
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.LightSensor.Name)
|
|
96
|
+
.getCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel)
|
|
97
|
+
.setProps({
|
|
98
|
+
minStep: 1,
|
|
99
|
+
})
|
|
100
|
+
.onGet(() => {
|
|
101
|
+
return this.LightSensor.CurrentAmbientLightLevel;
|
|
102
|
+
});
|
|
148
103
|
}
|
|
104
|
+
// Retrieve initial values and updateHomekit
|
|
105
|
+
this.refreshStatus();
|
|
149
106
|
// Retrieve initial values and update Homekit
|
|
150
107
|
this.updateHomeKitCharacteristics();
|
|
151
108
|
// Start an update interval
|
|
152
109
|
interval(this.deviceRefreshRate * 1000)
|
|
110
|
+
.pipe(skipWhile(() => this.hubUpdateInProgress))
|
|
153
111
|
.subscribe(async () => {
|
|
154
112
|
await this.refreshStatus();
|
|
155
113
|
});
|
|
156
114
|
//regisiter webhook event handler
|
|
157
|
-
|
|
158
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
|
|
159
|
-
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
160
|
-
try {
|
|
161
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
162
|
-
if (context.scale === 'CELSIUS') {
|
|
163
|
-
const { temperature, humidity, lightLevel } = context;
|
|
164
|
-
const { CurrentTemperature, CurrentRelativeHumidity, CurrentAmbientLightLevel } = this;
|
|
165
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
166
|
-
'(temperature, humidity, lightLevel) = ' +
|
|
167
|
-
`Webhook:(${temperature}, ${humidity}, ${lightLevel}), ` +
|
|
168
|
-
`current:(${CurrentTemperature}, ${CurrentRelativeHumidity}, ${CurrentAmbientLightLevel})`);
|
|
169
|
-
this.CurrentRelativeHumidity = humidity;
|
|
170
|
-
this.CurrentTemperature = temperature;
|
|
171
|
-
this.set_minLux = this.minLux();
|
|
172
|
-
this.set_maxLux = this.maxLux();
|
|
173
|
-
this.spaceBetweenLevels = 19;
|
|
174
|
-
switch (lightLevel) {
|
|
175
|
-
case 1:
|
|
176
|
-
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
177
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
178
|
-
break;
|
|
179
|
-
case 2:
|
|
180
|
-
this.CurrentAmbientLightLevel = (this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels;
|
|
181
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel},` +
|
|
182
|
-
` Calculation: ${(this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels}`);
|
|
183
|
-
break;
|
|
184
|
-
case 3:
|
|
185
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 2;
|
|
186
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
187
|
-
break;
|
|
188
|
-
case 4:
|
|
189
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 3;
|
|
190
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
191
|
-
break;
|
|
192
|
-
case 5:
|
|
193
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 4;
|
|
194
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
195
|
-
break;
|
|
196
|
-
case 6:
|
|
197
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 5;
|
|
198
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
199
|
-
break;
|
|
200
|
-
case 7:
|
|
201
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 6;
|
|
202
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
203
|
-
break;
|
|
204
|
-
case 8:
|
|
205
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 7;
|
|
206
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
207
|
-
break;
|
|
208
|
-
case 9:
|
|
209
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 8;
|
|
210
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
211
|
-
break;
|
|
212
|
-
case 10:
|
|
213
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 9;
|
|
214
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
215
|
-
break;
|
|
216
|
-
case 11:
|
|
217
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 10;
|
|
218
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
219
|
-
break;
|
|
220
|
-
case 12:
|
|
221
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 11;
|
|
222
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
223
|
-
break;
|
|
224
|
-
case 13:
|
|
225
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 12;
|
|
226
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
227
|
-
break;
|
|
228
|
-
case 14:
|
|
229
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 13;
|
|
230
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
231
|
-
break;
|
|
232
|
-
case 15:
|
|
233
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 14;
|
|
234
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
235
|
-
break;
|
|
236
|
-
case 16:
|
|
237
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 15;
|
|
238
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
239
|
-
break;
|
|
240
|
-
case 17:
|
|
241
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 16;
|
|
242
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
243
|
-
break;
|
|
244
|
-
case 18:
|
|
245
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 17;
|
|
246
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
247
|
-
break;
|
|
248
|
-
case 19:
|
|
249
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 18;
|
|
250
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
251
|
-
break;
|
|
252
|
-
case 20:
|
|
253
|
-
default:
|
|
254
|
-
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
255
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
256
|
-
}
|
|
257
|
-
this.updateHomeKitCharacteristics();
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
catch (e) {
|
|
261
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
262
|
-
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
}
|
|
115
|
+
this.registerWebhook(accessory, device);
|
|
266
116
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
async parseStatus() {
|
|
271
|
-
if (this.BLE) {
|
|
272
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE not supported`);
|
|
273
|
-
}
|
|
274
|
-
else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
275
|
-
await this.openAPIparseStatus();
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
await this.offlineOff();
|
|
279
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`);
|
|
280
|
-
}
|
|
117
|
+
async BLEparseStatus(serviceData) {
|
|
118
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
119
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(serviceData)}`);
|
|
281
120
|
}
|
|
282
|
-
async openAPIparseStatus() {
|
|
121
|
+
async openAPIparseStatus(deviceStatus) {
|
|
283
122
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
284
123
|
// CurrentRelativeHumidity
|
|
285
124
|
if (!this.device.hub?.hide_humidity) {
|
|
286
|
-
this.CurrentRelativeHumidity = Number(
|
|
287
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
|
|
125
|
+
this.HumiditySensor.CurrentRelativeHumidity = Number(deviceStatus.body.humidity);
|
|
126
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`);
|
|
288
127
|
}
|
|
289
128
|
// CurrentTemperature
|
|
290
129
|
if (!this.device.hub?.hide_temperature) {
|
|
291
|
-
this.CurrentTemperature = Number(
|
|
292
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
|
|
130
|
+
this.TemperatureSensor.CurrentTemperature = Number(deviceStatus.body.temperature);
|
|
131
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.TemperatureSensor.CurrentTemperature}°c`);
|
|
293
132
|
}
|
|
294
133
|
// Brightness
|
|
295
134
|
if (!this.device.hub?.hide_lightsensor) {
|
|
296
135
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
break;
|
|
305
|
-
case 2:
|
|
306
|
-
this.CurrentAmbientLightLevel = (this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels;
|
|
307
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel},` +
|
|
308
|
-
` Calculation: ${(this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels}`);
|
|
309
|
-
break;
|
|
310
|
-
case 3:
|
|
311
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 2;
|
|
312
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
313
|
-
break;
|
|
314
|
-
case 4:
|
|
315
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 3;
|
|
316
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
317
|
-
break;
|
|
318
|
-
case 5:
|
|
319
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 4;
|
|
320
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
321
|
-
break;
|
|
322
|
-
case 6:
|
|
323
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 5;
|
|
324
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
325
|
-
break;
|
|
326
|
-
case 7:
|
|
327
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 6;
|
|
328
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
329
|
-
break;
|
|
330
|
-
case 8:
|
|
331
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 7;
|
|
332
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
333
|
-
break;
|
|
334
|
-
case 9:
|
|
335
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 8;
|
|
336
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
337
|
-
break;
|
|
338
|
-
case 10:
|
|
339
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 9;
|
|
340
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
341
|
-
break;
|
|
342
|
-
case 11:
|
|
343
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 10;
|
|
344
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
345
|
-
break;
|
|
346
|
-
case 12:
|
|
347
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 11;
|
|
348
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
349
|
-
break;
|
|
350
|
-
case 13:
|
|
351
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 12;
|
|
352
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
353
|
-
break;
|
|
354
|
-
case 14:
|
|
355
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 13;
|
|
356
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
357
|
-
break;
|
|
358
|
-
case 15:
|
|
359
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 14;
|
|
360
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
361
|
-
break;
|
|
362
|
-
case 16:
|
|
363
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 15;
|
|
364
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
365
|
-
break;
|
|
366
|
-
case 17:
|
|
367
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 16;
|
|
368
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
369
|
-
break;
|
|
370
|
-
case 18:
|
|
371
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 17;
|
|
372
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
373
|
-
break;
|
|
374
|
-
case 19:
|
|
375
|
-
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 18;
|
|
376
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
377
|
-
break;
|
|
378
|
-
case 20:
|
|
379
|
-
default:
|
|
380
|
-
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
381
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
382
|
-
}
|
|
383
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel},` +
|
|
384
|
-
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
136
|
+
const set_minLux = this.device.curtain?.set_minLux ?? 1;
|
|
137
|
+
const set_maxLux = this.device.curtain?.set_maxLux ?? 6001;
|
|
138
|
+
const spaceBetweenLevels = 19;
|
|
139
|
+
const lightLevel = deviceStatus.body.lightLevel;
|
|
140
|
+
await this.getLightLevel(lightLevel, set_minLux, set_maxLux, spaceBetweenLevels);
|
|
141
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${deviceStatus.body.lightLevel},`
|
|
142
|
+
+ ` CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
385
143
|
}
|
|
386
144
|
if (!this.device.hub?.hide_lightsensor) {
|
|
387
|
-
this.
|
|
145
|
+
this.LightSensor.Service.setCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.LightSensor.CurrentAmbientLightLevel);
|
|
388
146
|
}
|
|
389
147
|
}
|
|
390
|
-
//
|
|
391
|
-
|
|
392
|
-
this.
|
|
148
|
+
// Firmware Version
|
|
149
|
+
const version = deviceStatus.body.version?.toString();
|
|
150
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
|
|
151
|
+
if (deviceStatus.body.version) {
|
|
152
|
+
const deviceVersion = version?.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
153
|
+
this.accessory
|
|
154
|
+
.getService(this.hap.Service.AccessoryInformation)
|
|
155
|
+
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
156
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
|
|
157
|
+
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
158
|
+
.updateValue(deviceVersion);
|
|
159
|
+
this.accessory.context.deviceVersion = deviceVersion;
|
|
160
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceVersion: ${this.accessory.context.deviceVersion}`);
|
|
161
|
+
}
|
|
393
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Asks the SwitchBot API for the latest device information
|
|
165
|
+
*/
|
|
394
166
|
async refreshStatus() {
|
|
395
|
-
if (this.
|
|
396
|
-
this.
|
|
167
|
+
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
168
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
169
|
+
}
|
|
170
|
+
else if (this.BLE) {
|
|
171
|
+
await this.BLERefreshStatus();
|
|
397
172
|
}
|
|
398
173
|
else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
399
174
|
await this.openAPIRefreshStatus();
|
|
400
175
|
}
|
|
401
176
|
else {
|
|
402
177
|
await this.offlineOff();
|
|
403
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type
|
|
178
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
179
|
+
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
async BLERefreshStatus() {
|
|
183
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
|
|
184
|
+
const switchbot = await this.switchbotBLE();
|
|
185
|
+
if (switchbot === undefined) {
|
|
186
|
+
await this.BLERefreshConnection(switchbot);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
// Start to monitor advertisement packets
|
|
190
|
+
(async () => {
|
|
191
|
+
// Start to monitor advertisement packets
|
|
192
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot);
|
|
193
|
+
// Update HomeKit
|
|
194
|
+
if (serviceData.model !== '' && serviceData.modelName !== '') {
|
|
195
|
+
await this.BLEparseStatus(serviceData);
|
|
196
|
+
await this.updateHomeKitCharacteristics();
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed to get serviceData, serviceData: ${serviceData}`);
|
|
200
|
+
await this.BLERefreshConnection(switchbot);
|
|
201
|
+
}
|
|
202
|
+
})();
|
|
404
203
|
}
|
|
405
204
|
}
|
|
406
205
|
async openAPIRefreshStatus() {
|
|
407
206
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
408
207
|
try {
|
|
409
|
-
const { body, statusCode } = await
|
|
410
|
-
headers: this.platform.generateHeaders(),
|
|
411
|
-
});
|
|
412
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
208
|
+
const { body, statusCode } = await this.deviceRefreshStatus();
|
|
413
209
|
const deviceStatus = await body.json();
|
|
414
|
-
this.
|
|
415
|
-
|
|
210
|
+
await this.refreshStatusCodes(statusCode, deviceStatus);
|
|
211
|
+
;
|
|
416
212
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
417
|
-
this.
|
|
418
|
-
|
|
419
|
-
this.
|
|
420
|
-
this.OpenAPI_CurrentRelativeHumidity = deviceStatus.body.humidity;
|
|
421
|
-
this.OpenAPI_CurrentAmbientLightLevel = deviceStatus.body.lightLevel;
|
|
422
|
-
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
423
|
-
this.openAPIparseStatus();
|
|
424
|
-
this.updateHomeKitCharacteristics();
|
|
213
|
+
await this.successfulRefreshStatus(statusCode, deviceStatus);
|
|
214
|
+
await this.openAPIparseStatus(deviceStatus);
|
|
215
|
+
await this.updateHomeKitCharacteristics();
|
|
425
216
|
}
|
|
426
217
|
else {
|
|
427
|
-
this.
|
|
428
|
-
this.statusCode(deviceStatus.statusCode);
|
|
218
|
+
await this.statusCodes(statusCode, deviceStatus);
|
|
429
219
|
}
|
|
430
220
|
}
|
|
431
221
|
catch (e) {
|
|
432
222
|
this.apiError(e);
|
|
433
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
|
|
434
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
223
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
|
|
224
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async registerWebhook(accessory, device) {
|
|
228
|
+
if (device.webhook) {
|
|
229
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
|
|
230
|
+
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
231
|
+
try {
|
|
232
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
233
|
+
const { temperature, humidity, lightLevel } = context;
|
|
234
|
+
const { CurrentTemperature } = this.TemperatureSensor || { CurrentTemperature: undefined };
|
|
235
|
+
const { CurrentAmbientLightLevel } = this.LightSensor || { CurrentAmbientLightLevel: undefined };
|
|
236
|
+
const { CurrentRelativeHumidity } = this.HumiditySensor || { CurrentRelativeHumidity: undefined };
|
|
237
|
+
if (context.scale !== 'CELCIUS' && device.hub?.convertUnitTo === undefined) {
|
|
238
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} received a non-CELCIUS Webhook scale: `
|
|
239
|
+
+ `${context.scale}, Use the *convertUnitsTo* config under Hub settings, if displaying incorrectly in HomeKit.`);
|
|
240
|
+
}
|
|
241
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
242
|
+
'(scale, temperature, humidity, lightLevel) = ' +
|
|
243
|
+
`Webhook:(${context.scale}, ${convertUnits(temperature, context.scale, device.hub?.convertUnitTo)}, ${humidity}, ${lightLevel}), `
|
|
244
|
+
+ `current:(${CurrentTemperature}, ${CurrentRelativeHumidity}, ${CurrentAmbientLightLevel})`);
|
|
245
|
+
if (!this.device.hub?.hide_humidity) {
|
|
246
|
+
this.HumiditySensor.CurrentRelativeHumidity = humidity;
|
|
247
|
+
}
|
|
248
|
+
if (!this.device.hub?.hide_temperature) {
|
|
249
|
+
this.TemperatureSensor.CurrentTemperature = convertUnits(temperature, context.scale, device.hub?.convertUnitTo);
|
|
250
|
+
}
|
|
251
|
+
if (!this.device.hub?.hide_lightsensor) {
|
|
252
|
+
const set_minLux = this.device.curtain?.set_minLux ?? 1;
|
|
253
|
+
const set_maxLux = this.device.curtain?.set_maxLux ?? 6001;
|
|
254
|
+
const spaceBetweenLevels = 19;
|
|
255
|
+
await this.getLightLevel(lightLevel, set_minLux, set_maxLux, spaceBetweenLevels);
|
|
256
|
+
}
|
|
257
|
+
this.updateHomeKitCharacteristics();
|
|
258
|
+
}
|
|
259
|
+
catch (e) {
|
|
260
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
261
|
+
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
262
|
+
}
|
|
263
|
+
};
|
|
435
264
|
}
|
|
436
265
|
}
|
|
437
266
|
/**
|
|
@@ -442,352 +271,187 @@ export class Hub {
|
|
|
442
271
|
const entry = { time: Math.round(new Date().valueOf() / 1000) };
|
|
443
272
|
// CurrentRelativeHumidity
|
|
444
273
|
if (!this.device.hub?.hide_humidity) {
|
|
445
|
-
if (this.CurrentRelativeHumidity === undefined) {
|
|
446
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
274
|
+
if (this.HumiditySensor.CurrentRelativeHumidity === undefined) {
|
|
275
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
276
|
+
+ ` CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}`);
|
|
447
277
|
}
|
|
448
278
|
else {
|
|
449
279
|
if (this.device.mqttURL) {
|
|
450
|
-
mqttmessage.push(`"humidity": ${this.CurrentRelativeHumidity}`);
|
|
280
|
+
mqttmessage.push(`"humidity": ${this.HumiditySensor.CurrentRelativeHumidity}`);
|
|
451
281
|
}
|
|
452
282
|
if (this.device.history) {
|
|
453
|
-
entry['humidity'] = this.CurrentRelativeHumidity;
|
|
283
|
+
entry['humidity'] = this.HumiditySensor.CurrentRelativeHumidity;
|
|
454
284
|
}
|
|
455
|
-
this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
|
|
456
|
-
this.
|
|
285
|
+
this.accessory.context.CurrentRelativeHumidity = this.HumiditySensor.CurrentRelativeHumidity;
|
|
286
|
+
this.HumiditySensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, this.HumiditySensor.CurrentRelativeHumidity);
|
|
457
287
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
458
|
-
+ `updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
288
|
+
+ `updateCharacteristic CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}`);
|
|
459
289
|
}
|
|
460
290
|
}
|
|
461
291
|
// CurrentTemperature
|
|
462
292
|
if (!this.device.hub?.hide_temperature) {
|
|
463
|
-
if (this.CurrentTemperature === undefined) {
|
|
464
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
293
|
+
if (this.TemperatureSensor.CurrentTemperature === undefined) {
|
|
294
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
465
295
|
}
|
|
466
296
|
else {
|
|
467
297
|
if (this.device.mqttURL) {
|
|
468
|
-
mqttmessage.push(`"temperature": ${this.CurrentTemperature}`);
|
|
298
|
+
mqttmessage.push(`"temperature": ${this.TemperatureSensor.CurrentTemperature}`);
|
|
469
299
|
}
|
|
470
300
|
if (this.device.history) {
|
|
471
|
-
entry['temp'] = this.CurrentTemperature;
|
|
301
|
+
entry['temp'] = this.TemperatureSensor.CurrentTemperature;
|
|
472
302
|
}
|
|
473
|
-
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
474
|
-
this.
|
|
475
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
303
|
+
this.accessory.context.CurrentTemperature = this.TemperatureSensor.CurrentTemperature;
|
|
304
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor.CurrentTemperature);
|
|
305
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
306
|
+
+ ` CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
476
307
|
}
|
|
477
308
|
}
|
|
478
309
|
// CurrentAmbientLightLevel
|
|
479
310
|
if (!this.device.hub?.hide_lightsensor) {
|
|
480
|
-
if (this.CurrentAmbientLightLevel === undefined) {
|
|
481
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
311
|
+
if (this.LightSensor.CurrentAmbientLightLevel === undefined) {
|
|
312
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
313
|
+
+ ` CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
482
314
|
}
|
|
483
315
|
else {
|
|
484
316
|
if (this.device.mqttURL) {
|
|
485
|
-
mqttmessage.push(`"light": ${this.CurrentAmbientLightLevel}`);
|
|
317
|
+
mqttmessage.push(`"light": ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
486
318
|
}
|
|
487
319
|
if (this.device.history) {
|
|
488
|
-
entry['lux'] = this.CurrentAmbientLightLevel;
|
|
320
|
+
entry['lux'] = this.LightSensor.CurrentAmbientLightLevel;
|
|
489
321
|
}
|
|
490
|
-
this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
|
|
491
|
-
this.
|
|
322
|
+
this.accessory.context.CurrentAmbientLightLevel = this.LightSensor.CurrentAmbientLightLevel;
|
|
323
|
+
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.LightSensor.CurrentAmbientLightLevel);
|
|
492
324
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
493
|
-
+ `updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
325
|
+
+ `updateCharacteristic CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
494
326
|
}
|
|
495
327
|
}
|
|
496
328
|
// MQTT
|
|
497
329
|
if (this.device.mqttURL) {
|
|
498
330
|
this.mqttPublish(`{${mqttmessage.join(',')}}`);
|
|
499
331
|
}
|
|
500
|
-
if (Number(this.CurrentRelativeHumidity) > 0) {
|
|
332
|
+
if (Number(this.HumiditySensor.CurrentRelativeHumidity) > 0) {
|
|
501
333
|
// reject unreliable data
|
|
502
334
|
if (this.device.history) {
|
|
503
335
|
this.historyService?.addEntry(entry);
|
|
504
336
|
}
|
|
505
337
|
}
|
|
506
338
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
.match(/[\s\S]{1,2}/g)
|
|
515
|
-
?.join(':');
|
|
516
|
-
const options = this.device.mqttPubOptions || {};
|
|
517
|
-
this.mqttClient?.publish(`homebridge-switchbot/hub/${mac}`, `${message}`, options);
|
|
518
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT message: ${message} options:${JSON.stringify(options)}`);
|
|
339
|
+
async BLERefreshConnection(switchbot) {
|
|
340
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot:`
|
|
341
|
+
+ ` ${JSON.stringify(switchbot)}`);
|
|
342
|
+
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
343
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
|
|
344
|
+
await this.openAPIRefreshStatus();
|
|
345
|
+
}
|
|
519
346
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
if (device.mqttURL) {
|
|
525
|
-
try {
|
|
526
|
-
const { connectAsync } = asyncmqtt;
|
|
527
|
-
this.mqttClient = await connectAsync(device.mqttURL, device.mqttOptions || {});
|
|
528
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT connection has been established successfully.`);
|
|
529
|
-
this.mqttClient.on('error', (e) => {
|
|
530
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to publish MQTT messages. ${e}`);
|
|
531
|
-
});
|
|
347
|
+
async offlineOff() {
|
|
348
|
+
if (this.device.offline) {
|
|
349
|
+
if (!this.device.hub?.hide_temperature) {
|
|
350
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.accessory.context.CurrentTemperature);
|
|
532
351
|
}
|
|
533
|
-
|
|
534
|
-
this.
|
|
535
|
-
|
|
352
|
+
if (!this.device.hub?.hide_humidity) {
|
|
353
|
+
this.HumiditySensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, this.accessory.context.CurrentRelativeHumidity);
|
|
354
|
+
}
|
|
355
|
+
if (!this.device.hub?.hide_lightsensor) {
|
|
356
|
+
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.accessory.context.CurrentAmbientLightLevel);
|
|
536
357
|
}
|
|
537
358
|
}
|
|
538
359
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
.
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
log: this.platform.log,
|
|
550
|
-
storage: 'fs',
|
|
551
|
-
filename: `${hostname().split('.')[0]}_${mac}_persist.json`,
|
|
552
|
-
})
|
|
553
|
-
: null;
|
|
360
|
+
async apiError(e) {
|
|
361
|
+
if (!this.device.hub?.hide_temperature) {
|
|
362
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
|
|
363
|
+
}
|
|
364
|
+
if (!this.device.hub?.hide_humidity) {
|
|
365
|
+
this.HumiditySensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
|
|
366
|
+
}
|
|
367
|
+
if (!this.device.hub?.hide_lightsensor) {
|
|
368
|
+
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e);
|
|
369
|
+
}
|
|
554
370
|
}
|
|
555
|
-
async
|
|
556
|
-
switch (
|
|
557
|
-
case
|
|
558
|
-
this.
|
|
371
|
+
async getLightLevel(lightLevel, set_minLux, set_maxLux, spaceBetweenLevels) {
|
|
372
|
+
switch (lightLevel) {
|
|
373
|
+
case 1:
|
|
374
|
+
this.LightSensor.CurrentAmbientLightLevel = set_minLux;
|
|
375
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
376
|
+
break;
|
|
377
|
+
case 2:
|
|
378
|
+
this.LightSensor.CurrentAmbientLightLevel = (set_maxLux - set_minLux) / spaceBetweenLevels;
|
|
379
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel},`
|
|
380
|
+
+ ` Calculation: ${(set_maxLux - set_minLux) / spaceBetweenLevels}`);
|
|
381
|
+
break;
|
|
382
|
+
case 3:
|
|
383
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 2;
|
|
384
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
559
385
|
break;
|
|
560
|
-
case
|
|
561
|
-
this.
|
|
386
|
+
case 4:
|
|
387
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 3;
|
|
388
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
562
389
|
break;
|
|
563
|
-
case
|
|
564
|
-
this.
|
|
390
|
+
case 5:
|
|
391
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 4;
|
|
392
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
565
393
|
break;
|
|
566
|
-
case
|
|
567
|
-
this.
|
|
568
|
-
this.
|
|
394
|
+
case 6:
|
|
395
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 5;
|
|
396
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
569
397
|
break;
|
|
570
|
-
case
|
|
571
|
-
this.
|
|
572
|
-
|
|
573
|
-
this.offlineOff();
|
|
398
|
+
case 7:
|
|
399
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 6;
|
|
400
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
574
401
|
break;
|
|
575
|
-
case
|
|
576
|
-
this.
|
|
577
|
-
|
|
402
|
+
case 8:
|
|
403
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 7;
|
|
404
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
578
405
|
break;
|
|
579
|
-
case
|
|
580
|
-
this.
|
|
406
|
+
case 9:
|
|
407
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 8;
|
|
408
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
581
409
|
break;
|
|
582
|
-
case
|
|
583
|
-
this.
|
|
410
|
+
case 10:
|
|
411
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 9;
|
|
412
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
584
413
|
break;
|
|
585
|
-
case
|
|
586
|
-
this.
|
|
587
|
-
|
|
414
|
+
case 11:
|
|
415
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 10;
|
|
416
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
588
417
|
break;
|
|
589
|
-
case
|
|
590
|
-
this.
|
|
591
|
-
|
|
418
|
+
case 12:
|
|
419
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 11;
|
|
420
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
592
421
|
break;
|
|
593
|
-
case
|
|
594
|
-
this.
|
|
595
|
-
|
|
422
|
+
case 13:
|
|
423
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 12;
|
|
424
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
596
425
|
break;
|
|
597
|
-
case
|
|
598
|
-
this.
|
|
599
|
-
|
|
426
|
+
case 14:
|
|
427
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 13;
|
|
428
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
600
429
|
break;
|
|
601
|
-
case
|
|
602
|
-
this.
|
|
603
|
-
|
|
430
|
+
case 15:
|
|
431
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 14;
|
|
432
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
604
433
|
break;
|
|
605
|
-
case
|
|
606
|
-
this.
|
|
607
|
-
|
|
434
|
+
case 16:
|
|
435
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 15;
|
|
436
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
608
437
|
break;
|
|
609
|
-
case
|
|
610
|
-
this.
|
|
611
|
-
|
|
438
|
+
case 17:
|
|
439
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 16;
|
|
440
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
612
441
|
break;
|
|
613
|
-
case
|
|
614
|
-
this.
|
|
615
|
-
|
|
442
|
+
case 18:
|
|
443
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 17;
|
|
444
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
616
445
|
break;
|
|
617
|
-
case
|
|
618
|
-
this.
|
|
619
|
-
|
|
446
|
+
case 19:
|
|
447
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 18;
|
|
448
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
620
449
|
break;
|
|
450
|
+
case 20:
|
|
621
451
|
default:
|
|
622
|
-
this.
|
|
623
|
-
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
async offlineOff() {
|
|
627
|
-
if (this.device.offline) {
|
|
628
|
-
await this.deviceContext();
|
|
629
|
-
await this.updateHomeKitCharacteristics();
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
async apiError(e) {
|
|
633
|
-
if (!this.device.hub?.hide_temperature) {
|
|
634
|
-
this.temperatureService?.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
|
|
635
|
-
}
|
|
636
|
-
if (!this.device.hub?.hide_humidity) {
|
|
637
|
-
this.humidityService?.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
|
|
638
|
-
}
|
|
639
|
-
if (!this.device.hub?.hide_lightsensor) {
|
|
640
|
-
this.lightSensorService?.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e);
|
|
452
|
+
this.LightSensor.CurrentAmbientLightLevel = set_maxLux;
|
|
453
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
641
454
|
}
|
|
642
455
|
}
|
|
643
|
-
minLux() {
|
|
644
|
-
if (this.device.curtain?.set_minLux) {
|
|
645
|
-
this.set_minLux = this.device.curtain?.set_minLux;
|
|
646
|
-
}
|
|
647
|
-
else {
|
|
648
|
-
this.set_minLux = 1;
|
|
649
|
-
}
|
|
650
|
-
return this.set_minLux;
|
|
651
|
-
}
|
|
652
|
-
maxLux() {
|
|
653
|
-
if (this.device.curtain?.set_maxLux) {
|
|
654
|
-
this.set_maxLux = this.device.curtain?.set_maxLux;
|
|
655
|
-
}
|
|
656
|
-
else {
|
|
657
|
-
this.set_maxLux = 6001;
|
|
658
|
-
}
|
|
659
|
-
return this.set_maxLux;
|
|
660
|
-
}
|
|
661
|
-
async deviceContext() {
|
|
662
|
-
if (this.CurrentRelativeHumidity === undefined) {
|
|
663
|
-
this.CurrentRelativeHumidity = 0;
|
|
664
|
-
}
|
|
665
|
-
else {
|
|
666
|
-
this.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity;
|
|
667
|
-
}
|
|
668
|
-
if (this.CurrentTemperature === undefined) {
|
|
669
|
-
this.CurrentTemperature = 0;
|
|
670
|
-
}
|
|
671
|
-
else {
|
|
672
|
-
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
673
|
-
}
|
|
674
|
-
if (this.CurrentAmbientLightLevel === undefined) {
|
|
675
|
-
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
676
|
-
}
|
|
677
|
-
else {
|
|
678
|
-
this.CurrentAmbientLightLevel = this.accessory.context.CurrentAmbientLightLevel;
|
|
679
|
-
}
|
|
680
|
-
if (this.FirmwareRevision === undefined) {
|
|
681
|
-
this.FirmwareRevision = this.platform.version;
|
|
682
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
async refreshRate(device) {
|
|
686
|
-
// refreshRate
|
|
687
|
-
if (device.refreshRate) {
|
|
688
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
689
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
690
|
-
}
|
|
691
|
-
else if (this.platform.config.options.refreshRate) {
|
|
692
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
693
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
694
|
-
}
|
|
695
|
-
// updateRate
|
|
696
|
-
if (device?.curtain?.updateRate) {
|
|
697
|
-
this.updateRate = device?.curtain?.updateRate;
|
|
698
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Curtain updateRate: ${this.updateRate}`);
|
|
699
|
-
}
|
|
700
|
-
else {
|
|
701
|
-
this.updateRate = 7;
|
|
702
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default Curtain updateRate: ${this.updateRate}`);
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
async deviceConfig(device) {
|
|
706
|
-
let config = {};
|
|
707
|
-
if (device.hub) {
|
|
708
|
-
config = device.hub;
|
|
709
|
-
}
|
|
710
|
-
if (device.connectionType !== undefined) {
|
|
711
|
-
config['connectionType'] = device.connectionType;
|
|
712
|
-
}
|
|
713
|
-
if (device.external !== undefined) {
|
|
714
|
-
config['external'] = device.external;
|
|
715
|
-
}
|
|
716
|
-
if (device.logging !== undefined) {
|
|
717
|
-
config['logging'] = device.logging;
|
|
718
|
-
}
|
|
719
|
-
if (device.refreshRate !== undefined) {
|
|
720
|
-
config['refreshRate'] = device.refreshRate;
|
|
721
|
-
}
|
|
722
|
-
if (device.webhook !== undefined) {
|
|
723
|
-
config['webhook'] = device.webhook;
|
|
724
|
-
}
|
|
725
|
-
if (Object.entries(config).length !== 0) {
|
|
726
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
async deviceLogs(device) {
|
|
730
|
-
if (this.platform.debugMode) {
|
|
731
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
732
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
733
|
-
}
|
|
734
|
-
else if (device.logging) {
|
|
735
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
736
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
737
|
-
}
|
|
738
|
-
else if (this.platform.config.options?.logging) {
|
|
739
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
740
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
741
|
-
}
|
|
742
|
-
else {
|
|
743
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
744
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
/**
|
|
748
|
-
* Logging for Device
|
|
749
|
-
*/
|
|
750
|
-
infoLog(...log) {
|
|
751
|
-
if (this.enablingDeviceLogging()) {
|
|
752
|
-
this.platform.log.info(String(...log));
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
warnLog(...log) {
|
|
756
|
-
if (this.enablingDeviceLogging()) {
|
|
757
|
-
this.platform.log.warn(String(...log));
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
debugWarnLog(...log) {
|
|
761
|
-
if (this.enablingDeviceLogging()) {
|
|
762
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
763
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
errorLog(...log) {
|
|
768
|
-
if (this.enablingDeviceLogging()) {
|
|
769
|
-
this.platform.log.error(String(...log));
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
debugErrorLog(...log) {
|
|
773
|
-
if (this.enablingDeviceLogging()) {
|
|
774
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
775
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
debugLog(...log) {
|
|
780
|
-
if (this.enablingDeviceLogging()) {
|
|
781
|
-
if (this.deviceLogging === 'debug') {
|
|
782
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
783
|
-
}
|
|
784
|
-
else {
|
|
785
|
-
this.platform.log.debug(String(...log));
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
enablingDeviceLogging() {
|
|
790
|
-
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
791
|
-
}
|
|
792
456
|
}
|
|
793
457
|
//# sourceMappingURL=hub.js.map
|