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