@switchbot/homebridge-switchbot 2.0.0-beta.2 → 2.0.0-beta.20
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 +8 -1
- package/README.md +1 -2
- package/config.schema.json +75 -20
- package/dist/device/bot.d.ts +32 -28
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +646 -648
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +34 -19
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +429 -304
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +16 -7
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +288 -230
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +21 -16
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +519 -489
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts +22 -18
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +415 -360
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +22 -8
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +253 -147
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +21 -16
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +325 -255
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +23 -12
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +346 -208
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +17 -8
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +261 -209
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +24 -16
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +267 -242
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +51 -16
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +527 -185
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +7 -12
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +261 -230
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +3 -3
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +137 -104
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +9 -8
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +116 -86
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +8 -7
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +143 -109
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +9 -8
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +120 -103
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +9 -8
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +128 -98
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +10 -9
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +126 -93
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +7 -10
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +115 -89
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +6 -9
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +115 -89
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +3 -5
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +203 -200
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +15 -11
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +12 -10
- package/src/device/bot.ts +641 -657
- package/src/device/colorbulb.ts +440 -339
- package/src/device/contact.ts +289 -233
- package/src/device/curtain.ts +523 -503
- package/src/device/humidifier.ts +421 -396
- package/src/device/lock.ts +257 -147
- package/src/device/meter.ts +335 -268
- package/src/device/meterplus.ts +354 -213
- package/src/device/motion.ts +264 -213
- package/src/device/plug.ts +270 -251
- package/src/device/striplight.ts +552 -207
- package/src/irdevice/airconditioner.ts +263 -241
- package/src/irdevice/airpurifier.ts +132 -103
- package/src/irdevice/camera.ts +112 -85
- package/src/irdevice/fan.ts +138 -106
- package/src/irdevice/light.ts +116 -103
- package/src/irdevice/other.ts +124 -97
- package/src/irdevice/tv.ts +123 -93
- package/src/irdevice/vacuumcleaner.ts +112 -89
- package/src/irdevice/waterheater.ts +111 -89
- package/src/platform.ts +195 -216
- package/src/settings.ts +15 -11
package/dist/device/contact.js
CHANGED
|
@@ -8,6 +8,7 @@ const https_1 = __importDefault(require("https"));
|
|
|
8
8
|
const crypto_1 = __importDefault(require("crypto"));
|
|
9
9
|
const rxjs_1 = require("rxjs");
|
|
10
10
|
const operators_1 = require("rxjs/operators");
|
|
11
|
+
const super_stringify_1 = __importDefault(require("super-stringify"));
|
|
11
12
|
const settings_1 = require("../settings");
|
|
12
13
|
/**
|
|
13
14
|
* Platform Accessory
|
|
@@ -19,12 +20,15 @@ class Contact {
|
|
|
19
20
|
this.platform = platform;
|
|
20
21
|
this.accessory = accessory;
|
|
21
22
|
this.device = device;
|
|
23
|
+
// Connection
|
|
24
|
+
this.BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'Both');
|
|
25
|
+
this.OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'Both');
|
|
22
26
|
// default placeholders
|
|
23
27
|
this.logs(device);
|
|
24
28
|
this.scan(device);
|
|
25
29
|
this.refreshRate(device);
|
|
26
30
|
this.config(device);
|
|
27
|
-
this.
|
|
31
|
+
this.context();
|
|
28
32
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
29
33
|
this.doContactUpdate = new rxjs_1.Subject();
|
|
30
34
|
this.contactUbpdateInProgress = false;
|
|
@@ -54,50 +58,50 @@ class Contact {
|
|
|
54
58
|
// see https://developers.homebridge.io/#/service/ContactSensor
|
|
55
59
|
// Motion Sensor Service
|
|
56
60
|
if (device.contact?.hide_motionsensor) {
|
|
57
|
-
this.debugLog(
|
|
61
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Motion Sensor Service`);
|
|
58
62
|
this.motionService = this.accessory.getService(this.platform.Service.MotionSensor);
|
|
59
63
|
accessory.removeService(this.motionService);
|
|
60
64
|
}
|
|
61
65
|
else if (!this.motionService) {
|
|
62
|
-
this.debugLog(
|
|
66
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Motion Sensor Service`);
|
|
63
67
|
(this.motionService =
|
|
64
68
|
this.accessory.getService(this.platform.Service.MotionSensor) || this.accessory.addService(this.platform.Service.MotionSensor)),
|
|
65
69
|
`${accessory.displayName} Motion Sensor`;
|
|
66
70
|
this.motionService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Motion Sensor`);
|
|
67
71
|
}
|
|
68
72
|
else {
|
|
69
|
-
this.debugLog(
|
|
73
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Motion Sensor Service Not Added`);
|
|
70
74
|
}
|
|
71
75
|
// Light Sensor Service
|
|
72
76
|
if (device.contact?.hide_lightsensor) {
|
|
73
|
-
this.debugLog(
|
|
77
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
|
|
74
78
|
this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor);
|
|
75
79
|
accessory.removeService(this.lightSensorService);
|
|
76
80
|
}
|
|
77
81
|
else if (!this.lightSensorService) {
|
|
78
|
-
this.debugLog(
|
|
82
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
|
|
79
83
|
(this.lightSensorService =
|
|
80
84
|
this.accessory.getService(this.platform.Service.LightSensor) || this.accessory.addService(this.platform.Service.LightSensor)),
|
|
81
85
|
`${accessory.displayName} Light Sensor`;
|
|
82
86
|
this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
|
|
83
87
|
}
|
|
84
88
|
else {
|
|
85
|
-
this.debugLog(
|
|
89
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Light Sensor Service Not Added`);
|
|
86
90
|
}
|
|
87
91
|
// Battery Service
|
|
88
|
-
if (!
|
|
89
|
-
this.debugLog(
|
|
92
|
+
if (!this.BLE) {
|
|
93
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Battery Service`);
|
|
90
94
|
this.batteryService = this.accessory.getService(this.platform.Service.Battery);
|
|
91
95
|
accessory.removeService(this.batteryService);
|
|
92
96
|
}
|
|
93
|
-
else if (
|
|
94
|
-
this.debugLog(
|
|
97
|
+
else if (this.BLE && !this.batteryService) {
|
|
98
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
|
|
95
99
|
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
|
|
96
100
|
`${accessory.displayName} Battery`;
|
|
97
101
|
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
98
102
|
}
|
|
99
103
|
else {
|
|
100
|
-
this.debugLog(
|
|
104
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
|
|
101
105
|
}
|
|
102
106
|
// Retrieve initial values and updateHomekit
|
|
103
107
|
this.updateHomeKitCharacteristics();
|
|
@@ -112,15 +116,20 @@ class Contact {
|
|
|
112
116
|
* Parse the device status from the SwitchBot api
|
|
113
117
|
*/
|
|
114
118
|
async parseStatus() {
|
|
115
|
-
if (this.
|
|
119
|
+
if (this.BLE && !this.SwitchToOpenAPI) {
|
|
120
|
+
await this.BLEparseStatus();
|
|
121
|
+
}
|
|
122
|
+
else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
123
|
+
this.SwitchToOpenAPI = false;
|
|
116
124
|
await this.openAPIparseStatus();
|
|
117
125
|
}
|
|
118
126
|
else {
|
|
119
|
-
|
|
127
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
128
|
+
+ ` ${this.device.connectionType}, parseStatus will not happen.`);
|
|
120
129
|
}
|
|
121
130
|
}
|
|
122
131
|
async BLEparseStatus() {
|
|
123
|
-
this.debugLog(
|
|
132
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
124
133
|
// Door State
|
|
125
134
|
switch (this.doorState) {
|
|
126
135
|
case 'open':
|
|
@@ -132,12 +141,12 @@ class Contact {
|
|
|
132
141
|
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
133
142
|
break;
|
|
134
143
|
default:
|
|
135
|
-
this.errorLog(
|
|
144
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} timeout no closed, doorstate: ${this.doorState}`);
|
|
136
145
|
}
|
|
137
146
|
// Movement
|
|
138
147
|
if (!this.device.contact?.hide_motionsensor) {
|
|
139
148
|
this.MotionDetected = Boolean(this.movement);
|
|
140
|
-
this.debugLog(
|
|
149
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
141
150
|
}
|
|
142
151
|
// Light Level
|
|
143
152
|
if (!this.device.contact?.hide_lightsensor) {
|
|
@@ -151,7 +160,7 @@ class Contact {
|
|
|
151
160
|
default:
|
|
152
161
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
153
162
|
}
|
|
154
|
-
this.debugLog(
|
|
163
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
|
|
155
164
|
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
156
165
|
}
|
|
157
166
|
// Battery
|
|
@@ -165,60 +174,60 @@ class Contact {
|
|
|
165
174
|
else {
|
|
166
175
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
167
176
|
}
|
|
168
|
-
this.debugLog(
|
|
177
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, `
|
|
178
|
+
+ `StatusLowBattery: ${this.StatusLowBattery}`);
|
|
169
179
|
}
|
|
170
180
|
async openAPIparseStatus() {
|
|
171
|
-
|
|
172
|
-
|
|
181
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
182
|
+
// Contact State
|
|
183
|
+
if (this.openState === 'open') {
|
|
184
|
+
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
|
|
185
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
173
186
|
}
|
|
174
|
-
if (this.
|
|
175
|
-
this.
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
switch (this.brightness) {
|
|
198
|
-
case 'dim':
|
|
199
|
-
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
200
|
-
break;
|
|
201
|
-
case 'bright':
|
|
202
|
-
default:
|
|
203
|
-
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
204
|
-
}
|
|
205
|
-
this.debugLog(`Contact Sensor: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
187
|
+
else if (this.openState === 'close') {
|
|
188
|
+
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
189
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openState: ${this.openState}`);
|
|
193
|
+
}
|
|
194
|
+
// Motion State
|
|
195
|
+
if (!this.device.contact?.hide_motionsensor) {
|
|
196
|
+
this.MotionDetected = this.moveDetected;
|
|
197
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
198
|
+
}
|
|
199
|
+
// Light Level
|
|
200
|
+
if (!this.device.contact?.hide_lightsensor) {
|
|
201
|
+
this.set_minLux = this.minLux();
|
|
202
|
+
this.set_maxLux = this.maxLux();
|
|
203
|
+
switch (this.brightness) {
|
|
204
|
+
case 'dim':
|
|
205
|
+
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
206
|
+
break;
|
|
207
|
+
case 'bright':
|
|
208
|
+
default:
|
|
209
|
+
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
206
210
|
}
|
|
211
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
207
212
|
}
|
|
208
213
|
}
|
|
209
214
|
/**
|
|
210
215
|
* Asks the SwitchBot API for the latest device information
|
|
211
216
|
*/
|
|
212
217
|
async refreshStatus() {
|
|
213
|
-
if (this.
|
|
218
|
+
if (this.BLE) {
|
|
214
219
|
await this.BLERefreshStatus();
|
|
215
220
|
}
|
|
216
|
-
else {
|
|
221
|
+
else if (this.OpenAPI) {
|
|
217
222
|
await this.openAPIRefreshStatus();
|
|
218
223
|
}
|
|
224
|
+
else {
|
|
225
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
226
|
+
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
227
|
+
}
|
|
219
228
|
}
|
|
220
229
|
async BLERefreshStatus() {
|
|
221
|
-
this.debugLog(
|
|
230
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
|
|
222
231
|
const switchbot = await this.platform.connectBLE();
|
|
223
232
|
// Convert to BLE Address
|
|
224
233
|
this.device.bleMac =
|
|
@@ -227,7 +236,7 @@ class Contact {
|
|
|
227
236
|
.deviceId.match(/.{1,2}/g)
|
|
228
237
|
.join(':')
|
|
229
238
|
.toLowerCase();
|
|
230
|
-
this.debugLog(
|
|
239
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
231
240
|
this.getCustomBLEAddress(switchbot);
|
|
232
241
|
// Start to monitor advertisement packets
|
|
233
242
|
if (switchbot !== false) {
|
|
@@ -243,24 +252,24 @@ class Contact {
|
|
|
243
252
|
if (this.deviceLogging.includes('debug')) {
|
|
244
253
|
this.infoLog(this.address);
|
|
245
254
|
this.infoLog(this.device.bleMac);
|
|
246
|
-
this.infoLog(
|
|
247
|
-
this.infoLog(
|
|
255
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
|
|
256
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
|
|
248
257
|
}
|
|
249
258
|
this.serviceData = ad.serviceData;
|
|
250
259
|
this.movement = ad.serviceData.movement;
|
|
251
260
|
this.doorState = ad.serviceData.doorState;
|
|
252
261
|
this.lightLevel = ad.serviceData.lightLevel;
|
|
253
262
|
this.battery = ad.serviceData.battery;
|
|
254
|
-
this.debugLog(
|
|
255
|
-
this.debugLog(
|
|
263
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${(0, super_stringify_1.default)(ad.serviceData)}`);
|
|
264
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, doorState: ` +
|
|
256
265
|
`${ad.serviceData.doorState}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`);
|
|
257
266
|
if (this.serviceData) {
|
|
258
267
|
this.connected = true;
|
|
259
|
-
this.debugLog(
|
|
268
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
260
269
|
}
|
|
261
270
|
else {
|
|
262
271
|
this.connected = false;
|
|
263
|
-
this.debugLog(
|
|
272
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
264
273
|
}
|
|
265
274
|
};
|
|
266
275
|
// Wait 2 seconds
|
|
@@ -278,106 +287,69 @@ class Contact {
|
|
|
278
287
|
}
|
|
279
288
|
})
|
|
280
289
|
.catch(async (e) => {
|
|
281
|
-
this.errorLog(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
282
|
-
if (this.deviceLogging.includes('debug')) {
|
|
283
|
-
this.errorLog(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` +
|
|
284
|
-
` Error Message: ${JSON.stringify(e.message)}`);
|
|
285
|
-
}
|
|
286
|
-
if (this.platform.config.credentials?.token) {
|
|
287
|
-
this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
288
|
-
this.SwitchToOpenAPI = true;
|
|
289
|
-
await this.openAPIRefreshStatus();
|
|
290
|
-
}
|
|
291
290
|
this.apiError(e);
|
|
291
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
|
|
292
|
+
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
293
|
+
await this.BLEconnection(switchbot);
|
|
292
294
|
});
|
|
293
295
|
}
|
|
294
296
|
else {
|
|
295
297
|
await this.BLEconnection(switchbot);
|
|
296
298
|
}
|
|
297
299
|
}
|
|
298
|
-
async getCustomBLEAddress(switchbot) {
|
|
299
|
-
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
300
|
-
(async () => {
|
|
301
|
-
// Start to monitor advertisement packets
|
|
302
|
-
await switchbot.startScan({
|
|
303
|
-
model: 'd',
|
|
304
|
-
});
|
|
305
|
-
// Set an event handler
|
|
306
|
-
switchbot.onadvertisement = (ad) => {
|
|
307
|
-
this.warnLog(`Contact Sensor: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
308
|
-
};
|
|
309
|
-
await switchbot.wait(10000);
|
|
310
|
-
// Stop to monitor
|
|
311
|
-
switchbot.stopScan();
|
|
312
|
-
})();
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
async BLEconnection(switchbot) {
|
|
316
|
-
this.errorLog(`Contact Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
317
|
-
if (this.platform.config.credentials?.token) {
|
|
318
|
-
this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
319
|
-
this.SwitchToOpenAPI = true;
|
|
320
|
-
await this.openAPIRefreshStatus();
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
300
|
async openAPIRefreshStatus() {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
this.debugLog(`Contact Sensor: ${this.accessory.displayName} d: ${d}`);
|
|
352
|
-
});
|
|
353
|
-
res.on('end', () => {
|
|
354
|
-
try {
|
|
355
|
-
this.deviceStatus = JSON.parse(rawData);
|
|
356
|
-
this.debugLog(`Contact Sensor: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
357
|
-
this.openState = this.deviceStatus.body.openState;
|
|
358
|
-
this.moveDetected = this.deviceStatus.body.moveDetected;
|
|
359
|
-
this.brightness = this.deviceStatus.body.brightness;
|
|
360
|
-
this.parseStatus();
|
|
361
|
-
this.updateHomeKitCharacteristics();
|
|
362
|
-
}
|
|
363
|
-
catch (e) {
|
|
364
|
-
this.errorLog(`Contact Sensor: ${this.accessory.displayName} error message: ${e.message}`);
|
|
365
|
-
}
|
|
366
|
-
});
|
|
301
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
302
|
+
try {
|
|
303
|
+
const t = Date.now();
|
|
304
|
+
const nonce = 'requestID';
|
|
305
|
+
const data = this.platform.config.credentials?.token + t + nonce;
|
|
306
|
+
const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
307
|
+
const sign = signTerm.toString('base64');
|
|
308
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
309
|
+
const options = {
|
|
310
|
+
hostname: settings_1.HostDomain,
|
|
311
|
+
port: 443,
|
|
312
|
+
path: `${settings_1.DevicePath}/${this.device.deviceId}/status`,
|
|
313
|
+
method: 'GET',
|
|
314
|
+
headers: {
|
|
315
|
+
Authorization: this.platform.config.credentials?.token,
|
|
316
|
+
sign: sign,
|
|
317
|
+
nonce: nonce,
|
|
318
|
+
t: t,
|
|
319
|
+
'Content-Type': 'application/json',
|
|
320
|
+
},
|
|
321
|
+
};
|
|
322
|
+
const req = https_1.default.request(options, (res) => {
|
|
323
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus statusCode: ${res.statusCode}`);
|
|
324
|
+
let rawData = '';
|
|
325
|
+
res.on('data', (d) => {
|
|
326
|
+
rawData += d;
|
|
327
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
367
328
|
});
|
|
368
|
-
|
|
369
|
-
|
|
329
|
+
res.on('end', () => {
|
|
330
|
+
try {
|
|
331
|
+
this.deviceStatus = JSON.parse(rawData);
|
|
332
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${(0, super_stringify_1.default)(this.deviceStatus)}`);
|
|
333
|
+
this.openState = this.deviceStatus.body.openState;
|
|
334
|
+
this.moveDetected = this.deviceStatus.body.moveDetected;
|
|
335
|
+
this.brightness = this.deviceStatus.body.brightness;
|
|
336
|
+
this.parseStatus();
|
|
337
|
+
this.updateHomeKitCharacteristics();
|
|
338
|
+
}
|
|
339
|
+
catch (e) {
|
|
340
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
341
|
+
}
|
|
370
342
|
});
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
343
|
+
});
|
|
344
|
+
req.on('error', (e) => {
|
|
345
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
346
|
+
});
|
|
347
|
+
req.end();
|
|
348
|
+
}
|
|
349
|
+
catch (e) {
|
|
350
|
+
this.apiError(e);
|
|
351
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
|
|
352
|
+
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
381
353
|
}
|
|
382
354
|
}
|
|
383
355
|
/**
|
|
@@ -385,129 +357,170 @@ class Contact {
|
|
|
385
357
|
*/
|
|
386
358
|
async updateHomeKitCharacteristics() {
|
|
387
359
|
if (this.ContactSensorState === undefined) {
|
|
388
|
-
this.debugLog(
|
|
360
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
389
361
|
}
|
|
390
362
|
else {
|
|
363
|
+
this.accessory.context.ContactSensorState = this.ContactSensorState;
|
|
391
364
|
this.contactSensorservice.updateCharacteristic(this.platform.Characteristic.ContactSensorState, this.ContactSensorState);
|
|
392
|
-
this.debugLog(
|
|
365
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ContactSensorState: ${this.ContactSensorState}`);
|
|
393
366
|
}
|
|
394
367
|
if (!this.device.contact?.hide_motionsensor) {
|
|
395
368
|
if (this.MotionDetected === undefined) {
|
|
396
|
-
this.debugLog(
|
|
369
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
397
370
|
}
|
|
398
371
|
else {
|
|
372
|
+
this.accessory.context.MotionDetected = this.MotionDetected;
|
|
399
373
|
this.motionService?.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected);
|
|
400
|
-
this.debugLog(
|
|
374
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`);
|
|
401
375
|
}
|
|
402
376
|
}
|
|
403
377
|
if (!this.device.contact?.hide_lightsensor) {
|
|
404
378
|
if (this.CurrentAmbientLightLevel === undefined) {
|
|
405
|
-
this.debugLog(
|
|
379
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
406
380
|
}
|
|
407
381
|
else {
|
|
382
|
+
this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
|
|
408
383
|
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
|
|
409
|
-
this.debugLog(
|
|
384
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
385
|
+
+ ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
410
386
|
}
|
|
411
387
|
}
|
|
412
|
-
if (this.
|
|
388
|
+
if (this.BLE) {
|
|
413
389
|
if (this.BatteryLevel === undefined) {
|
|
414
|
-
this.debugLog(
|
|
390
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
415
391
|
}
|
|
416
392
|
else {
|
|
393
|
+
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
417
394
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
418
|
-
this.debugLog(
|
|
395
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
419
396
|
}
|
|
420
397
|
if (this.StatusLowBattery === undefined) {
|
|
421
|
-
this.debugLog(
|
|
398
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
422
399
|
}
|
|
423
400
|
else {
|
|
401
|
+
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
424
402
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
425
|
-
this.debugLog(
|
|
403
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
426
404
|
}
|
|
427
405
|
}
|
|
428
406
|
}
|
|
429
|
-
async
|
|
430
|
-
this.
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
407
|
+
async getCustomBLEAddress(switchbot) {
|
|
408
|
+
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
409
|
+
(async () => {
|
|
410
|
+
// Start to monitor advertisement packets
|
|
411
|
+
await switchbot.startScan({
|
|
412
|
+
model: 'd',
|
|
413
|
+
});
|
|
414
|
+
// Set an event handler
|
|
415
|
+
switchbot.onadvertisement = (ad) => {
|
|
416
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${(0, super_stringify_1.default)(ad, null, ' ')}`);
|
|
417
|
+
};
|
|
418
|
+
await switchbot.wait(10000);
|
|
419
|
+
// Stop to monitor
|
|
420
|
+
switchbot.stopScan();
|
|
421
|
+
})();
|
|
440
422
|
}
|
|
441
|
-
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
442
423
|
}
|
|
443
|
-
async
|
|
444
|
-
|
|
445
|
-
if (device.
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
config['ble'] = device.ble;
|
|
450
|
-
}
|
|
451
|
-
if (device.logging !== undefined) {
|
|
452
|
-
config['logging'] = device.logging;
|
|
453
|
-
}
|
|
454
|
-
if (device.refreshRate !== undefined) {
|
|
455
|
-
config['refreshRate'] = device.refreshRate;
|
|
424
|
+
async BLEconnection(switchbot) {
|
|
425
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
426
|
+
if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
|
|
427
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
428
|
+
this.SwitchToOpenAPI = true;
|
|
429
|
+
await this.openAPIRefreshStatus();
|
|
456
430
|
}
|
|
457
|
-
|
|
458
|
-
|
|
431
|
+
}
|
|
432
|
+
minLux() {
|
|
433
|
+
if (this.device.contact?.set_minLux) {
|
|
434
|
+
this.set_minLux = this.device.contact.set_minLux;
|
|
459
435
|
}
|
|
460
|
-
|
|
461
|
-
this.
|
|
436
|
+
else {
|
|
437
|
+
this.set_minLux = 1;
|
|
462
438
|
}
|
|
439
|
+
return this.set_minLux;
|
|
463
440
|
}
|
|
464
|
-
|
|
465
|
-
if (device.
|
|
466
|
-
this.
|
|
467
|
-
this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
441
|
+
maxLux() {
|
|
442
|
+
if (this.device.contact?.set_maxLux) {
|
|
443
|
+
this.set_maxLux = this.device.contact.set_maxLux;
|
|
468
444
|
}
|
|
469
|
-
else
|
|
470
|
-
this.
|
|
471
|
-
this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
445
|
+
else {
|
|
446
|
+
this.set_maxLux = 6001;
|
|
472
447
|
}
|
|
448
|
+
return this.set_maxLux;
|
|
473
449
|
}
|
|
474
450
|
async scan(device) {
|
|
475
451
|
if (device.scanDuration) {
|
|
476
452
|
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
477
|
-
if (
|
|
478
|
-
this.debugLog(
|
|
453
|
+
if (this.BLE) {
|
|
454
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
479
455
|
}
|
|
480
456
|
}
|
|
481
457
|
else {
|
|
482
458
|
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
483
|
-
if (this.
|
|
484
|
-
this.debugLog(
|
|
459
|
+
if (this.BLE) {
|
|
460
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
485
461
|
}
|
|
486
462
|
}
|
|
487
463
|
}
|
|
488
|
-
async
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
464
|
+
async statusCode({ res }) {
|
|
465
|
+
switch (res.statusCode) {
|
|
466
|
+
case 151:
|
|
467
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
468
|
+
break;
|
|
469
|
+
case 152:
|
|
470
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
|
|
471
|
+
break;
|
|
472
|
+
case 160:
|
|
473
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
|
|
474
|
+
break;
|
|
475
|
+
case 161:
|
|
476
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
|
|
477
|
+
this.offlineOff();
|
|
478
|
+
break;
|
|
479
|
+
case 171:
|
|
480
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
|
|
481
|
+
this.offlineOff();
|
|
482
|
+
break;
|
|
483
|
+
case 190:
|
|
484
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
485
|
+
` Or command: ${(0, super_stringify_1.default)(res)} format is invalid`);
|
|
486
|
+
break;
|
|
487
|
+
case 100:
|
|
488
|
+
if (this.platform.debugMode) {
|
|
489
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
|
|
490
|
+
}
|
|
491
|
+
break;
|
|
492
|
+
default:
|
|
493
|
+
if (this.platform.debugMode) {
|
|
494
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
|
|
495
|
+
}
|
|
492
496
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
497
|
+
}
|
|
498
|
+
async offlineOff() {
|
|
499
|
+
if (this.device.offline) {
|
|
500
|
+
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
501
|
+
this.contactSensorservice.getCharacteristic(this.platform.Characteristic.ContactSensorState).updateValue(this.ContactSensorState);
|
|
502
|
+
await this.updateHomeKitCharacteristics();
|
|
496
503
|
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
504
|
+
}
|
|
505
|
+
async apiError(e) {
|
|
506
|
+
this.contactSensorservice.updateCharacteristic(this.platform.Characteristic.ContactSensorState, e);
|
|
507
|
+
if (!this.device.contact?.hide_motionsensor) {
|
|
508
|
+
this.motionService?.updateCharacteristic(this.platform.Characteristic.MotionDetected, e);
|
|
500
509
|
}
|
|
501
|
-
|
|
502
|
-
this.
|
|
503
|
-
|
|
510
|
+
if (!this.device.contact?.hide_lightsensor) {
|
|
511
|
+
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
|
|
512
|
+
}
|
|
513
|
+
if (this.BLE) {
|
|
514
|
+
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
|
|
515
|
+
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
|
|
504
516
|
}
|
|
505
517
|
}
|
|
506
518
|
FirmwareRevision(accessory, device) {
|
|
507
519
|
let FirmwareRevision;
|
|
508
|
-
this.debugLog(
|
|
509
|
-
|
|
510
|
-
this.debugLog(
|
|
520
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
521
|
+
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
522
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
523
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
511
524
|
if (accessory.context.FirmwareRevision) {
|
|
512
525
|
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
513
526
|
}
|
|
@@ -519,23 +532,68 @@ class Contact {
|
|
|
519
532
|
}
|
|
520
533
|
return FirmwareRevision;
|
|
521
534
|
}
|
|
522
|
-
|
|
523
|
-
if (this.
|
|
524
|
-
this.
|
|
535
|
+
async context() {
|
|
536
|
+
if (this.MotionDetected === undefined) {
|
|
537
|
+
this.MotionDetected = false;
|
|
525
538
|
}
|
|
526
539
|
else {
|
|
527
|
-
this.
|
|
540
|
+
this.MotionDetected = this.accessory.context.MotionDetected;
|
|
541
|
+
}
|
|
542
|
+
if (this.ContactSensorState === undefined) {
|
|
543
|
+
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
this.ContactSensorState = this.accessory.context.ContactSensorState;
|
|
528
547
|
}
|
|
529
|
-
return this.set_minLux;
|
|
530
548
|
}
|
|
531
|
-
|
|
532
|
-
if (
|
|
533
|
-
this.
|
|
549
|
+
async refreshRate(device) {
|
|
550
|
+
if (device.refreshRate) {
|
|
551
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
552
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
553
|
+
}
|
|
554
|
+
else if (this.platform.config.options.refreshRate) {
|
|
555
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
556
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
async config(device) {
|
|
560
|
+
let config = {};
|
|
561
|
+
if (device.contact) {
|
|
562
|
+
config = device.contact;
|
|
563
|
+
}
|
|
564
|
+
if (device.connectionType !== undefined) {
|
|
565
|
+
config['connectionType'] = device.connectionType;
|
|
566
|
+
}
|
|
567
|
+
if (device.logging !== undefined) {
|
|
568
|
+
config['logging'] = device.logging;
|
|
569
|
+
}
|
|
570
|
+
if (device.refreshRate !== undefined) {
|
|
571
|
+
config['refreshRate'] = device.refreshRate;
|
|
572
|
+
}
|
|
573
|
+
if (device.scanDuration !== undefined) {
|
|
574
|
+
config['scanDuration'] = device.scanDuration;
|
|
575
|
+
}
|
|
576
|
+
if (Object.entries(config).length !== 0) {
|
|
577
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${(0, super_stringify_1.default)(config)}`);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
async logs(device) {
|
|
581
|
+
if (this.platform.debugMode) {
|
|
582
|
+
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
583
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
584
|
+
}
|
|
585
|
+
else if (device.logging) {
|
|
586
|
+
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
587
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
588
|
+
}
|
|
589
|
+
else if (this.platform.config.options?.logging) {
|
|
590
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
591
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
534
592
|
}
|
|
535
593
|
else {
|
|
536
|
-
this.
|
|
594
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
595
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
537
596
|
}
|
|
538
|
-
return this.set_maxLux;
|
|
539
597
|
}
|
|
540
598
|
/**
|
|
541
599
|
* Logging for Device
|