@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
package/src/device/meter.ts
CHANGED
|
@@ -15,17 +15,20 @@ import type { device, devicesConfig, serviceData, deviceStatus} from '../setting
|
|
|
15
15
|
export class Meter extends deviceBase {
|
|
16
16
|
// Services
|
|
17
17
|
private Battery: {
|
|
18
|
+
Name: CharacteristicValue;
|
|
18
19
|
Service: Service;
|
|
19
20
|
BatteryLevel: CharacteristicValue;
|
|
20
21
|
StatusLowBattery: CharacteristicValue;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
private HumiditySensor?: {
|
|
25
|
+
Name: CharacteristicValue;
|
|
24
26
|
Service: Service;
|
|
25
27
|
CurrentRelativeHumidity: CharacteristicValue;
|
|
26
28
|
};
|
|
27
29
|
|
|
28
30
|
private TemperatureSensor?: {
|
|
31
|
+
Name: CharacteristicValue;
|
|
29
32
|
Service: Service;
|
|
30
33
|
CurrentTemperature: CharacteristicValue;
|
|
31
34
|
};
|
|
@@ -44,45 +47,45 @@ export class Meter extends deviceBase {
|
|
|
44
47
|
this.doMeterUpdate = new Subject();
|
|
45
48
|
this.meterUpdateInProgress = false;
|
|
46
49
|
|
|
47
|
-
// Initialize
|
|
48
|
-
if (!device.meter?.hide_temperature) {
|
|
49
|
-
this.TemperatureSensor = {
|
|
50
|
-
Service: accessory.getService(this.hap.Service.TemperatureSensor) as Service,
|
|
51
|
-
CurrentTemperature: accessory.context.CurrentTemperature || 30,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Initialize Humidity Sensor property
|
|
56
|
-
if (!device.meter?.hide_humidity) {
|
|
57
|
-
this.HumiditySensor = {
|
|
58
|
-
Service: accessory.getService(this.hap.Service.HumiditySensor) as Service,
|
|
59
|
-
CurrentRelativeHumidity: accessory.context.CurrentRelativeHumidity || 50,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Initialize Battery property
|
|
50
|
+
// Initialize Battery Service
|
|
64
51
|
this.Battery = {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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,
|
|
68
56
|
};
|
|
69
57
|
|
|
70
|
-
//
|
|
71
|
-
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;
|
|
72
73
|
|
|
73
|
-
// Temperature Sensor Service
|
|
74
|
+
// Initialize Temperature Sensor Service
|
|
74
75
|
if (device.meter?.hide_temperature) {
|
|
75
76
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
76
77
|
this.TemperatureSensor!.Service = this.accessory.getService(this.hap.Service.TemperatureSensor) as Service;
|
|
77
78
|
accessory.removeService(this.TemperatureSensor!.Service);
|
|
78
|
-
} else
|
|
79
|
-
this.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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)
|
|
86
89
|
.getCharacteristic(this.hap.Characteristic.CurrentTemperature)
|
|
87
90
|
.setProps({
|
|
88
91
|
unit: Units['CELSIUS'],
|
|
@@ -94,23 +97,23 @@ export class Meter extends deviceBase {
|
|
|
94
97
|
.onGet(() => {
|
|
95
98
|
return this.TemperatureSensor!.CurrentTemperature!;
|
|
96
99
|
});
|
|
97
|
-
|
|
98
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
100
|
+
accessory.context.TemperatureSensor.Name = this.TemperatureSensor.Name;
|
|
99
101
|
}
|
|
100
|
-
|
|
101
|
-
// Humidity Sensor Service
|
|
102
|
+
// Initialize Humidity Sensor Service
|
|
102
103
|
if (device.meter?.hide_humidity) {
|
|
103
104
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Humidity Sensor Service`);
|
|
104
105
|
this.HumiditySensor!.Service = this.accessory.getService(this.hap.Service.HumiditySensor) as Service;
|
|
105
106
|
accessory.removeService(this.HumiditySensor!.Service);
|
|
106
|
-
} else
|
|
107
|
-
this.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
+
};
|
|
111
113
|
|
|
112
|
-
|
|
114
|
+
// Initialize Humidity Sensor Characteristics
|
|
113
115
|
this.HumiditySensor!.Service
|
|
116
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.HumiditySensor.Name)
|
|
114
117
|
.getCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity)
|
|
115
118
|
.setProps({
|
|
116
119
|
minStep: 0.1,
|
|
@@ -118,17 +121,11 @@ export class Meter extends deviceBase {
|
|
|
118
121
|
.onGet(() => {
|
|
119
122
|
return this.HumiditySensor!.CurrentRelativeHumidity!;
|
|
120
123
|
});
|
|
121
|
-
|
|
122
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Humidity Sensor Service Not Added`);
|
|
124
|
+
accessory.context.HumiditySensor.Name = this.HumiditySensor.Name;
|
|
123
125
|
}
|
|
124
126
|
|
|
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);
|
|
127
|
+
// Retrieve initial values and updateHomekit
|
|
128
|
+
this.refreshStatus();
|
|
132
129
|
|
|
133
130
|
// Retrieve initial values and update Homekit
|
|
134
131
|
this.updateHomeKitCharacteristics();
|
package/src/device/meterplus.ts
CHANGED
|
@@ -19,17 +19,20 @@ import type { device, devicesConfig, serviceData, deviceStatus} from '../setting
|
|
|
19
19
|
export class MeterPlus extends deviceBase {
|
|
20
20
|
// Services
|
|
21
21
|
private Battery: {
|
|
22
|
+
Name: CharacteristicValue;
|
|
22
23
|
Service: Service;
|
|
23
24
|
BatteryLevel: CharacteristicValue;
|
|
24
25
|
StatusLowBattery: CharacteristicValue;
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
private HumiditySensor?: {
|
|
29
|
+
Name: CharacteristicValue;
|
|
28
30
|
Service: Service;
|
|
29
31
|
CurrentRelativeHumidity: CharacteristicValue;
|
|
30
32
|
};
|
|
31
33
|
|
|
32
34
|
private TemperatureSensor?: {
|
|
35
|
+
Name: CharacteristicValue;
|
|
33
36
|
Service: Service;
|
|
34
37
|
CurrentTemperature: CharacteristicValue;
|
|
35
38
|
};
|
|
@@ -48,45 +51,45 @@ export class MeterPlus extends deviceBase {
|
|
|
48
51
|
this.doMeterUpdate = new Subject();
|
|
49
52
|
this.meterUpdateInProgress = false;
|
|
50
53
|
|
|
51
|
-
// Initialize
|
|
52
|
-
if (!device.meter?.hide_temperature) {
|
|
53
|
-
this.TemperatureSensor = {
|
|
54
|
-
Service: accessory.getService(this.hap.Service.TemperatureSensor) as Service,
|
|
55
|
-
CurrentTemperature: accessory.context.CurrentTemperature || 30,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Initialize Humidity Sensor property
|
|
60
|
-
if (!device.meter?.hide_humidity) {
|
|
61
|
-
this.HumiditySensor = {
|
|
62
|
-
Service: accessory.getService(this.hap.Service.HumiditySensor) as Service,
|
|
63
|
-
CurrentRelativeHumidity: accessory.context.CurrentRelativeHumidity || 50,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Initialize Battery property
|
|
54
|
+
// Initialize Battery Service
|
|
68
55
|
this.Battery = {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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,
|
|
72
60
|
};
|
|
73
61
|
|
|
74
|
-
//
|
|
75
|
-
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;
|
|
76
77
|
|
|
77
|
-
// Temperature Sensor Service
|
|
78
|
+
// Initialize Temperature Sensor Service
|
|
78
79
|
if (device.meter?.hide_temperature) {
|
|
79
80
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
80
81
|
this.TemperatureSensor!.Service = this.accessory.getService(this.hap.Service.TemperatureSensor) as Service;
|
|
81
82
|
accessory.removeService(this.TemperatureSensor!.Service);
|
|
82
|
-
} else
|
|
83
|
-
this.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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)
|
|
90
93
|
.getCharacteristic(this.hap.Characteristic.CurrentTemperature)
|
|
91
94
|
.setProps({
|
|
92
95
|
unit: Units['CELSIUS'],
|
|
@@ -98,23 +101,23 @@ export class MeterPlus extends deviceBase {
|
|
|
98
101
|
.onGet(() => {
|
|
99
102
|
return this.TemperatureSensor!.CurrentTemperature!;
|
|
100
103
|
});
|
|
101
|
-
|
|
102
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
104
|
+
accessory.context.TemperatureSensor.Name = this.TemperatureSensor.Name;
|
|
103
105
|
}
|
|
104
|
-
|
|
105
|
-
// Humidity Sensor Service
|
|
106
|
+
// Initialize Humidity Sensor Service
|
|
106
107
|
if (device.meter?.hide_humidity) {
|
|
107
108
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Humidity Sensor Service`);
|
|
108
109
|
this.HumiditySensor!.Service = this.accessory.getService(this.hap.Service.HumiditySensor) as Service;
|
|
109
110
|
accessory.removeService(this.HumiditySensor!.Service);
|
|
110
|
-
} else
|
|
111
|
-
this.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
+
};
|
|
115
117
|
|
|
116
|
-
|
|
118
|
+
// Initialize Humidity Sensor Characteristics
|
|
117
119
|
this.HumiditySensor!.Service
|
|
120
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.HumiditySensor.Name)
|
|
118
121
|
.getCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity)
|
|
119
122
|
.setProps({
|
|
120
123
|
minStep: 0.1,
|
|
@@ -122,17 +125,11 @@ export class MeterPlus extends deviceBase {
|
|
|
122
125
|
.onGet(() => {
|
|
123
126
|
return this.HumiditySensor!.CurrentRelativeHumidity!;
|
|
124
127
|
});
|
|
125
|
-
|
|
126
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Humidity Sensor Service Not Added`);
|
|
128
|
+
accessory.context.HumiditySensor.Name = this.HumiditySensor.Name;
|
|
127
129
|
}
|
|
128
130
|
|
|
129
|
-
//
|
|
130
|
-
|
|
131
|
-
(this.Battery.Service = this.accessory.getService(this.hap.Service.Battery)
|
|
132
|
-
|| accessory.addService(this.hap.Service.Battery)), BatteryService;
|
|
133
|
-
|
|
134
|
-
this.Battery.Service.setCharacteristic(this.hap.Characteristic.Name, BatteryService);
|
|
135
|
-
this.Battery.Service.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
131
|
+
// Retrieve initial values and updateHomekit
|
|
132
|
+
this.refreshStatus();
|
|
136
133
|
|
|
137
134
|
// Retrieve initial values and updateHomekit
|
|
138
135
|
this.updateHomeKitCharacteristics();
|
package/src/device/motion.ts
CHANGED
|
@@ -19,17 +19,20 @@ import type { device, devicesConfig, serviceData, deviceStatus } from '../settin
|
|
|
19
19
|
export class Motion extends deviceBase {
|
|
20
20
|
// Services
|
|
21
21
|
private Battery: {
|
|
22
|
+
Name: CharacteristicValue;
|
|
22
23
|
Service: Service;
|
|
23
24
|
BatteryLevel: CharacteristicValue;
|
|
24
25
|
StatusLowBattery: CharacteristicValue;
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
private MotionSensor: {
|
|
29
|
+
Name: CharacteristicValue;
|
|
28
30
|
Service: Service;
|
|
29
31
|
MotionDetected: CharacteristicValue;
|
|
30
32
|
};
|
|
31
33
|
|
|
32
34
|
private LightSensor?: {
|
|
35
|
+
Name: CharacteristicValue;
|
|
33
36
|
Service: Service;
|
|
34
37
|
CurrentAmbientLightLevel: CharacteristicValue;
|
|
35
38
|
};
|
|
@@ -50,64 +53,72 @@ export class Motion extends deviceBase {
|
|
|
50
53
|
|
|
51
54
|
// Initialize Motion Sensor property
|
|
52
55
|
this.MotionSensor = {
|
|
56
|
+
Name: accessory.context.MotionSensor.Name ?? `${accessory.displayName} Motion Sensor`,
|
|
53
57
|
Service: accessory.getService(this.hap.Service.MotionSensor) ?? accessory.addService(this.hap.Service.MotionSensor) as Service,
|
|
54
|
-
MotionDetected: accessory.context.MotionDetected
|
|
58
|
+
MotionDetected: accessory.context.MotionDetected ?? false,
|
|
55
59
|
};
|
|
56
60
|
|
|
57
|
-
// Initialize
|
|
61
|
+
// Initialize Motion Sensor Characteristics
|
|
62
|
+
this.MotionSensor.Service
|
|
63
|
+
.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
|
|
64
|
+
.setCharacteristic(this.hap.Characteristic.StatusActive, true)
|
|
65
|
+
.getCharacteristic(this.hap.Characteristic.MotionDetected)
|
|
66
|
+
.onGet(() => {
|
|
67
|
+
return this.MotionSensor.MotionDetected;
|
|
68
|
+
});
|
|
69
|
+
accessory.context.MotionSensor.Name = this.MotionSensor.Name;
|
|
70
|
+
|
|
71
|
+
// Initialize Battery Service
|
|
58
72
|
this.Battery = {
|
|
73
|
+
Name: accessory.context.Battery.Name ?? `${accessory.displayName} Battery`,
|
|
59
74
|
Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
|
|
60
|
-
BatteryLevel: accessory.context.BatteryLevel
|
|
61
|
-
StatusLowBattery: accessory.context.StatusLowBattery
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
// Initialize Motion Sensor property
|
|
65
|
-
if (!device.motion?.hide_lightsensor) {
|
|
66
|
-
this.LightSensor = {
|
|
67
|
-
Service: accessory.getService(this.hap.Service.LightSensor) as Service,
|
|
68
|
-
CurrentAmbientLightLevel: accessory.context.CurrentAmbientLightLevel || 0,
|
|
69
|
-
};
|
|
75
|
+
BatteryLevel: accessory.context.BatteryLevel ?? 100,
|
|
76
|
+
StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
|
|
70
77
|
};
|
|
71
78
|
|
|
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
|
+
});
|
|
72
87
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
this.MotionSensor.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
84
|
-
// see https://developers.homebridge.io/#/service/MotionSensor
|
|
88
|
+
this.Battery.Service
|
|
89
|
+
.setCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery)
|
|
90
|
+
.getCharacteristic(this.hap.Characteristic.StatusLowBattery)
|
|
91
|
+
.onGet(() => {
|
|
92
|
+
return this.Battery.StatusLowBattery;
|
|
93
|
+
});
|
|
94
|
+
accessory.context.Battery.Name = this.Battery.Name;
|
|
85
95
|
|
|
86
|
-
// Light Sensor Service
|
|
96
|
+
// Initialize Light Sensor Service
|
|
87
97
|
if (device.motion?.hide_lightsensor) {
|
|
88
98
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
|
|
89
99
|
this.LightSensor!.Service = this.accessory.getService(this.hap.Service.LightSensor) as Service;
|
|
90
100
|
accessory.removeService(this.LightSensor!.Service);
|
|
91
|
-
} else if (!this.LightSensor?.Service) {
|
|
92
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
|
|
93
|
-
const LightSensorService = `${accessory.displayName} Light Sensor`;
|
|
94
|
-
(this.LightSensor!.Service = this.accessory.getService(this.hap.Service.LightSensor)
|
|
95
|
-
|| this.accessory.addService(this.hap.Service.LightSensor)), LightSensorService;
|
|
96
|
-
|
|
97
|
-
this.LightSensor!.Service.setCharacteristic(this.hap.Characteristic.Name, LightSensorService);
|
|
98
101
|
} else {
|
|
99
|
-
this.
|
|
100
|
-
|
|
102
|
+
this.LightSensor = {
|
|
103
|
+
Name: accessory.context.LightSensor.Name ?? `${accessory.displayName} Light Sensor`,
|
|
104
|
+
Service: accessory.getService(this.hap.Service.LightSensor) ?? this.accessory.addService(this.hap.Service.LightSensor) as Service,
|
|
105
|
+
CurrentAmbientLightLevel: accessory.context.CurrentAmbientLightLevel ?? 0,
|
|
106
|
+
};
|
|
101
107
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
108
|
+
// Initialize LightSensor Characteristics
|
|
109
|
+
this.LightSensor!.Service
|
|
110
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.LightSensor!.Name)
|
|
111
|
+
.setCharacteristic(this.hap.Characteristic.StatusActive, true)
|
|
112
|
+
.getCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel)
|
|
113
|
+
.onGet(() => {
|
|
114
|
+
return this.LightSensor!.CurrentAmbientLightLevel;
|
|
115
|
+
});
|
|
116
|
+
accessory.context.LightSensor.Name = this.LightSensor.Name;
|
|
117
|
+
};
|
|
106
118
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
119
|
+
|
|
120
|
+
// Retrieve initial values and updateHomekit
|
|
121
|
+
this.refreshStatus();
|
|
111
122
|
|
|
112
123
|
// Retrieve initial values and updateHomekit
|
|
113
124
|
this.updateHomeKitCharacteristics();
|
package/src/device/plug.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type { device, devicesConfig, serviceData, deviceStatus} from '../setting
|
|
|
13
13
|
export class Plug extends deviceBase {
|
|
14
14
|
// Services
|
|
15
15
|
private Outlet: {
|
|
16
|
+
Name: CharacteristicValue;
|
|
16
17
|
Service: Service;
|
|
17
18
|
On: CharacteristicValue;
|
|
18
19
|
};
|
|
@@ -31,28 +32,26 @@ export class Plug extends deviceBase {
|
|
|
31
32
|
this.doPlugUpdate = new Subject();
|
|
32
33
|
this.plugUpdateInProgress = false;
|
|
33
34
|
|
|
34
|
-
// Initialize Outlet
|
|
35
|
+
// Initialize Outlet Service
|
|
35
36
|
this.Outlet = {
|
|
36
|
-
|
|
37
|
+
Name: accessory.context.Outlet.Name ?? accessory.displayName,
|
|
38
|
+
Service: accessory.getService(this.hap.Service.Outlet) ?? accessory.addService(this.hap.Service.Outlet) as Service,
|
|
37
39
|
On: accessory.context.On || false,
|
|
38
40
|
};
|
|
39
41
|
|
|
42
|
+
// Initialize Outlet Characteristics
|
|
43
|
+
this.Outlet.Service
|
|
44
|
+
.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
|
|
45
|
+
.getCharacteristic(this.hap.Characteristic.On)
|
|
46
|
+
.onGet(() => {
|
|
47
|
+
return this.Outlet.On;
|
|
48
|
+
})
|
|
49
|
+
.onSet(this.OnSet.bind(this));
|
|
50
|
+
accessory.context.Outlet.Name = this.Outlet.Name;
|
|
51
|
+
|
|
40
52
|
// Retrieve initial values and updateHomekit
|
|
41
53
|
this.refreshStatus();
|
|
42
54
|
|
|
43
|
-
// get the Outlet service if it exists, otherwise create a new Outlet service
|
|
44
|
-
// you can create multiple services for each accessory
|
|
45
|
-
const OutletService = `${accessory.displayName} ${device.deviceType}`;
|
|
46
|
-
(this.Outlet.Service = accessory.getService(this.hap.Service.Outlet)
|
|
47
|
-
|| accessory.addService(this.hap.Service.Outlet)), OutletService;
|
|
48
|
-
|
|
49
|
-
this.Outlet.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
50
|
-
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
51
|
-
// see https://developers.homebridge.io/#/service/Outlet
|
|
52
|
-
|
|
53
|
-
// create handlers for required characteristics
|
|
54
|
-
this.Outlet.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
55
|
-
|
|
56
55
|
// Update Homekit
|
|
57
56
|
this.updateHomeKitCharacteristics();
|
|
58
57
|
|