@switchbot/homebridge-switchbot 3.5.0-beta.3 → 3.5.0-beta.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -1
- package/config.schema.json +147 -9
- package/dist/device/blindtilt.d.ts +21 -94
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +347 -756
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +25 -71
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +582 -759
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -67
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +209 -587
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +13 -74
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +250 -632
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +14 -65
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +204 -531
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +17 -86
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +335 -786
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +59 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +646 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/fan.d.ts +51 -0
- package/dist/device/fan.d.ts.map +1 -0
- package/dist/device/fan.js +499 -0
- package/dist/device/fan.js.map +1 -0
- package/dist/device/hub.d.ts +15 -59
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +242 -596
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +10 -65
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +207 -571
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +11 -64
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +174 -584
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -68
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +252 -568
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +15 -62
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +210 -542
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +13 -63
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +170 -577
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +13 -64
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +159 -577
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +13 -69
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +136 -518
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -57
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +82 -452
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -62
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +140 -451
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +9 -70
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +121 -664
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -48
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +309 -419
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +7 -38
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +72 -304
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +6 -35
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +34 -278
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +6 -39
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +67 -311
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +40 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +509 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +6 -34
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +23 -272
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +18 -47
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +352 -546
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +7 -39
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +82 -321
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +6 -35
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +41 -284
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +6 -35
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +42 -287
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +14 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +237 -94
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +40 -10
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +0 -552
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +77 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +638 -1
- package/dist/utils.js.map +1 -1
- package/package.json +16 -15
- package/src/custom.d.ts +2 -1
- package/src/device/blindtilt.ts +373 -782
- package/src/device/bot.ts +616 -844
- package/src/device/ceilinglight.ts +222 -607
- package/src/device/colorbulb.ts +264 -656
- package/src/device/contact.ts +229 -553
- package/src/device/curtain.ts +355 -810
- package/src/device/device.ts +673 -0
- package/src/device/fan.ts +548 -0
- package/src/device/hub.ts +268 -623
- package/src/device/humidifier.ts +237 -618
- package/src/device/iosensor.ts +200 -610
- package/src/device/lightstrip.ts +273 -596
- package/src/device/lock.ts +247 -582
- package/src/device/meter.ts +196 -601
- package/src/device/meterplus.ts +184 -602
- package/src/device/motion.ts +156 -541
- package/src/device/plug.ts +92 -480
- package/src/device/robotvacuumcleaner.ts +161 -477
- package/src/device/waterdetector.ts +139 -689
- package/src/index.ts +1 -1
- package/src/irdevice/airconditioner.ts +330 -446
- package/src/irdevice/airpurifier.ts +89 -321
- package/src/irdevice/camera.ts +42 -293
- package/src/irdevice/fan.ts +78 -327
- package/src/irdevice/irdevice.ts +526 -0
- package/src/irdevice/light.ts +32 -287
- package/src/irdevice/other.ts +396 -615
- package/src/irdevice/tv.ts +100 -339
- package/src/irdevice/vacuumcleaner.ts +49 -305
- package/src/irdevice/waterheater.ts +50 -310
- package/src/platform.ts +247 -102
- package/src/settings.ts +56 -565
- package/src/utils.ts +642 -1
package/src/device/contact.ts
CHANGED
|
@@ -1,185 +1,163 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* contact.ts: @switchbot/homebridge-switchbot.
|
|
4
|
+
*/
|
|
5
|
+
import { deviceBase } from './device.js';
|
|
3
6
|
import { interval, Subject } from 'rxjs';
|
|
4
7
|
import { skipWhile } from 'rxjs/operators';
|
|
5
8
|
import { SwitchBotPlatform } from '../platform.js';
|
|
6
|
-
import { Service, PlatformAccessory, CharacteristicValue
|
|
7
|
-
import { device, devicesConfig, serviceData, deviceStatus, Devices
|
|
9
|
+
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
10
|
+
import { device, devicesConfig, serviceData, deviceStatus, Devices } from '../settings.js';
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
13
|
* Platform Accessory
|
|
11
14
|
* An instance of this class is created for each accessory your platform registers
|
|
12
15
|
* Each accessory may expose multiple services of different service types.
|
|
13
16
|
*/
|
|
14
|
-
export class Contact {
|
|
15
|
-
public readonly api: API;
|
|
16
|
-
public readonly log: Logging;
|
|
17
|
-
public readonly config!: SwitchBotPlatformConfig;
|
|
18
|
-
protected readonly hap: HAP;
|
|
17
|
+
export class Contact extends deviceBase {
|
|
19
18
|
// Services
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// BLE Status
|
|
41
|
-
BLE_BatteryLevel!: serviceData['battery'];
|
|
42
|
-
BLE_MotionDetected!: serviceData['movement'];
|
|
43
|
-
BLE_ContactSensorState!: serviceData['doorState'];
|
|
44
|
-
BLE_CurrentAmbientLightLevel: serviceData['lightLevel'];
|
|
45
|
-
|
|
46
|
-
// BLE Others
|
|
47
|
-
scanning!: boolean;
|
|
48
|
-
BLE_IsConnected?: boolean;
|
|
49
|
-
|
|
50
|
-
// Config
|
|
51
|
-
set_minLux!: number;
|
|
52
|
-
set_maxLux!: number;
|
|
53
|
-
scanDuration!: number;
|
|
54
|
-
deviceLogging!: string;
|
|
55
|
-
deviceRefreshRate!: number;
|
|
19
|
+
private ContactSensor!: {
|
|
20
|
+
Service: Service;
|
|
21
|
+
ContactSensorState: CharacteristicValue;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
private MotionSensor?: {
|
|
25
|
+
Service: Service;
|
|
26
|
+
MotionDetected: CharacteristicValue;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
private LightSensor?: {
|
|
30
|
+
Service: Service;
|
|
31
|
+
CurrentAmbientLightLevel: CharacteristicValue;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
private Battery!: {
|
|
35
|
+
Service: Service;
|
|
36
|
+
BatteryLevel: CharacteristicValue;
|
|
37
|
+
StatusLowBattery: CharacteristicValue;
|
|
38
|
+
};
|
|
56
39
|
|
|
57
40
|
// Updates
|
|
58
|
-
|
|
41
|
+
contactUpdateInProgress!: boolean;
|
|
59
42
|
doContactUpdate!: Subject<void>;
|
|
60
43
|
|
|
61
|
-
// Connection
|
|
62
|
-
private readonly OpenAPI: boolean;
|
|
63
|
-
private readonly BLE: boolean;
|
|
64
|
-
|
|
65
44
|
constructor(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
45
|
+
readonly platform: SwitchBotPlatform,
|
|
46
|
+
accessory: PlatformAccessory,
|
|
47
|
+
device: device & devicesConfig,
|
|
69
48
|
) {
|
|
70
|
-
|
|
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';
|
|
77
|
-
// default placeholders
|
|
78
|
-
this.deviceLogs(device);
|
|
79
|
-
this.scan(device);
|
|
80
|
-
this.refreshRate(device);
|
|
81
|
-
this.deviceContext();
|
|
82
|
-
this.deviceConfig(device);
|
|
83
|
-
|
|
49
|
+
super(platform, accessory, device);
|
|
84
50
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
85
51
|
this.doContactUpdate = new Subject();
|
|
86
|
-
this.
|
|
52
|
+
this.contactUpdateInProgress = false;
|
|
53
|
+
|
|
54
|
+
// Initialize Contact Sensor property
|
|
55
|
+
this.ContactSensor = {
|
|
56
|
+
Service: accessory.getService(this.hap.Service.ContactSensor)!,
|
|
57
|
+
ContactSensorState: this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// Initialize Motion Sensor property
|
|
61
|
+
if (!this.device.contact?.hide_motionsensor) {
|
|
62
|
+
this.MotionSensor = {
|
|
63
|
+
Service: accessory.getService(this.hap.Service.MotionSensor)!,
|
|
64
|
+
MotionDetected: false,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Initialize Light Sensor property
|
|
69
|
+
if (!this.device.contact?.hide_lightsensor) {
|
|
70
|
+
this.LightSensor = {
|
|
71
|
+
Service: accessory.getService(this.hap.Service.LightSensor)!,
|
|
72
|
+
CurrentAmbientLightLevel: 0,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
87
75
|
|
|
88
76
|
// Retrieve initial values and updateHomekit
|
|
89
77
|
this.refreshStatus();
|
|
90
78
|
|
|
91
|
-
// set accessory information
|
|
92
|
-
accessory
|
|
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);
|
|
98
|
-
|
|
99
79
|
// get the Contact service if it exists, otherwise create a new Contact service
|
|
100
80
|
// you can create multiple services for each accessory
|
|
101
|
-
const
|
|
102
|
-
(this.
|
|
103
|
-
|| accessory.addService(this.hap.Service.ContactSensor)),
|
|
81
|
+
const ContactSensorService = `${accessory.displayName} Contact Sensor`;
|
|
82
|
+
(this.ContactSensor.Service = accessory.getService(this.hap.Service.ContactSensor)
|
|
83
|
+
|| accessory.addService(this.hap.Service.ContactSensor)), ContactSensorService;
|
|
104
84
|
|
|
105
|
-
this.
|
|
106
|
-
if (!this.contactSensorservice.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
107
|
-
this.contactSensorservice.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
108
|
-
}
|
|
85
|
+
this.ContactSensor.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
109
86
|
|
|
110
87
|
// Motion Sensor Service
|
|
111
88
|
if (device.contact?.hide_motionsensor) {
|
|
112
|
-
this.debugLog(`${
|
|
113
|
-
this.
|
|
114
|
-
accessory.removeService(this.
|
|
115
|
-
} else if (!this.
|
|
116
|
-
this.debugLog(`${
|
|
117
|
-
const
|
|
118
|
-
(this.
|
|
119
|
-
||
|
|
120
|
-
|
|
121
|
-
this.
|
|
122
|
-
this.motionService.setCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Motion Sensor`);
|
|
89
|
+
this.debugLog(`${device.deviceType}: ${accessory.displayName} Removing Motion Sensor Service`);
|
|
90
|
+
this.MotionSensor!.Service = accessory.getService(this.hap.Service.MotionSensor) as Service;
|
|
91
|
+
accessory.removeService(this.MotionSensor!.Service);
|
|
92
|
+
} else if (!this.MotionSensor?.Service && !device.contact?.hide_motionsensor) {
|
|
93
|
+
this.debugLog(`${device.deviceType}: ${accessory.displayName} Add Motion Sensor Service`);
|
|
94
|
+
const MotionService = `${accessory.displayName} Motion Sensor`;
|
|
95
|
+
(this.MotionSensor!.Service = accessory.getService(this.hap.Service.MotionSensor)
|
|
96
|
+
|| accessory.addService(this.hap.Service.MotionSensor)), MotionService;
|
|
97
|
+
|
|
98
|
+
this.MotionSensor!.Service.setCharacteristic(this.hap.Characteristic.Name, MotionService);
|
|
123
99
|
} else {
|
|
124
|
-
this.debugLog(`${
|
|
100
|
+
this.debugLog(`${device.deviceType}: ${accessory.displayName} Motion Sensor Service Not Added`);
|
|
125
101
|
}
|
|
126
102
|
|
|
127
103
|
// Light Sensor Service
|
|
128
104
|
if (device.contact?.hide_lightsensor) {
|
|
129
105
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
|
|
130
|
-
this.
|
|
131
|
-
accessory.removeService(this.
|
|
132
|
-
} else if (!this.
|
|
106
|
+
this.LightSensor!.Service = accessory.getService(this.hap.Service.LightSensor) as Service;
|
|
107
|
+
accessory.removeService(this.LightSensor!.Service);
|
|
108
|
+
} else if (!this.LightSensor?.Service && !device.contact?.hide_lightsensor) {
|
|
133
109
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
|
|
134
110
|
|
|
135
|
-
const
|
|
136
|
-
(this.
|
|
137
|
-
|| this.accessory.addService(this.hap.Service.LightSensor)),
|
|
111
|
+
const LightSensorService = `${accessory.displayName} Light Sensor`;
|
|
112
|
+
(this.LightSensor!.Service = this.accessory.getService(this.hap.Service.LightSensor)
|
|
113
|
+
|| this.accessory.addService(this.hap.Service.LightSensor)), LightSensorService;
|
|
138
114
|
|
|
139
|
-
this.
|
|
140
|
-
this.lightSensorService.setCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Light Sensor`);
|
|
115
|
+
this.LightSensor!.Service.setCharacteristic(this.hap.Characteristic.Name, LightSensorService);
|
|
141
116
|
} else {
|
|
142
117
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Light Sensor Service Not Added`);
|
|
143
118
|
}
|
|
144
119
|
|
|
145
120
|
// Battery Service
|
|
146
|
-
const
|
|
147
|
-
(this.
|
|
148
|
-
|| accessory.addService(this.hap.Service.Battery)),
|
|
121
|
+
const BatteryService = `${accessory.displayName} Battery`;
|
|
122
|
+
(this.Battery.Service = this.accessory.getService(this.hap.Service.Battery)
|
|
123
|
+
|| accessory.addService(this.hap.Service.Battery)), BatteryService;
|
|
149
124
|
|
|
150
|
-
this.
|
|
151
|
-
|
|
152
|
-
this.batteryService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
153
|
-
}
|
|
154
|
-
this.batteryService.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
125
|
+
this.Battery.Service.setCharacteristic(this.hap.Characteristic.Name, BatteryService);
|
|
126
|
+
this.Battery.Service.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
155
127
|
|
|
156
128
|
// Retrieve initial values and updateHomekit
|
|
157
129
|
this.updateHomeKitCharacteristics();
|
|
158
130
|
|
|
159
131
|
// Start an update interval
|
|
160
132
|
interval(this.deviceRefreshRate * 1000)
|
|
161
|
-
.pipe(skipWhile(() => this.
|
|
133
|
+
.pipe(skipWhile(() => this.contactUpdateInProgress))
|
|
162
134
|
.subscribe(async () => {
|
|
163
135
|
await this.refreshStatus();
|
|
164
136
|
});
|
|
165
137
|
|
|
166
138
|
//regisiter webhook event handler
|
|
167
|
-
if (
|
|
168
|
-
this.
|
|
139
|
+
if (device.webhook) {
|
|
140
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
|
|
169
141
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
170
142
|
try {
|
|
171
143
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
172
144
|
const { detectionState, brightness, openState } = context;
|
|
173
|
-
const {
|
|
145
|
+
const { ContactSensorState } = this.ContactSensor;
|
|
146
|
+
const { CurrentAmbientLightLevel } = this.LightSensor || {};
|
|
147
|
+
const { MotionDetected } = this.MotionSensor || {};
|
|
174
148
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
175
149
|
'(detectionState, brightness, openState) = ' +
|
|
176
150
|
`Webhook:(${detectionState}, ${brightness}, ${openState}), ` +
|
|
177
151
|
`current:(${MotionDetected}, ${CurrentAmbientLightLevel}, ${ContactSensorState})`);
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
this.
|
|
181
|
-
|
|
182
|
-
|
|
152
|
+
const set_minLux = await this.minLux();
|
|
153
|
+
const set_maxLux = await this.maxLux();
|
|
154
|
+
this.ContactSensor.ContactSensorState = openState === 'open' ? 1 : 0;
|
|
155
|
+
if (!this.device.contact?.hide_motionsensor) {
|
|
156
|
+
this.MotionSensor!.MotionDetected = detectionState === 'DETECTED' ? true : false;
|
|
157
|
+
}
|
|
158
|
+
if (!this.device.contact?.hide_lightsensor) {
|
|
159
|
+
this.LightSensor!.CurrentAmbientLightLevel = brightness === 'bright' ? set_maxLux : set_minLux;
|
|
160
|
+
}
|
|
183
161
|
this.updateHomeKitCharacteristics();
|
|
184
162
|
} catch (e: any) {
|
|
185
163
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
@@ -189,136 +167,124 @@ export class Contact {
|
|
|
189
167
|
}
|
|
190
168
|
}
|
|
191
169
|
|
|
192
|
-
|
|
193
|
-
* Parse the device status from the SwitchBot api
|
|
194
|
-
*/
|
|
195
|
-
async parseStatus(): Promise<void> {
|
|
196
|
-
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
197
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
198
|
-
} else if (this.BLE) {
|
|
199
|
-
await this.BLEparseStatus();
|
|
200
|
-
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
201
|
-
await this.openAPIparseStatus();
|
|
202
|
-
} else {
|
|
203
|
-
await this.offlineOff();
|
|
204
|
-
this.debugWarnLog(
|
|
205
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
async BLEparseStatus(): Promise<void> {
|
|
170
|
+
async BLEparseStatus(serviceData: serviceData): Promise<void> {
|
|
211
171
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
212
172
|
// Door State
|
|
213
|
-
switch (
|
|
173
|
+
switch (serviceData.doorState) {
|
|
214
174
|
case 'open':
|
|
215
175
|
case 1:
|
|
216
|
-
this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
|
|
176
|
+
this.ContactSensor.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
|
|
217
177
|
break;
|
|
218
178
|
case 'close':
|
|
219
179
|
case 0:
|
|
220
|
-
this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
180
|
+
this.ContactSensor.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
221
181
|
break;
|
|
222
182
|
default:
|
|
223
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} timeout no closed, doorstate: ${
|
|
183
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} timeout no closed, doorstate: ${serviceData.doorState}`);
|
|
224
184
|
}
|
|
225
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
185
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensor.ContactSensorState}`);
|
|
226
186
|
if (
|
|
227
|
-
this.ContactSensorState !== this.accessory.context.ContactSensorState &&
|
|
187
|
+
this.ContactSensor.ContactSensorState !== this.accessory.context.ContactSensorState &&
|
|
228
188
|
this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
|
|
229
189
|
) {
|
|
230
190
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Opened`);
|
|
231
191
|
}
|
|
232
192
|
// Movement
|
|
233
193
|
if (!this.device.contact?.hide_motionsensor) {
|
|
234
|
-
this.MotionDetected = Boolean(
|
|
235
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
236
|
-
if (this.MotionDetected !== this.accessory.context.MotionDetected && this.MotionDetected) {
|
|
194
|
+
this.MotionSensor!.MotionDetected = Boolean(serviceData.movement);
|
|
195
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionSensor!.MotionDetected}`);
|
|
196
|
+
if (this.MotionSensor!.MotionDetected !== this.accessory.context.MotionDetected && this.MotionSensor!.MotionDetected) {
|
|
237
197
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Detected Motion`);
|
|
238
198
|
}
|
|
239
199
|
}
|
|
240
200
|
// Light Level
|
|
241
201
|
if (!this.device.contact?.hide_lightsensor) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
switch (
|
|
202
|
+
const set_minLux = await this.minLux();
|
|
203
|
+
const set_maxLux = await this.maxLux();
|
|
204
|
+
switch (serviceData.lightLevel) {
|
|
245
205
|
case true:
|
|
246
|
-
this.CurrentAmbientLightLevel =
|
|
206
|
+
this.LightSensor!.CurrentAmbientLightLevel = set_minLux;
|
|
247
207
|
break;
|
|
248
208
|
default:
|
|
249
|
-
this.CurrentAmbientLightLevel =
|
|
209
|
+
this.LightSensor!.CurrentAmbientLightLevel = set_maxLux;
|
|
250
210
|
}
|
|
251
211
|
this.debugLog(
|
|
252
|
-
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${
|
|
253
|
-
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
212
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel},` +
|
|
213
|
+
` CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`,
|
|
254
214
|
);
|
|
255
|
-
if (this.CurrentAmbientLightLevel !== this.accessory.context.CurrentAmbientLightLevel) {
|
|
256
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
215
|
+
if (this.LightSensor!.CurrentAmbientLightLevel !== this.accessory.context.CurrentAmbientLightLevel) {
|
|
216
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
217
|
+
+ ` CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
|
|
257
218
|
}
|
|
258
219
|
}
|
|
259
220
|
// Battery
|
|
260
|
-
if (
|
|
261
|
-
|
|
221
|
+
if (serviceData.battery === undefined) {
|
|
222
|
+
serviceData.battery === 100;
|
|
262
223
|
}
|
|
263
|
-
this.BatteryLevel = Number(
|
|
264
|
-
if (this.BatteryLevel < 10) {
|
|
265
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
224
|
+
this.Battery.BatteryLevel = Number(serviceData.battery);
|
|
225
|
+
if (this.Battery.BatteryLevel < 10) {
|
|
226
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
266
227
|
} else {
|
|
267
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
228
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
268
229
|
}
|
|
269
230
|
this.debugLog(
|
|
270
|
-
`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, `
|
|
231
|
+
`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}, `
|
|
232
|
+
+ `StatusLowBattery: ${this.Battery.StatusLowBattery}`,
|
|
271
233
|
);
|
|
272
234
|
}
|
|
273
235
|
|
|
274
|
-
async openAPIparseStatus(): Promise<void> {
|
|
236
|
+
async openAPIparseStatus(deviceStatus: deviceStatus): Promise<void> {
|
|
275
237
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
276
238
|
// Contact State
|
|
277
|
-
if (
|
|
278
|
-
this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
|
|
279
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
280
|
-
} else if (
|
|
281
|
-
this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
282
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
239
|
+
if (deviceStatus.body.openState === 'open') {
|
|
240
|
+
this.ContactSensor.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
|
|
241
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensor.ContactSensorState}`);
|
|
242
|
+
} else if (deviceStatus.body.openState === 'close') {
|
|
243
|
+
this.ContactSensor.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
244
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensor.ContactSensorState}`);
|
|
283
245
|
} else {
|
|
284
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openState: ${
|
|
246
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openState: ${deviceStatus.body.openState}`);
|
|
285
247
|
}
|
|
286
248
|
// Motion State
|
|
287
249
|
if (!this.device.contact?.hide_motionsensor) {
|
|
288
|
-
this.MotionDetected =
|
|
289
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
250
|
+
this.MotionSensor!.MotionDetected = deviceStatus.body.moveDetected!;
|
|
251
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionSensor!.MotionDetected}`);
|
|
290
252
|
}
|
|
291
253
|
// Light Level
|
|
292
254
|
if (!this.device.contact?.hide_lightsensor) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
switch (
|
|
255
|
+
const set_minLux = await this.minLux();
|
|
256
|
+
const set_maxLux = await this.maxLux();
|
|
257
|
+
switch (deviceStatus.body.brightness) {
|
|
296
258
|
case 'dim':
|
|
297
|
-
this.CurrentAmbientLightLevel =
|
|
259
|
+
this.LightSensor!.CurrentAmbientLightLevel = set_minLux;
|
|
298
260
|
break;
|
|
299
261
|
case 'bright':
|
|
300
262
|
default:
|
|
301
|
-
this.CurrentAmbientLightLevel =
|
|
263
|
+
this.LightSensor!.CurrentAmbientLightLevel = set_maxLux;
|
|
302
264
|
}
|
|
303
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
265
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
266
|
+
+ ` CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
|
|
304
267
|
}
|
|
305
268
|
// Battery
|
|
306
|
-
if (
|
|
307
|
-
|
|
269
|
+
if (deviceStatus.body.battery === undefined) {
|
|
270
|
+
deviceStatus.body.battery === 100;
|
|
308
271
|
}
|
|
309
|
-
this.BatteryLevel = Number(
|
|
310
|
-
if (this.BatteryLevel < 10) {
|
|
311
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
272
|
+
this.Battery.BatteryLevel = Number(deviceStatus.body.battery);
|
|
273
|
+
if (this.Battery.BatteryLevel < 10) {
|
|
274
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
312
275
|
} else {
|
|
313
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
276
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
314
277
|
}
|
|
315
|
-
this.debugLog(
|
|
316
|
-
|
|
317
|
-
);
|
|
278
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}, `
|
|
279
|
+
+ `StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
318
280
|
|
|
319
281
|
// FirmwareRevision
|
|
320
|
-
this.FirmwareRevision =
|
|
321
|
-
this.accessory
|
|
282
|
+
this.accessory.context.FirmwareRevision = deviceStatus.body.version;
|
|
283
|
+
this.accessory
|
|
284
|
+
.getService(this.hap.Service.AccessoryInformation)!
|
|
285
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, this.accessory.context.FirmwareRevision)
|
|
286
|
+
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
287
|
+
.updateValue(this.accessory.context.FirmwareRevision);
|
|
322
288
|
}
|
|
323
289
|
|
|
324
290
|
/**
|
|
@@ -344,119 +310,59 @@ export class Contact {
|
|
|
344
310
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
|
|
345
311
|
const switchbot = await this.platform.connectBLE();
|
|
346
312
|
// Convert to BLE Address
|
|
347
|
-
this.device.bleMac =
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
.join(':')
|
|
352
|
-
.toLowerCase();
|
|
313
|
+
this.device.bleMac = this.device
|
|
314
|
+
.deviceId!.match(/.{1,2}/g)!
|
|
315
|
+
.join(':')
|
|
316
|
+
.toLowerCase();
|
|
353
317
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
354
318
|
this.getCustomBLEAddress(switchbot);
|
|
355
319
|
// Start to monitor advertisement packets
|
|
356
320
|
(async () => {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
id: this.device.bleMac,
|
|
360
|
-
});
|
|
321
|
+
// Start to monitor advertisement packets
|
|
322
|
+
await switchbot.startScan({ model: this.device.bleModel, id: this.device.bleMac });
|
|
361
323
|
// Set an event handler
|
|
362
324
|
switchbot.onadvertisement = (ad: any) => {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
325
|
+
if (this.device.bleMac === ad.address && ad.model === this.device.bleModel) {
|
|
326
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
|
|
327
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
|
|
366
328
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
367
|
-
this.BLE_MotionDetected = ad.serviceData.movement;
|
|
368
|
-
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
369
|
-
this.BLE_CurrentAmbientLightLevel = ad.serviceData.lightLevel;
|
|
370
329
|
} else {
|
|
371
330
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
372
331
|
}
|
|
373
332
|
};
|
|
374
|
-
// Wait
|
|
333
|
+
// Wait 10 seconds
|
|
375
334
|
await switchbot.wait(this.scanDuration * 1000);
|
|
376
335
|
// Stop to monitor
|
|
377
336
|
await switchbot.stopScan();
|
|
378
337
|
// Update HomeKit
|
|
379
|
-
await this.BLEparseStatus();
|
|
338
|
+
await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
|
|
380
339
|
await this.updateHomeKitCharacteristics();
|
|
381
340
|
})();
|
|
382
|
-
|
|
383
|
-
await switchbot
|
|
384
|
-
.startScan({
|
|
385
|
-
model: 'd',
|
|
386
|
-
id: this.device.bleMac,
|
|
387
|
-
})
|
|
388
|
-
.then(async () => {
|
|
389
|
-
// Set an event handler
|
|
390
|
-
this.scanning = true;
|
|
391
|
-
switchbot.onadvertisement = async (ad: ad) => {
|
|
392
|
-
this.debugLog(
|
|
393
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
394
|
-
` BLE Address Found: ${ad.address}`,
|
|
395
|
-
);
|
|
396
|
-
this.BLE_MotionDetected = ad.serviceData.movement;
|
|
397
|
-
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
398
|
-
this.BLE_ContactSensorState = ad.serviceData.doorState;
|
|
399
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
400
|
-
this.debugLog(
|
|
401
|
-
`${this.device.deviceType}: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, doorState: ` +
|
|
402
|
-
`${ad.serviceData.doorState}, battery: ${ad.serviceData.battery}`,
|
|
403
|
-
);
|
|
404
|
-
|
|
405
|
-
if (ad.serviceData) {
|
|
406
|
-
this.BLE_IsConnected = true;
|
|
407
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
408
|
-
await this.stopScanning(switchbot);
|
|
409
|
-
this.scanning = false;
|
|
410
|
-
} else {
|
|
411
|
-
this.BLE_IsConnected = false;
|
|
412
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
413
|
-
}
|
|
414
|
-
};
|
|
415
|
-
// Wait
|
|
416
|
-
return await sleep(this.scanDuration * 1000);
|
|
417
|
-
})
|
|
418
|
-
.then(async () => {
|
|
419
|
-
// Stop to monitor
|
|
420
|
-
if (this.scanning) {
|
|
421
|
-
await this.stopScanning(switchbot);
|
|
422
|
-
}
|
|
423
|
-
})
|
|
424
|
-
.catch(async (e: any) => {
|
|
425
|
-
this.apiError(e);
|
|
426
|
-
this.errorLog(
|
|
427
|
-
`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
|
|
428
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
429
|
-
);
|
|
430
|
-
await this.BLERefreshConnection(switchbot);
|
|
431
|
-
});
|
|
432
|
-
} else {
|
|
341
|
+
if (switchbot === undefined) {
|
|
433
342
|
await this.BLERefreshConnection(switchbot);
|
|
434
|
-
}
|
|
343
|
+
}
|
|
435
344
|
}
|
|
436
345
|
|
|
437
346
|
async openAPIRefreshStatus(): Promise<void> {
|
|
438
347
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
439
348
|
try {
|
|
440
|
-
const { body, statusCode } = await
|
|
441
|
-
headers: this.platform.generateHeaders()
|
|
442
|
-
});
|
|
349
|
+
const { body, statusCode } = await this.platform.retryRequest(this.deviceMaxRetries, this.deviceDelayBetweenRetries,
|
|
350
|
+
`${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
|
|
443
351
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
444
352
|
const deviceStatus: any = await body.json();
|
|
445
353
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
446
354
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
447
355
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
448
|
-
this.
|
|
356
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
449
357
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
450
|
-
this.
|
|
451
|
-
this.OpenAPI_MotionDetected = deviceStatus.body.moveDetected;
|
|
452
|
-
this.OpenAPI_CurrentAmbientLightLevel = deviceStatus.body.brightness;
|
|
453
|
-
this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
|
|
454
|
-
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
455
|
-
this.openAPIparseStatus();
|
|
358
|
+
this.openAPIparseStatus(deviceStatus);
|
|
456
359
|
this.updateHomeKitCharacteristics();
|
|
457
360
|
} else {
|
|
458
361
|
this.statusCode(statusCode);
|
|
459
362
|
this.statusCode(deviceStatus.statusCode);
|
|
363
|
+
if (deviceStatus.statusCode === 161 || deviceStatus.statusCode === 171) {
|
|
364
|
+
this.offlineOff();
|
|
365
|
+
}
|
|
460
366
|
}
|
|
461
367
|
} catch (e: any) {
|
|
462
368
|
this.apiError(e);
|
|
@@ -471,75 +377,51 @@ export class Contact {
|
|
|
471
377
|
* Updates the status for each of the HomeKit Characteristics
|
|
472
378
|
*/
|
|
473
379
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
474
|
-
if (this.ContactSensorState === undefined) {
|
|
475
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
380
|
+
if (this.ContactSensor.ContactSensorState === undefined) {
|
|
381
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensor.ContactSensorState}`);
|
|
476
382
|
} else {
|
|
477
|
-
this.accessory.context.ContactSensorState = this.ContactSensorState;
|
|
478
|
-
this.
|
|
479
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
383
|
+
this.accessory.context.ContactSensorState = this.ContactSensor.ContactSensorState;
|
|
384
|
+
this.ContactSensor.Service.updateCharacteristic(this.hap.Characteristic.ContactSensorState, this.ContactSensor.ContactSensorState);
|
|
385
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
386
|
+
+ ` ContactSensorState: ${this.ContactSensor.ContactSensorState}`);
|
|
480
387
|
}
|
|
481
388
|
if (!this.device.contact?.hide_motionsensor) {
|
|
482
|
-
if (this.MotionDetected === undefined) {
|
|
483
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
389
|
+
if (this.MotionSensor!.MotionDetected === undefined) {
|
|
390
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionSensor!.MotionDetected}`);
|
|
484
391
|
} else {
|
|
485
|
-
this.accessory.context.MotionDetected = this.MotionDetected;
|
|
486
|
-
this.
|
|
487
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
392
|
+
this.accessory.context.MotionDetected = this.MotionSensor!.MotionDetected;
|
|
393
|
+
this.MotionSensor!.Service.updateCharacteristic(this.hap.Characteristic.MotionDetected, this.MotionSensor!.MotionDetected);
|
|
394
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
395
|
+
+ ` MotionDetected: ${this.MotionSensor!.MotionDetected}`);
|
|
488
396
|
}
|
|
489
397
|
}
|
|
490
398
|
if (!this.device.contact?.hide_lightsensor) {
|
|
491
|
-
if (this.CurrentAmbientLightLevel === undefined) {
|
|
492
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
399
|
+
if (this.LightSensor?.CurrentAmbientLightLevel === undefined) {
|
|
400
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
401
|
+
+ ` CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
|
|
493
402
|
} else {
|
|
494
|
-
this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
|
|
495
|
-
this.
|
|
403
|
+
this.accessory.context.CurrentAmbientLightLevel = this.LightSensor.CurrentAmbientLightLevel;
|
|
404
|
+
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.LightSensor.CurrentAmbientLightLevel);
|
|
496
405
|
this.debugLog(
|
|
497
406
|
`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
498
|
-
` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
407
|
+
` updateCharacteristic CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`,
|
|
499
408
|
);
|
|
500
409
|
}
|
|
501
410
|
}
|
|
502
|
-
if (this.BatteryLevel === undefined) {
|
|
503
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
504
|
-
} else {
|
|
505
|
-
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
506
|
-
this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
507
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
508
|
-
}
|
|
509
|
-
if (this.StatusLowBattery === undefined) {
|
|
510
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
411
|
+
if (this.Battery.BatteryLevel === undefined) {
|
|
412
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
511
413
|
} else {
|
|
512
|
-
this.accessory.context.
|
|
513
|
-
this.
|
|
514
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
414
|
+
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
|
|
415
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
416
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
515
417
|
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
async stopScanning(switchbot: any) {
|
|
519
|
-
switchbot.stopScan();
|
|
520
|
-
if (this.BLE_IsConnected) {
|
|
521
|
-
await this.BLEparseStatus();
|
|
522
|
-
await this.updateHomeKitCharacteristics();
|
|
418
|
+
if (this.Battery.StatusLowBattery === undefined) {
|
|
419
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
523
420
|
} else {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
async getCustomBLEAddress(switchbot: any) {
|
|
529
|
-
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
530
|
-
(async () => {
|
|
531
|
-
// Start to monitor advertisement packets
|
|
532
|
-
await switchbot.startScan({
|
|
533
|
-
model: 'd',
|
|
534
|
-
});
|
|
535
|
-
// Set an event handler
|
|
536
|
-
switchbot.onadvertisement = (ad: any) => {
|
|
537
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
538
|
-
};
|
|
539
|
-
await sleep(10000);
|
|
540
|
-
// Stop to monitor
|
|
541
|
-
switchbot.stopScan();
|
|
542
|
-
})();
|
|
421
|
+
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
422
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
423
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
424
|
+
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
543
425
|
}
|
|
544
426
|
}
|
|
545
427
|
|
|
@@ -552,254 +434,48 @@ export class Contact {
|
|
|
552
434
|
}
|
|
553
435
|
}
|
|
554
436
|
|
|
555
|
-
minLux(): number {
|
|
437
|
+
async minLux(): Promise<number> {
|
|
438
|
+
let set_minLux: number;
|
|
556
439
|
if (this.device.contact?.set_minLux) {
|
|
557
|
-
|
|
440
|
+
set_minLux = this.device.contact!.set_minLux!;
|
|
558
441
|
} else {
|
|
559
|
-
|
|
442
|
+
set_minLux = 1;
|
|
560
443
|
}
|
|
561
|
-
return
|
|
444
|
+
return set_minLux;
|
|
562
445
|
}
|
|
563
446
|
|
|
564
|
-
maxLux(): number {
|
|
447
|
+
async maxLux(): Promise<number> {
|
|
448
|
+
let set_maxLux: number;
|
|
565
449
|
if (this.device.contact?.set_maxLux) {
|
|
566
|
-
|
|
567
|
-
} else {
|
|
568
|
-
this.set_maxLux = 6001;
|
|
569
|
-
}
|
|
570
|
-
return this.set_maxLux;
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
async scan(device: device & devicesConfig): Promise<void> {
|
|
574
|
-
if (device.scanDuration) {
|
|
575
|
-
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
576
|
-
if (this.BLE) {
|
|
577
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
578
|
-
}
|
|
450
|
+
set_maxLux = this.device.contact!.set_maxLux!;
|
|
579
451
|
} else {
|
|
580
|
-
|
|
581
|
-
if (this.BLE) {
|
|
582
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
async statusCode(statusCode: number): Promise<void> {
|
|
588
|
-
switch (statusCode) {
|
|
589
|
-
case 151:
|
|
590
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
591
|
-
break;
|
|
592
|
-
case 152:
|
|
593
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
594
|
-
break;
|
|
595
|
-
case 160:
|
|
596
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
597
|
-
break;
|
|
598
|
-
case 161:
|
|
599
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
600
|
-
this.offlineOff();
|
|
601
|
-
break;
|
|
602
|
-
case 171:
|
|
603
|
-
this.errorLog(
|
|
604
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
605
|
-
`Hub: ${this.device.hubDeviceId}`,
|
|
606
|
-
);
|
|
607
|
-
this.offlineOff();
|
|
608
|
-
break;
|
|
609
|
-
case 190:
|
|
610
|
-
this.errorLog(
|
|
611
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
612
|
-
` Or command format is invalid, statusCode: ${statusCode}`,
|
|
613
|
-
);
|
|
614
|
-
break;
|
|
615
|
-
case 100:
|
|
616
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
617
|
-
break;
|
|
618
|
-
case 200:
|
|
619
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
620
|
-
break;
|
|
621
|
-
case 400:
|
|
622
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
623
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
624
|
-
break;
|
|
625
|
-
case 401:
|
|
626
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
627
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
628
|
-
break;
|
|
629
|
-
case 403:
|
|
630
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
631
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
632
|
-
break;
|
|
633
|
-
case 404:
|
|
634
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
635
|
-
+ `statusCode: ${statusCode}`);
|
|
636
|
-
break;
|
|
637
|
-
case 406:
|
|
638
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
639
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
640
|
-
break;
|
|
641
|
-
case 415:
|
|
642
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
643
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
644
|
-
break;
|
|
645
|
-
case 422:
|
|
646
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, `
|
|
647
|
-
+ `but the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
648
|
-
break;
|
|
649
|
-
case 429:
|
|
650
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
651
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
652
|
-
break;
|
|
653
|
-
case 500:
|
|
654
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
655
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
656
|
-
break;
|
|
657
|
-
default:
|
|
658
|
-
this.infoLog(
|
|
659
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
660
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
661
|
-
);
|
|
452
|
+
set_maxLux = 6001;
|
|
662
453
|
}
|
|
454
|
+
return set_maxLux;
|
|
663
455
|
}
|
|
664
456
|
|
|
665
457
|
async offlineOff(): Promise<void> {
|
|
666
458
|
if (this.device.offline) {
|
|
667
|
-
|
|
668
|
-
|
|
459
|
+
this.ContactSensor.Service.updateCharacteristic(this.hap.Characteristic.ContactSensorState,
|
|
460
|
+
this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED);
|
|
461
|
+
if (!this.device.contact?.hide_motionsensor) {
|
|
462
|
+
this.MotionSensor!.Service.updateCharacteristic(this.hap.Characteristic.MotionDetected, false);
|
|
463
|
+
}
|
|
464
|
+
if (!this.device.contact?.hide_lightsensor) {
|
|
465
|
+
this.LightSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, 100);
|
|
466
|
+
}
|
|
669
467
|
}
|
|
670
468
|
}
|
|
671
469
|
|
|
672
470
|
async apiError(e: any): Promise<void> {
|
|
673
|
-
this.
|
|
471
|
+
this.ContactSensor.Service.updateCharacteristic(this.hap.Characteristic.ContactSensorState, e);
|
|
674
472
|
if (!this.device.contact?.hide_motionsensor) {
|
|
675
|
-
this.
|
|
473
|
+
this.MotionSensor!.Service.updateCharacteristic(this.hap.Characteristic.MotionDetected, e);
|
|
676
474
|
}
|
|
677
475
|
if (!this.device.contact?.hide_lightsensor) {
|
|
678
|
-
this.
|
|
679
|
-
}
|
|
680
|
-
this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
681
|
-
this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
async deviceContext() {
|
|
685
|
-
if (this.MotionDetected === undefined) {
|
|
686
|
-
this.MotionDetected = false;
|
|
687
|
-
} else {
|
|
688
|
-
this.MotionDetected = this.accessory.context.MotionDetected;
|
|
689
|
-
}
|
|
690
|
-
if (this.ContactSensorState === undefined) {
|
|
691
|
-
this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
692
|
-
} else {
|
|
693
|
-
this.ContactSensorState = this.accessory.context.ContactSensorState;
|
|
694
|
-
}
|
|
695
|
-
if (this.FirmwareRevision === undefined) {
|
|
696
|
-
this.FirmwareRevision = this.platform.version;
|
|
697
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
async refreshRate(device: device & devicesConfig): Promise<void> {
|
|
702
|
-
if (device.refreshRate) {
|
|
703
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
704
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
705
|
-
} else if (this.platform.config.options!.refreshRate) {
|
|
706
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
707
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
async deviceConfig(device: device & devicesConfig): Promise<void> {
|
|
712
|
-
let config = {};
|
|
713
|
-
if (device.contact) {
|
|
714
|
-
config = device.contact;
|
|
715
|
-
}
|
|
716
|
-
if (device.connectionType !== undefined) {
|
|
717
|
-
config['connectionType'] = device.connectionType;
|
|
718
|
-
}
|
|
719
|
-
if (device.external !== undefined) {
|
|
720
|
-
config['external'] = device.external;
|
|
721
|
-
}
|
|
722
|
-
if (device.logging !== undefined) {
|
|
723
|
-
config['logging'] = device.logging;
|
|
724
|
-
}
|
|
725
|
-
if (device.refreshRate !== undefined) {
|
|
726
|
-
config['refreshRate'] = device.refreshRate;
|
|
727
|
-
}
|
|
728
|
-
if (device.scanDuration !== undefined) {
|
|
729
|
-
config['scanDuration'] = device.scanDuration;
|
|
476
|
+
this.LightSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e);
|
|
730
477
|
}
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
}
|
|
734
|
-
if (Object.entries(config).length !== 0) {
|
|
735
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
async deviceLogs(device: device & devicesConfig): Promise<void> {
|
|
740
|
-
if (this.platform.debugMode) {
|
|
741
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
742
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
743
|
-
} else if (device.logging) {
|
|
744
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
745
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
746
|
-
} else if (this.platform.config.options?.logging) {
|
|
747
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
748
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
749
|
-
} else {
|
|
750
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
751
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
/**
|
|
756
|
-
* Logging for Device
|
|
757
|
-
*/
|
|
758
|
-
infoLog(...log: any[]): void {
|
|
759
|
-
if (this.enablingDeviceLogging()) {
|
|
760
|
-
this.platform.log.info(String(...log));
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
warnLog(...log: any[]): void {
|
|
765
|
-
if (this.enablingDeviceLogging()) {
|
|
766
|
-
this.platform.log.warn(String(...log));
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
debugWarnLog(...log: any[]): void {
|
|
771
|
-
if (this.enablingDeviceLogging()) {
|
|
772
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
773
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
errorLog(...log: any[]): void {
|
|
779
|
-
if (this.enablingDeviceLogging()) {
|
|
780
|
-
this.platform.log.error(String(...log));
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
debugErrorLog(...log: any[]): void {
|
|
785
|
-
if (this.enablingDeviceLogging()) {
|
|
786
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
787
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
debugLog(...log: any[]): void {
|
|
793
|
-
if (this.enablingDeviceLogging()) {
|
|
794
|
-
if (this.deviceLogging === 'debug') {
|
|
795
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
796
|
-
} else {
|
|
797
|
-
this.platform.log.debug(String(...log));
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
enablingDeviceLogging(): boolean {
|
|
803
|
-
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
478
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
479
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
804
480
|
}
|
|
805
481
|
}
|