@switchbot/homebridge-switchbot 3.5.0-beta.57 → 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/.vscode/settings.json +4 -1
- package/dist/device/blindtilt.d.ts +5 -5
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +103 -69
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +4 -4
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +201 -154
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +3 -3
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +41 -36
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +3 -3
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +36 -37
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +4 -4
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +76 -55
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +4 -4
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +99 -55
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +4 -4
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +11 -9
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +3 -3
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +54 -24
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +4 -4
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +40 -57
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +3 -3
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +39 -39
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +3 -3
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +41 -50
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +4 -4
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +36 -33
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +3 -3
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +68 -59
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +3 -3
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +42 -51
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +3 -3
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +42 -51
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +3 -3
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +52 -40
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +3 -3
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +13 -13
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +4 -4
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +81 -98
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +3 -3
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +39 -31
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +20 -14
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +3 -3
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +9 -9
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +3 -3
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +1 -1
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +3 -3
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +2 -2
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +6 -6
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +37 -29
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +3 -3
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +9 -14
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +67 -88
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +3 -3
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +1 -1
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +3 -3
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +3 -3
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +3 -3
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +2 -2
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +3 -3
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +2 -2
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +7 -7
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +20 -23
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +24 -10
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +16 -0
- package/dist/settings.js.map +1 -1
- package/eslint.config.js +89 -78
- package/package.json +3 -3
- package/src/device/blindtilt.ts +120 -87
- package/src/device/bot.ts +238 -175
- package/src/device/ceilinglight.ts +49 -46
- package/src/device/colorbulb.ts +40 -43
- package/src/device/contact.ts +91 -65
- package/src/device/curtain.ts +113 -66
- package/src/device/device.ts +12 -13
- package/src/device/fan.ts +66 -29
- package/src/device/hub.ts +53 -60
- package/src/device/humidifier.ts +54 -56
- package/src/device/iosensor.ts +57 -56
- package/src/device/lightstrip.ts +43 -39
- package/src/device/lock.ts +79 -68
- package/src/device/meter.ts +54 -54
- package/src/device/meterplus.ts +54 -54
- package/src/device/motion.ts +62 -46
- package/src/device/plug.ts +19 -18
- package/src/device/robotvacuumcleaner.ts +89 -104
- package/src/device/waterdetector.ts +46 -34
- package/src/homebridge-ui/public/index.html +20 -14
- package/src/index.ts +3 -2
- package/src/irdevice/airconditioner.ts +13 -11
- package/src/irdevice/airpurifier.ts +5 -3
- package/src/irdevice/camera.ts +6 -4
- package/src/irdevice/fan.ts +42 -29
- package/src/irdevice/irdevice.ts +4 -5
- package/src/irdevice/light.ts +83 -103
- package/src/irdevice/other.ts +5 -3
- package/src/irdevice/tv.ts +7 -5
- package/src/irdevice/vacuumcleaner.ts +6 -4
- package/src/irdevice/waterheater.ts +6 -4
- package/src/platform.ts +59 -66
- package/src/settings.ts +73 -58
package/src/device/lock.ts
CHANGED
|
@@ -1,31 +1,37 @@
|
|
|
1
1
|
import { request } from 'undici';
|
|
2
2
|
import { deviceBase } from './device.js';
|
|
3
3
|
import { interval, Subject } from 'rxjs';
|
|
4
|
-
import {
|
|
4
|
+
import { Devices } from '../settings.js';
|
|
5
5
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
6
|
-
|
|
7
|
-
import {
|
|
6
|
+
|
|
7
|
+
import type { SwitchBotPlatform } from '../platform.js';
|
|
8
|
+
import type { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
9
|
+
import type { device, devicesConfig, deviceStatus, serviceData } from '../settings.js';
|
|
8
10
|
|
|
9
11
|
export class Lock extends deviceBase {
|
|
10
12
|
// Services
|
|
11
13
|
private LockMechanism: {
|
|
14
|
+
Name: CharacteristicValue;
|
|
12
15
|
Service: Service;
|
|
13
16
|
LockTargetState: CharacteristicValue;
|
|
14
17
|
LockCurrentState: CharacteristicValue;
|
|
15
18
|
};
|
|
16
19
|
|
|
17
20
|
private Battery: {
|
|
21
|
+
Name: CharacteristicValue;
|
|
18
22
|
Service: Service;
|
|
19
23
|
BatteryLevel: CharacteristicValue;
|
|
20
24
|
StatusLowBattery: CharacteristicValue;
|
|
21
25
|
};
|
|
22
26
|
|
|
23
27
|
private ContactSensor?: {
|
|
28
|
+
Name: CharacteristicValue;
|
|
24
29
|
Service: Service;
|
|
25
30
|
ContactSensorState: CharacteristicValue;
|
|
26
31
|
};
|
|
27
32
|
|
|
28
33
|
private Switch?: {
|
|
34
|
+
Name: CharacteristicValue;
|
|
29
35
|
Service: Service;
|
|
30
36
|
On: CharacteristicValue;
|
|
31
37
|
};
|
|
@@ -44,91 +50,96 @@ export class Lock extends deviceBase {
|
|
|
44
50
|
this.doLockUpdate = new Subject();
|
|
45
51
|
this.lockUpdateInProgress = false;
|
|
46
52
|
|
|
47
|
-
// Initialize LockMechanism
|
|
53
|
+
// Initialize LockMechanism Service
|
|
48
54
|
this.LockMechanism = {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
Name: accessory.context.LockMechanism.Name ?? accessory.displayName,
|
|
56
|
+
Service: accessory.getService(this.hap.Service.LockMechanism) ?? accessory.addService(this.hap.Service.LockMechanism) as Service,
|
|
57
|
+
LockTargetState: accessory.context.LockTargetState ?? this.hap.Characteristic.LockTargetState.SECURED,
|
|
58
|
+
LockCurrentState: accessory.context.LockCurrentState ?? this.hap.Characteristic.LockCurrentState.SECURED,
|
|
52
59
|
};
|
|
53
60
|
|
|
61
|
+
// Initialize LockMechanism Characteristics
|
|
62
|
+
this.LockMechanism.Service
|
|
63
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.LockMechanism.Name)
|
|
64
|
+
.getCharacteristic(this.hap.Characteristic.LockTargetState)
|
|
65
|
+
.onGet(() => {
|
|
66
|
+
return this.LockMechanism.LockTargetState;
|
|
67
|
+
})
|
|
68
|
+
.onSet(this.LockTargetStateSet.bind(this));
|
|
69
|
+
accessory.context.LockMechanism.Name = this.LockMechanism.Name;
|
|
70
|
+
|
|
54
71
|
// Initialize Battery property
|
|
55
72
|
this.Battery = {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
73
|
+
Name: accessory.context.Battery.Name ?? `${accessory.displayName} Battery`,
|
|
74
|
+
Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
|
|
75
|
+
BatteryLevel: accessory.context.BatteryLevel ?? 100,
|
|
76
|
+
StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
|
|
59
77
|
};
|
|
60
78
|
|
|
61
|
-
// Initialize
|
|
62
|
-
|
|
79
|
+
// Initialize Battery Characteristics
|
|
80
|
+
this.Battery.Service
|
|
81
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name)
|
|
82
|
+
.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE)
|
|
83
|
+
.getCharacteristic(this.hap.Characteristic.BatteryLevel)
|
|
84
|
+
.onGet(() => {
|
|
85
|
+
return this.Battery.BatteryLevel;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
this.Battery.Service
|
|
89
|
+
.getCharacteristic(this.hap.Characteristic.StatusLowBattery)
|
|
90
|
+
.onGet(() => {
|
|
91
|
+
return this.Battery.StatusLowBattery;
|
|
92
|
+
});
|
|
93
|
+
accessory.context.Battery.Name = this.Battery.Name;
|
|
94
|
+
|
|
95
|
+
// Contact Sensor Service
|
|
96
|
+
if (device.lock?.hide_contactsensor) {
|
|
97
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Contact Sensor Service`);
|
|
98
|
+
this.ContactSensor!.Service = this.accessory.getService(this.hap.Service.ContactSensor) as Service;
|
|
99
|
+
accessory.removeService(this.ContactSensor!.Service);
|
|
100
|
+
} else {
|
|
63
101
|
this.ContactSensor = {
|
|
64
|
-
|
|
65
|
-
|
|
102
|
+
Name: accessory.context.ContactSensor.Name ?? `${accessory.displayName} Contact Sensor`,
|
|
103
|
+
Service: accessory.getService(this.hap.Service.ContactSensor) ?? this.accessory.addService(this.hap.Service.ContactSensor) as Service,
|
|
104
|
+
ContactSensorState: accessory.context.ContactSensorState ?? this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED,
|
|
66
105
|
};
|
|
67
|
-
}
|
|
68
106
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
107
|
+
// Initialize Contact Sensor Characteristics
|
|
108
|
+
this.ContactSensor.Service
|
|
109
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.ContactSensor.Name)
|
|
110
|
+
.setCharacteristic(this.hap.Characteristic.StatusActive, true)
|
|
111
|
+
.getCharacteristic(this.hap.Characteristic.ContactSensorState)
|
|
112
|
+
.onGet(() => {
|
|
113
|
+
return this.ContactSensor!.ContactSensorState;
|
|
114
|
+
});
|
|
115
|
+
accessory.context.ContactSensor.Name = this.ContactSensor.Name;
|
|
75
116
|
}
|
|
76
117
|
|
|
77
|
-
//
|
|
78
|
-
this.refreshStatus();
|
|
79
|
-
|
|
80
|
-
// get the LockMechanism service if it exists, otherwise create a new LockMechanism service
|
|
81
|
-
// you can create multiple services for each accessory
|
|
82
|
-
const LockMechanismService = `${accessory.displayName} ${device.deviceType}`;
|
|
83
|
-
(this.LockMechanism.Service = accessory.getService(this.hap.Service.LockMechanism)
|
|
84
|
-
|| accessory.addService(this.hap.Service.LockMechanism)), LockMechanismService;
|
|
85
|
-
|
|
86
|
-
this.LockMechanism.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
87
|
-
|
|
88
|
-
this.LockMechanism.Service.getCharacteristic(this.hap.Characteristic.LockTargetState).onSet(this.LockTargetStateSet.bind(this));
|
|
89
|
-
|
|
90
|
-
// Latch Button Service
|
|
118
|
+
// Initialize Latch Button Service
|
|
91
119
|
if (device.lock?.activate_latchbutton === false) { // remove the service when this variable is false
|
|
92
120
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Latch Button Service`);
|
|
93
121
|
this.Switch!.Service = accessory.getService(this.hap.Service.Switch) as Service;
|
|
94
122
|
accessory.removeService(this.Switch!.Service);
|
|
95
|
-
} else if (!this.Switch!.Service && device.lock?.activate_latchbutton === true) {
|
|
96
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Adding Latch Button Service`);
|
|
97
|
-
const latchServiceName = `${accessory.displayName} Latch`;
|
|
98
|
-
this.Switch!.Service = accessory.getService(this.hap.Service.Switch)
|
|
99
|
-
|| accessory.addService(this.hap.Service.Switch, latchServiceName, 'Switch.ServiceIdentifier');
|
|
100
|
-
|
|
101
|
-
this.Switch!.Service.setCharacteristic(this.hap.Characteristic.Name, latchServiceName);
|
|
102
|
-
|
|
103
|
-
this.Switch!.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
104
123
|
} else {
|
|
105
|
-
this.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (device.lock?.hide_contactsensor) {
|
|
111
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Contact Sensor Service`);
|
|
112
|
-
this.ContactSensor!.Service = this.accessory.getService(this.hap.Service.ContactSensor) as Service;
|
|
113
|
-
accessory.removeService(this.ContactSensor!.Service);
|
|
114
|
-
} else if (!this.ContactSensor?.Service) {
|
|
115
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Contact Sensor Service`);
|
|
116
|
-
const ContactSensorService = `${accessory.displayName} Contact Sensor`;
|
|
117
|
-
(this.ContactSensor!.Service = this.accessory.getService(this.hap.Service.ContactSensor)
|
|
118
|
-
|| this.accessory.addService(this.hap.Service.ContactSensor)), ContactSensorService;
|
|
124
|
+
this.Switch = {
|
|
125
|
+
Name: accessory.context.Switch.Name ?? `${accessory.displayName} Latch`,
|
|
126
|
+
Service: accessory.getService(this.hap.Service.Switch) ?? accessory.addService(this.hap.Service.Switch) as Service,
|
|
127
|
+
On: accessory.context.On ?? false,
|
|
128
|
+
};
|
|
119
129
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
130
|
+
// Initialize Latch Button Characteristics
|
|
131
|
+
this.Switch.Service
|
|
132
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name)
|
|
133
|
+
.getCharacteristic(this.hap.Characteristic.On)
|
|
134
|
+
.onGet(() => {
|
|
135
|
+
return this.Switch!.On;
|
|
136
|
+
})
|
|
137
|
+
.onSet(this.OnSet.bind(this));
|
|
138
|
+
accessory.context.Switch.Name = this.Switch.Name;
|
|
123
139
|
}
|
|
124
140
|
|
|
125
|
-
//
|
|
126
|
-
|
|
127
|
-
(this.Battery.Service = this.accessory.getService(this.hap.Service.Battery)
|
|
128
|
-
|| accessory.addService(this.hap.Service.Battery)), BatteryService;
|
|
129
|
-
|
|
130
|
-
this.Battery.Service.setCharacteristic(this.hap.Characteristic.Name, BatteryService);
|
|
131
|
-
this.Battery.Service.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
141
|
+
// Retrieve initial values and updateHomekit
|
|
142
|
+
this.refreshStatus();
|
|
132
143
|
|
|
133
144
|
// Update Homekit
|
|
134
145
|
this.updateHomeKitCharacteristics();
|
package/src/device/meter.ts
CHANGED
|
@@ -2,27 +2,33 @@
|
|
|
2
2
|
*
|
|
3
3
|
* meter.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
+
import { Units } from 'homebridge';
|
|
6
|
+
import { Devices } from '../settings.js';
|
|
5
7
|
import { deviceBase } from './device.js';
|
|
6
|
-
import { SwitchBotPlatform } from '../platform.js';
|
|
7
8
|
import { convertUnits } from '../utils.js';
|
|
8
9
|
import { Subject, interval, skipWhile } from 'rxjs';
|
|
9
|
-
|
|
10
|
-
import {
|
|
10
|
+
|
|
11
|
+
import type { SwitchBotPlatform } from '../platform.js';
|
|
12
|
+
import type { CharacteristicValue, PlatformAccessory, Service} from 'homebridge';
|
|
13
|
+
import type { device, devicesConfig, serviceData, deviceStatus} from '../settings.js';
|
|
11
14
|
|
|
12
15
|
export class Meter extends deviceBase {
|
|
13
16
|
// Services
|
|
14
|
-
private Battery
|
|
17
|
+
private Battery: {
|
|
18
|
+
Name: CharacteristicValue;
|
|
15
19
|
Service: Service;
|
|
16
20
|
BatteryLevel: CharacteristicValue;
|
|
17
21
|
StatusLowBattery: CharacteristicValue;
|
|
18
22
|
};
|
|
19
23
|
|
|
20
24
|
private HumiditySensor?: {
|
|
25
|
+
Name: CharacteristicValue;
|
|
21
26
|
Service: Service;
|
|
22
27
|
CurrentRelativeHumidity: CharacteristicValue;
|
|
23
28
|
};
|
|
24
29
|
|
|
25
30
|
private TemperatureSensor?: {
|
|
31
|
+
Name: CharacteristicValue;
|
|
26
32
|
Service: Service;
|
|
27
33
|
CurrentTemperature: CharacteristicValue;
|
|
28
34
|
};
|
|
@@ -41,45 +47,45 @@ export class Meter extends deviceBase {
|
|
|
41
47
|
this.doMeterUpdate = new Subject();
|
|
42
48
|
this.meterUpdateInProgress = false;
|
|
43
49
|
|
|
44
|
-
// Initialize
|
|
45
|
-
if (!device.meter?.hide_temperature) {
|
|
46
|
-
this.TemperatureSensor = {
|
|
47
|
-
Service: accessory.getService(this.hap.Service.TemperatureSensor) as Service,
|
|
48
|
-
CurrentTemperature: accessory.context.CurrentTemperature || 30,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Initialize Humidity Sensor property
|
|
53
|
-
if (!device.meter?.hide_humidity) {
|
|
54
|
-
this.HumiditySensor = {
|
|
55
|
-
Service: accessory.getService(this.hap.Service.HumiditySensor) as Service,
|
|
56
|
-
CurrentRelativeHumidity: accessory.context.CurrentRelativeHumidity || 50,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Initialize Battery property
|
|
50
|
+
// Initialize Battery Service
|
|
61
51
|
this.Battery = {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
52
|
+
Name: accessory.context.Battery.Name ?? `${accessory.displayName} Battery`,
|
|
53
|
+
Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
|
|
54
|
+
BatteryLevel: accessory.context.BatteryLevel ?? 100,
|
|
55
|
+
StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
|
|
65
56
|
};
|
|
66
57
|
|
|
67
|
-
//
|
|
68
|
-
this.
|
|
58
|
+
// Initialize Battery Characteristics
|
|
59
|
+
this.Battery.Service
|
|
60
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name)
|
|
61
|
+
.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE)
|
|
62
|
+
.getCharacteristic(this.hap.Characteristic.BatteryLevel)
|
|
63
|
+
.onGet(() => {
|
|
64
|
+
return this.Battery.BatteryLevel;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
this.Battery.Service
|
|
68
|
+
.getCharacteristic(this.hap.Characteristic.StatusLowBattery)
|
|
69
|
+
.onGet(() => {
|
|
70
|
+
return this.Battery.StatusLowBattery;
|
|
71
|
+
});
|
|
72
|
+
accessory.context.Battery.Name = this.Battery.Name;
|
|
69
73
|
|
|
70
|
-
// Temperature Sensor Service
|
|
74
|
+
// Initialize Temperature Sensor Service
|
|
71
75
|
if (device.meter?.hide_temperature) {
|
|
72
76
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
73
77
|
this.TemperatureSensor!.Service = this.accessory.getService(this.hap.Service.TemperatureSensor) as Service;
|
|
74
78
|
accessory.removeService(this.TemperatureSensor!.Service);
|
|
75
|
-
} else
|
|
76
|
-
this.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
} else {
|
|
80
|
+
this.TemperatureSensor = {
|
|
81
|
+
Name: accessory.context.TemperatureSensor.Name ?? `${accessory.displayName} Temperature Sensor`,
|
|
82
|
+
Service: accessory.getService(this.hap.Service.TemperatureSensor) ?? this.accessory.addService(this.hap.Service.TemperatureSensor) as Service,
|
|
83
|
+
CurrentTemperature: accessory.context.CurrentTemperature ?? 30,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// Initialize Temperature Sensor Characteristics
|
|
87
|
+
this.TemperatureSensor.Service
|
|
88
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.TemperatureSensor.Name)
|
|
83
89
|
.getCharacteristic(this.hap.Characteristic.CurrentTemperature)
|
|
84
90
|
.setProps({
|
|
85
91
|
unit: Units['CELSIUS'],
|
|
@@ -91,23 +97,23 @@ export class Meter extends deviceBase {
|
|
|
91
97
|
.onGet(() => {
|
|
92
98
|
return this.TemperatureSensor!.CurrentTemperature!;
|
|
93
99
|
});
|
|
94
|
-
|
|
95
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
100
|
+
accessory.context.TemperatureSensor.Name = this.TemperatureSensor.Name;
|
|
96
101
|
}
|
|
97
|
-
|
|
98
|
-
// Humidity Sensor Service
|
|
102
|
+
// Initialize Humidity Sensor Service
|
|
99
103
|
if (device.meter?.hide_humidity) {
|
|
100
104
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Humidity Sensor Service`);
|
|
101
105
|
this.HumiditySensor!.Service = this.accessory.getService(this.hap.Service.HumiditySensor) as Service;
|
|
102
106
|
accessory.removeService(this.HumiditySensor!.Service);
|
|
103
|
-
} else
|
|
104
|
-
this.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
107
|
+
} else {
|
|
108
|
+
this.HumiditySensor = {
|
|
109
|
+
Name: accessory.context.HumiditySensor.Name ?? `${accessory.displayName} Humidity Sensor`,
|
|
110
|
+
Service: accessory.getService(this.hap.Service.HumiditySensor) ?? this.accessory.addService(this.hap.Service.HumiditySensor) as Service,
|
|
111
|
+
CurrentRelativeHumidity: accessory.context.CurrentRelativeHumidity ?? 50,
|
|
112
|
+
};
|
|
108
113
|
|
|
109
|
-
|
|
114
|
+
// Initialize Humidity Sensor Characteristics
|
|
110
115
|
this.HumiditySensor!.Service
|
|
116
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.HumiditySensor.Name)
|
|
111
117
|
.getCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity)
|
|
112
118
|
.setProps({
|
|
113
119
|
minStep: 0.1,
|
|
@@ -115,17 +121,11 @@ export class Meter extends deviceBase {
|
|
|
115
121
|
.onGet(() => {
|
|
116
122
|
return this.HumiditySensor!.CurrentRelativeHumidity!;
|
|
117
123
|
});
|
|
118
|
-
|
|
119
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Humidity Sensor Service Not Added`);
|
|
124
|
+
accessory.context.HumiditySensor.Name = this.HumiditySensor.Name;
|
|
120
125
|
}
|
|
121
126
|
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
(this.Battery.Service = this.accessory.getService(this.hap.Service.Battery)
|
|
125
|
-
|| accessory.addService(this.hap.Service.Battery)), BatteryService;
|
|
126
|
-
|
|
127
|
-
this.Battery.Service.setCharacteristic(this.hap.Characteristic.Name, BatteryService);
|
|
128
|
-
this.Battery.Service.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
127
|
+
// Retrieve initial values and updateHomekit
|
|
128
|
+
this.refreshStatus();
|
|
129
129
|
|
|
130
130
|
// Retrieve initial values and update Homekit
|
|
131
131
|
this.updateHomeKitCharacteristics();
|
package/src/device/meterplus.ts
CHANGED
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
*
|
|
3
3
|
* meterplus.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
+
import { Units } from 'homebridge';
|
|
6
|
+
import { Devices } from '../settings.js';
|
|
5
7
|
import { deviceBase } from './device.js';
|
|
6
|
-
import { SwitchBotPlatform } from '../platform.js';
|
|
7
8
|
import { Subject, interval, skipWhile } from 'rxjs';
|
|
8
|
-
|
|
9
|
-
import {
|
|
9
|
+
|
|
10
|
+
import type { SwitchBotPlatform } from '../platform.js';
|
|
11
|
+
import type { CharacteristicValue, PlatformAccessory, Service} from 'homebridge';
|
|
12
|
+
import type { device, devicesConfig, serviceData, deviceStatus} from '../settings.js';
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
15
|
* Platform Accessory
|
|
@@ -15,18 +18,21 @@ import { device, devicesConfig, serviceData, deviceStatus, Devices } from '../se
|
|
|
15
18
|
*/
|
|
16
19
|
export class MeterPlus extends deviceBase {
|
|
17
20
|
// Services
|
|
18
|
-
private Battery
|
|
21
|
+
private Battery: {
|
|
22
|
+
Name: CharacteristicValue;
|
|
19
23
|
Service: Service;
|
|
20
24
|
BatteryLevel: CharacteristicValue;
|
|
21
25
|
StatusLowBattery: CharacteristicValue;
|
|
22
26
|
};
|
|
23
27
|
|
|
24
28
|
private HumiditySensor?: {
|
|
29
|
+
Name: CharacteristicValue;
|
|
25
30
|
Service: Service;
|
|
26
31
|
CurrentRelativeHumidity: CharacteristicValue;
|
|
27
32
|
};
|
|
28
33
|
|
|
29
34
|
private TemperatureSensor?: {
|
|
35
|
+
Name: CharacteristicValue;
|
|
30
36
|
Service: Service;
|
|
31
37
|
CurrentTemperature: CharacteristicValue;
|
|
32
38
|
};
|
|
@@ -45,45 +51,45 @@ export class MeterPlus extends deviceBase {
|
|
|
45
51
|
this.doMeterUpdate = new Subject();
|
|
46
52
|
this.meterUpdateInProgress = false;
|
|
47
53
|
|
|
48
|
-
// Initialize
|
|
49
|
-
if (!device.meter?.hide_temperature) {
|
|
50
|
-
this.TemperatureSensor = {
|
|
51
|
-
Service: accessory.getService(this.hap.Service.TemperatureSensor) as Service,
|
|
52
|
-
CurrentTemperature: accessory.context.CurrentTemperature || 30,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Initialize Humidity Sensor property
|
|
57
|
-
if (!device.meter?.hide_humidity) {
|
|
58
|
-
this.HumiditySensor = {
|
|
59
|
-
Service: accessory.getService(this.hap.Service.HumiditySensor) as Service,
|
|
60
|
-
CurrentRelativeHumidity: accessory.context.CurrentRelativeHumidity || 50,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Initialize Battery property
|
|
54
|
+
// Initialize Battery Service
|
|
65
55
|
this.Battery = {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
56
|
+
Name: accessory.context.Battery.Name ?? `${accessory.displayName} Battery`,
|
|
57
|
+
Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
|
|
58
|
+
BatteryLevel: accessory.context.BatteryLevel ?? 100,
|
|
59
|
+
StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
|
|
69
60
|
};
|
|
70
61
|
|
|
71
|
-
//
|
|
72
|
-
this.
|
|
62
|
+
// Initialize Battery Characteristics
|
|
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.BatteryLevel;
|
|
69
|
+
});
|
|
70
|
+
|
|
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;
|
|
73
77
|
|
|
74
|
-
// Temperature Sensor Service
|
|
78
|
+
// Initialize Temperature Sensor Service
|
|
75
79
|
if (device.meter?.hide_temperature) {
|
|
76
80
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
77
81
|
this.TemperatureSensor!.Service = this.accessory.getService(this.hap.Service.TemperatureSensor) as Service;
|
|
78
82
|
accessory.removeService(this.TemperatureSensor!.Service);
|
|
79
|
-
} else
|
|
80
|
-
this.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
} else {
|
|
84
|
+
this.TemperatureSensor = {
|
|
85
|
+
Name: accessory.context.TemperatureSensor.Name ?? `${accessory.displayName} Temperature Sensor`,
|
|
86
|
+
Service: accessory.getService(this.hap.Service.TemperatureSensor) ?? this.accessory.addService(this.hap.Service.TemperatureSensor) as Service,
|
|
87
|
+
CurrentTemperature: accessory.context.CurrentTemperature ?? 30,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// Initialize Temperature Sensor Characteristics
|
|
91
|
+
this.TemperatureSensor.Service
|
|
92
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.TemperatureSensor.Name)
|
|
87
93
|
.getCharacteristic(this.hap.Characteristic.CurrentTemperature)
|
|
88
94
|
.setProps({
|
|
89
95
|
unit: Units['CELSIUS'],
|
|
@@ -95,23 +101,23 @@ export class MeterPlus extends deviceBase {
|
|
|
95
101
|
.onGet(() => {
|
|
96
102
|
return this.TemperatureSensor!.CurrentTemperature!;
|
|
97
103
|
});
|
|
98
|
-
|
|
99
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
104
|
+
accessory.context.TemperatureSensor.Name = this.TemperatureSensor.Name;
|
|
100
105
|
}
|
|
101
|
-
|
|
102
|
-
// Humidity Sensor Service
|
|
106
|
+
// Initialize Humidity Sensor Service
|
|
103
107
|
if (device.meter?.hide_humidity) {
|
|
104
108
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Humidity Sensor Service`);
|
|
105
109
|
this.HumiditySensor!.Service = this.accessory.getService(this.hap.Service.HumiditySensor) as Service;
|
|
106
110
|
accessory.removeService(this.HumiditySensor!.Service);
|
|
107
|
-
} else
|
|
108
|
-
this.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
111
|
+
} else {
|
|
112
|
+
this.HumiditySensor = {
|
|
113
|
+
Name: accessory.context.HumiditySensor.Name ?? `${accessory.displayName} Humidity Sensor`,
|
|
114
|
+
Service: accessory.getService(this.hap.Service.HumiditySensor) ?? this.accessory.addService(this.hap.Service.HumiditySensor) as Service,
|
|
115
|
+
CurrentRelativeHumidity: accessory.context.CurrentRelativeHumidity ?? 50,
|
|
116
|
+
};
|
|
112
117
|
|
|
113
|
-
|
|
118
|
+
// Initialize Humidity Sensor Characteristics
|
|
114
119
|
this.HumiditySensor!.Service
|
|
120
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.HumiditySensor.Name)
|
|
115
121
|
.getCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity)
|
|
116
122
|
.setProps({
|
|
117
123
|
minStep: 0.1,
|
|
@@ -119,17 +125,11 @@ export class MeterPlus extends deviceBase {
|
|
|
119
125
|
.onGet(() => {
|
|
120
126
|
return this.HumiditySensor!.CurrentRelativeHumidity!;
|
|
121
127
|
});
|
|
122
|
-
|
|
123
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Humidity Sensor Service Not Added`);
|
|
128
|
+
accessory.context.HumiditySensor.Name = this.HumiditySensor.Name;
|
|
124
129
|
}
|
|
125
130
|
|
|
126
|
-
//
|
|
127
|
-
|
|
128
|
-
(this.Battery.Service = this.accessory.getService(this.hap.Service.Battery)
|
|
129
|
-
|| accessory.addService(this.hap.Service.Battery)), BatteryService;
|
|
130
|
-
|
|
131
|
-
this.Battery.Service.setCharacteristic(this.hap.Characteristic.Name, BatteryService);
|
|
132
|
-
this.Battery.Service.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
131
|
+
// Retrieve initial values and updateHomekit
|
|
132
|
+
this.refreshStatus();
|
|
133
133
|
|
|
134
134
|
// Retrieve initial values and updateHomekit
|
|
135
135
|
this.updateHomeKitCharacteristics();
|