@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/humidifier.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
|
7
7
|
|
|
8
8
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
9
9
|
import type { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
10
|
-
import type { device, devicesConfig, serviceData, deviceStatus} from '../settings.js';
|
|
10
|
+
import type { device, devicesConfig, serviceData, deviceStatus } from '../settings.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Platform Accessory
|
|
@@ -17,6 +17,7 @@ import type { device, devicesConfig, serviceData, deviceStatus} from '../setting
|
|
|
17
17
|
export class Humidifier extends deviceBase {
|
|
18
18
|
// Services
|
|
19
19
|
private HumidifierDehumidifier: {
|
|
20
|
+
Name: CharacteristicValue;
|
|
20
21
|
Service: Service;
|
|
21
22
|
Active: CharacteristicValue;
|
|
22
23
|
WaterLevel: CharacteristicValue;
|
|
@@ -27,6 +28,7 @@ export class Humidifier extends deviceBase {
|
|
|
27
28
|
};
|
|
28
29
|
|
|
29
30
|
private TemperatureSensor?: {
|
|
31
|
+
Name: CharacteristicValue;
|
|
30
32
|
Service: Service;
|
|
31
33
|
CurrentTemperature: CharacteristicValue;
|
|
32
34
|
};
|
|
@@ -47,46 +49,24 @@ export class Humidifier extends deviceBase {
|
|
|
47
49
|
|
|
48
50
|
// Initialize the HumidifierDehumidifier Service
|
|
49
51
|
this.HumidifierDehumidifier = {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
Name: accessory.context.HumidifierDehumidifier.Name ?? accessory.displayName,
|
|
53
|
+
Service: accessory.getService(this.hap.Service.HumidifierDehumidifier)
|
|
54
|
+
?? accessory.addService(this.hap.Service.HumidifierDehumidifier) as Service,
|
|
55
|
+
Active: accessory.context.Active ?? this.hap.Characteristic.Active.ACTIVE,
|
|
56
|
+
WaterLevel: accessory.context.WaterLevel ?? 100,
|
|
57
|
+
CurrentRelativeHumidity: accessory.context.CurrentRelativeHumidity ?? 50,
|
|
54
58
|
TargetHumidifierDehumidifierState: accessory.context.TargetHumidifierDehumidifierState
|
|
55
|
-
|
|
59
|
+
?? this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER,
|
|
56
60
|
CurrentHumidifierDehumidifierState: accessory.context.CurrentHumidifierDehumidifierState
|
|
57
|
-
|
|
58
|
-
RelativeHumidityHumidifierThreshold: accessory.context.RelativeHumidityHumidifierThreshold
|
|
61
|
+
?? this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE,
|
|
62
|
+
RelativeHumidityHumidifierThreshold: accessory.context.RelativeHumidityHumidifierThreshold ?? 50,
|
|
59
63
|
};
|
|
60
64
|
|
|
61
|
-
// Initialize the
|
|
62
|
-
if (!device.humidifier?.hide_temperature) {
|
|
63
|
-
this.TemperatureSensor = {
|
|
64
|
-
Service: accessory.getService(this.hap.Service.TemperatureSensor) as Service,
|
|
65
|
-
CurrentTemperature: accessory.context.CurrentTemperature || 30,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Retrieve initial values and updateHomekit
|
|
70
|
-
this.refreshStatus();
|
|
71
|
-
|
|
72
|
-
// get the service if it exists, otherwise create a new service
|
|
73
|
-
// you can create multiple services for each accessory
|
|
74
|
-
const HumidifierDehumidifierService = `${accessory.displayName} Humidifier`;
|
|
75
|
-
(this.HumidifierDehumidifier.Service = accessory.getService(this.hap.Service.HumidifierDehumidifier)
|
|
76
|
-
|| accessory.addService(this.hap.Service.HumidifierDehumidifier)), HumidifierDehumidifierService;
|
|
77
|
-
|
|
78
|
-
this.HumidifierDehumidifier.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
79
|
-
|
|
80
|
-
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
81
|
-
// see https://developers.homebridge.io/#/service/HumidifierDehumidifier
|
|
82
|
-
|
|
83
|
-
// create handlers for required characteristics
|
|
84
|
-
this.HumidifierDehumidifier.Service.setCharacteristic(
|
|
85
|
-
this.hap.Characteristic.CurrentHumidifierDehumidifierState,
|
|
86
|
-
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState,
|
|
87
|
-
);
|
|
88
|
-
|
|
65
|
+
// Initialize the HumidifierDehumidifier Characteristics
|
|
89
66
|
this.HumidifierDehumidifier.Service
|
|
67
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.HumidifierDehumidifier.Name)
|
|
68
|
+
.setCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState,
|
|
69
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState)
|
|
90
70
|
.getCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState)
|
|
91
71
|
.setProps({
|
|
92
72
|
validValueRanges: [0, 1],
|
|
@@ -94,9 +74,17 @@ export class Humidifier extends deviceBase {
|
|
|
94
74
|
maxValue: 1,
|
|
95
75
|
validValues: [0, 1],
|
|
96
76
|
})
|
|
77
|
+
.onGet(() => {
|
|
78
|
+
return this.HumidifierDehumidifier.TargetHumidifierDehumidifierState;
|
|
79
|
+
})
|
|
97
80
|
.onSet(this.TargetHumidifierDehumidifierStateSet.bind(this));
|
|
98
81
|
|
|
99
|
-
this.HumidifierDehumidifier.Service
|
|
82
|
+
this.HumidifierDehumidifier.Service
|
|
83
|
+
.getCharacteristic(this.hap.Characteristic.Active)
|
|
84
|
+
.onGet(() => {
|
|
85
|
+
return this.HumidifierDehumidifier.Active;
|
|
86
|
+
})
|
|
87
|
+
.onSet(this.ActiveSet.bind(this));
|
|
100
88
|
|
|
101
89
|
this.HumidifierDehumidifier.Service
|
|
102
90
|
.getCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold)
|
|
@@ -106,21 +94,27 @@ export class Humidifier extends deviceBase {
|
|
|
106
94
|
maxValue: 100,
|
|
107
95
|
minStep: this.minStep(device),
|
|
108
96
|
})
|
|
97
|
+
.onGet(() => {
|
|
98
|
+
return this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold;
|
|
99
|
+
})
|
|
109
100
|
.onSet(this.RelativeHumidityHumidifierThresholdSet.bind(this));
|
|
101
|
+
accessory.context.HumidifierDehumidifier.Name = this.HumidifierDehumidifier.Name;
|
|
110
102
|
|
|
111
|
-
// Temperature Sensor Service
|
|
112
|
-
if (device.humidifier?.hide_temperature
|
|
103
|
+
// Initialize the Temperature Sensor Service
|
|
104
|
+
if (device.humidifier?.hide_temperature) {
|
|
113
105
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
114
106
|
this.TemperatureSensor!.Service = this.accessory.getService(this.hap.Service.TemperatureSensor) as Service;
|
|
115
107
|
accessory.removeService(this.TemperatureSensor!.Service);
|
|
116
|
-
} else
|
|
117
|
-
this.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
108
|
+
} else {
|
|
109
|
+
this.TemperatureSensor = {
|
|
110
|
+
Name: accessory.context.TemperatureSensor.Name ?? `${accessory.displayName} Temperature Sensor`,
|
|
111
|
+
Service: accessory.getService(this.hap.Service.TemperatureSensor) ?? this.accessory.addService(this.hap.Service.TemperatureSensor) as Service,
|
|
112
|
+
CurrentTemperature: accessory.context.CurrentTemperature || 30,
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// Initialize the Temperature Sensor Characteristics
|
|
116
|
+
this.TemperatureSensor.Service
|
|
117
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.TemperatureSensor.Name)
|
|
124
118
|
.getCharacteristic(this.hap.Characteristic.CurrentTemperature)
|
|
125
119
|
.setProps({
|
|
126
120
|
validValueRanges: [-273.15, 100],
|
|
@@ -131,10 +125,12 @@ export class Humidifier extends deviceBase {
|
|
|
131
125
|
.onGet(() => {
|
|
132
126
|
return this.TemperatureSensor!.CurrentTemperature;
|
|
133
127
|
});
|
|
134
|
-
|
|
135
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
128
|
+
accessory.context.TemperatureSensor.Name = this.TemperatureSensor.Name;
|
|
136
129
|
}
|
|
137
130
|
|
|
131
|
+
// Retrieve initial values and updateHomekit
|
|
132
|
+
this.refreshStatus();
|
|
133
|
+
|
|
138
134
|
// Retrieve initial values and updateHomekit
|
|
139
135
|
this.updateHomeKitCharacteristics();
|
|
140
136
|
|
|
@@ -155,9 +151,9 @@ export class Humidifier extends deviceBase {
|
|
|
155
151
|
const { CurrentRelativeHumidity } = this.HumidifierDehumidifier;
|
|
156
152
|
const { CurrentTemperature } = this.TemperatureSensor || { CurrentTemperature: undefined };
|
|
157
153
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
154
|
+
'(temperature, humidity) = ' +
|
|
155
|
+
`Webhook:(${convertUnits(temperature, context.scale, device.iosensor?.convertUnitTo)}, ${humidity}), ` +
|
|
156
|
+
`current:(${CurrentTemperature}, ${CurrentRelativeHumidity})`);
|
|
161
157
|
this.HumidifierDehumidifier.CurrentRelativeHumidity = humidity;
|
|
162
158
|
if (!this.device.humidifier?.hide_temperature) {
|
|
163
159
|
this.TemperatureSensor!.CurrentTemperature = convertUnits(temperature, context.scale, device.iosensor?.convertUnitTo);
|
package/src/device/iosensor.ts
CHANGED
|
@@ -9,8 +9,8 @@ import { convertUnits } from '../utils.js';
|
|
|
9
9
|
import { Subject, interval, skipWhile } from 'rxjs';
|
|
10
10
|
|
|
11
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';
|
|
12
|
+
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
13
|
+
import type { device, devicesConfig, serviceData, deviceStatus } from '../settings.js';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Platform Accessory
|
|
@@ -20,17 +20,20 @@ import type { device, devicesConfig, serviceData, deviceStatus} from '../setting
|
|
|
20
20
|
export class IOSensor extends deviceBase {
|
|
21
21
|
// Services
|
|
22
22
|
private Battery: {
|
|
23
|
+
Name: CharacteristicValue;
|
|
23
24
|
Service: Service;
|
|
24
25
|
BatteryLevel: CharacteristicValue;
|
|
25
26
|
StatusLowBattery: CharacteristicValue;
|
|
26
27
|
};
|
|
27
28
|
|
|
28
29
|
private HumiditySensor?: {
|
|
30
|
+
Name: CharacteristicValue;
|
|
29
31
|
Service: Service;
|
|
30
32
|
CurrentRelativeHumidity: CharacteristicValue;
|
|
31
33
|
};
|
|
32
34
|
|
|
33
35
|
private TemperatureSensor?: {
|
|
36
|
+
Name: CharacteristicValue;
|
|
34
37
|
Service: Service;
|
|
35
38
|
CurrentTemperature: CharacteristicValue;
|
|
36
39
|
};
|
|
@@ -49,45 +52,45 @@ export class IOSensor extends deviceBase {
|
|
|
49
52
|
this.doIOSensorUpdate = new Subject();
|
|
50
53
|
this.ioSensorUpdateInProgress = false;
|
|
51
54
|
|
|
52
|
-
// Initialize Temperature Sensor property
|
|
53
|
-
if (!device.iosensor?.hide_temperature) {
|
|
54
|
-
this.TemperatureSensor = {
|
|
55
|
-
Service: accessory.getService(this.hap.Service.TemperatureSensor) as Service,
|
|
56
|
-
CurrentTemperature: accessory.context.CurrentTemperature || 30,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Initialize Humidity Sensor property
|
|
61
|
-
if (!device.iosensor?.hide_humidity) {
|
|
62
|
-
this.HumiditySensor = {
|
|
63
|
-
Service: accessory.getService(this.hap.Service.HumiditySensor) as Service,
|
|
64
|
-
CurrentRelativeHumidity: accessory.context.CurrentRelativeHumidity || 50,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
55
|
// Initialize Battery property
|
|
69
56
|
this.Battery = {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
57
|
+
Name: accessory.context.Battery.Name ?? `${accessory.displayName} Battery`,
|
|
58
|
+
Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
|
|
59
|
+
BatteryLevel: accessory.context.BatteryLevel ?? 100,
|
|
60
|
+
StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
|
|
73
61
|
};
|
|
74
62
|
|
|
75
|
-
//
|
|
76
|
-
this.
|
|
63
|
+
// Initialize Battery Characteristics
|
|
64
|
+
this.Battery.Service
|
|
65
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name)
|
|
66
|
+
.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE)
|
|
67
|
+
.getCharacteristic(this.hap.Characteristic.BatteryLevel)
|
|
68
|
+
.onGet(() => {
|
|
69
|
+
return this.Battery.BatteryLevel;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
this.Battery.Service
|
|
73
|
+
.getCharacteristic(this.hap.Characteristic.StatusLowBattery)
|
|
74
|
+
.onGet(() => {
|
|
75
|
+
return this.Battery.StatusLowBattery;
|
|
76
|
+
});
|
|
77
|
+
accessory.context.Battery.Name = this.Battery.Name;
|
|
77
78
|
|
|
78
|
-
//
|
|
79
|
+
// InitializeTemperature Sensor Service
|
|
79
80
|
if (device.iosensor?.hide_temperature) {
|
|
80
81
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
81
82
|
this.TemperatureSensor!.Service = this.accessory.getService(this.hap.Service.TemperatureSensor) as Service;
|
|
82
83
|
accessory.removeService(this.TemperatureSensor!.Service);
|
|
83
|
-
} else
|
|
84
|
-
this.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
84
|
+
} else {
|
|
85
|
+
this.TemperatureSensor = {
|
|
86
|
+
Name: accessory.context.TemperatureSensor.Name ?? `${accessory.displayName} Temperature Sensor`,
|
|
87
|
+
Service: accessory.getService(this.hap.Service.TemperatureSensor) ?? this.accessory.addService(this.hap.Service.TemperatureSensor) as Service,
|
|
88
|
+
CurrentTemperature: accessory.context.CurrentTemperature ?? 30,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// Initialize Temperature Sensor Characteristics
|
|
92
|
+
this.TemperatureSensor.Service
|
|
93
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.TemperatureSensor.Name)
|
|
91
94
|
.getCharacteristic(this.hap.Characteristic.CurrentTemperature)
|
|
92
95
|
.setProps({
|
|
93
96
|
unit: Units['CELSIUS'],
|
|
@@ -97,25 +100,26 @@ export class IOSensor extends deviceBase {
|
|
|
97
100
|
minStep: 0.1,
|
|
98
101
|
})
|
|
99
102
|
.onGet(() => {
|
|
100
|
-
return this.TemperatureSensor!.CurrentTemperature
|
|
103
|
+
return this.TemperatureSensor!.CurrentTemperature;
|
|
101
104
|
});
|
|
102
|
-
|
|
103
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
105
|
+
accessory.context.TemperatureSensor.Name = this.TemperatureSensor.Name;
|
|
104
106
|
}
|
|
105
107
|
|
|
106
|
-
// Humidity Sensor Service
|
|
108
|
+
// Initialize Humidity Sensor Service
|
|
107
109
|
if (device.iosensor?.hide_humidity) {
|
|
108
110
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Humidity Sensor Service`);
|
|
109
111
|
this.HumiditySensor!.Service = this.accessory.getService(this.hap.Service.HumiditySensor) as Service;
|
|
110
112
|
accessory.removeService(this.HumiditySensor!.Service);
|
|
111
|
-
} else
|
|
112
|
-
this.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
113
|
+
} else {
|
|
114
|
+
this.HumiditySensor = {
|
|
115
|
+
Name: accessory.context.HumiditySensor.Name ?? `${accessory.displayName} Humidity Sensor`,
|
|
116
|
+
Service: accessory.getService(this.hap.Service.HumiditySensor) ?? this.accessory.addService(this.hap.Service.HumiditySensor) as Service,
|
|
117
|
+
CurrentRelativeHumidity: accessory.context.CurrentRelativeHumidity ?? 50,
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// Initialize Humidity Sensor Characteristics
|
|
121
|
+
this.HumiditySensor.Service
|
|
122
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.HumiditySensor.Name)
|
|
119
123
|
.getCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity)
|
|
120
124
|
.setProps({
|
|
121
125
|
minStep: 0.1,
|
|
@@ -123,17 +127,11 @@ export class IOSensor extends deviceBase {
|
|
|
123
127
|
.onGet(() => {
|
|
124
128
|
return this.HumiditySensor!.CurrentRelativeHumidity;
|
|
125
129
|
});
|
|
126
|
-
|
|
127
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Humidity Sensor Service Not Added`);
|
|
130
|
+
accessory.context.HumiditySensor.Name = this.HumiditySensor.Name;
|
|
128
131
|
}
|
|
129
132
|
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
(this.Battery.Service = this.accessory.getService(this.hap.Service.Battery)
|
|
133
|
-
|| accessory.addService(this.hap.Service.Battery)), BatteryService;
|
|
134
|
-
|
|
135
|
-
this.Battery.Service.setCharacteristic(this.hap.Characteristic.Name, BatteryService);
|
|
136
|
-
this.Battery.Service.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
133
|
+
// Retrieve initial values and updateHomekit
|
|
134
|
+
this.refreshStatus();
|
|
137
135
|
|
|
138
136
|
// Retrieve initial values and updateHomekit
|
|
139
137
|
this.updateHomeKitCharacteristics();
|
package/src/device/lightstrip.ts
CHANGED
|
@@ -17,6 +17,7 @@ import type { Service, PlatformAccessory, CharacteristicValue, ControllerConstru
|
|
|
17
17
|
export class StripLight extends deviceBase {
|
|
18
18
|
// Services
|
|
19
19
|
private LightBulb: {
|
|
20
|
+
Name: CharacteristicValue;
|
|
20
21
|
Service: Service;
|
|
21
22
|
On: CharacteristicValue;
|
|
22
23
|
Hue: CharacteristicValue;
|
|
@@ -44,37 +45,47 @@ export class StripLight extends deviceBase {
|
|
|
44
45
|
this.doStripLightUpdate = new Subject();
|
|
45
46
|
this.stripLightUpdateInProgress = false;
|
|
46
47
|
|
|
47
|
-
// Initialize the LightBulb
|
|
48
|
+
// Initialize the LightBulb Service
|
|
48
49
|
this.LightBulb = {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
Name: accessory.context.LightBulb.Name ?? accessory.displayName,
|
|
51
|
+
Service: accessory.getService(this.hap.Service.Lightbulb) ?? accessory.addService(this.hap.Service.Lightbulb) as Service,
|
|
52
|
+
On: accessory.context.On ?? false,
|
|
53
|
+
Hue: accessory.context.Hue ?? 0,
|
|
54
|
+
Saturation: accessory.context.Saturation ?? 0,
|
|
55
|
+
Brightness: accessory.context.Brightness ?? 0,
|
|
56
|
+
ColorTemperature: accessory.context.ColorTemperature ?? 140,
|
|
55
57
|
};
|
|
56
58
|
|
|
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
|
-
|
|
59
|
+
// Adaptive Lighting
|
|
66
60
|
if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
|
|
67
61
|
this.accessory.removeService(this.LightBulb.Service);
|
|
68
62
|
this.LightBulb.Service = this.accessory.addService(this.hap.Service.Lightbulb);
|
|
69
63
|
this.accessory.context.adaptiveLighting = false;
|
|
70
64
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
|
|
71
65
|
}
|
|
66
|
+
if (this.adaptiveLightingShift !== -1) {
|
|
67
|
+
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.LightBulb.Service, {
|
|
68
|
+
customTemperatureAdjustment: this.adaptiveLightingShift,
|
|
69
|
+
});
|
|
70
|
+
this.accessory.configureController(this.AdaptiveLightingController);
|
|
71
|
+
this.accessory.context.adaptiveLighting = true;
|
|
72
|
+
this.debugLog(
|
|
73
|
+
`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
|
|
74
|
+
` adaptiveLightingShift: ${this.adaptiveLightingShift}`,
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
72
78
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
79
|
+
// Initialize LightBulb Characteristics
|
|
80
|
+
this.LightBulb.Service
|
|
81
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.LightBulb.Name)
|
|
82
|
+
.getCharacteristic(this.hap.Characteristic.On)
|
|
83
|
+
.onGet(() => {
|
|
84
|
+
return this.LightBulb.On;
|
|
85
|
+
})
|
|
86
|
+
.onSet(this.OnSet.bind(this));
|
|
76
87
|
|
|
77
|
-
//
|
|
88
|
+
// Initialize LightBulb Brightness Characteristic
|
|
78
89
|
this.LightBulb.Service
|
|
79
90
|
.getCharacteristic(this.hap.Characteristic.Brightness)
|
|
80
91
|
.setProps({
|
|
@@ -88,7 +99,7 @@ export class StripLight extends deviceBase {
|
|
|
88
99
|
})
|
|
89
100
|
.onSet(this.BrightnessSet.bind(this));
|
|
90
101
|
|
|
91
|
-
//
|
|
102
|
+
// Initialize LightBulb ColorTemperature Characteristic
|
|
92
103
|
this.LightBulb.Service
|
|
93
104
|
.getCharacteristic(this.hap.Characteristic.ColorTemperature)
|
|
94
105
|
.setProps({
|
|
@@ -101,7 +112,7 @@ export class StripLight extends deviceBase {
|
|
|
101
112
|
})
|
|
102
113
|
.onSet(this.ColorTemperatureSet.bind(this));
|
|
103
114
|
|
|
104
|
-
//
|
|
115
|
+
// Initialize LightBulb Hue Characteristic
|
|
105
116
|
this.LightBulb.Service
|
|
106
117
|
.getCharacteristic(this.hap.Characteristic.Hue)
|
|
107
118
|
.setProps({
|
|
@@ -114,7 +125,7 @@ export class StripLight extends deviceBase {
|
|
|
114
125
|
})
|
|
115
126
|
.onSet(this.HueSet.bind(this));
|
|
116
127
|
|
|
117
|
-
//
|
|
128
|
+
// Initialize LightBulb Saturation Characteristic
|
|
118
129
|
this.LightBulb.Service
|
|
119
130
|
.getCharacteristic(this.hap.Characteristic.Saturation)
|
|
120
131
|
.setProps({
|
|
@@ -126,19 +137,10 @@ export class StripLight extends deviceBase {
|
|
|
126
137
|
return this.LightBulb.Saturation;
|
|
127
138
|
})
|
|
128
139
|
.onSet(this.SaturationSet.bind(this));
|
|
140
|
+
accessory.context.LightBulb.Name = this.LightBulb.Name;
|
|
129
141
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.LightBulb.Service, {
|
|
133
|
-
customTemperatureAdjustment: this.adaptiveLightingShift,
|
|
134
|
-
});
|
|
135
|
-
this.accessory.configureController(this.AdaptiveLightingController);
|
|
136
|
-
this.accessory.context.adaptiveLighting = true;
|
|
137
|
-
this.debugLog(
|
|
138
|
-
`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
|
|
139
|
-
` adaptiveLightingShift: ${this.adaptiveLightingShift}`,
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
+
// Retrieve initial values and updateHomekit
|
|
143
|
+
this.refreshStatus();
|
|
142
144
|
|
|
143
145
|
// Update Homekit
|
|
144
146
|
this.updateHomeKitCharacteristics();
|
package/src/device/lock.ts
CHANGED
|
@@ -11,23 +11,27 @@ import type { device, devicesConfig, deviceStatus, serviceData } from '../settin
|
|
|
11
11
|
export class Lock extends deviceBase {
|
|
12
12
|
// Services
|
|
13
13
|
private LockMechanism: {
|
|
14
|
+
Name: CharacteristicValue;
|
|
14
15
|
Service: Service;
|
|
15
16
|
LockTargetState: CharacteristicValue;
|
|
16
17
|
LockCurrentState: CharacteristicValue;
|
|
17
18
|
};
|
|
18
19
|
|
|
19
20
|
private Battery: {
|
|
21
|
+
Name: CharacteristicValue;
|
|
20
22
|
Service: Service;
|
|
21
23
|
BatteryLevel: CharacteristicValue;
|
|
22
24
|
StatusLowBattery: CharacteristicValue;
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
private ContactSensor?: {
|
|
28
|
+
Name: CharacteristicValue;
|
|
26
29
|
Service: Service;
|
|
27
30
|
ContactSensorState: CharacteristicValue;
|
|
28
31
|
};
|
|
29
32
|
|
|
30
33
|
private Switch?: {
|
|
34
|
+
Name: CharacteristicValue;
|
|
31
35
|
Service: Service;
|
|
32
36
|
On: CharacteristicValue;
|
|
33
37
|
};
|
|
@@ -46,91 +50,96 @@ export class Lock extends deviceBase {
|
|
|
46
50
|
this.doLockUpdate = new Subject();
|
|
47
51
|
this.lockUpdateInProgress = false;
|
|
48
52
|
|
|
49
|
-
// Initialize LockMechanism
|
|
53
|
+
// Initialize LockMechanism Service
|
|
50
54
|
this.LockMechanism = {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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,
|
|
54
59
|
};
|
|
55
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
|
+
|
|
56
71
|
// Initialize Battery property
|
|
57
72
|
this.Battery = {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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,
|
|
61
77
|
};
|
|
62
78
|
|
|
63
|
-
// Initialize
|
|
64
|
-
|
|
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 {
|
|
65
101
|
this.ContactSensor = {
|
|
66
|
-
|
|
67
|
-
|
|
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,
|
|
68
105
|
};
|
|
69
|
-
}
|
|
70
106
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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;
|
|
77
116
|
}
|
|
78
117
|
|
|
79
|
-
//
|
|
80
|
-
this.refreshStatus();
|
|
81
|
-
|
|
82
|
-
// get the LockMechanism service if it exists, otherwise create a new LockMechanism service
|
|
83
|
-
// you can create multiple services for each accessory
|
|
84
|
-
const LockMechanismService = `${accessory.displayName} ${device.deviceType}`;
|
|
85
|
-
(this.LockMechanism.Service = accessory.getService(this.hap.Service.LockMechanism)
|
|
86
|
-
|| accessory.addService(this.hap.Service.LockMechanism)), LockMechanismService;
|
|
87
|
-
|
|
88
|
-
this.LockMechanism.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
89
|
-
|
|
90
|
-
this.LockMechanism.Service.getCharacteristic(this.hap.Characteristic.LockTargetState).onSet(this.LockTargetStateSet.bind(this));
|
|
91
|
-
|
|
92
|
-
// Latch Button Service
|
|
118
|
+
// Initialize Latch Button Service
|
|
93
119
|
if (device.lock?.activate_latchbutton === false) { // remove the service when this variable is false
|
|
94
120
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Latch Button Service`);
|
|
95
121
|
this.Switch!.Service = accessory.getService(this.hap.Service.Switch) as Service;
|
|
96
122
|
accessory.removeService(this.Switch!.Service);
|
|
97
|
-
} else if (!this.Switch!.Service && device.lock?.activate_latchbutton === true) {
|
|
98
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Adding Latch Button Service`);
|
|
99
|
-
const latchServiceName = `${accessory.displayName} Latch`;
|
|
100
|
-
this.Switch!.Service = accessory.getService(this.hap.Service.Switch)
|
|
101
|
-
|| accessory.addService(this.hap.Service.Switch, latchServiceName, 'Switch.ServiceIdentifier');
|
|
102
|
-
|
|
103
|
-
this.Switch!.Service.setCharacteristic(this.hap.Characteristic.Name, latchServiceName);
|
|
104
|
-
|
|
105
|
-
this.Switch!.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
106
123
|
} else {
|
|
107
|
-
this.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (device.lock?.hide_contactsensor) {
|
|
113
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Contact Sensor Service`);
|
|
114
|
-
this.ContactSensor!.Service = this.accessory.getService(this.hap.Service.ContactSensor) as Service;
|
|
115
|
-
accessory.removeService(this.ContactSensor!.Service);
|
|
116
|
-
} else if (!this.ContactSensor?.Service) {
|
|
117
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Contact Sensor Service`);
|
|
118
|
-
const ContactSensorService = `${accessory.displayName} Contact Sensor`;
|
|
119
|
-
(this.ContactSensor!.Service = this.accessory.getService(this.hap.Service.ContactSensor)
|
|
120
|
-
|| 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
|
+
};
|
|
121
129
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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;
|
|
125
139
|
}
|
|
126
140
|
|
|
127
|
-
//
|
|
128
|
-
|
|
129
|
-
(this.Battery.Service = this.accessory.getService(this.hap.Service.Battery)
|
|
130
|
-
|| accessory.addService(this.hap.Service.Battery)), BatteryService;
|
|
131
|
-
|
|
132
|
-
this.Battery.Service.setCharacteristic(this.hap.Characteristic.Name, BatteryService);
|
|
133
|
-
this.Battery.Service.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
141
|
+
// Retrieve initial values and updateHomekit
|
|
142
|
+
this.refreshStatus();
|
|
134
143
|
|
|
135
144
|
// Update Homekit
|
|
136
145
|
this.updateHomeKitCharacteristics();
|