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