@switchbot/homebridge-switchbot 2.14.0 → 3.0.0-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/.github/npm-version-script.cjs +81 -0
- package/.github/workflows/dependabot.yml +10 -11
- package/CHANGELOG.md +11 -2
- package/LICENSE +1 -1
- package/config.schema.json +1 -0
- package/dist/device/blindtilt.d.ts +9 -5
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +151 -91
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -5
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +234 -184
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +9 -5
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +110 -64
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +9 -5
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +121 -69
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +9 -5
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +111 -66
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +9 -5
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +164 -107
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +9 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +87 -51
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +9 -5
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +133 -90
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +9 -5
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +108 -66
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +9 -5
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +110 -65
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +10 -6
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +125 -84
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +9 -5
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +102 -63
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +9 -5
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +102 -63
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +9 -5
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +95 -54
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -5
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +68 -40
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +9 -5
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +86 -52
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/homebridge-ui/server.d.ts +2 -0
- package/dist/homebridge-ui/server.d.ts.map +1 -0
- package/dist/homebridge-ui/server.js +44 -0
- package/dist/homebridge-ui/server.js.map +1 -0
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -4
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +105 -71
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +8 -4
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +78 -46
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +8 -4
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +41 -25
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +8 -4
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +62 -39
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +8 -4
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +67 -45
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +8 -4
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +176 -150
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -4
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +81 -62
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +8 -4
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +41 -25
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +8 -4
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +48 -32
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +8 -9
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +147 -162
- package/dist/platform.js.map +1 -1
- package/dist/settings.js +7 -14
- package/dist/settings.js.map +1 -1
- package/dist/utils.js +1 -5
- package/dist/utils.js.map +1 -1
- package/package.json +28 -16
- package/src/device/blindtilt.ts +80 -69
- package/src/device/bot.ts +189 -178
- package/src/device/ceilinglight.ts +55 -42
- package/src/device/colorbulb.ts +51 -38
- package/src/device/contact.ts +69 -58
- package/src/device/curtain.ts +94 -83
- package/src/device/hub.ts +54 -43
- package/src/device/humidifier.ts +86 -75
- package/src/device/iosensor.ts +63 -52
- package/src/device/lightstrip.ts +54 -41
- package/src/device/lock.ts +89 -79
- package/src/device/meter.ts +59 -48
- package/src/device/meterplus.ts +63 -52
- package/src/device/motion.ts +56 -45
- package/src/device/plug.ts +36 -25
- package/src/device/robotvacuumcleaner.ts +47 -36
- package/src/homebridge-ui/public/index.html +240 -0
- package/src/homebridge-ui/server.ts +48 -0
- package/src/index.ts +10 -7
- package/src/irdevice/airconditioner.ts +70 -62
- package/src/irdevice/airpurifier.ts +47 -39
- package/src/irdevice/camera.ts +27 -19
- package/src/irdevice/fan.ts +41 -33
- package/src/irdevice/light.ts +47 -39
- package/src/irdevice/other.ts +163 -155
- package/src/irdevice/tv.ts +65 -57
- package/src/irdevice/vacuumcleaner.ts +27 -19
- package/src/irdevice/waterheater.ts +34 -26
- package/src/platform.ts +35 -21
- package/tsconfig.json +11 -13
- package/homebridge-ui/server.js +0 -50
- /package/{homebridge-ui → dist/homebridge-ui}/public/index.html +0 -0
package/src/device/contact.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { sleep } from '../utils';
|
|
|
3
3
|
import { interval, Subject } from 'rxjs';
|
|
4
4
|
import { skipWhile } from 'rxjs/operators';
|
|
5
5
|
import { SwitchBotPlatform } from '../platform';
|
|
6
|
-
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
7
|
-
import { device, devicesConfig, serviceData, deviceStatus, ad, Devices } from '../settings';
|
|
6
|
+
import { Service, PlatformAccessory, CharacteristicValue, API, Logging, HAP } from 'homebridge';
|
|
7
|
+
import { device, devicesConfig, serviceData, deviceStatus, ad, Devices, SwitchBotPlatformConfig } from '../settings';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Platform Accessory
|
|
@@ -12,6 +12,10 @@ import { device, devicesConfig, serviceData, deviceStatus, ad, Devices } from '.
|
|
|
12
12
|
* Each accessory may expose multiple services of different service types.
|
|
13
13
|
*/
|
|
14
14
|
export class Contact {
|
|
15
|
+
public readonly api: API;
|
|
16
|
+
public readonly log: Logging;
|
|
17
|
+
public readonly config!: SwitchBotPlatformConfig;
|
|
18
|
+
protected readonly hap: HAP;
|
|
15
19
|
// Services
|
|
16
20
|
motionService?: Service;
|
|
17
21
|
batteryService: Service;
|
|
@@ -55,20 +59,27 @@ export class Contact {
|
|
|
55
59
|
doContactUpdate!: Subject<void>;
|
|
56
60
|
|
|
57
61
|
// Connection
|
|
58
|
-
private readonly
|
|
59
|
-
private readonly
|
|
62
|
+
private readonly OpenAPI: boolean;
|
|
63
|
+
private readonly BLE: boolean;
|
|
60
64
|
|
|
61
65
|
constructor(
|
|
62
66
|
private readonly platform: SwitchBotPlatform,
|
|
63
67
|
private accessory: PlatformAccessory,
|
|
64
68
|
public device: device & devicesConfig,
|
|
65
69
|
) {
|
|
70
|
+
this.api = this.platform.api;
|
|
71
|
+
this.log = this.platform.log;
|
|
72
|
+
this.config = this.platform.config;
|
|
73
|
+
this.hap = this.api.hap;
|
|
74
|
+
// Connection
|
|
75
|
+
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
76
|
+
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
66
77
|
// default placeholders
|
|
67
|
-
this.
|
|
78
|
+
this.devicedeviceLogs(device);
|
|
68
79
|
this.scan(device);
|
|
69
80
|
this.refreshRate(device);
|
|
70
81
|
this.context();
|
|
71
|
-
this.
|
|
82
|
+
this.devicedeviceConfig(device);
|
|
72
83
|
|
|
73
84
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
74
85
|
this.doContactUpdate = new Subject();
|
|
@@ -79,36 +90,36 @@ export class Contact {
|
|
|
79
90
|
|
|
80
91
|
// set accessory information
|
|
81
92
|
accessory
|
|
82
|
-
.getService(this.
|
|
83
|
-
.setCharacteristic(this.
|
|
84
|
-
.setCharacteristic(this.
|
|
85
|
-
.setCharacteristic(this.
|
|
86
|
-
.setCharacteristic(this.
|
|
93
|
+
.getService(this.hap.Service.AccessoryInformation)!
|
|
94
|
+
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
95
|
+
.setCharacteristic(this.hap.Characteristic.Model, 'W1201500')
|
|
96
|
+
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
97
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
87
98
|
|
|
88
99
|
// get the Contact service if it exists, otherwise create a new Contact service
|
|
89
100
|
// you can create multiple services for each accessory
|
|
90
101
|
const contactSensorservice = `${accessory.displayName} Contact Sensor`;
|
|
91
|
-
(this.contactSensorservice = accessory.getService(this.
|
|
92
|
-
|| accessory.addService(this.
|
|
102
|
+
(this.contactSensorservice = accessory.getService(this.hap.Service.ContactSensor)
|
|
103
|
+
|| accessory.addService(this.hap.Service.ContactSensor)), contactSensorservice;
|
|
93
104
|
|
|
94
|
-
this.contactSensorservice.setCharacteristic(this.
|
|
95
|
-
if (!this.contactSensorservice.testCharacteristic(this.
|
|
96
|
-
this.contactSensorservice.addCharacteristic(this.
|
|
105
|
+
this.contactSensorservice.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
106
|
+
if (!this.contactSensorservice.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
107
|
+
this.contactSensorservice.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
97
108
|
}
|
|
98
109
|
|
|
99
110
|
// Motion Sensor Service
|
|
100
111
|
if (device.contact?.hide_motionsensor) {
|
|
101
112
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Motion Sensor Service`);
|
|
102
|
-
this.motionService = this.accessory.getService(this.
|
|
113
|
+
this.motionService = this.accessory.getService(this.hap.Service.MotionSensor);
|
|
103
114
|
accessory.removeService(this.motionService!);
|
|
104
115
|
} else if (!this.motionService) {
|
|
105
116
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Motion Sensor Service`);
|
|
106
117
|
const motionService = `${accessory.displayName} Motion Sensor`;
|
|
107
|
-
(this.motionService = this.accessory.getService(this.
|
|
108
|
-
|| this.accessory.addService(this.
|
|
118
|
+
(this.motionService = this.accessory.getService(this.hap.Service.MotionSensor)
|
|
119
|
+
|| this.accessory.addService(this.hap.Service.MotionSensor)), motionService;
|
|
109
120
|
|
|
110
|
-
this.motionService.setCharacteristic(this.
|
|
111
|
-
this.motionService.setCharacteristic(this.
|
|
121
|
+
this.motionService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Motion Sensor`);
|
|
122
|
+
this.motionService.setCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Motion Sensor`);
|
|
112
123
|
} else {
|
|
113
124
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Motion Sensor Service Not Added`);
|
|
114
125
|
}
|
|
@@ -116,31 +127,31 @@ export class Contact {
|
|
|
116
127
|
// Light Sensor Service
|
|
117
128
|
if (device.contact?.hide_lightsensor) {
|
|
118
129
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
|
|
119
|
-
this.lightSensorService = this.accessory.getService(this.
|
|
130
|
+
this.lightSensorService = this.accessory.getService(this.hap.Service.LightSensor);
|
|
120
131
|
accessory.removeService(this.lightSensorService!);
|
|
121
132
|
} else if (!this.lightSensorService) {
|
|
122
133
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
|
|
123
134
|
|
|
124
135
|
const lightSensorService = `${accessory.displayName} Light Sensor`;
|
|
125
|
-
(this.lightSensorService = this.accessory.getService(this.
|
|
126
|
-
|| this.accessory.addService(this.
|
|
136
|
+
(this.lightSensorService = this.accessory.getService(this.hap.Service.LightSensor)
|
|
137
|
+
|| this.accessory.addService(this.hap.Service.LightSensor)), lightSensorService;
|
|
127
138
|
|
|
128
|
-
this.lightSensorService.setCharacteristic(this.
|
|
129
|
-
this.lightSensorService.setCharacteristic(this.
|
|
139
|
+
this.lightSensorService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Light Sensor`);
|
|
140
|
+
this.lightSensorService.setCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Light Sensor`);
|
|
130
141
|
} else {
|
|
131
142
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Light Sensor Service Not Added`);
|
|
132
143
|
}
|
|
133
144
|
|
|
134
145
|
// Battery Service
|
|
135
146
|
const batteryService = `${accessory.displayName} Battery`;
|
|
136
|
-
(this.batteryService = this.accessory.getService(this.
|
|
137
|
-
|| accessory.addService(this.
|
|
147
|
+
(this.batteryService = this.accessory.getService(this.hap.Service.Battery)
|
|
148
|
+
|| accessory.addService(this.hap.Service.Battery)), batteryService;
|
|
138
149
|
|
|
139
|
-
this.batteryService.setCharacteristic(this.
|
|
140
|
-
if (!this.batteryService.testCharacteristic(this.
|
|
141
|
-
this.batteryService.addCharacteristic(this.
|
|
150
|
+
this.batteryService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
151
|
+
if (!this.batteryService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
152
|
+
this.batteryService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
142
153
|
}
|
|
143
|
-
this.batteryService.setCharacteristic(this.
|
|
154
|
+
this.batteryService.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
144
155
|
|
|
145
156
|
// Retrieve initial values and updateHomekit
|
|
146
157
|
this.updateHomeKitCharacteristics();
|
|
@@ -161,9 +172,9 @@ export class Contact {
|
|
|
161
172
|
const { detectionState, brightness, openState } = context;
|
|
162
173
|
const { MotionDetected, CurrentAmbientLightLevel, ContactSensorState } = this;
|
|
163
174
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
175
|
+
'(detectionState, brightness, openState) = ' +
|
|
176
|
+
`Webhook:(${detectionState}, ${brightness}, ${openState}), ` +
|
|
177
|
+
`current:(${MotionDetected}, ${CurrentAmbientLightLevel}, ${ContactSensorState})`);
|
|
167
178
|
this.set_minLux = this.minLux();
|
|
168
179
|
this.set_maxLux = this.maxLux();
|
|
169
180
|
this.MotionDetected = detectionState === 'DETECTED' ? true : false;
|
|
@@ -172,7 +183,7 @@ export class Contact {
|
|
|
172
183
|
this.updateHomeKitCharacteristics();
|
|
173
184
|
} catch (e: any) {
|
|
174
185
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
175
|
-
|
|
186
|
+
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
176
187
|
}
|
|
177
188
|
};
|
|
178
189
|
}
|
|
@@ -202,11 +213,11 @@ export class Contact {
|
|
|
202
213
|
switch (this.BLE_ContactSensorState) {
|
|
203
214
|
case 'open':
|
|
204
215
|
case 1:
|
|
205
|
-
this.ContactSensorState = this.
|
|
216
|
+
this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
|
|
206
217
|
break;
|
|
207
218
|
case 'close':
|
|
208
219
|
case 0:
|
|
209
|
-
this.ContactSensorState = this.
|
|
220
|
+
this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
210
221
|
break;
|
|
211
222
|
default:
|
|
212
223
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} timeout no closed, doorstate: ${this.BLE_ContactSensorState}`);
|
|
@@ -214,7 +225,7 @@ export class Contact {
|
|
|
214
225
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
215
226
|
if (
|
|
216
227
|
this.ContactSensorState !== this.accessory.context.ContactSensorState &&
|
|
217
|
-
this.
|
|
228
|
+
this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
|
|
218
229
|
) {
|
|
219
230
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Opened`);
|
|
220
231
|
}
|
|
@@ -251,9 +262,9 @@ export class Contact {
|
|
|
251
262
|
}
|
|
252
263
|
this.BatteryLevel = Number(this.BLE_BateryLevel);
|
|
253
264
|
if (this.BatteryLevel < 10) {
|
|
254
|
-
this.StatusLowBattery = this.
|
|
265
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
255
266
|
} else {
|
|
256
|
-
this.StatusLowBattery = this.
|
|
267
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
257
268
|
}
|
|
258
269
|
this.debugLog(
|
|
259
270
|
`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, ` + `StatusLowBattery: ${this.StatusLowBattery}`,
|
|
@@ -264,10 +275,10 @@ export class Contact {
|
|
|
264
275
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
265
276
|
// Contact State
|
|
266
277
|
if (this.OpenAPI_ContactSensorState === 'open') {
|
|
267
|
-
this.ContactSensorState = this.
|
|
278
|
+
this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
|
|
268
279
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
269
280
|
} else if (this.OpenAPI_ContactSensorState === 'close') {
|
|
270
|
-
this.ContactSensorState = this.
|
|
281
|
+
this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
271
282
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
272
283
|
} else {
|
|
273
284
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openState: ${this.OpenAPI_ContactSensorState}`);
|
|
@@ -297,9 +308,9 @@ export class Contact {
|
|
|
297
308
|
}
|
|
298
309
|
this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
|
|
299
310
|
if (this.BatteryLevel < 10) {
|
|
300
|
-
this.StatusLowBattery = this.
|
|
311
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
301
312
|
} else {
|
|
302
|
-
this.StatusLowBattery = this.
|
|
313
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
303
314
|
}
|
|
304
315
|
this.debugLog(
|
|
305
316
|
`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, ` + `StatusLowBattery: ${this.StatusLowBattery}`,
|
|
@@ -441,7 +452,7 @@ export class Contact {
|
|
|
441
452
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
442
453
|
} else {
|
|
443
454
|
this.accessory.context.ContactSensorState = this.ContactSensorState;
|
|
444
|
-
this.contactSensorservice.updateCharacteristic(this.
|
|
455
|
+
this.contactSensorservice.updateCharacteristic(this.hap.Characteristic.ContactSensorState, this.ContactSensorState);
|
|
445
456
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ContactSensorState: ${this.ContactSensorState}`);
|
|
446
457
|
}
|
|
447
458
|
if (!this.device.contact?.hide_motionsensor) {
|
|
@@ -449,7 +460,7 @@ export class Contact {
|
|
|
449
460
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
450
461
|
} else {
|
|
451
462
|
this.accessory.context.MotionDetected = this.MotionDetected;
|
|
452
|
-
this.motionService?.updateCharacteristic(this.
|
|
463
|
+
this.motionService?.updateCharacteristic(this.hap.Characteristic.MotionDetected, this.MotionDetected);
|
|
453
464
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`);
|
|
454
465
|
}
|
|
455
466
|
}
|
|
@@ -458,7 +469,7 @@ export class Contact {
|
|
|
458
469
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
459
470
|
} else {
|
|
460
471
|
this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
|
|
461
|
-
this.lightSensorService?.updateCharacteristic(this.
|
|
472
|
+
this.lightSensorService?.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
|
|
462
473
|
this.debugLog(
|
|
463
474
|
`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
464
475
|
` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
@@ -469,14 +480,14 @@ export class Contact {
|
|
|
469
480
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
470
481
|
} else {
|
|
471
482
|
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
472
|
-
this.batteryService?.updateCharacteristic(this.
|
|
483
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
473
484
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
474
485
|
}
|
|
475
486
|
if (this.StatusLowBattery === undefined) {
|
|
476
487
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
477
488
|
} else {
|
|
478
489
|
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
479
|
-
this.batteryService?.updateCharacteristic(this.
|
|
490
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
480
491
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
481
492
|
}
|
|
482
493
|
}
|
|
@@ -599,15 +610,15 @@ export class Contact {
|
|
|
599
610
|
}
|
|
600
611
|
|
|
601
612
|
async apiError(e: any): Promise<void> {
|
|
602
|
-
this.contactSensorservice.updateCharacteristic(this.
|
|
613
|
+
this.contactSensorservice.updateCharacteristic(this.hap.Characteristic.ContactSensorState, e);
|
|
603
614
|
if (!this.device.contact?.hide_motionsensor) {
|
|
604
|
-
this.motionService?.updateCharacteristic(this.
|
|
615
|
+
this.motionService?.updateCharacteristic(this.hap.Characteristic.MotionDetected, e);
|
|
605
616
|
}
|
|
606
617
|
if (!this.device.contact?.hide_lightsensor) {
|
|
607
|
-
this.lightSensorService?.updateCharacteristic(this.
|
|
618
|
+
this.lightSensorService?.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e);
|
|
608
619
|
}
|
|
609
|
-
this.batteryService?.updateCharacteristic(this.
|
|
610
|
-
this.batteryService?.updateCharacteristic(this.
|
|
620
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
621
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
611
622
|
}
|
|
612
623
|
|
|
613
624
|
async context() {
|
|
@@ -617,7 +628,7 @@ export class Contact {
|
|
|
617
628
|
this.MotionDetected = this.accessory.context.MotionDetected;
|
|
618
629
|
}
|
|
619
630
|
if (this.ContactSensorState === undefined) {
|
|
620
|
-
this.ContactSensorState = this.
|
|
631
|
+
this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
621
632
|
} else {
|
|
622
633
|
this.ContactSensorState = this.accessory.context.ContactSensorState;
|
|
623
634
|
}
|
|
@@ -637,7 +648,7 @@ export class Contact {
|
|
|
637
648
|
}
|
|
638
649
|
}
|
|
639
650
|
|
|
640
|
-
async
|
|
651
|
+
async devicedeviceConfig(device: device & devicesConfig): Promise<void> {
|
|
641
652
|
let config = {};
|
|
642
653
|
if (device.contact) {
|
|
643
654
|
config = device.contact;
|
|
@@ -662,7 +673,7 @@ export class Contact {
|
|
|
662
673
|
}
|
|
663
674
|
}
|
|
664
675
|
|
|
665
|
-
async
|
|
676
|
+
async devicedeviceLogs(device: device & devicesConfig): Promise<void> {
|
|
666
677
|
if (this.platform.debugMode) {
|
|
667
678
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
668
679
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|