@switchbot/homebridge-switchbot 3.5.0-beta.7 → 3.5.0-beta.70
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/.vscode/settings.json +4 -1
- package/CHANGELOG.md +4 -1
- package/config.schema.json +120 -17
- package/dist/device/blindtilt.d.ts +23 -96
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +425 -778
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +26 -72
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +803 -837
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +14 -68
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +241 -606
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +14 -75
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +283 -658
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +15 -66
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +254 -545
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +19 -88
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +412 -806
- 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 +711 -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 +540 -0
- package/dist/device/fan.js.map +1 -0
- package/dist/device/hub.d.ts +16 -60
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +261 -616
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +11 -66
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +240 -594
- 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 +196 -600
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +11 -69
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +281 -586
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +16 -63
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +252 -560
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +14 -64
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +191 -593
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +14 -65
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +180 -593
- 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 +188 -532
- 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 +96 -458
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +12 -63
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +202 -521
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +10 -63
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +146 -475
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +22 -16
- package/dist/homebridge-ui/server.js +1 -1
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +10 -50
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +324 -452
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +8 -39
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +93 -307
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +7 -36
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +39 -281
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +10 -43
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +113 -341
- 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 +330 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +12 -45
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +118 -362
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +19 -48
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +438 -570
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -40
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +87 -335
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +7 -36
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +45 -285
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +7 -36
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +47 -291
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +19 -6
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +310 -172
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +62 -19
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +16 -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/eslint.config.js +96 -0
- package/package.json +19 -15
- package/src/custom.d.ts +2 -1
- package/src/device/blindtilt.ts +462 -817
- package/src/device/bot.ts +862 -931
- package/src/device/ceilinglight.ts +259 -633
- package/src/device/colorbulb.ts +300 -688
- package/src/device/contact.ts +288 -571
- package/src/device/curtain.ts +441 -838
- package/src/device/device.ts +734 -0
- package/src/device/fan.ts +596 -0
- package/src/device/hub.ts +299 -645
- package/src/device/humidifier.ts +274 -647
- package/src/device/iosensor.ts +233 -626
- package/src/device/lightstrip.ts +309 -620
- package/src/device/lock.ts +292 -601
- package/src/device/meter.ts +228 -619
- package/src/device/meterplus.ts +216 -619
- package/src/device/motion.ts +218 -559
- package/src/device/plug.ts +111 -490
- package/src/device/robotvacuumcleaner.ts +228 -550
- package/src/device/waterdetector.ts +169 -501
- package/src/homebridge-ui/public/index.html +22 -16
- package/src/homebridge-ui/server.ts +1 -1
- package/src/index.ts +4 -3
- package/src/irdevice/airconditioner.ts +350 -477
- package/src/irdevice/airpurifier.ts +120 -330
- package/src/irdevice/camera.ts +53 -301
- package/src/irdevice/fan.ts +130 -360
- package/src/irdevice/irdevice.ts +346 -0
- package/src/irdevice/light.ts +157 -412
- package/src/irdevice/other.ts +507 -648
- package/src/irdevice/tv.ts +117 -367
- package/src/irdevice/vacuumcleaner.ts +59 -311
- package/src/irdevice/waterheater.ts +61 -320
- package/src/platform.ts +355 -219
- package/src/settings.ts +116 -611
- package/src/utils.ts +642 -1
- package/src/device/waterdetector.json +0 -11
|
@@ -1,115 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* waterdetector.ts: @switchbot/homebridge-switchbot.
|
|
4
|
+
*/
|
|
5
|
+
import { deviceBase } from './device.js';
|
|
5
6
|
import { interval, Subject } from 'rxjs';
|
|
6
|
-
import { skipWhile } from 'rxjs/operators';
|
|
7
7
|
import { Devices } from '../settings.js';
|
|
8
|
+
import { skipWhile } from 'rxjs/operators';
|
|
8
9
|
/**
|
|
9
10
|
* Platform Accessory
|
|
10
11
|
* An instance of this class is created for each accessory your platform registers
|
|
11
12
|
* Each accessory may expose multiple services of different service types.
|
|
12
13
|
*/
|
|
13
|
-
export class WaterDetector {
|
|
14
|
+
export class WaterDetector extends deviceBase {
|
|
14
15
|
platform;
|
|
15
|
-
accessory;
|
|
16
|
-
device;
|
|
17
|
-
api;
|
|
18
|
-
log;
|
|
19
|
-
config;
|
|
20
|
-
hap;
|
|
21
16
|
// Services
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// Characteristic Values
|
|
25
|
-
StatusActive;
|
|
26
|
-
LeakDetected;
|
|
27
|
-
BatteryLevel;
|
|
28
|
-
ChargingState;
|
|
29
|
-
StatusLowBattery;
|
|
30
|
-
FirmwareRevision;
|
|
31
|
-
// OpenAPI Status
|
|
32
|
-
OpenAPI_BatteryLevel;
|
|
33
|
-
OpenAPI_FirmwareRevision;
|
|
34
|
-
OpenAPI_LeakDetected;
|
|
35
|
-
// BLE Status
|
|
36
|
-
BLE_BatteryLevel;
|
|
37
|
-
BLE_LeakDetected; //serviceData['status'];
|
|
38
|
-
// BLE Others
|
|
39
|
-
BLE_IsConnected;
|
|
40
|
-
//MQTT stuff
|
|
41
|
-
mqttClient = null;
|
|
42
|
-
// EVE history service handler
|
|
43
|
-
historyService;
|
|
44
|
-
// Config
|
|
45
|
-
scanDuration;
|
|
46
|
-
deviceLogging;
|
|
47
|
-
deviceRefreshRate;
|
|
17
|
+
Battery;
|
|
18
|
+
LeakSensor;
|
|
48
19
|
// Updates
|
|
49
20
|
WaterDetectorUpdateInProgress;
|
|
50
21
|
doWaterDetectorUpdate;
|
|
51
|
-
// Connection
|
|
52
|
-
OpenAPI;
|
|
53
|
-
BLE;
|
|
54
22
|
constructor(platform, accessory, device) {
|
|
23
|
+
super(platform, accessory, device);
|
|
55
24
|
this.platform = platform;
|
|
56
|
-
this.accessory = accessory;
|
|
57
|
-
this.device = device;
|
|
58
|
-
this.api = this.platform.api;
|
|
59
|
-
this.log = this.platform.log;
|
|
60
|
-
this.config = this.platform.config;
|
|
61
|
-
this.hap = this.api.hap;
|
|
62
|
-
// Connection
|
|
63
|
-
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
64
|
-
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
65
25
|
// default placeholders
|
|
66
|
-
this.deviceLogs(device);
|
|
67
|
-
this.scan(device);
|
|
68
|
-
this.refreshRate(device);
|
|
69
|
-
this.deviceContext();
|
|
70
26
|
this.setupHistoryService(device);
|
|
71
|
-
this.setupMqtt(device);
|
|
72
|
-
this.deviceConfig(device);
|
|
73
27
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
74
28
|
this.doWaterDetectorUpdate = new Subject();
|
|
75
29
|
this.WaterDetectorUpdateInProgress = false;
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
.getService(this.hap.Service.
|
|
81
|
-
.
|
|
82
|
-
.
|
|
83
|
-
.
|
|
84
|
-
|
|
85
|
-
|
|
30
|
+
// Initialize Battery Service
|
|
31
|
+
accessory.context.Battery = accessory.context.Battery ?? {};
|
|
32
|
+
this.Battery = {
|
|
33
|
+
Name: accessory.context.Battery.Name ?? `${accessory.displayName} Battery`,
|
|
34
|
+
Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery),
|
|
35
|
+
BatteryLevel: accessory.context.BatteryLevel ?? 100,
|
|
36
|
+
StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
|
|
37
|
+
ChargingState: accessory.context.ChargingState ?? this.hap.Characteristic.ChargingState.NOT_CHARGEABLE,
|
|
38
|
+
};
|
|
39
|
+
accessory.context.Battery = this.Battery;
|
|
40
|
+
// Initialize Battery Characteristic
|
|
41
|
+
this.Battery.Service
|
|
42
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name)
|
|
43
|
+
.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE)
|
|
44
|
+
.getCharacteristic(this.hap.Characteristic.BatteryLevel)
|
|
45
|
+
.onGet(() => {
|
|
46
|
+
return this.Battery.StatusLowBattery;
|
|
47
|
+
});
|
|
48
|
+
this.Battery.Service
|
|
49
|
+
.getCharacteristic(this.hap.Characteristic.StatusLowBattery)
|
|
50
|
+
.onGet(() => {
|
|
51
|
+
return this.Battery.StatusLowBattery;
|
|
52
|
+
});
|
|
53
|
+
// Initialize Leak Sensor Service
|
|
86
54
|
if (device.waterdetector?.hide_leak) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
else if (!this.leakService) {
|
|
92
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Leak Sensor Service`);
|
|
93
|
-
const leakService = `${accessory.displayName} Leak Sensor`;
|
|
94
|
-
(this.leakService = this.accessory.getService(this.hap.Service.LeakSensor)
|
|
95
|
-
|| this.accessory.addService(this.hap.Service.LeakSensor)), leakService;
|
|
96
|
-
this.leakService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Leak Sensor`);
|
|
97
|
-
if (!this.leakService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
98
|
-
this.leakService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Leak Sensor`);
|
|
55
|
+
if (this.LeakSensor) {
|
|
56
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leak Sensor Service`);
|
|
57
|
+
this.LeakSensor.Service = this.accessory.getService(this.hap.Service.LeakSensor);
|
|
58
|
+
accessory.removeService(this.LeakSensor.Service);
|
|
99
59
|
}
|
|
100
60
|
}
|
|
101
61
|
else {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
62
|
+
accessory.context.LeakSensor = accessory.context.LeakSensor ?? {};
|
|
63
|
+
this.LeakSensor = {
|
|
64
|
+
Name: accessory.context.LeakSensor.Name ?? `${accessory.displayName} Leak Sensor`,
|
|
65
|
+
Service: accessory.getService(this.hap.Service.LeakSensor) ?? this.accessory.addService(this.hap.Service.LeakSensor),
|
|
66
|
+
StatusActive: accessory.context.StatusActive ?? false,
|
|
67
|
+
LeakDetected: accessory.context.LeakDetected ?? this.hap.Characteristic.LeakDetected.LEAK_NOT_DETECTED,
|
|
68
|
+
};
|
|
69
|
+
accessory.context.LeakSensor = this.LeakSensor;
|
|
70
|
+
// Initialize LeakSensor Characteristic
|
|
71
|
+
this.LeakSensor.Service
|
|
72
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.LeakSensor.Name)
|
|
73
|
+
.setCharacteristic(this.hap.Characteristic.StatusActive, true)
|
|
74
|
+
.getCharacteristic(this.hap.Characteristic.LeakDetected)
|
|
75
|
+
.onGet(() => {
|
|
76
|
+
return this.LeakSensor.LeakDetected;
|
|
77
|
+
});
|
|
111
78
|
}
|
|
112
|
-
|
|
79
|
+
// Retrieve initial values and updateHomekit
|
|
80
|
+
this.refreshStatus();
|
|
113
81
|
// Retrieve initial values and updateHomekit
|
|
114
82
|
this.updateHomeKitCharacteristics();
|
|
115
83
|
// Start an update interval
|
|
@@ -119,18 +87,20 @@ export class WaterDetector {
|
|
|
119
87
|
await this.refreshStatus();
|
|
120
88
|
});
|
|
121
89
|
//regisiter webhook event handler
|
|
122
|
-
if (this.device.
|
|
123
|
-
this.
|
|
90
|
+
if (device.webhook && !this.device.waterdetector?.hide_leak) {
|
|
91
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
|
|
124
92
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
125
93
|
try {
|
|
126
94
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
127
|
-
const {
|
|
128
|
-
const { LeakDetected } = this;
|
|
95
|
+
const { detectionState, battery } = context;
|
|
96
|
+
const { LeakDetected } = this.LeakSensor;
|
|
97
|
+
const { BatteryLevel } = this.Battery;
|
|
129
98
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
130
|
-
'(
|
|
131
|
-
`Webhook:(${
|
|
132
|
-
`current:(${LeakDetected})`);
|
|
133
|
-
this.LeakDetected =
|
|
99
|
+
'(detectionState, battery) = ' +
|
|
100
|
+
`Webhook:(${detectionState}, ${battery}), ` +
|
|
101
|
+
`current:(${LeakDetected}, ${BatteryLevel})`);
|
|
102
|
+
this.LeakSensor.LeakDetected = detectionState;
|
|
103
|
+
this.Battery.BatteryLevel = battery;
|
|
134
104
|
this.updateHomeKitCharacteristics();
|
|
135
105
|
}
|
|
136
106
|
catch (e) {
|
|
@@ -140,65 +110,59 @@ export class WaterDetector {
|
|
|
140
110
|
};
|
|
141
111
|
}
|
|
142
112
|
}
|
|
143
|
-
|
|
144
|
-
* Parse the device status from the SwitchBot api
|
|
145
|
-
*/
|
|
146
|
-
async parseStatus() {
|
|
147
|
-
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
148
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
149
|
-
}
|
|
150
|
-
else if (this.BLE) {
|
|
151
|
-
await this.BLEparseStatus();
|
|
152
|
-
}
|
|
153
|
-
else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
154
|
-
await this.openAPIparseStatus();
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
await this.offlineOff();
|
|
158
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
async BLEparseStatus() {
|
|
113
|
+
async BLEparseStatus(serviceData) {
|
|
162
114
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
163
115
|
// Battery
|
|
164
|
-
this.BatteryLevel = Number(
|
|
165
|
-
if (this.BatteryLevel < 15) {
|
|
166
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
116
|
+
this.Battery.BatteryLevel = Number(serviceData.battery);
|
|
117
|
+
if (this.Battery.BatteryLevel < 15) {
|
|
118
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
167
119
|
}
|
|
168
120
|
else {
|
|
169
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
121
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
170
122
|
}
|
|
171
|
-
this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
|
|
123
|
+
this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}, StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
172
124
|
// LeakDetected
|
|
173
|
-
this.
|
|
174
|
-
|
|
125
|
+
if (this.device.waterdetector?.hide_leak) {
|
|
126
|
+
this.LeakSensor.LeakDetected = serviceData.status;
|
|
127
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LeakDetected: ${this.LeakSensor.LeakDetected}`);
|
|
128
|
+
}
|
|
175
129
|
}
|
|
176
|
-
async openAPIparseStatus() {
|
|
130
|
+
async openAPIparseStatus(deviceStatus) {
|
|
177
131
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
178
132
|
// StatusLowBattery
|
|
179
|
-
this.BatteryLevel = Number(
|
|
180
|
-
if (this.BatteryLevel < 10) {
|
|
181
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
133
|
+
this.Battery.BatteryLevel = Number(deviceStatus.body.battery);
|
|
134
|
+
if (this.Battery.BatteryLevel < 10) {
|
|
135
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
182
136
|
}
|
|
183
137
|
else {
|
|
184
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
138
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
185
139
|
}
|
|
186
|
-
this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
|
|
140
|
+
this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}, StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
187
141
|
// BatteryLevel
|
|
188
|
-
if (Number.isNaN(this.BatteryLevel)) {
|
|
189
|
-
this.BatteryLevel = 100;
|
|
142
|
+
if (Number.isNaN(this.Battery.BatteryLevel)) {
|
|
143
|
+
this.Battery.BatteryLevel = 100;
|
|
190
144
|
}
|
|
191
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
145
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
192
146
|
// LeakDetected
|
|
193
|
-
this.
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
147
|
+
if (!this.device.waterdetector?.hide_leak) {
|
|
148
|
+
this.LeakSensor.LeakDetected = deviceStatus.body.status;
|
|
149
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LeakDetected: ${this.LeakSensor.LeakDetected}`);
|
|
150
|
+
}
|
|
151
|
+
// Firmware Version
|
|
152
|
+
const version = deviceStatus.body.version?.toString();
|
|
153
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
|
|
154
|
+
if (deviceStatus.body.version) {
|
|
155
|
+
const deviceVersion = version?.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
156
|
+
this.accessory
|
|
157
|
+
.getService(this.hap.Service.AccessoryInformation)
|
|
158
|
+
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
159
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
|
|
160
|
+
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
161
|
+
.updateValue(deviceVersion);
|
|
162
|
+
this.accessory.context.deviceVersion = deviceVersion;
|
|
163
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceVersion: ${this.accessory.context.deviceVersion}`);
|
|
164
|
+
}
|
|
198
165
|
}
|
|
199
|
-
/**
|
|
200
|
-
* Asks the SwitchBot API for the latest device information
|
|
201
|
-
*/
|
|
202
166
|
async refreshStatus() {
|
|
203
167
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
204
168
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
@@ -228,49 +192,42 @@ export class WaterDetector {
|
|
|
228
192
|
// Start to monitor advertisement packets
|
|
229
193
|
(async () => {
|
|
230
194
|
// Start to monitor advertisement packets
|
|
231
|
-
await switchbot.startScan({
|
|
232
|
-
model: 'l',
|
|
233
|
-
id: this.device.bleMac,
|
|
234
|
-
});
|
|
195
|
+
await switchbot.startScan({ model: this.device.bleModel, id: this.device.bleMac });
|
|
235
196
|
// Set an event handler
|
|
236
197
|
switchbot.onadvertisement = (ad) => {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
198
|
+
if (this.device.bleMac === ad.address && ad.model === this.device.bleModel) {
|
|
199
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
|
|
200
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
|
|
240
201
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
241
|
-
this.BLE_LeakDetected = ad.serviceData.status;
|
|
242
|
-
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
243
202
|
}
|
|
244
203
|
else {
|
|
245
204
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
246
205
|
}
|
|
247
206
|
};
|
|
248
|
-
// Wait
|
|
207
|
+
// Wait 10 seconds
|
|
249
208
|
await switchbot.wait(this.scanDuration * 1000);
|
|
250
209
|
// Stop to monitor
|
|
251
210
|
await switchbot.stopScan();
|
|
252
211
|
// Update HomeKit
|
|
253
|
-
await this.BLEparseStatus();
|
|
212
|
+
await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
|
|
254
213
|
await this.updateHomeKitCharacteristics();
|
|
255
214
|
})();
|
|
215
|
+
if (switchbot === undefined) {
|
|
216
|
+
await this.BLERefreshConnection(switchbot);
|
|
217
|
+
}
|
|
256
218
|
}
|
|
257
219
|
async openAPIRefreshStatus() {
|
|
258
220
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
259
221
|
try {
|
|
260
|
-
const { body, statusCode } = await
|
|
261
|
-
headers: this.platform.generateHeaders(),
|
|
262
|
-
});
|
|
222
|
+
const { body, statusCode } = await this.platform.retryRequest(this.deviceMaxRetries, this.deviceDelayBetweenRetries, `${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
|
|
263
223
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
264
224
|
const deviceStatus = await body.json();
|
|
265
225
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
266
226
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
267
227
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
268
|
-
this.
|
|
228
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
269
229
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
270
|
-
this.
|
|
271
|
-
this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
|
|
272
|
-
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
273
|
-
this.openAPIparseStatus();
|
|
230
|
+
this.openAPIparseStatus(deviceStatus);
|
|
274
231
|
this.updateHomeKitCharacteristics();
|
|
275
232
|
}
|
|
276
233
|
else {
|
|
@@ -291,128 +248,56 @@ export class WaterDetector {
|
|
|
291
248
|
const mqttmessage = [];
|
|
292
249
|
const entry = { time: Math.round(new Date().valueOf() / 1000) };
|
|
293
250
|
if (!this.device.waterdetector?.hide_leak) {
|
|
294
|
-
if (this.LeakDetected === undefined) {
|
|
295
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LeakDetected: ${this.LeakDetected}`);
|
|
251
|
+
if (this.LeakSensor.LeakDetected === undefined) {
|
|
252
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LeakDetected: ${this.LeakSensor.LeakDetected}`);
|
|
296
253
|
}
|
|
297
254
|
else {
|
|
298
255
|
if (this.device.mqttURL) {
|
|
299
|
-
mqttmessage.push(`"LeakDetected": ${this.LeakDetected}`);
|
|
256
|
+
mqttmessage.push(`"LeakDetected": ${this.LeakSensor.LeakDetected}`);
|
|
300
257
|
}
|
|
301
258
|
if (this.device.history) {
|
|
302
|
-
entry['leak'] = this.LeakDetected;
|
|
259
|
+
entry['leak'] = this.LeakSensor.LeakDetected;
|
|
303
260
|
}
|
|
304
|
-
this.accessory.context.LeakDetected = this.LeakDetected;
|
|
305
|
-
this.
|
|
306
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic LeakDetected: ${this.LeakDetected}`);
|
|
261
|
+
this.accessory.context.LeakDetected = this.LeakSensor.LeakDetected;
|
|
262
|
+
this.LeakSensor.Service.updateCharacteristic(this.hap.Characteristic.LeakDetected, this.LeakSensor.LeakDetected);
|
|
263
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic LeakDetected: ${this.LeakSensor.LeakDetected}`);
|
|
307
264
|
}
|
|
308
265
|
}
|
|
309
|
-
if (this.BatteryLevel === undefined) {
|
|
310
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
266
|
+
if (this.Battery.BatteryLevel === undefined) {
|
|
267
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
311
268
|
}
|
|
312
269
|
else {
|
|
313
270
|
if (this.device.mqttURL) {
|
|
314
|
-
mqttmessage.push(`"battery": ${this.BatteryLevel}`);
|
|
271
|
+
mqttmessage.push(`"battery": ${this.Battery.BatteryLevel}`);
|
|
315
272
|
}
|
|
316
|
-
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
317
|
-
this.
|
|
318
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
273
|
+
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
|
|
274
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
275
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
319
276
|
}
|
|
320
|
-
if (this.StatusLowBattery === undefined) {
|
|
321
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
277
|
+
if (this.Battery.StatusLowBattery === undefined) {
|
|
278
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
322
279
|
}
|
|
323
280
|
else {
|
|
324
281
|
if (this.device.mqttURL) {
|
|
325
|
-
mqttmessage.push(`"lowBattery": ${this.StatusLowBattery}`);
|
|
282
|
+
mqttmessage.push(`"lowBattery": ${this.Battery.StatusLowBattery}`);
|
|
326
283
|
}
|
|
327
|
-
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
328
|
-
this.
|
|
329
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
284
|
+
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
285
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
286
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
287
|
+
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
330
288
|
}
|
|
331
289
|
if (this.device.mqttURL) {
|
|
332
290
|
this.mqttPublish(`{${mqttmessage.join(',')}}`);
|
|
333
291
|
}
|
|
334
|
-
if (
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
this.
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}
|
|
341
|
-
/*
|
|
342
|
-
* Publish MQTT message for topics of
|
|
343
|
-
* 'homebridge-switchbot/meter/xx:xx:xx:xx:xx:xx'
|
|
344
|
-
*/
|
|
345
|
-
mqttPublish(message) {
|
|
346
|
-
const mac = this.device.deviceId
|
|
347
|
-
?.toLowerCase()
|
|
348
|
-
.match(/[\s\S]{1,2}/g)
|
|
349
|
-
?.join(':');
|
|
350
|
-
const options = this.device.mqttPubOptions || {};
|
|
351
|
-
this.mqttClient?.publish(`homebridge-switchbot/meter/${mac}`, `${message}`, options);
|
|
352
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT message: ${message} options:${JSON.stringify(options)}`);
|
|
353
|
-
}
|
|
354
|
-
/*
|
|
355
|
-
* Setup MQTT hadler if URL is specified.
|
|
356
|
-
*/
|
|
357
|
-
async setupMqtt(device) {
|
|
358
|
-
if (device.mqttURL) {
|
|
359
|
-
try {
|
|
360
|
-
const { connectAsync } = asyncmqtt;
|
|
361
|
-
this.mqttClient = await connectAsync(device.mqttURL, device.mqttOptions || {});
|
|
362
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT connection has been established successfully.`);
|
|
363
|
-
this.mqttClient.on('error', (e) => {
|
|
364
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to publish MQTT messages. ${e}`);
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
catch (e) {
|
|
368
|
-
this.mqttClient = null;
|
|
369
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to establish MQTT connection. ${e}`);
|
|
292
|
+
if (!this.device.waterdetector?.hide_leak) {
|
|
293
|
+
if (Number(this.LeakSensor.LeakDetected) > 0) {
|
|
294
|
+
// reject unreliable data
|
|
295
|
+
if (this.device.history) {
|
|
296
|
+
this.historyService?.addEntry(entry);
|
|
297
|
+
}
|
|
370
298
|
}
|
|
371
299
|
}
|
|
372
300
|
}
|
|
373
|
-
/*
|
|
374
|
-
* Setup EVE history graph feature if enabled.
|
|
375
|
-
*/
|
|
376
|
-
async setupHistoryService(device) {
|
|
377
|
-
const mac = this.device
|
|
378
|
-
.deviceId.match(/.{1,2}/g)
|
|
379
|
-
.join(':')
|
|
380
|
-
.toLowerCase();
|
|
381
|
-
this.historyService = device.history
|
|
382
|
-
? new this.platform.fakegatoAPI('room', this.accessory, {
|
|
383
|
-
log: this.platform.log,
|
|
384
|
-
storage: 'fs',
|
|
385
|
-
filename: `${hostname().split('.')[0]}_${mac}_persist.json`,
|
|
386
|
-
})
|
|
387
|
-
: null;
|
|
388
|
-
}
|
|
389
|
-
async stopScanning(switchbot) {
|
|
390
|
-
switchbot.stopScan();
|
|
391
|
-
if (this.BLE_IsConnected) {
|
|
392
|
-
await this.BLEparseStatus();
|
|
393
|
-
await this.updateHomeKitCharacteristics();
|
|
394
|
-
}
|
|
395
|
-
else {
|
|
396
|
-
await this.BLERefreshConnection(switchbot);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
async getCustomBLEAddress(switchbot) {
|
|
400
|
-
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
401
|
-
(async () => {
|
|
402
|
-
// Start to monitor advertisement packets
|
|
403
|
-
await switchbot.startScan({
|
|
404
|
-
model: 'i',
|
|
405
|
-
});
|
|
406
|
-
// Set an event handler
|
|
407
|
-
switchbot.onadvertisement = (ad) => {
|
|
408
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
409
|
-
};
|
|
410
|
-
await sleep(10000);
|
|
411
|
-
// Stop to monitor
|
|
412
|
-
switchbot.stopScan();
|
|
413
|
-
})();
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
301
|
async BLERefreshConnection(switchbot) {
|
|
417
302
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot:`
|
|
418
303
|
+ ` ${JSON.stringify(switchbot)}`);
|
|
@@ -421,231 +306,17 @@ export class WaterDetector {
|
|
|
421
306
|
await this.openAPIRefreshStatus();
|
|
422
307
|
}
|
|
423
308
|
}
|
|
424
|
-
async scan(device) {
|
|
425
|
-
if (device.scanDuration) {
|
|
426
|
-
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
427
|
-
if (this.BLE) {
|
|
428
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
else {
|
|
432
|
-
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
433
|
-
if (this.BLE) {
|
|
434
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
async statusCode(statusCode) {
|
|
439
|
-
switch (statusCode) {
|
|
440
|
-
case 151:
|
|
441
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
442
|
-
break;
|
|
443
|
-
case 152:
|
|
444
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
445
|
-
break;
|
|
446
|
-
case 160:
|
|
447
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
448
|
-
break;
|
|
449
|
-
case 161:
|
|
450
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
451
|
-
this.offlineOff();
|
|
452
|
-
break;
|
|
453
|
-
case 171:
|
|
454
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
455
|
-
`Hub: ${this.device.hubDeviceId}`);
|
|
456
|
-
this.offlineOff();
|
|
457
|
-
break;
|
|
458
|
-
case 190:
|
|
459
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
460
|
-
` Or command format is invalid, statusCode: ${statusCode}`);
|
|
461
|
-
break;
|
|
462
|
-
case 100:
|
|
463
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
464
|
-
break;
|
|
465
|
-
case 200:
|
|
466
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
467
|
-
break;
|
|
468
|
-
case 400:
|
|
469
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
470
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
471
|
-
break;
|
|
472
|
-
case 401:
|
|
473
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
474
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
475
|
-
break;
|
|
476
|
-
case 403:
|
|
477
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
478
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
479
|
-
break;
|
|
480
|
-
case 404:
|
|
481
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
482
|
-
+ `statusCode: ${statusCode}`);
|
|
483
|
-
break;
|
|
484
|
-
case 406:
|
|
485
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
486
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
487
|
-
break;
|
|
488
|
-
case 415:
|
|
489
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
490
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
491
|
-
break;
|
|
492
|
-
case 422:
|
|
493
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, `
|
|
494
|
-
+ `but the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
495
|
-
break;
|
|
496
|
-
case 429:
|
|
497
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
498
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
499
|
-
break;
|
|
500
|
-
case 500:
|
|
501
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
502
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
503
|
-
break;
|
|
504
|
-
default:
|
|
505
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
506
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
309
|
async offlineOff() {
|
|
510
|
-
if (this.device.offline) {
|
|
511
|
-
|
|
512
|
-
await this.updateHomeKitCharacteristics();
|
|
310
|
+
if (this.device.offline && !this.device.waterdetector?.hide_leak) {
|
|
311
|
+
this.LeakSensor.Service.updateCharacteristic(this.hap.Characteristic.LeakDetected, this.hap.Characteristic.LeakDetected.LEAK_NOT_DETECTED);
|
|
513
312
|
}
|
|
514
313
|
}
|
|
515
314
|
async apiError(e) {
|
|
516
315
|
if (!this.device.waterdetector?.hide_leak) {
|
|
517
|
-
this.
|
|
518
|
-
}
|
|
519
|
-
this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
520
|
-
this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
521
|
-
}
|
|
522
|
-
async deviceContext() {
|
|
523
|
-
if (this.LeakDetected === undefined) {
|
|
524
|
-
this.LeakDetected = 0;
|
|
525
|
-
}
|
|
526
|
-
else {
|
|
527
|
-
this.LeakDetected = this.accessory.context.LeakDetected;
|
|
528
|
-
}
|
|
529
|
-
if (this.BatteryLevel === undefined) {
|
|
530
|
-
this.BatteryLevel = 100;
|
|
531
|
-
}
|
|
532
|
-
else {
|
|
533
|
-
this.BatteryLevel = this.accessory.context.BatteryLevel;
|
|
534
|
-
}
|
|
535
|
-
if (this.StatusLowBattery === undefined) {
|
|
536
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
537
|
-
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
538
|
-
}
|
|
539
|
-
else {
|
|
540
|
-
this.StatusLowBattery = this.accessory.context.StatusLowBattery;
|
|
541
|
-
}
|
|
542
|
-
if (this.FirmwareRevision === undefined) {
|
|
543
|
-
this.FirmwareRevision = this.platform.version;
|
|
544
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
async refreshRate(device) {
|
|
548
|
-
if (device.refreshRate) {
|
|
549
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
550
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
551
|
-
}
|
|
552
|
-
else if (this.platform.config.options.refreshRate) {
|
|
553
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
554
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
async deviceConfig(device) {
|
|
558
|
-
let config = {};
|
|
559
|
-
if (device.waterdetector) {
|
|
560
|
-
config = device.waterdetector;
|
|
561
|
-
}
|
|
562
|
-
if (device.connectionType !== undefined) {
|
|
563
|
-
config['connectionType'] = device.connectionType;
|
|
564
|
-
}
|
|
565
|
-
if (device.external !== undefined) {
|
|
566
|
-
config['external'] = device.external;
|
|
567
|
-
}
|
|
568
|
-
if (device.mqttURL !== undefined) {
|
|
569
|
-
config['mqttURL'] = device.mqttURL;
|
|
570
|
-
}
|
|
571
|
-
if (device.logging !== undefined) {
|
|
572
|
-
config['logging'] = device.logging;
|
|
573
|
-
}
|
|
574
|
-
if (device.refreshRate !== undefined) {
|
|
575
|
-
config['refreshRate'] = device.refreshRate;
|
|
316
|
+
this.LeakSensor.Service.updateCharacteristic(this.hap.Characteristic.LeakDetected, e);
|
|
576
317
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
}
|
|
580
|
-
if (device.webhook !== undefined) {
|
|
581
|
-
config['webhook'] = device.webhook;
|
|
582
|
-
}
|
|
583
|
-
if (Object.entries(config).length !== 0) {
|
|
584
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
async deviceLogs(device) {
|
|
588
|
-
if (this.platform.debugMode) {
|
|
589
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
590
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
591
|
-
}
|
|
592
|
-
else if (device.logging) {
|
|
593
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
594
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
595
|
-
}
|
|
596
|
-
else if (this.platform.config.options?.logging) {
|
|
597
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
598
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
599
|
-
}
|
|
600
|
-
else {
|
|
601
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
602
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
/**
|
|
606
|
-
* Logging for Device
|
|
607
|
-
*/
|
|
608
|
-
infoLog(...log) {
|
|
609
|
-
if (this.enablingDeviceLogging()) {
|
|
610
|
-
this.platform.log.info(String(...log));
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
warnLog(...log) {
|
|
614
|
-
if (this.enablingDeviceLogging()) {
|
|
615
|
-
this.platform.log.warn(String(...log));
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
debugWarnLog(...log) {
|
|
619
|
-
if (this.enablingDeviceLogging()) {
|
|
620
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
621
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
errorLog(...log) {
|
|
626
|
-
if (this.enablingDeviceLogging()) {
|
|
627
|
-
this.platform.log.error(String(...log));
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
debugErrorLog(...log) {
|
|
631
|
-
if (this.enablingDeviceLogging()) {
|
|
632
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
633
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
debugLog(...log) {
|
|
638
|
-
if (this.enablingDeviceLogging()) {
|
|
639
|
-
if (this.deviceLogging === 'debug') {
|
|
640
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
641
|
-
}
|
|
642
|
-
else {
|
|
643
|
-
this.platform.log.debug(String(...log));
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
enablingDeviceLogging() {
|
|
648
|
-
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
318
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
319
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
649
320
|
}
|
|
650
321
|
}
|
|
651
322
|
//# sourceMappingURL=waterdetector.js.map
|