@switchbot/homebridge-switchbot 3.5.0-beta.3 → 3.5.0-beta.31
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/CHANGELOG.md +4 -1
- package/config.schema.json +147 -9
- package/dist/device/blindtilt.d.ts +21 -94
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +347 -756
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +25 -71
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +582 -759
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -67
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +209 -587
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +13 -74
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +250 -632
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +14 -65
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +204 -531
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +17 -86
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +335 -786
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +59 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +654 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/fan.d.ts +51 -0
- package/dist/device/fan.d.ts.map +1 -0
- package/dist/device/fan.js +499 -0
- package/dist/device/fan.js.map +1 -0
- package/dist/device/hub.d.ts +15 -59
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +242 -596
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +10 -65
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +207 -571
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +11 -64
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +174 -584
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -68
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +252 -568
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +15 -62
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +210 -542
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +13 -63
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +170 -577
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +13 -64
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +159 -577
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +13 -69
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +136 -518
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -57
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +82 -452
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -62
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +140 -451
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +9 -70
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +121 -664
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -48
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +309 -419
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +7 -38
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +72 -304
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +6 -35
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +34 -278
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +6 -39
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +67 -311
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +40 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +509 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +6 -34
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +23 -272
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +18 -47
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +352 -546
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +7 -39
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +82 -321
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +6 -35
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +41 -284
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +6 -35
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +42 -287
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +14 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +237 -94
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +40 -10
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +0 -552
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +77 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +638 -1
- package/dist/utils.js.map +1 -1
- package/package.json +16 -15
- package/src/custom.d.ts +2 -1
- package/src/device/blindtilt.ts +373 -782
- package/src/device/bot.ts +616 -844
- package/src/device/ceilinglight.ts +222 -607
- package/src/device/colorbulb.ts +264 -656
- package/src/device/contact.ts +229 -553
- package/src/device/curtain.ts +355 -810
- package/src/device/device.ts +681 -0
- package/src/device/fan.ts +548 -0
- package/src/device/hub.ts +268 -623
- package/src/device/humidifier.ts +237 -618
- package/src/device/iosensor.ts +200 -610
- package/src/device/lightstrip.ts +273 -596
- package/src/device/lock.ts +247 -582
- package/src/device/meter.ts +196 -601
- package/src/device/meterplus.ts +184 -602
- package/src/device/motion.ts +156 -541
- package/src/device/plug.ts +92 -480
- package/src/device/robotvacuumcleaner.ts +161 -477
- package/src/device/waterdetector.ts +139 -689
- package/src/index.ts +1 -1
- package/src/irdevice/airconditioner.ts +330 -446
- package/src/irdevice/airpurifier.ts +89 -321
- package/src/irdevice/camera.ts +42 -293
- package/src/irdevice/fan.ts +78 -327
- package/src/irdevice/irdevice.ts +526 -0
- package/src/irdevice/light.ts +32 -287
- package/src/irdevice/other.ts +396 -615
- package/src/irdevice/tv.ts +100 -339
- package/src/irdevice/vacuumcleaner.ts +49 -305
- package/src/irdevice/waterheater.ts +50 -310
- package/src/platform.ts +247 -102
- package/src/settings.ts +56 -565
- package/src/utils.ts +642 -1
package/dist/device/hub.js
CHANGED
|
@@ -1,92 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* hub.ts: @switchbot/homebridge-switchbot.
|
|
4
|
+
*/
|
|
5
|
+
import { Subject, interval, skipWhile } from 'rxjs';
|
|
6
|
+
import { deviceBase } from './device.js';
|
|
5
7
|
import { Devices } from '../settings.js';
|
|
6
|
-
|
|
8
|
+
import { convertUnits } from '../utils.js';
|
|
9
|
+
export class Hub extends deviceBase {
|
|
7
10
|
platform;
|
|
8
|
-
accessory;
|
|
9
|
-
device;
|
|
10
|
-
api;
|
|
11
|
-
log;
|
|
12
|
-
config;
|
|
13
|
-
hap;
|
|
14
11
|
// 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;
|
|
12
|
+
LightSensor;
|
|
13
|
+
HumiditySensor;
|
|
14
|
+
TemperatureSensor;
|
|
15
|
+
// Updates
|
|
16
|
+
hubUpdateInProgress;
|
|
17
|
+
doHubUpdate;
|
|
45
18
|
constructor(platform, accessory, device) {
|
|
19
|
+
super(platform, accessory, device);
|
|
46
20
|
this.platform = platform;
|
|
47
|
-
this
|
|
48
|
-
this.
|
|
49
|
-
this.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
21
|
+
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
22
|
+
this.doHubUpdate = new Subject();
|
|
23
|
+
this.hubUpdateInProgress = false;
|
|
24
|
+
// Initialize Temperature Sensor property
|
|
25
|
+
if (!device.hub?.hide_temperature) {
|
|
26
|
+
this.TemperatureSensor = {
|
|
27
|
+
Service: accessory.getService(this.hap.Service.TemperatureSensor),
|
|
28
|
+
CurrentTemperature: accessory.context.CurrentTemperature || 0,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
// Initialize Humidity Sensor property
|
|
32
|
+
if (!device.hub?.hide_humidity) {
|
|
33
|
+
this.HumiditySensor = {
|
|
34
|
+
Service: accessory.getService(this.hap.Service.HumiditySensor),
|
|
35
|
+
CurrentRelativeHumidity: accessory.context.CurrentRelativeHumidity || 0,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// Initialize Light Sensor property
|
|
39
|
+
if (!device.hub?.hide_lightsensor) {
|
|
40
|
+
this.LightSensor = {
|
|
41
|
+
Service: accessory.getService(this.hap.Service.LightSensor),
|
|
42
|
+
CurrentAmbientLightLevel: accessory.context.CurrentAmbientLightLevel || 0.0001,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
65
45
|
// Retrieve initial values and updateHomekit
|
|
66
46
|
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
47
|
// Temperature Sensor Service
|
|
75
48
|
if (device.hub?.hide_temperature) {
|
|
76
49
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
77
|
-
this.
|
|
78
|
-
accessory.removeService(this.
|
|
50
|
+
this.TemperatureSensor.Service = this.accessory.getService(this.hap.Service.TemperatureSensor);
|
|
51
|
+
accessory.removeService(this.TemperatureSensor.Service);
|
|
79
52
|
}
|
|
80
|
-
else if (!this.
|
|
53
|
+
else if (!this.TemperatureSensor?.Service) {
|
|
81
54
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
82
|
-
const
|
|
83
|
-
(this.
|
|
84
|
-
|| this.accessory.addService(this.hap.Service.TemperatureSensor)),
|
|
85
|
-
this.
|
|
86
|
-
|
|
87
|
-
this.temperatureService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Temperature Sensor`);
|
|
88
|
-
}
|
|
89
|
-
this.temperatureService
|
|
55
|
+
const TemperatureSensorService = `${accessory.displayName} Temperature Sensor`;
|
|
56
|
+
(this.TemperatureSensor.Service = this.accessory.getService(this.hap.Service.TemperatureSensor)
|
|
57
|
+
|| this.accessory.addService(this.hap.Service.TemperatureSensor)), TemperatureSensorService;
|
|
58
|
+
this.TemperatureSensor.Service.setCharacteristic(this.hap.Characteristic.Name, TemperatureSensorService);
|
|
59
|
+
this.TemperatureSensor.Service
|
|
90
60
|
.getCharacteristic(this.hap.Characteristic.CurrentTemperature)
|
|
91
61
|
.setProps({
|
|
92
62
|
unit: "celsius" /* Units['CELSIUS'] */,
|
|
@@ -96,7 +66,7 @@ export class Hub {
|
|
|
96
66
|
minStep: 0.1,
|
|
97
67
|
})
|
|
98
68
|
.onGet(() => {
|
|
99
|
-
return this.CurrentTemperature;
|
|
69
|
+
return this.TemperatureSensor.CurrentTemperature;
|
|
100
70
|
});
|
|
101
71
|
}
|
|
102
72
|
else {
|
|
@@ -105,25 +75,22 @@ export class Hub {
|
|
|
105
75
|
// Humidity Sensor Service
|
|
106
76
|
if (device.hub?.hide_humidity) {
|
|
107
77
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Humidity Sensor Service`);
|
|
108
|
-
this.
|
|
109
|
-
accessory.removeService(this.
|
|
78
|
+
this.HumiditySensor.Service = this.accessory.getService(this.hap.Service.HumiditySensor);
|
|
79
|
+
accessory.removeService(this.HumiditySensor.Service);
|
|
110
80
|
}
|
|
111
|
-
else if (!this.
|
|
81
|
+
else if (!this.HumiditySensor?.Service) {
|
|
112
82
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Humidity Sensor Service`);
|
|
113
|
-
const
|
|
114
|
-
(this.
|
|
115
|
-
|| this.accessory.addService(this.hap.Service.HumiditySensor)),
|
|
116
|
-
this.
|
|
117
|
-
|
|
118
|
-
this.humidityService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Humidity Sensor`);
|
|
119
|
-
}
|
|
120
|
-
this.humidityService
|
|
83
|
+
const HumiditySensorService = `${accessory.displayName} Humidity Sensor`;
|
|
84
|
+
(this.HumiditySensor.Service = this.accessory.getService(this.hap.Service.HumiditySensor)
|
|
85
|
+
|| this.accessory.addService(this.hap.Service.HumiditySensor)), HumiditySensorService;
|
|
86
|
+
this.HumiditySensor.Service.setCharacteristic(this.hap.Characteristic.Name, HumiditySensorService);
|
|
87
|
+
this.HumiditySensor.Service
|
|
121
88
|
.getCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity)
|
|
122
89
|
.setProps({
|
|
123
90
|
minStep: 0.1,
|
|
124
91
|
})
|
|
125
92
|
.onGet(() => {
|
|
126
|
-
return this.CurrentRelativeHumidity;
|
|
93
|
+
return this.HumiditySensor.CurrentRelativeHumidity;
|
|
127
94
|
});
|
|
128
95
|
}
|
|
129
96
|
else {
|
|
@@ -132,16 +99,15 @@ export class Hub {
|
|
|
132
99
|
// Light Sensor Service
|
|
133
100
|
if (device.hub?.hide_lightsensor) {
|
|
134
101
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
|
|
135
|
-
this.
|
|
136
|
-
accessory.removeService(this.
|
|
102
|
+
this.LightSensor.Service = this.accessory.getService(this.hap.Service.LightSensor);
|
|
103
|
+
accessory.removeService(this.LightSensor.Service);
|
|
137
104
|
}
|
|
138
|
-
else if (!this.
|
|
105
|
+
else if (!this.LightSensor?.Service) {
|
|
139
106
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
|
|
140
|
-
const
|
|
141
|
-
(this.
|
|
142
|
-
|| this.accessory.addService(this.hap.Service.LightSensor)),
|
|
143
|
-
this.
|
|
144
|
-
this.lightSensorService.setCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Light Sensor`);
|
|
107
|
+
const LightSensorService = `${accessory.displayName} Light Sensor`;
|
|
108
|
+
(this.LightSensor.Service = this.accessory.getService(this.hap.Service.LightSensor)
|
|
109
|
+
|| this.accessory.addService(this.hap.Service.LightSensor)), LightSensorService;
|
|
110
|
+
this.LightSensor.Service.setCharacteristic(this.hap.Characteristic.Name, LightSensorService);
|
|
145
111
|
}
|
|
146
112
|
else {
|
|
147
113
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Light Sensor Service Not Added`);
|
|
@@ -150,112 +116,41 @@ export class Hub {
|
|
|
150
116
|
this.updateHomeKitCharacteristics();
|
|
151
117
|
// Start an update interval
|
|
152
118
|
interval(this.deviceRefreshRate * 1000)
|
|
119
|
+
.pipe(skipWhile(() => this.hubUpdateInProgress))
|
|
153
120
|
.subscribe(async () => {
|
|
154
121
|
await this.refreshStatus();
|
|
155
122
|
});
|
|
156
123
|
//regisiter webhook event handler
|
|
157
|
-
if (
|
|
158
|
-
this.
|
|
124
|
+
if (device.webhook) {
|
|
125
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
|
|
159
126
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
160
127
|
try {
|
|
161
128
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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();
|
|
129
|
+
const { temperature, humidity, lightLevel } = context;
|
|
130
|
+
const { CurrentTemperature } = this.TemperatureSensor || { CurrentTemperature: undefined };
|
|
131
|
+
const { CurrentAmbientLightLevel } = this.LightSensor || { CurrentAmbientLightLevel: undefined };
|
|
132
|
+
const { CurrentRelativeHumidity } = this.HumiditySensor || { CurrentRelativeHumidity: undefined };
|
|
133
|
+
if (context.scale !== 'CELCIUS' && device.hub?.convertUnitTo === undefined) {
|
|
134
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} received a non-CELCIUS Webhook scale: `
|
|
135
|
+
+ `${context.scale}, Use the *convertUnitsTo* config under Hub settings, if displaying incorrectly in HomeKit.`);
|
|
136
|
+
}
|
|
137
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
138
|
+
'(scale, temperature, humidity, lightLevel) = ' +
|
|
139
|
+
`Webhook:(${context.scale}, ${convertUnits(temperature, context.scale, device.hub?.convertUnitTo)}, ${humidity}, ${lightLevel}), ` +
|
|
140
|
+
`current:(${CurrentTemperature}, ${CurrentRelativeHumidity}, ${CurrentAmbientLightLevel})`);
|
|
141
|
+
if (!this.device.hub?.hide_humidity) {
|
|
142
|
+
this.HumiditySensor.CurrentRelativeHumidity = humidity;
|
|
143
|
+
}
|
|
144
|
+
if (!this.device.hub?.hide_temperature) {
|
|
145
|
+
this.TemperatureSensor.CurrentTemperature = convertUnits(temperature, context.scale, device.hub?.convertUnitTo);
|
|
146
|
+
}
|
|
147
|
+
if (!this.device.hub?.hide_lightsensor) {
|
|
148
|
+
const set_minLux = await this.minLux();
|
|
149
|
+
const set_maxLux = await this.maxLux();
|
|
150
|
+
const spaceBetweenLevels = 19;
|
|
151
|
+
await this.getLightLevel(lightLevel, set_minLux, set_maxLux, spaceBetweenLevels);
|
|
258
152
|
}
|
|
153
|
+
this.updateHomeKitCharacteristics();
|
|
259
154
|
}
|
|
260
155
|
catch (e) {
|
|
261
156
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
@@ -264,132 +159,40 @@ export class Hub {
|
|
|
264
159
|
};
|
|
265
160
|
}
|
|
266
161
|
}
|
|
267
|
-
|
|
268
|
-
* Parse the device status from the SwitchBot api
|
|
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
|
-
}
|
|
281
|
-
}
|
|
282
|
-
async openAPIparseStatus() {
|
|
162
|
+
async openAPIparseStatus(deviceStatus) {
|
|
283
163
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
284
164
|
// CurrentRelativeHumidity
|
|
285
165
|
if (!this.device.hub?.hide_humidity) {
|
|
286
|
-
this.CurrentRelativeHumidity = Number(
|
|
287
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
|
|
166
|
+
this.HumiditySensor.CurrentRelativeHumidity = Number(deviceStatus.body.humidity);
|
|
167
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`);
|
|
288
168
|
}
|
|
289
169
|
// CurrentTemperature
|
|
290
170
|
if (!this.device.hub?.hide_temperature) {
|
|
291
|
-
this.CurrentTemperature = Number(
|
|
292
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
|
|
171
|
+
this.TemperatureSensor.CurrentTemperature = Number(deviceStatus.body.temperature);
|
|
172
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.TemperatureSensor.CurrentTemperature}°c`);
|
|
293
173
|
}
|
|
294
174
|
// Brightness
|
|
295
175
|
if (!this.device.hub?.hide_lightsensor) {
|
|
296
176
|
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}`);
|
|
177
|
+
const set_minLux = await this.minLux();
|
|
178
|
+
const set_maxLux = await this.maxLux();
|
|
179
|
+
const spaceBetweenLevels = 19;
|
|
180
|
+
const lightLevel = deviceStatus.body.lightLevel;
|
|
181
|
+
await this.getLightLevel(lightLevel, set_minLux, set_maxLux, spaceBetweenLevels);
|
|
182
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${deviceStatus.body.lightLevel},` +
|
|
183
|
+
` CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
385
184
|
}
|
|
386
185
|
if (!this.device.hub?.hide_lightsensor) {
|
|
387
|
-
this.
|
|
186
|
+
this.LightSensor.Service.setCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.LightSensor.CurrentAmbientLightLevel);
|
|
388
187
|
}
|
|
389
188
|
}
|
|
390
189
|
// FirmwareRevision
|
|
391
|
-
this.FirmwareRevision =
|
|
392
|
-
this.accessory
|
|
190
|
+
this.accessory.context.FirmwareRevision = deviceStatus.body.version;
|
|
191
|
+
this.accessory
|
|
192
|
+
.getService(this.hap.Service.AccessoryInformation)
|
|
193
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, this.accessory.context.FirmwareRevision)
|
|
194
|
+
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
195
|
+
.updateValue(this.accessory.context.FirmwareRevision);
|
|
393
196
|
}
|
|
394
197
|
async refreshStatus() {
|
|
395
198
|
if (this.BLE) {
|
|
@@ -406,7 +209,7 @@ export class Hub {
|
|
|
406
209
|
async openAPIRefreshStatus() {
|
|
407
210
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
408
211
|
try {
|
|
409
|
-
const { body, statusCode } = await
|
|
212
|
+
const { body, statusCode } = await this.platform.retryRequest(this.deviceMaxRetries, this.deviceDelayBetweenRetries, `${Devices}/${this.device.deviceId}/status`, {
|
|
410
213
|
headers: this.platform.generateHeaders(),
|
|
411
214
|
});
|
|
412
215
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
@@ -414,13 +217,9 @@ export class Hub {
|
|
|
414
217
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
415
218
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
416
219
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
417
|
-
this.
|
|
220
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
418
221
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
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();
|
|
222
|
+
this.openAPIparseStatus(deviceStatus);
|
|
424
223
|
this.updateHomeKitCharacteristics();
|
|
425
224
|
}
|
|
426
225
|
else {
|
|
@@ -442,352 +241,199 @@ export class Hub {
|
|
|
442
241
|
const entry = { time: Math.round(new Date().valueOf() / 1000) };
|
|
443
242
|
// CurrentRelativeHumidity
|
|
444
243
|
if (!this.device.hub?.hide_humidity) {
|
|
445
|
-
if (this.CurrentRelativeHumidity === undefined) {
|
|
446
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
244
|
+
if (this.HumiditySensor.CurrentRelativeHumidity === undefined) {
|
|
245
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
246
|
+
+ ` CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}`);
|
|
447
247
|
}
|
|
448
248
|
else {
|
|
449
249
|
if (this.device.mqttURL) {
|
|
450
|
-
mqttmessage.push(`"humidity": ${this.CurrentRelativeHumidity}`);
|
|
250
|
+
mqttmessage.push(`"humidity": ${this.HumiditySensor.CurrentRelativeHumidity}`);
|
|
451
251
|
}
|
|
452
252
|
if (this.device.history) {
|
|
453
|
-
entry['humidity'] = this.CurrentRelativeHumidity;
|
|
253
|
+
entry['humidity'] = this.HumiditySensor.CurrentRelativeHumidity;
|
|
454
254
|
}
|
|
455
|
-
this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
|
|
456
|
-
this.
|
|
255
|
+
this.accessory.context.CurrentRelativeHumidity = this.HumiditySensor.CurrentRelativeHumidity;
|
|
256
|
+
this.HumiditySensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, this.HumiditySensor.CurrentRelativeHumidity);
|
|
457
257
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
458
|
-
+ `updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
258
|
+
+ `updateCharacteristic CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}`);
|
|
459
259
|
}
|
|
460
260
|
}
|
|
461
261
|
// CurrentTemperature
|
|
462
262
|
if (!this.device.hub?.hide_temperature) {
|
|
463
|
-
if (this.CurrentTemperature === undefined) {
|
|
464
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
263
|
+
if (this.TemperatureSensor.CurrentTemperature === undefined) {
|
|
264
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
465
265
|
}
|
|
466
266
|
else {
|
|
467
267
|
if (this.device.mqttURL) {
|
|
468
|
-
mqttmessage.push(`"temperature": ${this.CurrentTemperature}`);
|
|
268
|
+
mqttmessage.push(`"temperature": ${this.TemperatureSensor.CurrentTemperature}`);
|
|
469
269
|
}
|
|
470
270
|
if (this.device.history) {
|
|
471
|
-
entry['temp'] = this.CurrentTemperature;
|
|
271
|
+
entry['temp'] = this.TemperatureSensor.CurrentTemperature;
|
|
472
272
|
}
|
|
473
|
-
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
474
|
-
this.
|
|
475
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
273
|
+
this.accessory.context.CurrentTemperature = this.TemperatureSensor.CurrentTemperature;
|
|
274
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor.CurrentTemperature);
|
|
275
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
276
|
+
+ ` CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
476
277
|
}
|
|
477
278
|
}
|
|
478
279
|
// CurrentAmbientLightLevel
|
|
479
280
|
if (!this.device.hub?.hide_lightsensor) {
|
|
480
|
-
if (this.CurrentAmbientLightLevel === undefined) {
|
|
481
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
281
|
+
if (this.LightSensor.CurrentAmbientLightLevel === undefined) {
|
|
282
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
283
|
+
+ ` CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
482
284
|
}
|
|
483
285
|
else {
|
|
484
286
|
if (this.device.mqttURL) {
|
|
485
|
-
mqttmessage.push(`"light": ${this.CurrentAmbientLightLevel}`);
|
|
287
|
+
mqttmessage.push(`"light": ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
486
288
|
}
|
|
487
289
|
if (this.device.history) {
|
|
488
|
-
entry['lux'] = this.CurrentAmbientLightLevel;
|
|
290
|
+
entry['lux'] = this.LightSensor.CurrentAmbientLightLevel;
|
|
489
291
|
}
|
|
490
|
-
this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
|
|
491
|
-
this.
|
|
292
|
+
this.accessory.context.CurrentAmbientLightLevel = this.LightSensor.CurrentAmbientLightLevel;
|
|
293
|
+
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.LightSensor.CurrentAmbientLightLevel);
|
|
492
294
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
493
|
-
+ `updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
295
|
+
+ `updateCharacteristic CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
494
296
|
}
|
|
495
297
|
}
|
|
496
298
|
// MQTT
|
|
497
299
|
if (this.device.mqttURL) {
|
|
498
300
|
this.mqttPublish(`{${mqttmessage.join(',')}}`);
|
|
499
301
|
}
|
|
500
|
-
if (Number(this.CurrentRelativeHumidity) > 0) {
|
|
302
|
+
if (Number(this.HumiditySensor.CurrentRelativeHumidity) > 0) {
|
|
501
303
|
// reject unreliable data
|
|
502
304
|
if (this.device.history) {
|
|
503
305
|
this.historyService?.addEntry(entry);
|
|
504
306
|
}
|
|
505
307
|
}
|
|
506
308
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
mqttPublish(message) {
|
|
512
|
-
const mac = this.device.deviceId
|
|
513
|
-
?.toLowerCase()
|
|
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)}`);
|
|
519
|
-
}
|
|
520
|
-
/*
|
|
521
|
-
* Setup MQTT hadler if URL is specified.
|
|
522
|
-
*/
|
|
523
|
-
async setupMqtt(device) {
|
|
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
|
-
});
|
|
309
|
+
async offlineOff() {
|
|
310
|
+
if (this.device.offline) {
|
|
311
|
+
if (!this.device.hub?.hide_temperature) {
|
|
312
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.accessory.context.CurrentTemperature);
|
|
532
313
|
}
|
|
533
|
-
|
|
534
|
-
this.
|
|
535
|
-
|
|
314
|
+
if (!this.device.hub?.hide_humidity) {
|
|
315
|
+
this.HumiditySensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, this.accessory.context.CurrentRelativeHumidity);
|
|
316
|
+
}
|
|
317
|
+
if (!this.device.hub?.hide_lightsensor) {
|
|
318
|
+
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.accessory.context.CurrentAmbientLightLevel);
|
|
536
319
|
}
|
|
537
320
|
}
|
|
538
321
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
.
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
322
|
+
async apiError(e) {
|
|
323
|
+
if (!this.device.hub?.hide_temperature) {
|
|
324
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
|
|
325
|
+
}
|
|
326
|
+
if (!this.device.hub?.hide_humidity) {
|
|
327
|
+
this.HumiditySensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
|
|
328
|
+
}
|
|
329
|
+
if (!this.device.hub?.hide_lightsensor) {
|
|
330
|
+
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
async minLux() {
|
|
334
|
+
let set_minLux;
|
|
335
|
+
if (this.device.curtain?.set_minLux) {
|
|
336
|
+
set_minLux = this.device.curtain?.set_minLux;
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
set_minLux = 1;
|
|
340
|
+
}
|
|
341
|
+
return set_minLux;
|
|
554
342
|
}
|
|
555
|
-
async
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
343
|
+
async maxLux() {
|
|
344
|
+
let set_maxLux;
|
|
345
|
+
if (this.device.curtain?.set_maxLux) {
|
|
346
|
+
set_maxLux = this.device.curtain?.set_maxLux;
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
set_maxLux = 6001;
|
|
350
|
+
}
|
|
351
|
+
return set_maxLux;
|
|
352
|
+
}
|
|
353
|
+
async getLightLevel(lightLevel, set_minLux, set_maxLux, spaceBetweenLevels) {
|
|
354
|
+
switch (lightLevel) {
|
|
355
|
+
case 1:
|
|
356
|
+
this.LightSensor.CurrentAmbientLightLevel = set_minLux;
|
|
357
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
358
|
+
break;
|
|
359
|
+
case 2:
|
|
360
|
+
this.LightSensor.CurrentAmbientLightLevel = (set_maxLux - set_minLux) / spaceBetweenLevels;
|
|
361
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel},` +
|
|
362
|
+
` Calculation: ${(set_maxLux - set_minLux) / spaceBetweenLevels}`);
|
|
559
363
|
break;
|
|
560
|
-
case
|
|
561
|
-
this.
|
|
364
|
+
case 3:
|
|
365
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 2;
|
|
366
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
562
367
|
break;
|
|
563
|
-
case
|
|
564
|
-
this.
|
|
368
|
+
case 4:
|
|
369
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 3;
|
|
370
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
565
371
|
break;
|
|
566
|
-
case
|
|
567
|
-
this.
|
|
568
|
-
this.
|
|
372
|
+
case 5:
|
|
373
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 4;
|
|
374
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
569
375
|
break;
|
|
570
|
-
case
|
|
571
|
-
this.
|
|
572
|
-
|
|
573
|
-
this.offlineOff();
|
|
376
|
+
case 6:
|
|
377
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 5;
|
|
378
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
574
379
|
break;
|
|
575
|
-
case
|
|
576
|
-
this.
|
|
577
|
-
|
|
380
|
+
case 7:
|
|
381
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 6;
|
|
382
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
578
383
|
break;
|
|
579
|
-
case
|
|
580
|
-
this.
|
|
384
|
+
case 8:
|
|
385
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 7;
|
|
386
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
581
387
|
break;
|
|
582
|
-
case
|
|
583
|
-
this.
|
|
388
|
+
case 9:
|
|
389
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 8;
|
|
390
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
584
391
|
break;
|
|
585
|
-
case
|
|
586
|
-
this.
|
|
587
|
-
|
|
392
|
+
case 10:
|
|
393
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 9;
|
|
394
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
588
395
|
break;
|
|
589
|
-
case
|
|
590
|
-
this.
|
|
591
|
-
|
|
396
|
+
case 11:
|
|
397
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 10;
|
|
398
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
592
399
|
break;
|
|
593
|
-
case
|
|
594
|
-
this.
|
|
595
|
-
|
|
400
|
+
case 12:
|
|
401
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 11;
|
|
402
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
596
403
|
break;
|
|
597
|
-
case
|
|
598
|
-
this.
|
|
599
|
-
|
|
404
|
+
case 13:
|
|
405
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 12;
|
|
406
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
600
407
|
break;
|
|
601
|
-
case
|
|
602
|
-
this.
|
|
603
|
-
|
|
408
|
+
case 14:
|
|
409
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 13;
|
|
410
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
604
411
|
break;
|
|
605
|
-
case
|
|
606
|
-
this.
|
|
607
|
-
|
|
412
|
+
case 15:
|
|
413
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 14;
|
|
414
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
608
415
|
break;
|
|
609
|
-
case
|
|
610
|
-
this.
|
|
611
|
-
|
|
416
|
+
case 16:
|
|
417
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 15;
|
|
418
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
612
419
|
break;
|
|
613
|
-
case
|
|
614
|
-
this.
|
|
615
|
-
|
|
420
|
+
case 17:
|
|
421
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 16;
|
|
422
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
616
423
|
break;
|
|
617
|
-
case
|
|
618
|
-
this.
|
|
619
|
-
|
|
424
|
+
case 18:
|
|
425
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 17;
|
|
426
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
620
427
|
break;
|
|
428
|
+
case 19:
|
|
429
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 18;
|
|
430
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
431
|
+
break;
|
|
432
|
+
case 20:
|
|
621
433
|
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);
|
|
434
|
+
this.LightSensor.CurrentAmbientLightLevel = set_maxLux;
|
|
435
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${lightLevel}`);
|
|
638
436
|
}
|
|
639
|
-
if (!this.device.hub?.hide_lightsensor) {
|
|
640
|
-
this.lightSensorService?.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e);
|
|
641
|
-
}
|
|
642
|
-
}
|
|
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
437
|
}
|
|
792
438
|
}
|
|
793
439
|
//# sourceMappingURL=hub.js.map
|