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