@switchbot/homebridge-switchbot 3.5.0-beta.58 → 3.5.0-beta.59
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/dist/device/blindtilt.d.ts +1 -1
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +101 -67
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +1 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +200 -153
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +39 -34
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +35 -36
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +71 -56
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +98 -54
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +7 -9
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +53 -23
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +39 -52
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +38 -38
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +40 -45
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +34 -31
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +67 -58
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +41 -46
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +41 -46
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +48 -38
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +12 -12
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +78 -95
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +38 -30
- package/dist/device/waterdetector.js.map +1 -1
- package/package.json +1 -1
- package/src/device/blindtilt.ts +115 -84
- package/src/device/bot.ts +233 -172
- package/src/device/ceilinglight.ts +43 -42
- package/src/device/colorbulb.ts +35 -40
- package/src/device/contact.ts +77 -60
- package/src/device/curtain.ts +106 -61
- package/src/device/device.ts +7 -9
- package/src/device/fan.ts +61 -26
- package/src/device/hub.ts +47 -57
- package/src/device/humidifier.ts +48 -52
- package/src/device/iosensor.ts +51 -53
- package/src/device/lightstrip.ts +37 -35
- package/src/device/lock.ts +74 -65
- package/src/device/meter.ts +47 -50
- package/src/device/meterplus.ts +47 -50
- package/src/device/motion.ts +53 -42
- package/src/device/plug.ts +14 -15
- package/src/device/robotvacuumcleaner.ts +83 -100
- package/src/device/waterdetector.ts +41 -31
|
@@ -10,20 +10,23 @@ import { debounceTime, take, tap } from 'rxjs/operators';
|
|
|
10
10
|
|
|
11
11
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
12
12
|
import type { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
13
|
-
import type { device, devicesConfig, deviceStatus, serviceData} from '../settings.js';
|
|
13
|
+
import type { device, devicesConfig, deviceStatus, serviceData } from '../settings.js';
|
|
14
14
|
|
|
15
15
|
export class RobotVacuumCleaner extends deviceBase {
|
|
16
16
|
// Services
|
|
17
17
|
private LightBulb: {
|
|
18
|
+
Name: CharacteristicValue;
|
|
18
19
|
Service: Service;
|
|
19
20
|
On: CharacteristicValue;
|
|
20
21
|
Brightness: CharacteristicValue;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
private Battery: {
|
|
25
|
+
Name: CharacteristicValue;
|
|
24
26
|
Service: Service;
|
|
25
27
|
BatteryLevel: CharacteristicValue;
|
|
26
28
|
StatusLowBattery: CharacteristicValue;
|
|
29
|
+
ChargingState: CharacteristicValue;
|
|
27
30
|
};
|
|
28
31
|
|
|
29
32
|
// Updates
|
|
@@ -40,37 +43,24 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
40
43
|
this.doRobotVacuumCleanerUpdate = new Subject();
|
|
41
44
|
this.robotVacuumCleanerUpdateInProgress = false;
|
|
42
45
|
|
|
43
|
-
// Initialize Lightbulb
|
|
46
|
+
// Initialize Lightbulb Service
|
|
44
47
|
this.LightBulb = {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
Name: accessory.context.LightBulb.Name ?? accessory.displayName,
|
|
49
|
+
Service: accessory.getService(this.hap.Service.Lightbulb) ?? accessory.addService(this.hap.Service.Lightbulb) as Service,
|
|
50
|
+
On: accessory.context.On ?? false,
|
|
51
|
+
Brightness: accessory.context.Brightness ?? 0,
|
|
48
52
|
};
|
|
49
53
|
|
|
50
|
-
// Initialize
|
|
51
|
-
this.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.refreshStatus();
|
|
59
|
-
|
|
60
|
-
// get the Lightbulb service if it exists, otherwise create a new Lightbulb service
|
|
61
|
-
// you can create multiple services for each accessory
|
|
62
|
-
const LightBulbService = `${accessory.displayName} ${device.deviceType}`;
|
|
63
|
-
(this.LightBulb.Service = accessory.getService(this.hap.Service.Lightbulb)
|
|
64
|
-
|| accessory.addService(this.hap.Service.Lightbulb)), LightBulbService;
|
|
65
|
-
|
|
66
|
-
this.LightBulb.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
67
|
-
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
68
|
-
// see https://developers.homebridge.io/#/service/Lightbulb
|
|
69
|
-
|
|
70
|
-
// create handlers for required characteristics
|
|
71
|
-
this.LightBulb.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
54
|
+
// Initialize LightBulb Characteristics
|
|
55
|
+
this.LightBulb.Service
|
|
56
|
+
.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
|
|
57
|
+
.getCharacteristic(this.hap.Characteristic.On)
|
|
58
|
+
.onGet(() => {
|
|
59
|
+
return this.LightBulb.On;
|
|
60
|
+
})
|
|
61
|
+
.onSet(this.OnSet.bind(this));
|
|
72
62
|
|
|
73
|
-
//
|
|
63
|
+
// Initialize LightBulb Brightness Characteristic
|
|
74
64
|
this.LightBulb.Service
|
|
75
65
|
.getCharacteristic(this.hap.Characteristic.Brightness)
|
|
76
66
|
.setProps({
|
|
@@ -84,14 +74,40 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
84
74
|
return this.LightBulb.Brightness;
|
|
85
75
|
})
|
|
86
76
|
.onSet(this.BrightnessSet.bind(this));
|
|
77
|
+
accessory.context.LightBulb.Name = this.LightBulb.Name;
|
|
87
78
|
|
|
88
|
-
// Battery Service
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
79
|
+
// Initialize Battery Service
|
|
80
|
+
this.Battery = {
|
|
81
|
+
Name: accessory.context.Battery.Name ?? `${accessory.displayName} Battery`,
|
|
82
|
+
Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
|
|
83
|
+
BatteryLevel: accessory.context.BatteryLevel ?? 100,
|
|
84
|
+
StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
|
|
85
|
+
ChargingState: accessory.context.ChargingState ?? this.hap.Characteristic.ChargingState.NOT_CHARGING,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// Initialize Battery Characteristics
|
|
89
|
+
this.Battery.Service
|
|
90
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name)
|
|
91
|
+
.getCharacteristic(this.hap.Characteristic.BatteryLevel)
|
|
92
|
+
.onGet(() => {
|
|
93
|
+
return this.Battery.BatteryLevel;
|
|
94
|
+
});
|
|
92
95
|
|
|
93
|
-
this.Battery.Service
|
|
96
|
+
this.Battery.Service
|
|
97
|
+
.getCharacteristic(this.hap.Characteristic.StatusLowBattery)
|
|
98
|
+
.onGet(() => {
|
|
99
|
+
return this.Battery.StatusLowBattery;
|
|
100
|
+
});
|
|
94
101
|
|
|
102
|
+
this.Battery.Service
|
|
103
|
+
.getCharacteristic(this.hap.Characteristic.ChargingState)
|
|
104
|
+
.onGet(() => {
|
|
105
|
+
return this.Battery.ChargingState;
|
|
106
|
+
});
|
|
107
|
+
accessory.context.Battery.Name = this.Battery.Name;
|
|
108
|
+
|
|
109
|
+
// Retrieve initial values and updateHomekit
|
|
110
|
+
this.refreshStatus();
|
|
95
111
|
// Update Homekit
|
|
96
112
|
this.updateHomeKitCharacteristics();
|
|
97
113
|
|
|
@@ -108,14 +124,16 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
108
124
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
109
125
|
try {
|
|
110
126
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
111
|
-
const { onlineStatus, battery } = context;
|
|
127
|
+
const { onlineStatus, battery, workingStatus } = context;
|
|
112
128
|
const { On } = this.LightBulb;
|
|
113
|
-
const { BatteryLevel } = this.Battery;
|
|
129
|
+
const { BatteryLevel, ChargingState } = this.Battery;
|
|
114
130
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
115
|
-
'(onlineStatus, battery) = ' +
|
|
116
|
-
`Webhook:(${onlineStatus}, ${battery}), ` +
|
|
117
|
-
`current:(${On}, ${BatteryLevel})`);
|
|
131
|
+
'(onlineStatus, battery, workingStatus) = ' +
|
|
132
|
+
`Webhook:(${onlineStatus}, ${battery}, ${workingStatus}), ` +
|
|
133
|
+
`current:(${On}, ${BatteryLevel}, ${ChargingState})`);
|
|
118
134
|
this.LightBulb.On = onlineStatus === 'online' ? true : false;
|
|
135
|
+
this.Battery.ChargingState = workingStatus === 'Charging'
|
|
136
|
+
? this.hap.Characteristic.ChargingState.CHARGING : this.hap.Characteristic.ChargingState.NOT_CHARGING;
|
|
119
137
|
this.Battery.BatteryLevel = battery;
|
|
120
138
|
this.updateHomeKitCharacteristics();
|
|
121
139
|
} catch (e: any) {
|
|
@@ -189,6 +207,8 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
189
207
|
|
|
190
208
|
// BatteryLevel
|
|
191
209
|
this.Battery.BatteryLevel = Number(deviceStatus.body.battery);
|
|
210
|
+
|
|
211
|
+
// StatusLowBattery
|
|
192
212
|
if (this.Battery.BatteryLevel < 10) {
|
|
193
213
|
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
194
214
|
} else {
|
|
@@ -197,8 +217,11 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
197
217
|
if (Number.isNaN(this.Battery.BatteryLevel)) {
|
|
198
218
|
this.Battery.BatteryLevel = 100;
|
|
199
219
|
}
|
|
220
|
+
// ChargingState
|
|
221
|
+
this.Battery.ChargingState = deviceStatus.body.workingStatus === 'Charging'
|
|
222
|
+
? this.hap.Characteristic.ChargingState.CHARGING : this.hap.Characteristic.ChargingState.NOT_CHARGING;
|
|
200
223
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
|
|
201
|
-
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
224
|
+
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}, ChargingState: ${this.Battery.ChargingState}`);
|
|
202
225
|
|
|
203
226
|
// Firmware Version
|
|
204
227
|
const version = deviceStatus.body.version?.toString();
|
|
@@ -219,8 +242,8 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
219
242
|
async refreshStatus(): Promise<void> {
|
|
220
243
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
221
244
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
222
|
-
|
|
223
|
-
|
|
245
|
+
} else if (this.BLE) {
|
|
246
|
+
await this.BLERefreshStatus();
|
|
224
247
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
225
248
|
await this.openAPIRefreshStatus();
|
|
226
249
|
} else {
|
|
@@ -244,21 +267,19 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
244
267
|
this.getCustomBLEAddress(switchbot);
|
|
245
268
|
// Start to monitor advertisement packets
|
|
246
269
|
(async () => {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
id: this.device.bleMac,
|
|
250
|
-
});
|
|
270
|
+
// Start to monitor advertisement packets
|
|
271
|
+
await switchbot.startScan({ model: this.device.bleModel, id: this.device.bleMac });
|
|
251
272
|
// Set an event handler
|
|
252
273
|
switchbot.onadvertisement = (ad: any) => {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
274
|
+
if (this.device.bleMac === ad.address && ad.model === this.device.bleModel) {
|
|
275
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
|
|
276
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
|
|
256
277
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
257
278
|
} else {
|
|
258
279
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
259
280
|
}
|
|
260
281
|
};
|
|
261
|
-
// Wait
|
|
282
|
+
// Wait 10 seconds
|
|
262
283
|
await switchbot.wait(this.scanDuration * 1000);
|
|
263
284
|
// Stop to monitor
|
|
264
285
|
await switchbot.stopScan();
|
|
@@ -266,63 +287,16 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
266
287
|
await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
|
|
267
288
|
await this.updateHomeKitCharacteristics();
|
|
268
289
|
})();
|
|
269
|
-
|
|
270
|
-
switchbot
|
|
271
|
-
.startScan({
|
|
272
|
-
model: this.BLEmodel(),
|
|
273
|
-
id: this.device.bleMac,
|
|
274
|
-
})
|
|
275
|
-
.then(async () => {
|
|
276
|
-
// Set an event handler
|
|
277
|
-
switchbot.onadvertisement = async (ad: ad) => {
|
|
278
|
-
this.debugLog(
|
|
279
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
280
|
-
` BLE Address Found: ${ad.address}`,
|
|
281
|
-
);
|
|
282
|
-
serviceData.state = ad.serviceData.state;
|
|
283
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
284
|
-
this.debugLog(
|
|
285
|
-
`${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
|
|
286
|
-
`delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
|
|
287
|
-
`wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
|
|
288
|
-
);
|
|
289
|
-
|
|
290
|
-
if (ad.serviceData) {
|
|
291
|
-
this.BLE_IsConnected = true;
|
|
292
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
293
|
-
await this.stopScanning(switchbot);
|
|
294
|
-
} else {
|
|
295
|
-
this.BLE_IsConnected = false;
|
|
296
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
// Wait
|
|
300
|
-
return await sleep(this.scanDuration * 1000);
|
|
301
|
-
})
|
|
302
|
-
.then(async () => {
|
|
303
|
-
// Stop to monitor
|
|
304
|
-
await this.stopScanning(switchbot);
|
|
305
|
-
})
|
|
306
|
-
.catch(async (e: any) => {
|
|
307
|
-
this.apiError(e);
|
|
308
|
-
this.errorLog(
|
|
309
|
-
`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
|
|
310
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
311
|
-
);
|
|
312
|
-
await this.BLERefreshConnection(switchbot);
|
|
313
|
-
});
|
|
314
|
-
} else {
|
|
290
|
+
if (switchbot === undefined) {
|
|
315
291
|
await this.BLERefreshConnection(switchbot);
|
|
316
|
-
}
|
|
292
|
+
}
|
|
317
293
|
}
|
|
318
294
|
|
|
319
|
-
async openAPIRefreshStatus() {
|
|
295
|
+
async openAPIRefreshStatus(): Promise<void> {
|
|
320
296
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
321
297
|
try {
|
|
322
298
|
const { body, statusCode } = await this.platform.retryRequest(this.deviceMaxRetries, this.deviceDelayBetweenRetries,
|
|
323
|
-
`${Devices}/${this.device.deviceId}/status`, {
|
|
324
|
-
headers: this.platform.generateHeaders(),
|
|
325
|
-
});
|
|
299
|
+
`${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
|
|
326
300
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
327
301
|
const deviceStatus: any = await body.json();
|
|
328
302
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
@@ -608,6 +582,15 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
608
582
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
609
583
|
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
610
584
|
}
|
|
585
|
+
// ChargingState
|
|
586
|
+
if (this.Battery.ChargingState === undefined) {
|
|
587
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ChargingState: ${this.Battery.ChargingState}`);
|
|
588
|
+
} else {
|
|
589
|
+
this.accessory.context.ChargingState = this.Battery.ChargingState;
|
|
590
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.ChargingState, this.Battery.ChargingState);
|
|
591
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
592
|
+
+ ` ChargingState: ${this.Battery.ChargingState}`);
|
|
593
|
+
}
|
|
611
594
|
}
|
|
612
595
|
|
|
613
596
|
async BLEPushConnection() {
|
|
@@ -19,6 +19,7 @@ import type { device, devicesConfig, serviceData, deviceStatus} from '../setting
|
|
|
19
19
|
export class WaterDetector extends deviceBase {
|
|
20
20
|
// Services
|
|
21
21
|
private Battery: {
|
|
22
|
+
Name: CharacteristicValue
|
|
22
23
|
Service: Service;
|
|
23
24
|
BatteryLevel: CharacteristicValue;
|
|
24
25
|
StatusLowBattery: CharacteristicValue;
|
|
@@ -26,6 +27,7 @@ export class WaterDetector extends deviceBase {
|
|
|
26
27
|
};
|
|
27
28
|
|
|
28
29
|
private LeakSensor?: {
|
|
30
|
+
Name: CharacteristicValue;
|
|
29
31
|
Service: Service;
|
|
30
32
|
StatusActive: CharacteristicValue;
|
|
31
33
|
LeakDetected: CharacteristicValue;
|
|
@@ -48,49 +50,57 @@ export class WaterDetector extends deviceBase {
|
|
|
48
50
|
this.doWaterDetectorUpdate = new Subject();
|
|
49
51
|
this.WaterDetectorUpdateInProgress = false;
|
|
50
52
|
|
|
51
|
-
// Initialize Battery
|
|
53
|
+
// Initialize Battery Service
|
|
52
54
|
this.Battery = {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
Name: accessory.context.Battery.Name ?? `${accessory.displayName} Battery`,
|
|
56
|
+
Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
|
|
57
|
+
BatteryLevel: accessory.context.BatteryLevel ?? 100,
|
|
58
|
+
StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
|
|
59
|
+
ChargingState: accessory.context.ChargingState ?? this.hap.Characteristic.ChargingState.NOT_CHARGEABLE,
|
|
57
60
|
};
|
|
58
61
|
|
|
59
|
-
// Initialize
|
|
60
|
-
|
|
61
|
-
this.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
// Initialize Battery Characteristic
|
|
63
|
+
this.Battery.Service
|
|
64
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name)
|
|
65
|
+
.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE)
|
|
66
|
+
.getCharacteristic(this.hap.Characteristic.BatteryLevel)
|
|
67
|
+
.onGet(() => {
|
|
68
|
+
return this.Battery.StatusLowBattery;
|
|
69
|
+
});
|
|
67
70
|
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
this.Battery.Service
|
|
72
|
+
.getCharacteristic(this.hap.Characteristic.StatusLowBattery)
|
|
73
|
+
.onGet(() => {
|
|
74
|
+
return this.Battery.StatusLowBattery;
|
|
75
|
+
});
|
|
76
|
+
accessory.context.Battery.Name = this.Battery.Name;
|
|
70
77
|
|
|
71
|
-
// Leak Sensor Service
|
|
78
|
+
// Initialize Leak Sensor Service
|
|
72
79
|
if (device.waterdetector?.hide_leak) {
|
|
73
80
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leak Sensor Service`);
|
|
74
81
|
this.LeakSensor!.Service = this.accessory.getService(this.hap.Service.LeakSensor) as Service;
|
|
75
82
|
accessory.removeService(this.LeakSensor!.Service);
|
|
76
|
-
} else if (!this.LeakSensor?.Service) {
|
|
77
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Leak Sensor Service`);
|
|
78
|
-
const LeakSensorService = `${accessory.displayName} Leak Sensor`;
|
|
79
|
-
(this.LeakSensor!.Service = this.accessory.getService(this.hap.Service.LeakSensor)
|
|
80
|
-
|| this.accessory.addService(this.hap.Service.LeakSensor)), LeakSensorService;
|
|
81
|
-
|
|
82
|
-
this.LeakSensor!.Service.setCharacteristic(this.hap.Characteristic.Name, LeakSensorService);
|
|
83
83
|
} else {
|
|
84
|
-
this.
|
|
85
|
-
|
|
84
|
+
this.LeakSensor = {
|
|
85
|
+
Name: accessory.context.LeakSensor.Name ?? `${accessory.displayName} Leak Sensor`,
|
|
86
|
+
Service: accessory.getService(this.hap.Service.LeakSensor) ?? this.accessory.addService(this.hap.Service.LeakSensor) as Service,
|
|
87
|
+
StatusActive: accessory.context.StatusActive ?? false,
|
|
88
|
+
LeakDetected: accessory.context.LeakDetected ?? this.hap.Characteristic.LeakDetected.LEAK_NOT_DETECTED,
|
|
89
|
+
};
|
|
86
90
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
// Initialize LeakSensor Characteristic
|
|
92
|
+
this.LeakSensor!.Service
|
|
93
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.LeakSensor.Name)
|
|
94
|
+
.setCharacteristic(this.hap.Characteristic.StatusActive, true)
|
|
95
|
+
.getCharacteristic(this.hap.Characteristic.LeakDetected)
|
|
96
|
+
.onGet(() => {
|
|
97
|
+
return this.LeakSensor!.LeakDetected;
|
|
98
|
+
});
|
|
99
|
+
accessory.context.LeakSensor.Name = this.LeakSensor.Name;
|
|
100
|
+
}
|
|
91
101
|
|
|
92
|
-
|
|
93
|
-
this.
|
|
102
|
+
// Retrieve initial values and updateHomekit
|
|
103
|
+
this.refreshStatus();
|
|
94
104
|
|
|
95
105
|
// Retrieve initial values and updateHomekit
|
|
96
106
|
this.updateHomeKitCharacteristics();
|