@switchbot/homebridge-switchbot 1.8.2 → 1.8.3-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +1 -1
- package/.vscode/extensions.json +5 -0
- package/.vscode/settings.json +15 -0
- package/dist/devices/bots.d.ts +34 -35
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +241 -184
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +50 -50
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +145 -131
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +27 -29
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +138 -115
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +29 -31
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +211 -176
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +33 -33
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +214 -189
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +30 -31
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +124 -100
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +25 -26
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +120 -102
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +23 -23
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +81 -63
- package/dist/devices/plugs.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -3
- package/dist/index.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +6 -6
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +105 -79
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +5 -5
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +56 -42
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +5 -5
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +31 -27
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +5 -5
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +45 -38
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +5 -5
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +37 -33
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +5 -5
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +34 -29
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +5 -5
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +91 -76
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +5 -5
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +31 -27
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +5 -5
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +31 -27
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +12 -12
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +241 -172
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +4 -4
- package/dist/settings.js.map +1 -1
- package/package.json +72 -71
- package/src/devices/bots.ts +927 -442
- package/src/devices/colorbulb.ts +473 -246
- package/src/devices/contact.ts +381 -208
- package/src/devices/curtains.ts +613 -321
- package/src/devices/humidifiers.ts +594 -323
- package/src/devices/meters.ts +331 -186
- package/src/devices/motion.ts +327 -184
- package/src/devices/plugs.ts +175 -107
- package/src/index.ts +5 -5
- package/src/irdevices/airconditioners.ts +360 -149
- package/src/irdevices/airpurifiers.ts +178 -80
- package/src/irdevices/cameras.ts +109 -51
- package/src/irdevices/fans.ts +174 -77
- package/src/irdevices/lights.ts +110 -57
- package/src/irdevices/others.ts +137 -62
- package/src/irdevices/tvs.ts +249 -124
- package/src/irdevices/vacuumcleaners.ts +112 -52
- package/src/irdevices/waterheaters.ts +115 -53
- package/src/platform.ts +768 -357
- package/src/settings.ts +17 -23
package/src/devices/contact.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import * as homebridge from "homebridge";
|
|
2
|
+
import * as rxjs from "rxjs";
|
|
3
|
+
import * as operators from "rxjs/operators";
|
|
4
|
+
import * as platform from "../platform";
|
|
5
|
+
import * as settings from "../settings";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Platform Accessory
|
|
@@ -11,33 +11,32 @@ import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusR
|
|
|
11
11
|
*/
|
|
12
12
|
export class Contact {
|
|
13
13
|
// Services
|
|
14
|
-
private service: Service;
|
|
15
|
-
private motionService?: Service;
|
|
16
|
-
private lightSensorService?: Service;
|
|
17
|
-
private batteryService?: Service;
|
|
14
|
+
private service: homebridge.Service;
|
|
15
|
+
private motionService?: homebridge.Service;
|
|
16
|
+
private lightSensorService?: homebridge.Service;
|
|
17
|
+
private batteryService?: homebridge.Service;
|
|
18
18
|
|
|
19
19
|
// Characteristic Values
|
|
20
|
-
ContactSensorState!: CharacteristicValue;
|
|
21
|
-
MotionDetected!: CharacteristicValue;
|
|
22
|
-
CurrentAmbientLightLevel!: CharacteristicValue;
|
|
23
|
-
BatteryLevel!: CharacteristicValue;
|
|
24
|
-
StatusLowBattery!: CharacteristicValue;
|
|
20
|
+
ContactSensorState!: homebridge.CharacteristicValue;
|
|
21
|
+
MotionDetected!: homebridge.CharacteristicValue;
|
|
22
|
+
CurrentAmbientLightLevel!: homebridge.CharacteristicValue;
|
|
23
|
+
BatteryLevel!: homebridge.CharacteristicValue;
|
|
24
|
+
StatusLowBattery!: homebridge.CharacteristicValue;
|
|
25
25
|
|
|
26
26
|
// OpenAPI others
|
|
27
|
-
openState: deviceStatus[
|
|
28
|
-
moveDetected: deviceStatus[
|
|
29
|
-
brightness: deviceStatus[
|
|
30
|
-
deviceStatus!: deviceStatusResponse;
|
|
27
|
+
openState: settings.deviceStatus["openState"];
|
|
28
|
+
moveDetected: settings.deviceStatus["moveDetected"];
|
|
29
|
+
brightness: settings.deviceStatus["brightness"];
|
|
30
|
+
deviceStatus!: settings.deviceStatusResponse;
|
|
31
31
|
|
|
32
32
|
// BLE Others
|
|
33
33
|
connected?: boolean;
|
|
34
|
-
switchbot!: switchbot;
|
|
35
34
|
SwitchToOpenAPI!: boolean;
|
|
36
|
-
serviceData!: serviceData;
|
|
37
|
-
battery!: serviceData[
|
|
38
|
-
movement!: serviceData[
|
|
39
|
-
doorState!: serviceData[
|
|
40
|
-
lightLevel!: serviceData[
|
|
35
|
+
serviceData!: settings.serviceData;
|
|
36
|
+
battery!: settings.serviceData["battery"];
|
|
37
|
+
movement!: settings.serviceData["movement"];
|
|
38
|
+
doorState!: settings.serviceData["doorState"];
|
|
39
|
+
lightLevel!: settings.serviceData["lightLevel"];
|
|
41
40
|
|
|
42
41
|
// Config
|
|
43
42
|
set_minLux!: number;
|
|
@@ -48,22 +47,23 @@ export class Contact {
|
|
|
48
47
|
|
|
49
48
|
// Updates
|
|
50
49
|
contactUbpdateInProgress!: boolean;
|
|
51
|
-
doContactUpdate!: Subject<void>;
|
|
50
|
+
doContactUpdate!: rxjs.Subject<void>;
|
|
52
51
|
|
|
53
52
|
constructor(
|
|
54
|
-
private readonly platform: SwitchBotPlatform,
|
|
55
|
-
private accessory: PlatformAccessory,
|
|
56
|
-
public device: device & devicesConfig,
|
|
53
|
+
private readonly platform: platform.SwitchBotPlatform,
|
|
54
|
+
private accessory: homebridge.PlatformAccessory,
|
|
55
|
+
public device: settings.device & settings.devicesConfig,
|
|
57
56
|
) {
|
|
58
57
|
// default placeholders
|
|
59
58
|
this.logs(device);
|
|
60
59
|
this.scan(device);
|
|
61
60
|
this.refreshRate(device);
|
|
62
61
|
this.config(device);
|
|
63
|
-
this.ContactSensorState =
|
|
62
|
+
this.ContactSensorState =
|
|
63
|
+
this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
64
64
|
|
|
65
65
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
66
|
-
this.doContactUpdate = new Subject();
|
|
66
|
+
this.doContactUpdate = new rxjs.Subject();
|
|
67
67
|
this.contactUbpdateInProgress = false;
|
|
68
68
|
|
|
69
69
|
// Retrieve initial values and updateHomekit
|
|
@@ -72,15 +72,22 @@ export class Contact {
|
|
|
72
72
|
// set accessory information
|
|
73
73
|
accessory
|
|
74
74
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
75
|
-
.setCharacteristic(this.platform.Characteristic.Manufacturer,
|
|
76
|
-
.setCharacteristic(
|
|
77
|
-
|
|
75
|
+
.setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
|
|
76
|
+
.setCharacteristic(
|
|
77
|
+
this.platform.Characteristic.Model,
|
|
78
|
+
"SWITCHBOT-WOCONTACT-W1201500",
|
|
79
|
+
)
|
|
80
|
+
.setCharacteristic(
|
|
81
|
+
this.platform.Characteristic.SerialNumber,
|
|
82
|
+
device.deviceId!,
|
|
83
|
+
);
|
|
78
84
|
|
|
79
85
|
// get the Contact service if it exists, otherwise create a new Contact service
|
|
80
86
|
// you can create multiple services for each accessory
|
|
81
87
|
(this.service =
|
|
82
88
|
accessory.getService(this.platform.Service.ContactSensor) ||
|
|
83
|
-
accessory.addService(this.platform.Service.ContactSensor)),
|
|
89
|
+
accessory.addService(this.platform.Service.ContactSensor)),
|
|
90
|
+
`${accessory.displayName} Contact Sensor`;
|
|
84
91
|
|
|
85
92
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
86
93
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
@@ -88,68 +95,105 @@ export class Contact {
|
|
|
88
95
|
|
|
89
96
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
90
97
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
91
|
-
this.service.setCharacteristic(
|
|
98
|
+
this.service.setCharacteristic(
|
|
99
|
+
this.platform.Characteristic.Name,
|
|
100
|
+
accessory.displayName,
|
|
101
|
+
);
|
|
92
102
|
|
|
93
103
|
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
94
104
|
// see https://developers.homebridge.io/#/service/ContactSensor
|
|
95
105
|
|
|
96
106
|
// Motion Sensor Service
|
|
97
107
|
if (device.contact?.hide_motionsensor) {
|
|
98
|
-
this.debugLog(
|
|
99
|
-
|
|
108
|
+
this.debugLog(
|
|
109
|
+
`Contact Sensor: ${accessory.displayName} Removing Motion Sensor Service`,
|
|
110
|
+
);
|
|
111
|
+
this.motionService = this.accessory.getService(
|
|
112
|
+
this.platform.Service.MotionSensor,
|
|
113
|
+
);
|
|
100
114
|
accessory.removeService(this.motionService!);
|
|
101
115
|
} else if (!this.motionService) {
|
|
102
|
-
this.debugLog(
|
|
116
|
+
this.debugLog(
|
|
117
|
+
`Contact Sensor: ${accessory.displayName} Add Motion Sensor Service`,
|
|
118
|
+
);
|
|
103
119
|
(this.motionService =
|
|
104
120
|
this.accessory.getService(this.platform.Service.MotionSensor) ||
|
|
105
|
-
this.accessory.addService(this.platform.Service.MotionSensor)),
|
|
106
|
-
|
|
107
|
-
this.motionService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Motion Sensor`);
|
|
121
|
+
this.accessory.addService(this.platform.Service.MotionSensor)),
|
|
122
|
+
`${accessory.displayName} Motion Sensor`;
|
|
108
123
|
|
|
124
|
+
this.motionService.setCharacteristic(
|
|
125
|
+
this.platform.Characteristic.Name,
|
|
126
|
+
`${accessory.displayName} Motion Sensor`,
|
|
127
|
+
);
|
|
109
128
|
} else {
|
|
110
|
-
this.debugLog(
|
|
129
|
+
this.debugLog(
|
|
130
|
+
`Contact Sensor: ${accessory.displayName} Motion Sensor Service Not Added`,
|
|
131
|
+
);
|
|
111
132
|
}
|
|
112
133
|
|
|
113
134
|
// Light Sensor Service
|
|
114
135
|
if (device.contact?.hide_lightsensor) {
|
|
115
|
-
this.debugLog(
|
|
116
|
-
|
|
136
|
+
this.debugLog(
|
|
137
|
+
`Contact Sensor: ${accessory.displayName} Removing Light Sensor Service`,
|
|
138
|
+
);
|
|
139
|
+
this.lightSensorService = this.accessory.getService(
|
|
140
|
+
this.platform.Service.LightSensor,
|
|
141
|
+
);
|
|
117
142
|
accessory.removeService(this.lightSensorService!);
|
|
118
143
|
} else if (!this.lightSensorService) {
|
|
119
|
-
this.debugLog(
|
|
144
|
+
this.debugLog(
|
|
145
|
+
`Contact Sensor: ${accessory.displayName} Add Light Sensor Service`,
|
|
146
|
+
);
|
|
120
147
|
(this.lightSensorService =
|
|
121
148
|
this.accessory.getService(this.platform.Service.LightSensor) ||
|
|
122
|
-
this.accessory.addService(this.platform.Service.LightSensor)),
|
|
123
|
-
|
|
124
|
-
this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
|
|
149
|
+
this.accessory.addService(this.platform.Service.LightSensor)),
|
|
150
|
+
`${accessory.displayName} Light Sensor`;
|
|
125
151
|
|
|
152
|
+
this.lightSensorService.setCharacteristic(
|
|
153
|
+
this.platform.Characteristic.Name,
|
|
154
|
+
`${accessory.displayName} Light Sensor`,
|
|
155
|
+
);
|
|
126
156
|
} else {
|
|
127
|
-
this.debugLog(
|
|
157
|
+
this.debugLog(
|
|
158
|
+
`Contact Sensor: ${accessory.displayName} Light Sensor Service Not Added`,
|
|
159
|
+
);
|
|
128
160
|
}
|
|
129
161
|
|
|
130
162
|
// Battery Service
|
|
131
163
|
if (!device.ble) {
|
|
132
|
-
this.debugLog(
|
|
133
|
-
|
|
164
|
+
this.debugLog(
|
|
165
|
+
`Contact Sensor: ${accessory.displayName} Removing Battery Service`,
|
|
166
|
+
);
|
|
167
|
+
this.batteryService = this.accessory.getService(
|
|
168
|
+
this.platform.Service.Battery,
|
|
169
|
+
);
|
|
134
170
|
accessory.removeService(this.batteryService!);
|
|
135
171
|
} else if (device.ble && !this.batteryService) {
|
|
136
|
-
this.debugLog(
|
|
172
|
+
this.debugLog(
|
|
173
|
+
`Contact Sensor: ${accessory.displayName} Add Battery Service`,
|
|
174
|
+
);
|
|
137
175
|
(this.batteryService =
|
|
138
176
|
this.accessory.getService(this.platform.Service.Battery) ||
|
|
139
|
-
this.accessory.addService(this.platform.Service.Battery)),
|
|
140
|
-
|
|
141
|
-
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
177
|
+
this.accessory.addService(this.platform.Service.Battery)),
|
|
178
|
+
`${accessory.displayName} Battery`;
|
|
142
179
|
|
|
180
|
+
this.batteryService.setCharacteristic(
|
|
181
|
+
this.platform.Characteristic.Name,
|
|
182
|
+
`${accessory.displayName} Battery`,
|
|
183
|
+
);
|
|
143
184
|
} else {
|
|
144
|
-
this.debugLog(
|
|
185
|
+
this.debugLog(
|
|
186
|
+
`Contact Sensor: ${accessory.displayName} Battery Service Not Added`,
|
|
187
|
+
);
|
|
145
188
|
}
|
|
146
189
|
|
|
147
190
|
// Retrieve initial values and updateHomekit
|
|
148
191
|
this.updateHomeKitCharacteristics();
|
|
149
192
|
|
|
150
193
|
// Start an update interval
|
|
151
|
-
|
|
152
|
-
.
|
|
194
|
+
rxjs
|
|
195
|
+
.interval(this.deviceRefreshRate * 1000)
|
|
196
|
+
.pipe(operators.skipWhile(() => this.contactUbpdateInProgress))
|
|
153
197
|
.subscribe(() => {
|
|
154
198
|
this.refreshStatus();
|
|
155
199
|
});
|
|
@@ -167,51 +211,65 @@ export class Contact {
|
|
|
167
211
|
}
|
|
168
212
|
|
|
169
213
|
async BLEparseStatus() {
|
|
170
|
-
this.debugLog(
|
|
214
|
+
this.debugLog(
|
|
215
|
+
`Contact Sensor: ${this.accessory.displayName} BLE parseStatus`,
|
|
216
|
+
);
|
|
171
217
|
// Door State
|
|
172
218
|
switch (this.doorState) {
|
|
173
|
-
case
|
|
219
|
+
case "open":
|
|
174
220
|
case 1:
|
|
175
|
-
this.ContactSensorState =
|
|
221
|
+
this.ContactSensorState =
|
|
222
|
+
this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
|
|
176
223
|
break;
|
|
177
|
-
case
|
|
224
|
+
case "close":
|
|
178
225
|
case 0:
|
|
179
|
-
this.ContactSensorState =
|
|
226
|
+
this.ContactSensorState =
|
|
227
|
+
this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
180
228
|
break;
|
|
181
229
|
default:
|
|
182
|
-
this.errorLog(
|
|
230
|
+
this.errorLog(
|
|
231
|
+
`Contact Sensor: ${this.accessory.displayName} timeout no closed, doorstate: ${this.doorState}`,
|
|
232
|
+
);
|
|
183
233
|
}
|
|
184
234
|
// Movement
|
|
185
235
|
if (!this.device.contact?.hide_motionsensor) {
|
|
186
236
|
this.MotionDetected = Boolean(this.movement);
|
|
187
|
-
this.debugLog(
|
|
237
|
+
this.debugLog(
|
|
238
|
+
`Contact Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`,
|
|
239
|
+
);
|
|
188
240
|
}
|
|
189
241
|
// Light Level
|
|
190
242
|
if (!this.device.contact?.hide_lightsensor) {
|
|
191
243
|
this.set_minLux = this.minLux();
|
|
192
244
|
this.set_maxLux = this.maxLux();
|
|
193
245
|
switch (this.lightLevel) {
|
|
194
|
-
case
|
|
246
|
+
case "dark":
|
|
195
247
|
case 0:
|
|
196
248
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
197
249
|
break;
|
|
198
250
|
default:
|
|
199
251
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
200
252
|
}
|
|
201
|
-
this.debugLog(
|
|
202
|
-
|
|
253
|
+
this.debugLog(
|
|
254
|
+
`Contact Sensor: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
|
|
255
|
+
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
256
|
+
);
|
|
203
257
|
}
|
|
204
258
|
// Battery
|
|
205
259
|
if (this.battery === undefined) {
|
|
206
260
|
this.battery === 100;
|
|
207
261
|
}
|
|
208
|
-
this.BatteryLevel =
|
|
262
|
+
this.BatteryLevel = this.battery!;
|
|
209
263
|
if (this.BatteryLevel < 10) {
|
|
210
|
-
this.StatusLowBattery =
|
|
264
|
+
this.StatusLowBattery =
|
|
265
|
+
this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
211
266
|
} else {
|
|
212
|
-
this.StatusLowBattery =
|
|
267
|
+
this.StatusLowBattery =
|
|
268
|
+
this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
213
269
|
}
|
|
214
|
-
this.debugLog(
|
|
270
|
+
this.debugLog(
|
|
271
|
+
`Contact Sensor: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`,
|
|
272
|
+
);
|
|
215
273
|
}
|
|
216
274
|
|
|
217
275
|
async openAPIparseStatus() {
|
|
@@ -219,35 +277,49 @@ export class Contact {
|
|
|
219
277
|
this.SwitchToOpenAPI = false;
|
|
220
278
|
}
|
|
221
279
|
if (this.platform.config.credentials?.openToken) {
|
|
222
|
-
this.debugLog(
|
|
280
|
+
this.debugLog(
|
|
281
|
+
`Contact Sensor: ${this.accessory.displayName} OpenAPI parseStatus`,
|
|
282
|
+
);
|
|
223
283
|
// Contact State
|
|
224
|
-
if (this.openState ===
|
|
225
|
-
this.ContactSensorState =
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
284
|
+
if (this.openState === "open") {
|
|
285
|
+
this.ContactSensorState =
|
|
286
|
+
this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
|
|
287
|
+
this.debugLog(
|
|
288
|
+
`Contact Sensor: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`,
|
|
289
|
+
);
|
|
290
|
+
} else if (this.openState === "close") {
|
|
291
|
+
this.ContactSensorState =
|
|
292
|
+
this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
293
|
+
this.debugLog(
|
|
294
|
+
`Contact Sensor: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`,
|
|
295
|
+
);
|
|
230
296
|
} else {
|
|
231
|
-
this.debugLog(
|
|
297
|
+
this.debugLog(
|
|
298
|
+
`Contact Sensor: ${this.accessory.displayName} openState: ${this.openState}`,
|
|
299
|
+
);
|
|
232
300
|
}
|
|
233
301
|
// Motion State
|
|
234
302
|
if (!this.device.contact?.hide_motionsensor) {
|
|
235
303
|
this.MotionDetected = this.moveDetected!;
|
|
236
|
-
this.debugLog(
|
|
304
|
+
this.debugLog(
|
|
305
|
+
`Contact Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`,
|
|
306
|
+
);
|
|
237
307
|
}
|
|
238
308
|
// Light Level
|
|
239
309
|
if (!this.device.contact?.hide_lightsensor) {
|
|
240
310
|
this.set_minLux = this.minLux();
|
|
241
311
|
this.set_maxLux = this.maxLux();
|
|
242
312
|
switch (this.brightness) {
|
|
243
|
-
case
|
|
313
|
+
case "dim":
|
|
244
314
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
245
315
|
break;
|
|
246
|
-
case
|
|
316
|
+
case "bright":
|
|
247
317
|
default:
|
|
248
318
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
249
319
|
}
|
|
250
|
-
this.debugLog(
|
|
320
|
+
this.debugLog(
|
|
321
|
+
`Contact Sensor: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
322
|
+
);
|
|
251
323
|
}
|
|
252
324
|
}
|
|
253
325
|
}
|
|
@@ -264,102 +336,127 @@ export class Contact {
|
|
|
264
336
|
}
|
|
265
337
|
|
|
266
338
|
private async BLERefreshStatus() {
|
|
267
|
-
this.debugLog(
|
|
339
|
+
this.debugLog(
|
|
340
|
+
`Contact Sensor: ${this.accessory.displayName} BLE refreshStatus`,
|
|
341
|
+
);
|
|
268
342
|
const switchbot = await this.platform.connectBLE();
|
|
269
343
|
// Convert to BLE Address
|
|
270
|
-
this.device.bleMac =
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
344
|
+
this.device.bleMac = this.device
|
|
345
|
+
.deviceId!.match(/.{1,2}/g)!
|
|
346
|
+
.join(":")
|
|
347
|
+
.toLowerCase();
|
|
348
|
+
this.debugLog(
|
|
349
|
+
`Contact Sensor: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`,
|
|
350
|
+
);
|
|
351
|
+
try {
|
|
352
|
+
await switchbot.discover({
|
|
353
|
+
model: "d",
|
|
354
|
+
quick: false,
|
|
355
|
+
});
|
|
356
|
+
// Start to monitor advertisement packets
|
|
357
|
+
await switchbot.startScan({
|
|
358
|
+
model: "d",
|
|
276
359
|
id: this.device.bleMac,
|
|
277
|
-
})
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
// Stop to monitor
|
|
301
|
-
switchbot.stopScan();
|
|
302
|
-
if (this.connected) {
|
|
303
|
-
this.parseStatus();
|
|
304
|
-
this.updateHomeKitCharacteristics();
|
|
360
|
+
});
|
|
361
|
+
// Set an event hander
|
|
362
|
+
switchbot.onadvertisement = (ad: settings.ad) => {
|
|
363
|
+
this.serviceData = ad.serviceData;
|
|
364
|
+
this.movement = ad.serviceData.movement;
|
|
365
|
+
this.doorState = ad.serviceData.doorState;
|
|
366
|
+
this.lightLevel = ad.serviceData.lightLevel;
|
|
367
|
+
this.battery = ad.serviceData.battery;
|
|
368
|
+
this.debugLog(
|
|
369
|
+
`Contact Sensor: ${
|
|
370
|
+
this.accessory.displayName
|
|
371
|
+
} serviceData: ${JSON.stringify(ad.serviceData)}`,
|
|
372
|
+
);
|
|
373
|
+
this.debugLog(
|
|
374
|
+
`Contact Sensor: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, doorState: ` +
|
|
375
|
+
`${ad.serviceData.doorState}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`,
|
|
376
|
+
);
|
|
377
|
+
|
|
378
|
+
if (this.serviceData) {
|
|
379
|
+
this.connected = true;
|
|
380
|
+
this.debugLog(
|
|
381
|
+
`Contact Sensor: ${this.accessory.displayName} connected: ${this.connected}`,
|
|
382
|
+
);
|
|
305
383
|
} else {
|
|
306
|
-
this.
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}).catch(async (e: any) => {
|
|
313
|
-
this.errorLog(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
314
|
-
if (this.deviceLogging === 'debug') {
|
|
315
|
-
this.errorLog(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
316
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
317
|
-
}
|
|
318
|
-
if (this.platform.debugMode) {
|
|
319
|
-
this.errorLog(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
320
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
384
|
+
this.connected = false;
|
|
385
|
+
this.debugLog(
|
|
386
|
+
`Contact Sensor: ${this.accessory.displayName} connected: ${this.connected}`,
|
|
387
|
+
);
|
|
321
388
|
}
|
|
389
|
+
};
|
|
390
|
+
// Wait 10 seconds
|
|
391
|
+
await switchbot.wait(this.scanDuration * 1000);
|
|
392
|
+
// Stop to monitor
|
|
393
|
+
switchbot.stopScan();
|
|
394
|
+
if (this.connected) {
|
|
395
|
+
this.parseStatus();
|
|
396
|
+
this.updateHomeKitCharacteristics();
|
|
397
|
+
} else {
|
|
398
|
+
this.errorLog(
|
|
399
|
+
`Contact Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection`,
|
|
400
|
+
);
|
|
322
401
|
if (this.platform.config.credentials?.openToken) {
|
|
323
|
-
this.warnLog(
|
|
402
|
+
this.warnLog(
|
|
403
|
+
`Contact Sensor: ${this.accessory.displayName} Using OpenAPI Connection`,
|
|
404
|
+
);
|
|
324
405
|
this.SwitchToOpenAPI = true;
|
|
325
406
|
await this.openAPIRefreshStatus();
|
|
326
407
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
this.
|
|
339
|
-
|
|
408
|
+
}
|
|
409
|
+
} catch (e: any) {
|
|
410
|
+
this.errorLog(
|
|
411
|
+
`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection`,
|
|
412
|
+
);
|
|
413
|
+
if (this.deviceLogging.includes("debug")) {
|
|
414
|
+
this.errorLog(
|
|
415
|
+
`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` +
|
|
416
|
+
` Error Message: ${e.message}`,
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
if (this.platform.config.credentials?.openToken) {
|
|
420
|
+
this.warnLog(
|
|
421
|
+
`Contact Sensor: ${this.accessory.displayName} Using OpenAPI Connection`,
|
|
422
|
+
);
|
|
423
|
+
this.SwitchToOpenAPI = true;
|
|
424
|
+
await this.openAPIRefreshStatus();
|
|
425
|
+
}
|
|
426
|
+
this.apiError(e);
|
|
340
427
|
}
|
|
341
428
|
}
|
|
342
429
|
|
|
343
430
|
private async openAPIRefreshStatus() {
|
|
344
431
|
if (this.platform.config.credentials?.openToken) {
|
|
345
|
-
this.debugLog(
|
|
432
|
+
this.debugLog(
|
|
433
|
+
`Contact Sensor: ${this.accessory.displayName} OpenAPI refreshStatus`,
|
|
434
|
+
);
|
|
346
435
|
try {
|
|
347
|
-
this.deviceStatus = (
|
|
348
|
-
|
|
436
|
+
this.deviceStatus = (
|
|
437
|
+
await this.platform.axios.get(
|
|
438
|
+
`${settings.DeviceURL}/${this.device.deviceId}/status`,
|
|
439
|
+
)
|
|
440
|
+
).data;
|
|
441
|
+
this.debugLog(
|
|
442
|
+
`Contact Sensor: ${
|
|
443
|
+
this.accessory.displayName
|
|
444
|
+
} refreshStatus: ${JSON.stringify(this.deviceStatus)}`,
|
|
445
|
+
);
|
|
349
446
|
this.openState = this.deviceStatus.body.openState;
|
|
350
447
|
this.moveDetected = this.deviceStatus.body.moveDetected;
|
|
351
448
|
this.brightness = this.deviceStatus.body.brightness;
|
|
352
449
|
this.parseStatus();
|
|
353
450
|
this.updateHomeKitCharacteristics();
|
|
354
451
|
} catch (e: any) {
|
|
355
|
-
this.errorLog(
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
452
|
+
this.errorLog(
|
|
453
|
+
`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`,
|
|
454
|
+
);
|
|
455
|
+
if (this.deviceLogging.includes("debug")) {
|
|
456
|
+
this.errorLog(
|
|
457
|
+
`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
|
|
458
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
459
|
+
);
|
|
363
460
|
}
|
|
364
461
|
this.apiError(e);
|
|
365
462
|
}
|
|
@@ -371,118 +468,192 @@ export class Contact {
|
|
|
371
468
|
*/
|
|
372
469
|
updateHomeKitCharacteristics() {
|
|
373
470
|
if (this.ContactSensorState === undefined) {
|
|
374
|
-
this.debugLog(
|
|
471
|
+
this.debugLog(
|
|
472
|
+
`Contact Sensor: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`,
|
|
473
|
+
);
|
|
375
474
|
} else {
|
|
376
|
-
this.service.updateCharacteristic(
|
|
377
|
-
|
|
475
|
+
this.service.updateCharacteristic(
|
|
476
|
+
this.platform.Characteristic.ContactSensorState,
|
|
477
|
+
this.ContactSensorState,
|
|
478
|
+
);
|
|
479
|
+
this.debugLog(
|
|
480
|
+
`Contact Sensor: ${this.accessory.displayName} updateCharacteristic ContactSensorState: ${this.ContactSensorState}`,
|
|
481
|
+
);
|
|
378
482
|
}
|
|
379
483
|
if (!this.device.contact?.hide_motionsensor) {
|
|
380
484
|
if (this.MotionDetected === undefined) {
|
|
381
|
-
this.debugLog(
|
|
485
|
+
this.debugLog(
|
|
486
|
+
`Contact Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`,
|
|
487
|
+
);
|
|
382
488
|
} else {
|
|
383
|
-
this.motionService?.updateCharacteristic(
|
|
384
|
-
|
|
489
|
+
this.motionService?.updateCharacteristic(
|
|
490
|
+
this.platform.Characteristic.MotionDetected,
|
|
491
|
+
this.MotionDetected,
|
|
492
|
+
);
|
|
493
|
+
this.debugLog(
|
|
494
|
+
`Contact Sensor: ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`,
|
|
495
|
+
);
|
|
385
496
|
}
|
|
386
497
|
}
|
|
387
498
|
if (!this.device.contact?.hide_lightsensor) {
|
|
388
499
|
if (this.CurrentAmbientLightLevel === undefined) {
|
|
389
|
-
this.debugLog(
|
|
500
|
+
this.debugLog(
|
|
501
|
+
`Contact Sensor: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
502
|
+
);
|
|
390
503
|
} else {
|
|
391
|
-
this.lightSensorService?.updateCharacteristic(
|
|
392
|
-
|
|
393
|
-
|
|
504
|
+
this.lightSensorService?.updateCharacteristic(
|
|
505
|
+
this.platform.Characteristic.CurrentAmbientLightLevel,
|
|
506
|
+
this.CurrentAmbientLightLevel,
|
|
507
|
+
);
|
|
508
|
+
this.debugLog(
|
|
509
|
+
`Contact Sensor: ${this.accessory.displayName}` +
|
|
510
|
+
` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
511
|
+
);
|
|
394
512
|
}
|
|
395
513
|
}
|
|
396
514
|
if (this.device.ble) {
|
|
397
515
|
if (this.BatteryLevel === undefined) {
|
|
398
|
-
this.debugLog(
|
|
516
|
+
this.debugLog(
|
|
517
|
+
`Contact Sensor: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`,
|
|
518
|
+
);
|
|
399
519
|
} else {
|
|
400
|
-
this.batteryService?.updateCharacteristic(
|
|
401
|
-
|
|
520
|
+
this.batteryService?.updateCharacteristic(
|
|
521
|
+
this.platform.Characteristic.BatteryLevel,
|
|
522
|
+
this.BatteryLevel,
|
|
523
|
+
);
|
|
524
|
+
this.debugLog(
|
|
525
|
+
`Contact Sensor: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`,
|
|
526
|
+
);
|
|
402
527
|
}
|
|
403
528
|
if (this.StatusLowBattery === undefined) {
|
|
404
|
-
this.debugLog(
|
|
529
|
+
this.debugLog(
|
|
530
|
+
`Contact Sensor: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`,
|
|
531
|
+
);
|
|
405
532
|
} else {
|
|
406
|
-
this.batteryService?.updateCharacteristic(
|
|
407
|
-
|
|
533
|
+
this.batteryService?.updateCharacteristic(
|
|
534
|
+
this.platform.Characteristic.StatusLowBattery,
|
|
535
|
+
this.StatusLowBattery,
|
|
536
|
+
);
|
|
537
|
+
this.debugLog(
|
|
538
|
+
`Contact Sensor: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`,
|
|
539
|
+
);
|
|
408
540
|
}
|
|
409
541
|
}
|
|
410
542
|
}
|
|
411
543
|
|
|
412
544
|
public apiError(e: any) {
|
|
413
|
-
this.service.updateCharacteristic(
|
|
545
|
+
this.service.updateCharacteristic(
|
|
546
|
+
this.platform.Characteristic.ContactSensorState,
|
|
547
|
+
e,
|
|
548
|
+
);
|
|
414
549
|
if (!this.device.contact?.hide_motionsensor) {
|
|
415
|
-
this.motionService?.updateCharacteristic(
|
|
550
|
+
this.motionService?.updateCharacteristic(
|
|
551
|
+
this.platform.Characteristic.MotionDetected,
|
|
552
|
+
e,
|
|
553
|
+
);
|
|
416
554
|
}
|
|
417
555
|
if (!this.device.contact?.hide_lightsensor) {
|
|
418
|
-
this.lightSensorService?.updateCharacteristic(
|
|
556
|
+
this.lightSensorService?.updateCharacteristic(
|
|
557
|
+
this.platform.Characteristic.CurrentAmbientLightLevel,
|
|
558
|
+
e,
|
|
559
|
+
);
|
|
419
560
|
}
|
|
420
561
|
if (this.device.ble) {
|
|
421
|
-
this.batteryService?.updateCharacteristic(
|
|
422
|
-
|
|
562
|
+
this.batteryService?.updateCharacteristic(
|
|
563
|
+
this.platform.Characteristic.BatteryLevel,
|
|
564
|
+
e,
|
|
565
|
+
);
|
|
566
|
+
this.batteryService?.updateCharacteristic(
|
|
567
|
+
this.platform.Characteristic.StatusLowBattery,
|
|
568
|
+
e,
|
|
569
|
+
);
|
|
423
570
|
}
|
|
424
571
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
425
572
|
}
|
|
426
573
|
|
|
427
|
-
config(device: device & devicesConfig) {
|
|
574
|
+
config(device: settings.device & settings.devicesConfig) {
|
|
428
575
|
let config = {};
|
|
429
576
|
if (device.contact) {
|
|
430
577
|
config = device.contact;
|
|
431
578
|
}
|
|
432
579
|
if (device.ble) {
|
|
433
|
-
config[
|
|
580
|
+
config["ble"] = device.ble;
|
|
434
581
|
}
|
|
435
582
|
if (device.logging !== undefined) {
|
|
436
|
-
config[
|
|
583
|
+
config["logging"] = device.logging;
|
|
437
584
|
}
|
|
438
585
|
if (device.refreshRate !== undefined) {
|
|
439
|
-
config[
|
|
586
|
+
config["refreshRate"] = device.refreshRate;
|
|
440
587
|
}
|
|
441
588
|
if (device.scanDuration !== undefined) {
|
|
442
|
-
config[
|
|
589
|
+
config["scanDuration"] = device.scanDuration;
|
|
443
590
|
}
|
|
444
591
|
if (Object.entries(config).length !== 0) {
|
|
445
|
-
this.warnLog(
|
|
592
|
+
this.warnLog(
|
|
593
|
+
`Contact Sensor: ${this.accessory.displayName} Config: ${JSON.stringify(
|
|
594
|
+
config,
|
|
595
|
+
)}`,
|
|
596
|
+
);
|
|
446
597
|
}
|
|
447
598
|
}
|
|
448
599
|
|
|
449
|
-
refreshRate(device: device & devicesConfig) {
|
|
600
|
+
refreshRate(device: settings.device & settings.devicesConfig) {
|
|
450
601
|
if (device.refreshRate) {
|
|
451
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
452
|
-
|
|
602
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
603
|
+
device.refreshRate;
|
|
604
|
+
this.debugLog(
|
|
605
|
+
`Contact Sensor: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`,
|
|
606
|
+
);
|
|
453
607
|
} else if (this.platform.config.options!.refreshRate) {
|
|
454
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
455
|
-
|
|
608
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
609
|
+
this.platform.config.options!.refreshRate;
|
|
610
|
+
this.debugLog(
|
|
611
|
+
`Contact Sensor: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`,
|
|
612
|
+
);
|
|
456
613
|
}
|
|
457
614
|
}
|
|
458
615
|
|
|
459
|
-
scan(device: device & devicesConfig) {
|
|
616
|
+
scan(device: settings.device & settings.devicesConfig) {
|
|
460
617
|
if (device.scanDuration) {
|
|
461
|
-
this.scanDuration = this.accessory.context.scanDuration =
|
|
618
|
+
this.scanDuration = this.accessory.context.scanDuration =
|
|
619
|
+
device.scanDuration;
|
|
462
620
|
if (device.ble) {
|
|
463
|
-
this.debugLog(
|
|
621
|
+
this.debugLog(
|
|
622
|
+
`Contact Sensor: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`,
|
|
623
|
+
);
|
|
464
624
|
}
|
|
465
625
|
} else {
|
|
466
626
|
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
467
627
|
if (this.device.ble) {
|
|
468
|
-
this.debugLog(
|
|
628
|
+
this.debugLog(
|
|
629
|
+
`Contact Sensor: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`,
|
|
630
|
+
);
|
|
469
631
|
}
|
|
470
632
|
}
|
|
471
633
|
}
|
|
472
634
|
|
|
473
|
-
logs(device: device & devicesConfig) {
|
|
635
|
+
logs(device: settings.device & settings.devicesConfig) {
|
|
474
636
|
if (this.platform.debugMode) {
|
|
475
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
476
|
-
this.debugLog(
|
|
637
|
+
this.deviceLogging = this.accessory.context.logging = "debugMode";
|
|
638
|
+
this.debugLog(
|
|
639
|
+
`Contact Sensor: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
|
|
640
|
+
);
|
|
477
641
|
} else if (device.logging) {
|
|
478
642
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
479
|
-
this.debugLog(
|
|
643
|
+
this.debugLog(
|
|
644
|
+
`Contact Sensor: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
|
|
645
|
+
);
|
|
480
646
|
} else if (this.platform.config.options?.logging) {
|
|
481
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
482
|
-
|
|
647
|
+
this.deviceLogging = this.accessory.context.logging =
|
|
648
|
+
this.platform.config.options?.logging;
|
|
649
|
+
this.debugLog(
|
|
650
|
+
`Contact Sensor: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
|
|
651
|
+
);
|
|
483
652
|
} else {
|
|
484
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
485
|
-
this.debugLog(
|
|
653
|
+
this.deviceLogging = this.accessory.context.logging = "standard";
|
|
654
|
+
this.debugLog(
|
|
655
|
+
`Contact Sensor: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
|
|
656
|
+
);
|
|
486
657
|
}
|
|
487
658
|
}
|
|
488
659
|
|
|
@@ -505,8 +676,8 @@ export class Contact {
|
|
|
505
676
|
}
|
|
506
677
|
|
|
507
678
|
/**
|
|
508
|
-
|
|
509
|
-
|
|
679
|
+
* Logging for Device
|
|
680
|
+
*/
|
|
510
681
|
infoLog(...log: any[]) {
|
|
511
682
|
if (this.enablingDeviceLogging()) {
|
|
512
683
|
this.platform.log.info(String(...log));
|
|
@@ -527,8 +698,8 @@ export class Contact {
|
|
|
527
698
|
|
|
528
699
|
debugLog(...log: any[]) {
|
|
529
700
|
if (this.enablingDeviceLogging()) {
|
|
530
|
-
if (this.deviceLogging ===
|
|
531
|
-
this.platform.log.info(
|
|
701
|
+
if (this.deviceLogging === "debug") {
|
|
702
|
+
this.platform.log.info("[DEBUG]", String(...log));
|
|
532
703
|
} else {
|
|
533
704
|
this.platform.log.debug(String(...log));
|
|
534
705
|
}
|
|
@@ -536,6 +707,8 @@ export class Contact {
|
|
|
536
707
|
}
|
|
537
708
|
|
|
538
709
|
enablingDeviceLogging(): boolean {
|
|
539
|
-
return
|
|
710
|
+
return (
|
|
711
|
+
this.deviceLogging.includes("debug") || this.deviceLogging === "standard"
|
|
712
|
+
);
|
|
540
713
|
}
|
|
541
714
|
}
|