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