@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
|
@@ -4,12 +4,14 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { request } from 'undici';
|
|
6
6
|
import { deviceBase } from './device.js';
|
|
7
|
-
import { hs2rgb, rgb2hs, m2hs } from '../utils.js';
|
|
8
7
|
import { interval, Subject } from 'rxjs';
|
|
9
|
-
import {
|
|
8
|
+
import { Devices } from '../settings.js';
|
|
9
|
+
import { hs2rgb, rgb2hs, m2hs } from '../utils.js';
|
|
10
10
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
11
|
-
|
|
12
|
-
import {
|
|
11
|
+
|
|
12
|
+
import type { SwitchBotPlatform } from '../platform.js';
|
|
13
|
+
import type { device, devicesConfig, serviceData, deviceStatus} from '../settings.js';
|
|
14
|
+
import type { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* Platform Accessory
|
|
@@ -19,6 +21,7 @@ import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor,
|
|
|
19
21
|
export class CeilingLight extends deviceBase {
|
|
20
22
|
// Services
|
|
21
23
|
private LightBulb: {
|
|
24
|
+
Name: CharacteristicValue;
|
|
22
25
|
Service: Service;
|
|
23
26
|
On: CharacteristicValue;
|
|
24
27
|
Hue: CharacteristicValue;
|
|
@@ -50,35 +53,44 @@ export class CeilingLight extends deviceBase {
|
|
|
50
53
|
|
|
51
54
|
// Initialize LightBulb property
|
|
52
55
|
this.LightBulb = {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
Name: accessory.context.LightBulb.Name ?? accessory.displayName,
|
|
57
|
+
Service: accessory.getService(this.hap.Service.Lightbulb) ?? accessory.addService(this.hap.Service.Lightbulb) as Service,
|
|
58
|
+
On: accessory.context.On ?? false,
|
|
59
|
+
Hue: accessory.context.Hue ?? 0,
|
|
60
|
+
Saturation: accessory.context.Saturation ?? 0,
|
|
61
|
+
Brightness: accessory.context.Brightness ?? 0,
|
|
62
|
+
ColorTemperature: accessory.context.ColorTemperature ?? 140,
|
|
59
63
|
};
|
|
60
64
|
|
|
61
|
-
//
|
|
62
|
-
this.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this.accessory.
|
|
73
|
-
this.
|
|
65
|
+
// Adaptive Lighting
|
|
66
|
+
if (this.adaptiveLightingShift === -1 && accessory.context.adaptiveLighting) {
|
|
67
|
+
accessory.removeService(this.LightBulb.Service);
|
|
68
|
+
this.LightBulb.Service = accessory.addService(this.hap.Service.Lightbulb);
|
|
69
|
+
accessory.context.adaptiveLighting = false;
|
|
70
|
+
this.debugLog(`${device.deviceType}: ${accessory.displayName} adaptiveLighting: ${accessory.context.adaptiveLighting}`);
|
|
71
|
+
}
|
|
72
|
+
if (this.adaptiveLightingShift !== -1) {
|
|
73
|
+
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.LightBulb.Service, {
|
|
74
|
+
customTemperatureAdjustment: this.adaptiveLightingShift,
|
|
75
|
+
});
|
|
76
|
+
this.accessory.configureController(this.AdaptiveLightingController);
|
|
77
|
+
this.accessory.context.adaptiveLighting = true;
|
|
78
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},`
|
|
79
|
+
+ ` adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
74
80
|
}
|
|
81
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
75
82
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
83
|
+
// Initialize LightBulb Characteristics
|
|
84
|
+
this.LightBulb.Service
|
|
85
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.LightBulb.Name)
|
|
86
|
+
.getCharacteristic(this.hap.Characteristic.On)
|
|
87
|
+
.onGet(() => {
|
|
88
|
+
return this.LightBulb.On;
|
|
89
|
+
})
|
|
90
|
+
.onSet(this.OnSet.bind(this));
|
|
79
91
|
|
|
80
|
-
//
|
|
81
|
-
this.LightBulb
|
|
92
|
+
// Initialize LightBulb Brightness
|
|
93
|
+
this.LightBulb.Service
|
|
82
94
|
.getCharacteristic(this.hap.Characteristic.Brightness)
|
|
83
95
|
.setProps({
|
|
84
96
|
minStep: this.minStep(device),
|
|
@@ -91,8 +103,8 @@ export class CeilingLight extends deviceBase {
|
|
|
91
103
|
})
|
|
92
104
|
.onSet(this.BrightnessSet.bind(this));
|
|
93
105
|
|
|
94
|
-
//
|
|
95
|
-
this.LightBulb
|
|
106
|
+
// Initialize LightBulb ColorTemperature
|
|
107
|
+
this.LightBulb.Service
|
|
96
108
|
.getCharacteristic(this.hap.Characteristic.ColorTemperature)
|
|
97
109
|
.setProps({
|
|
98
110
|
minValue: 140,
|
|
@@ -104,8 +116,8 @@ export class CeilingLight extends deviceBase {
|
|
|
104
116
|
})
|
|
105
117
|
.onSet(this.ColorTemperatureSet.bind(this));
|
|
106
118
|
|
|
107
|
-
//
|
|
108
|
-
this.LightBulb
|
|
119
|
+
// Initialize LightBulb Hue
|
|
120
|
+
this.LightBulb.Service
|
|
109
121
|
.getCharacteristic(this.hap.Characteristic.Hue)
|
|
110
122
|
.setProps({
|
|
111
123
|
minValue: 0,
|
|
@@ -117,8 +129,8 @@ export class CeilingLight extends deviceBase {
|
|
|
117
129
|
})
|
|
118
130
|
.onSet(this.HueSet.bind(this));
|
|
119
131
|
|
|
120
|
-
//
|
|
121
|
-
this.LightBulb
|
|
132
|
+
// Initialize LightBulb Saturation
|
|
133
|
+
this.LightBulb.Service
|
|
122
134
|
.getCharacteristic(this.hap.Characteristic.Saturation)
|
|
123
135
|
.setProps({
|
|
124
136
|
minValue: 0,
|
|
@@ -129,19 +141,10 @@ export class CeilingLight extends deviceBase {
|
|
|
129
141
|
return this.LightBulb.Saturation;
|
|
130
142
|
})
|
|
131
143
|
.onSet(this.SaturationSet.bind(this));
|
|
144
|
+
accessory.context.LightBulb.Name = this.LightBulb.Name;
|
|
132
145
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.LightBulb!.Service, {
|
|
136
|
-
customTemperatureAdjustment: this.adaptiveLightingShift,
|
|
137
|
-
});
|
|
138
|
-
this.accessory.configureController(this.AdaptiveLightingController);
|
|
139
|
-
this.accessory.context.adaptiveLighting = true;
|
|
140
|
-
this.debugLog(
|
|
141
|
-
`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
|
|
142
|
-
` adaptiveLightingShift: ${this.adaptiveLightingShift}`,
|
|
143
|
-
);
|
|
144
|
-
}
|
|
146
|
+
// Retrieve initial values and updateHomekit
|
|
147
|
+
this.refreshStatus();
|
|
145
148
|
|
|
146
149
|
// Update Homekit
|
|
147
150
|
this.updateHomeKitCharacteristics();
|
package/src/device/colorbulb.ts
CHANGED
|
@@ -5,11 +5,13 @@
|
|
|
5
5
|
import { request } from 'undici';
|
|
6
6
|
import { deviceBase } from './device.js';
|
|
7
7
|
import { interval, Subject } from 'rxjs';
|
|
8
|
-
import {
|
|
8
|
+
import { Devices } from '../settings.js';
|
|
9
9
|
import { hs2rgb, rgb2hs, m2hs } from '../utils.js';
|
|
10
10
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
11
|
-
|
|
12
|
-
import {
|
|
11
|
+
|
|
12
|
+
import type { SwitchBotPlatform } from '../platform.js';
|
|
13
|
+
import type { device, devicesConfig, deviceStatus, serviceData} from '../settings.js';
|
|
14
|
+
import type { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* Platform Accessory
|
|
@@ -19,6 +21,7 @@ import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor,
|
|
|
19
21
|
export class ColorBulb extends deviceBase {
|
|
20
22
|
// Services
|
|
21
23
|
private LightBulb: {
|
|
24
|
+
Name: CharacteristicValue;
|
|
22
25
|
Service: Service;
|
|
23
26
|
On: CharacteristicValue;
|
|
24
27
|
Hue: CharacteristicValue;
|
|
@@ -51,36 +54,42 @@ export class ColorBulb extends deviceBase {
|
|
|
51
54
|
|
|
52
55
|
// Initialize LightBulb property
|
|
53
56
|
this.LightBulb = {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
Name: accessory.context.LightBulb.Name ?? accessory.displayName,
|
|
58
|
+
Service: accessory.getService(this.hap.Service.Lightbulb) ?? accessory.addService(this.hap.Service.Lightbulb) as Service,
|
|
59
|
+
On: accessory.context.On ?? false,
|
|
60
|
+
Hue: accessory.context.Hue ?? 0,
|
|
61
|
+
Saturation: accessory.context.Saturation ?? 0,
|
|
62
|
+
Brightness: accessory.context.Brightness ?? 0,
|
|
63
|
+
ColorTemperature: accessory.context.ColorTemperature ?? 140,
|
|
60
64
|
};
|
|
61
65
|
|
|
62
|
-
//
|
|
63
|
-
this.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
(this.LightBulb.Service = accessory.getService(this.hap.Service.Lightbulb)
|
|
69
|
-
|| accessory.addService(this.hap.Service.Lightbulb)), lightBulbService;
|
|
70
|
-
|
|
71
|
-
if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
|
|
72
|
-
this.accessory.removeService(this.LightBulb.Service);
|
|
73
|
-
this.LightBulb.Service = this.accessory.addService(this.hap.Service.Lightbulb);
|
|
74
|
-
this.accessory.context.adaptiveLighting = false;
|
|
75
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
|
|
66
|
+
// Adaptive Lighting
|
|
67
|
+
if (this.adaptiveLightingShift === -1 && accessory.context.adaptiveLighting) {
|
|
68
|
+
accessory.removeService(this.LightBulb.Service);
|
|
69
|
+
this.LightBulb.Service = accessory.addService(this.hap.Service.Lightbulb);
|
|
70
|
+
accessory.context.adaptiveLighting = false;
|
|
71
|
+
this.debugLog(`${device.deviceType}: ${accessory.displayName} adaptiveLighting: ${accessory.context.adaptiveLighting}`);
|
|
76
72
|
}
|
|
73
|
+
if (this.adaptiveLightingShift !== -1) {
|
|
74
|
+
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.LightBulb.Service, {
|
|
75
|
+
customTemperatureAdjustment: this.adaptiveLightingShift,
|
|
76
|
+
});
|
|
77
|
+
accessory.configureController(this.AdaptiveLightingController);
|
|
78
|
+
accessory.context.adaptiveLighting = true;
|
|
79
|
+
this.debugLog(`${device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${accessory.context.adaptiveLighting},`
|
|
80
|
+
+ ` adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
81
|
+
}
|
|
82
|
+
this.debugLog(`${device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
77
83
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
// Initialize LightBulb Characteristics
|
|
85
|
+
this.LightBulb.Service
|
|
86
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.LightBulb.Name)
|
|
87
|
+
.getCharacteristic(this.hap.Characteristic.On)
|
|
88
|
+
.onGet(() => {
|
|
89
|
+
return this.LightBulb.On;
|
|
90
|
+
})
|
|
91
|
+
.onSet(this.OnSet.bind(this));
|
|
82
92
|
|
|
83
|
-
// handle Brightness events using the Brightness characteristic
|
|
84
93
|
this.LightBulb.Service
|
|
85
94
|
.getCharacteristic(this.hap.Characteristic.Brightness)
|
|
86
95
|
.setProps({
|
|
@@ -94,7 +103,6 @@ export class ColorBulb extends deviceBase {
|
|
|
94
103
|
})
|
|
95
104
|
.onSet(this.BrightnessSet.bind(this));
|
|
96
105
|
|
|
97
|
-
// handle ColorTemperature events using the ColorTemperature characteristic
|
|
98
106
|
this.LightBulb.Service
|
|
99
107
|
.getCharacteristic(this.hap.Characteristic.ColorTemperature)
|
|
100
108
|
.setProps({
|
|
@@ -107,7 +115,6 @@ export class ColorBulb extends deviceBase {
|
|
|
107
115
|
})
|
|
108
116
|
.onSet(this.ColorTemperatureSet.bind(this));
|
|
109
117
|
|
|
110
|
-
// handle Hue events using the Hue characteristic
|
|
111
118
|
this.LightBulb.Service
|
|
112
119
|
.getCharacteristic(this.hap.Characteristic.Hue)
|
|
113
120
|
.setProps({
|
|
@@ -120,7 +127,6 @@ export class ColorBulb extends deviceBase {
|
|
|
120
127
|
})
|
|
121
128
|
.onSet(this.HueSet.bind(this));
|
|
122
129
|
|
|
123
|
-
// handle Hue events using the Hue characteristic
|
|
124
130
|
this.LightBulb.Service
|
|
125
131
|
.getCharacteristic(this.hap.Characteristic.Saturation)
|
|
126
132
|
.setProps({
|
|
@@ -132,19 +138,10 @@ export class ColorBulb extends deviceBase {
|
|
|
132
138
|
return this.LightBulb.Saturation;
|
|
133
139
|
})
|
|
134
140
|
.onSet(this.SaturationSet.bind(this));
|
|
141
|
+
accessory.context.LightBulb.Name = this.LightBulb.Name;
|
|
135
142
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.LightBulb.Service, {
|
|
139
|
-
customTemperatureAdjustment: this.adaptiveLightingShift,
|
|
140
|
-
});
|
|
141
|
-
this.accessory.configureController(this.AdaptiveLightingController);
|
|
142
|
-
this.accessory.context.adaptiveLighting = true;
|
|
143
|
-
this.debugLog(
|
|
144
|
-
`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
|
|
145
|
-
` adaptiveLightingShift: ${this.adaptiveLightingShift}`,
|
|
146
|
-
);
|
|
147
|
-
}
|
|
143
|
+
// Retrieve initial values and updateHomekit
|
|
144
|
+
this.refreshStatus();
|
|
148
145
|
|
|
149
146
|
// Update Homekit
|
|
150
147
|
this.updateHomeKitCharacteristics();
|
package/src/device/contact.ts
CHANGED
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { deviceBase } from './device.js';
|
|
6
6
|
import { interval, Subject } from 'rxjs';
|
|
7
|
+
import { Devices } from '../settings.js';
|
|
7
8
|
import { skipWhile } from 'rxjs/operators';
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
|
|
10
|
+
import type { SwitchBotPlatform } from '../platform.js';
|
|
11
|
+
import type { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
12
|
+
import type { device, devicesConfig, serviceData, deviceStatus } from '../settings.js';
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Platform Accessory
|
|
@@ -16,27 +18,31 @@ import { device, devicesConfig, serviceData, deviceStatus, Devices } from '../se
|
|
|
16
18
|
*/
|
|
17
19
|
export class Contact extends deviceBase {
|
|
18
20
|
// Services
|
|
19
|
-
private ContactSensor
|
|
21
|
+
private ContactSensor: {
|
|
22
|
+
Name: CharacteristicValue;
|
|
20
23
|
Service: Service;
|
|
21
24
|
ContactSensorState: CharacteristicValue;
|
|
22
25
|
};
|
|
23
26
|
|
|
27
|
+
private Battery: {
|
|
28
|
+
Name: CharacteristicValue;
|
|
29
|
+
Service: Service;
|
|
30
|
+
BatteryLevel: CharacteristicValue;
|
|
31
|
+
StatusLowBattery: CharacteristicValue;
|
|
32
|
+
};
|
|
33
|
+
|
|
24
34
|
private MotionSensor?: {
|
|
35
|
+
Name: CharacteristicValue;
|
|
25
36
|
Service: Service;
|
|
26
37
|
MotionDetected: CharacteristicValue;
|
|
27
38
|
};
|
|
28
39
|
|
|
29
40
|
private LightSensor?: {
|
|
41
|
+
Name: CharacteristicValue;
|
|
30
42
|
Service: Service;
|
|
31
43
|
CurrentAmbientLightLevel: CharacteristicValue;
|
|
32
44
|
};
|
|
33
45
|
|
|
34
|
-
private Battery!: {
|
|
35
|
-
Service: Service;
|
|
36
|
-
BatteryLevel: CharacteristicValue;
|
|
37
|
-
StatusLowBattery: CharacteristicValue;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
46
|
// Updates
|
|
41
47
|
contactUpdateInProgress!: boolean;
|
|
42
48
|
doContactUpdate!: Subject<void>;
|
|
@@ -53,77 +59,94 @@ export class Contact extends deviceBase {
|
|
|
53
59
|
|
|
54
60
|
// Initialize Contact Sensor property
|
|
55
61
|
this.ContactSensor = {
|
|
56
|
-
|
|
57
|
-
|
|
62
|
+
Name: accessory.context.ContactSensor.Name ?? accessory.displayName,
|
|
63
|
+
Service: accessory.getService(this.hap.Service.ContactSensor) ?? accessory.addService(this.hap.Service.ContactSensor) as Service,
|
|
64
|
+
ContactSensorState: accessory.context.ContactSensorState ?? this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED,
|
|
58
65
|
};
|
|
59
66
|
|
|
60
|
-
// Initialize
|
|
61
|
-
|
|
62
|
-
this.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
this.refreshStatus();
|
|
67
|
+
// Initialize ContactSensor Characteristics
|
|
68
|
+
this.ContactSensor.Service
|
|
69
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.ContactSensor.Name)
|
|
70
|
+
.setCharacteristic(this.hap.Characteristic.StatusActive, true)
|
|
71
|
+
.getCharacteristic(this.hap.Characteristic.ContactSensorState)
|
|
72
|
+
.onGet(() => {
|
|
73
|
+
return this.ContactSensor.ContactSensorState;
|
|
74
|
+
});
|
|
75
|
+
accessory.context.ContactSensor.Name = this.ContactSensor.Name;
|
|
76
|
+
|
|
77
|
+
// Initialize Battery property
|
|
78
|
+
this.Battery = {
|
|
79
|
+
Name: accessory.context.Battery.Name ?? `${accessory.displayName} Battery`,
|
|
80
|
+
Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
|
|
81
|
+
BatteryLevel: accessory.context.BatteryLevel ?? 100,
|
|
82
|
+
StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
|
|
83
|
+
};
|
|
78
84
|
|
|
79
|
-
//
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
85
|
+
// Initialize Battery Characteristics
|
|
86
|
+
this.Battery.Service
|
|
87
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name)
|
|
88
|
+
.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE)
|
|
89
|
+
.getCharacteristic(this.hap.Characteristic.BatteryLevel)
|
|
90
|
+
.onGet(() => {
|
|
91
|
+
return this.Battery.BatteryLevel;
|
|
92
|
+
});
|
|
84
93
|
|
|
85
|
-
this.
|
|
94
|
+
this.Battery.Service
|
|
95
|
+
.setCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery)
|
|
96
|
+
.getCharacteristic(this.hap.Characteristic.StatusLowBattery)
|
|
97
|
+
.onGet(() => {
|
|
98
|
+
return this.Battery.StatusLowBattery;
|
|
99
|
+
});
|
|
100
|
+
accessory.context.Battery.Name = this.Battery.Name;
|
|
86
101
|
|
|
87
|
-
// Motion Sensor Service
|
|
88
|
-
if (device.contact?.hide_motionsensor) {
|
|
102
|
+
// Initialize Motion Sensor Service
|
|
103
|
+
if (this.device.contact?.hide_motionsensor) {
|
|
89
104
|
this.debugLog(`${device.deviceType}: ${accessory.displayName} Removing Motion Sensor Service`);
|
|
90
105
|
this.MotionSensor!.Service = accessory.getService(this.hap.Service.MotionSensor) as Service;
|
|
91
106
|
accessory.removeService(this.MotionSensor!.Service);
|
|
92
|
-
} else if (!this.MotionSensor?.Service && !device.contact?.hide_motionsensor) {
|
|
93
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} Add Motion Sensor Service`);
|
|
94
|
-
const MotionService = `${accessory.displayName} Motion Sensor`;
|
|
95
|
-
(this.MotionSensor!.Service = accessory.getService(this.hap.Service.MotionSensor)
|
|
96
|
-
|| accessory.addService(this.hap.Service.MotionSensor)), MotionService;
|
|
97
|
-
|
|
98
|
-
this.MotionSensor!.Service.setCharacteristic(this.hap.Characteristic.Name, MotionService);
|
|
99
107
|
} else {
|
|
100
|
-
this.
|
|
108
|
+
this.MotionSensor = {
|
|
109
|
+
Name: accessory.context.MotionSensor.Name ?? `${accessory.displayName} Motion Sensor`,
|
|
110
|
+
Service: accessory.getService(this.hap.Service.MotionSensor) ?? accessory.addService(this.hap.Service.MotionSensor) as Service,
|
|
111
|
+
MotionDetected: accessory.context.MotionDetected ?? false,
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// Motion Sensor Characteristics
|
|
115
|
+
this.MotionSensor.Service
|
|
116
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.MotionSensor.Name)
|
|
117
|
+
.setCharacteristic(this.hap.Characteristic.StatusActive, true)
|
|
118
|
+
.getCharacteristic(this.hap.Characteristic.MotionDetected)
|
|
119
|
+
.onGet(() => {
|
|
120
|
+
return this.MotionSensor!.MotionDetected;
|
|
121
|
+
});
|
|
122
|
+
accessory.context.MotionSensor.Name = this.MotionSensor.Name;
|
|
101
123
|
}
|
|
102
124
|
|
|
103
|
-
// Light Sensor Service
|
|
125
|
+
// Initialize Light Sensor Service
|
|
104
126
|
if (device.contact?.hide_lightsensor) {
|
|
105
127
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
|
|
106
128
|
this.LightSensor!.Service = accessory.getService(this.hap.Service.LightSensor) as Service;
|
|
107
129
|
accessory.removeService(this.LightSensor!.Service);
|
|
108
|
-
} else if (!this.LightSensor?.Service && !device.contact?.hide_lightsensor) {
|
|
109
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
|
|
110
|
-
|
|
111
|
-
const LightSensorService = `${accessory.displayName} Light Sensor`;
|
|
112
|
-
(this.LightSensor!.Service = this.accessory.getService(this.hap.Service.LightSensor)
|
|
113
|
-
|| this.accessory.addService(this.hap.Service.LightSensor)), LightSensorService;
|
|
114
|
-
|
|
115
|
-
this.LightSensor!.Service.setCharacteristic(this.hap.Characteristic.Name, LightSensorService);
|
|
116
130
|
} else {
|
|
117
|
-
this.
|
|
118
|
-
|
|
131
|
+
this.LightSensor = {
|
|
132
|
+
Name: accessory.context.LightSensor.Name ?? `${accessory.displayName} Light Sensor`,
|
|
133
|
+
Service: accessory.getService(this.hap.Service.LightSensor) ?? accessory.addService(this.hap.Service.LightSensor) as Service,
|
|
134
|
+
CurrentAmbientLightLevel: accessory.context.CurrentAmbientLightLevel ?? 0.0001,
|
|
135
|
+
};
|
|
119
136
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
137
|
+
// Light Sensor Characteristics
|
|
138
|
+
this.LightSensor.Service
|
|
139
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.LightSensor.Name)
|
|
140
|
+
.setCharacteristic(this.hap.Characteristic.StatusActive, true)
|
|
141
|
+
.getCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel)
|
|
142
|
+
.onGet(() => {
|
|
143
|
+
return this.LightSensor!.CurrentAmbientLightLevel;
|
|
144
|
+
});
|
|
145
|
+
accessory.context.LightSensor.Name = this.LightSensor.Name;
|
|
146
|
+
}
|
|
124
147
|
|
|
125
|
-
|
|
126
|
-
this.
|
|
148
|
+
// Retrieve initial values and updateHomekit
|
|
149
|
+
this.refreshStatus();
|
|
127
150
|
|
|
128
151
|
// Retrieve initial values and updateHomekit
|
|
129
152
|
this.updateHomeKitCharacteristics();
|
|
@@ -143,8 +166,8 @@ export class Contact extends deviceBase {
|
|
|
143
166
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
144
167
|
const { detectionState, brightness, openState } = context;
|
|
145
168
|
const { ContactSensorState } = this.ContactSensor;
|
|
146
|
-
const { CurrentAmbientLightLevel } = this.LightSensor
|
|
147
|
-
const { MotionDetected } = this.MotionSensor
|
|
169
|
+
const { CurrentAmbientLightLevel } = this.LightSensor ?? {};
|
|
170
|
+
const { MotionDetected } = this.MotionSensor ?? {};
|
|
148
171
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
149
172
|
'(detectionState, brightness, openState) = ' +
|
|
150
173
|
`Webhook:(${detectionState}, ${brightness}, ${openState}), ` +
|
|
@@ -473,11 +496,14 @@ export class Contact extends deviceBase {
|
|
|
473
496
|
|
|
474
497
|
async apiError(e: any): Promise<void> {
|
|
475
498
|
this.ContactSensor.Service.updateCharacteristic(this.hap.Characteristic.ContactSensorState, e);
|
|
499
|
+
this.ContactSensor.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e);
|
|
476
500
|
if (!this.device.contact?.hide_motionsensor) {
|
|
477
501
|
this.MotionSensor!.Service.updateCharacteristic(this.hap.Characteristic.MotionDetected, e);
|
|
502
|
+
this.MotionSensor!.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e);
|
|
478
503
|
}
|
|
479
504
|
if (!this.device.contact?.hide_lightsensor) {
|
|
480
505
|
this.LightSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e);
|
|
506
|
+
this.LightSensor!.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e);
|
|
481
507
|
}
|
|
482
508
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
483
509
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|