@switchbot/homebridge-switchbot 2.14.0 → 3.0.0-beta.0
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/.github/npm-version-script.cjs +81 -0
- package/.github/workflows/dependabot.yml +10 -11
- package/CHANGELOG.md +11 -2
- package/LICENSE +1 -1
- package/config.schema.json +1 -0
- package/dist/device/blindtilt.d.ts +9 -5
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +151 -91
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -5
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +234 -184
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +9 -5
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +110 -64
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +9 -5
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +121 -69
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +9 -5
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +111 -66
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +9 -5
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +164 -107
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +9 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +87 -51
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +9 -5
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +133 -90
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +9 -5
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +108 -66
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +9 -5
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +110 -65
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +10 -6
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +125 -84
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +9 -5
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +102 -63
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +9 -5
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +102 -63
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +9 -5
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +95 -54
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -5
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +68 -40
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +9 -5
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +86 -52
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/homebridge-ui/server.d.ts +2 -0
- package/dist/homebridge-ui/server.d.ts.map +1 -0
- package/dist/homebridge-ui/server.js +44 -0
- package/dist/homebridge-ui/server.js.map +1 -0
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -4
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +105 -71
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +8 -4
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +78 -46
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +8 -4
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +41 -25
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +8 -4
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +62 -39
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +8 -4
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +67 -45
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +8 -4
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +176 -150
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -4
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +81 -62
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +8 -4
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +41 -25
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +8 -4
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +48 -32
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +8 -9
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +147 -162
- package/dist/platform.js.map +1 -1
- package/dist/settings.js +7 -14
- package/dist/settings.js.map +1 -1
- package/dist/utils.js +1 -5
- package/dist/utils.js.map +1 -1
- package/package.json +28 -16
- package/src/device/blindtilt.ts +80 -69
- package/src/device/bot.ts +189 -178
- package/src/device/ceilinglight.ts +55 -42
- package/src/device/colorbulb.ts +51 -38
- package/src/device/contact.ts +69 -58
- package/src/device/curtain.ts +94 -83
- package/src/device/hub.ts +54 -43
- package/src/device/humidifier.ts +86 -75
- package/src/device/iosensor.ts +63 -52
- package/src/device/lightstrip.ts +54 -41
- package/src/device/lock.ts +89 -79
- package/src/device/meter.ts +59 -48
- package/src/device/meterplus.ts +63 -52
- package/src/device/motion.ts +56 -45
- package/src/device/plug.ts +36 -25
- package/src/device/robotvacuumcleaner.ts +47 -36
- package/src/homebridge-ui/public/index.html +240 -0
- package/src/homebridge-ui/server.ts +48 -0
- package/src/index.ts +10 -7
- package/src/irdevice/airconditioner.ts +70 -62
- package/src/irdevice/airpurifier.ts +47 -39
- package/src/irdevice/camera.ts +27 -19
- package/src/irdevice/fan.ts +41 -33
- package/src/irdevice/light.ts +47 -39
- package/src/irdevice/other.ts +163 -155
- package/src/irdevice/tv.ts +65 -57
- package/src/irdevice/vacuumcleaner.ts +27 -19
- package/src/irdevice/waterheater.ts +34 -26
- package/src/platform.ts +35 -21
- package/tsconfig.json +11 -13
- package/homebridge-ui/server.js +0 -50
- /package/{homebridge-ui → dist/homebridge-ui}/public/index.html +0 -0
|
@@ -3,8 +3,10 @@ import { sleep } from '../utils';
|
|
|
3
3
|
import { interval, Subject } from 'rxjs';
|
|
4
4
|
import { SwitchBotPlatform } from '../platform';
|
|
5
5
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
6
|
-
import { device, devicesConfig, deviceStatus, hs2rgb, rgb2hs, m2hs, serviceData, ad, Devices } from '../settings';
|
|
7
|
-
import {
|
|
6
|
+
import { device, devicesConfig, deviceStatus, hs2rgb, rgb2hs, m2hs, serviceData, ad, Devices, SwitchBotPlatformConfig } from '../settings';
|
|
7
|
+
import {
|
|
8
|
+
Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap, API, Logging, HAP,
|
|
9
|
+
} from 'homebridge';
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* Platform Accessory
|
|
@@ -12,6 +14,10 @@ import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor,
|
|
|
12
14
|
* Each accessory may expose multiple services of different service types.
|
|
13
15
|
*/
|
|
14
16
|
export class CeilingLight {
|
|
17
|
+
public readonly api: API;
|
|
18
|
+
public readonly log: Logging;
|
|
19
|
+
public readonly config!: SwitchBotPlatformConfig;
|
|
20
|
+
protected readonly hap: HAP;
|
|
15
21
|
// Services
|
|
16
22
|
lightBulbService!: Service;
|
|
17
23
|
|
|
@@ -58,21 +64,28 @@ export class CeilingLight {
|
|
|
58
64
|
doCeilingLightUpdate!: Subject<void>;
|
|
59
65
|
|
|
60
66
|
// Connection
|
|
61
|
-
private readonly
|
|
62
|
-
private readonly
|
|
67
|
+
private readonly OpenAPI: boolean;
|
|
68
|
+
private readonly BLE: boolean;
|
|
63
69
|
|
|
64
70
|
constructor(
|
|
65
71
|
private readonly platform: SwitchBotPlatform,
|
|
66
72
|
private accessory: PlatformAccessory,
|
|
67
73
|
public device: device & devicesConfig,
|
|
68
74
|
) {
|
|
75
|
+
this.api = this.platform.api;
|
|
76
|
+
this.log = this.platform.log;
|
|
77
|
+
this.config = this.platform.config;
|
|
78
|
+
this.hap = this.api.hap;
|
|
79
|
+
// Connection
|
|
80
|
+
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
81
|
+
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
69
82
|
// default placeholders
|
|
70
|
-
this.
|
|
83
|
+
this.deviceLogs(device);
|
|
71
84
|
this.scan(device);
|
|
72
85
|
this.refreshRate(device);
|
|
73
86
|
this.adaptiveLighting(device);
|
|
74
87
|
this.context();
|
|
75
|
-
this.
|
|
88
|
+
this.deviceConfig(device);
|
|
76
89
|
|
|
77
90
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
78
91
|
this.doCeilingLightUpdate = new Subject();
|
|
@@ -83,35 +96,35 @@ export class CeilingLight {
|
|
|
83
96
|
|
|
84
97
|
// set accessory information
|
|
85
98
|
accessory
|
|
86
|
-
.getService(this.
|
|
87
|
-
.setCharacteristic(this.
|
|
88
|
-
.setCharacteristic(this.
|
|
89
|
-
.setCharacteristic(this.
|
|
90
|
-
.setCharacteristic(this.
|
|
99
|
+
.getService(this.hap.Service.AccessoryInformation)!
|
|
100
|
+
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
101
|
+
.setCharacteristic(this.hap.Characteristic.Model, this.model(device))
|
|
102
|
+
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
103
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
91
104
|
|
|
92
105
|
// get the Lightbulb service if it exists, otherwise create a new Lightbulb service
|
|
93
106
|
// you can create multiple services for each accessory
|
|
94
107
|
const lightBulbService = `${accessory.displayName} ${device.deviceType}`;
|
|
95
|
-
(this.lightBulbService = accessory.getService(this.
|
|
96
|
-
|| accessory.addService(this.
|
|
108
|
+
(this.lightBulbService = accessory.getService(this.hap.Service.Lightbulb)
|
|
109
|
+
|| accessory.addService(this.hap.Service.Lightbulb)), lightBulbService;
|
|
97
110
|
|
|
98
111
|
if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
|
|
99
112
|
this.accessory.removeService(this.lightBulbService);
|
|
100
|
-
this.lightBulbService = this.accessory.addService(this.
|
|
113
|
+
this.lightBulbService = this.accessory.addService(this.hap.Service.Lightbulb);
|
|
101
114
|
this.accessory.context.adaptiveLighting = false;
|
|
102
115
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
|
|
103
116
|
}
|
|
104
117
|
|
|
105
|
-
this.lightBulbService.setCharacteristic(this.
|
|
106
|
-
if (!this.lightBulbService.testCharacteristic(this.
|
|
107
|
-
this.lightBulbService.addCharacteristic(this.
|
|
118
|
+
this.lightBulbService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
119
|
+
if (!this.lightBulbService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
120
|
+
this.lightBulbService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
108
121
|
}
|
|
109
122
|
// handle on / off events using the On characteristic
|
|
110
|
-
this.lightBulbService.getCharacteristic(this.
|
|
123
|
+
this.lightBulbService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
111
124
|
|
|
112
125
|
// handle Brightness events using the Brightness characteristic
|
|
113
126
|
this.lightBulbService
|
|
114
|
-
.getCharacteristic(this.
|
|
127
|
+
.getCharacteristic(this.hap.Characteristic.Brightness)
|
|
115
128
|
.setProps({
|
|
116
129
|
minStep: this.minStep(device),
|
|
117
130
|
minValue: 0,
|
|
@@ -125,7 +138,7 @@ export class CeilingLight {
|
|
|
125
138
|
|
|
126
139
|
// handle ColorTemperature events using the ColorTemperature characteristic
|
|
127
140
|
this.lightBulbService
|
|
128
|
-
.getCharacteristic(this.
|
|
141
|
+
.getCharacteristic(this.hap.Characteristic.ColorTemperature)
|
|
129
142
|
.setProps({
|
|
130
143
|
minValue: 140,
|
|
131
144
|
maxValue: 500,
|
|
@@ -138,7 +151,7 @@ export class CeilingLight {
|
|
|
138
151
|
|
|
139
152
|
// handle Hue events using the Hue characteristic
|
|
140
153
|
this.lightBulbService
|
|
141
|
-
.getCharacteristic(this.
|
|
154
|
+
.getCharacteristic(this.hap.Characteristic.Hue)
|
|
142
155
|
.setProps({
|
|
143
156
|
minValue: 0,
|
|
144
157
|
maxValue: 360,
|
|
@@ -151,7 +164,7 @@ export class CeilingLight {
|
|
|
151
164
|
|
|
152
165
|
// handle Hue events using the Hue characteristic
|
|
153
166
|
this.lightBulbService
|
|
154
|
-
.getCharacteristic(this.
|
|
167
|
+
.getCharacteristic(this.hap.Characteristic.Saturation)
|
|
155
168
|
.setProps({
|
|
156
169
|
minValue: 0,
|
|
157
170
|
maxValue: 100,
|
|
@@ -194,16 +207,16 @@ export class CeilingLight {
|
|
|
194
207
|
const { powerState, brightness, colorTemperature } = context;
|
|
195
208
|
const { On, Brightness, ColorTemperature } = this;
|
|
196
209
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
210
|
+
'(powerState, brightness, colorTemperature) = ' +
|
|
211
|
+
`Webhook:(${powerState}, ${brightness}, ${colorTemperature}), ` +
|
|
212
|
+
`current:(${On}, ${Brightness}, ${ColorTemperature})`);
|
|
200
213
|
this.On = powerState === 'ON' ? true : false;
|
|
201
214
|
this.Brightness = brightness;
|
|
202
215
|
this.ColorTemperature = colorTemperature;
|
|
203
216
|
this.updateHomeKitCharacteristics();
|
|
204
217
|
} catch (e: any) {
|
|
205
218
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
206
|
-
|
|
219
|
+
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
207
220
|
}
|
|
208
221
|
};
|
|
209
222
|
}
|
|
@@ -788,8 +801,8 @@ export class CeilingLight {
|
|
|
788
801
|
|
|
789
802
|
// Updating the hue/sat to the corresponding values mimics native adaptive lighting
|
|
790
803
|
const hs = m2hs(value);
|
|
791
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
792
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
804
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Hue, hs[0]);
|
|
805
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Saturation, hs[1]);
|
|
793
806
|
|
|
794
807
|
this.ColorTemperature = value;
|
|
795
808
|
this.doCeilingLightUpdate.next();
|
|
@@ -807,7 +820,7 @@ export class CeilingLight {
|
|
|
807
820
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Hue: ${value}`);
|
|
808
821
|
}
|
|
809
822
|
|
|
810
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
823
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
|
|
811
824
|
|
|
812
825
|
this.Hue = value;
|
|
813
826
|
this.doCeilingLightUpdate.next();
|
|
@@ -825,7 +838,7 @@ export class CeilingLight {
|
|
|
825
838
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Saturation: ${value}`);
|
|
826
839
|
}
|
|
827
840
|
|
|
828
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
841
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
|
|
829
842
|
|
|
830
843
|
this.Saturation = value;
|
|
831
844
|
this.doCeilingLightUpdate.next();
|
|
@@ -836,35 +849,35 @@ export class CeilingLight {
|
|
|
836
849
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
837
850
|
} else {
|
|
838
851
|
this.accessory.context.On = this.On;
|
|
839
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
852
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.On, this.On);
|
|
840
853
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
841
854
|
}
|
|
842
855
|
if (this.Brightness === undefined) {
|
|
843
856
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
844
857
|
} else {
|
|
845
858
|
this.accessory.context.Brightness = this.Brightness;
|
|
846
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
859
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Brightness, this.Brightness);
|
|
847
860
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
|
|
848
861
|
}
|
|
849
862
|
if (this.ColorTemperature === undefined) {
|
|
850
863
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
851
864
|
} else {
|
|
852
865
|
this.accessory.context.ColorTemperature = this.ColorTemperature;
|
|
853
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
866
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.ColorTemperature, this.ColorTemperature);
|
|
854
867
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
|
|
855
868
|
}
|
|
856
869
|
if (this.Hue === undefined) {
|
|
857
870
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
858
871
|
} else {
|
|
859
872
|
this.accessory.context.Hue = this.Hue;
|
|
860
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
873
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Hue, this.Hue);
|
|
861
874
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
|
|
862
875
|
}
|
|
863
876
|
if (this.Saturation === undefined) {
|
|
864
877
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
865
878
|
} else {
|
|
866
879
|
this.accessory.context.Saturation = this.Saturation;
|
|
867
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
880
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Saturation, this.Saturation);
|
|
868
881
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
|
|
869
882
|
}
|
|
870
883
|
}
|
|
@@ -1016,11 +1029,11 @@ export class CeilingLight {
|
|
|
1016
1029
|
}
|
|
1017
1030
|
|
|
1018
1031
|
apiError(e: any): void {
|
|
1019
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
1020
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
1021
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
1022
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
1023
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
1032
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
1033
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Hue, e);
|
|
1034
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Brightness, e);
|
|
1035
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Saturation, e);
|
|
1036
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.ColorTemperature, e);
|
|
1024
1037
|
}
|
|
1025
1038
|
|
|
1026
1039
|
async context() {
|
|
@@ -1067,7 +1080,7 @@ export class CeilingLight {
|
|
|
1067
1080
|
}
|
|
1068
1081
|
}
|
|
1069
1082
|
|
|
1070
|
-
async
|
|
1083
|
+
async deviceConfig(device: device & devicesConfig): Promise<void> {
|
|
1071
1084
|
let config = {};
|
|
1072
1085
|
if (device.ceilinglight) {
|
|
1073
1086
|
config = device.ceilinglight;
|
|
@@ -1098,7 +1111,7 @@ export class CeilingLight {
|
|
|
1098
1111
|
}
|
|
1099
1112
|
}
|
|
1100
1113
|
|
|
1101
|
-
async
|
|
1114
|
+
async deviceLogs(device: device & devicesConfig): Promise<void> {
|
|
1102
1115
|
if (this.platform.debugMode) {
|
|
1103
1116
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
1104
1117
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
package/src/device/colorbulb.ts
CHANGED
|
@@ -3,8 +3,10 @@ import { sleep } from '../utils';
|
|
|
3
3
|
import { interval, Subject } from 'rxjs';
|
|
4
4
|
import { SwitchBotPlatform } from '../platform';
|
|
5
5
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
6
|
-
import { device, devicesConfig, deviceStatus, hs2rgb, rgb2hs, m2hs, serviceData, ad, Devices } from '../settings';
|
|
7
|
-
import {
|
|
6
|
+
import { device, devicesConfig, deviceStatus, hs2rgb, rgb2hs, m2hs, serviceData, ad, Devices, SwitchBotPlatformConfig } from '../settings';
|
|
7
|
+
import {
|
|
8
|
+
Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap, API, Logging, HAP,
|
|
9
|
+
} from 'homebridge';
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* Platform Accessory
|
|
@@ -12,6 +14,10 @@ import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor,
|
|
|
12
14
|
* Each accessory may expose multiple services of different service types.
|
|
13
15
|
*/
|
|
14
16
|
export class ColorBulb {
|
|
17
|
+
public readonly api: API;
|
|
18
|
+
public readonly log: Logging;
|
|
19
|
+
public readonly config!: SwitchBotPlatformConfig;
|
|
20
|
+
protected readonly hap: HAP;
|
|
15
21
|
// Services
|
|
16
22
|
lightBulbService!: Service;
|
|
17
23
|
|
|
@@ -64,21 +70,28 @@ export class ColorBulb {
|
|
|
64
70
|
doColorBulbUpdate!: Subject<void>;
|
|
65
71
|
|
|
66
72
|
// Connection
|
|
67
|
-
private readonly
|
|
68
|
-
private readonly
|
|
73
|
+
private readonly OpenAPI: boolean;
|
|
74
|
+
private readonly BLE: boolean;
|
|
69
75
|
|
|
70
76
|
constructor(
|
|
71
77
|
private readonly platform: SwitchBotPlatform,
|
|
72
78
|
private accessory: PlatformAccessory,
|
|
73
79
|
public device: device & devicesConfig,
|
|
74
80
|
) {
|
|
81
|
+
this.api = this.platform.api;
|
|
82
|
+
this.log = this.platform.log;
|
|
83
|
+
this.config = this.platform.config;
|
|
84
|
+
this.hap = this.api.hap;
|
|
85
|
+
// Connection
|
|
86
|
+
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
87
|
+
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
75
88
|
// default placeholders
|
|
76
|
-
this.
|
|
89
|
+
this.deviceLogs(device);
|
|
77
90
|
this.scan(device);
|
|
78
91
|
this.refreshRate(device);
|
|
79
92
|
this.adaptiveLighting(device);
|
|
80
93
|
this.context();
|
|
81
|
-
this.
|
|
94
|
+
this.deviceConfig(device);
|
|
82
95
|
|
|
83
96
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
84
97
|
this.doColorBulbUpdate = new Subject();
|
|
@@ -89,36 +102,36 @@ export class ColorBulb {
|
|
|
89
102
|
|
|
90
103
|
// set accessory information
|
|
91
104
|
accessory
|
|
92
|
-
.getService(this.
|
|
93
|
-
.setCharacteristic(this.
|
|
94
|
-
.setCharacteristic(this.
|
|
95
|
-
.setCharacteristic(this.
|
|
96
|
-
.setCharacteristic(this.
|
|
105
|
+
.getService(this.hap.Service.AccessoryInformation)!
|
|
106
|
+
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
107
|
+
.setCharacteristic(this.hap.Characteristic.Model, 'W1401400')
|
|
108
|
+
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
109
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
97
110
|
|
|
98
111
|
// get the Lightbulb service if it exists, otherwise create a new Lightbulb service
|
|
99
112
|
// you can create multiple services for each accessory
|
|
100
113
|
const lightBulbService = `${accessory.displayName} ${device.deviceType}`;
|
|
101
|
-
(this.lightBulbService = accessory.getService(this.
|
|
102
|
-
|| accessory.addService(this.
|
|
114
|
+
(this.lightBulbService = accessory.getService(this.hap.Service.Lightbulb)
|
|
115
|
+
|| accessory.addService(this.hap.Service.Lightbulb)), lightBulbService;
|
|
103
116
|
|
|
104
117
|
if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
|
|
105
118
|
this.accessory.removeService(this.lightBulbService);
|
|
106
|
-
this.lightBulbService = this.accessory.addService(this.
|
|
119
|
+
this.lightBulbService = this.accessory.addService(this.hap.Service.Lightbulb);
|
|
107
120
|
this.accessory.context.adaptiveLighting = false;
|
|
108
121
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
|
|
109
122
|
}
|
|
110
123
|
|
|
111
|
-
this.lightBulbService.setCharacteristic(this.
|
|
112
|
-
if (!this.lightBulbService.testCharacteristic(this.
|
|
113
|
-
this.lightBulbService.addCharacteristic(this.
|
|
124
|
+
this.lightBulbService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
125
|
+
if (!this.lightBulbService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
126
|
+
this.lightBulbService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
114
127
|
}
|
|
115
128
|
|
|
116
129
|
// handle on / off events using the On characteristic
|
|
117
|
-
this.lightBulbService.getCharacteristic(this.
|
|
130
|
+
this.lightBulbService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
118
131
|
|
|
119
132
|
// handle Brightness events using the Brightness characteristic
|
|
120
133
|
this.lightBulbService
|
|
121
|
-
.getCharacteristic(this.
|
|
134
|
+
.getCharacteristic(this.hap.Characteristic.Brightness)
|
|
122
135
|
.setProps({
|
|
123
136
|
minStep: this.minStep(device),
|
|
124
137
|
minValue: 0,
|
|
@@ -132,7 +145,7 @@ export class ColorBulb {
|
|
|
132
145
|
|
|
133
146
|
// handle ColorTemperature events using the ColorTemperature characteristic
|
|
134
147
|
this.lightBulbService
|
|
135
|
-
.getCharacteristic(this.
|
|
148
|
+
.getCharacteristic(this.hap.Characteristic.ColorTemperature)
|
|
136
149
|
.setProps({
|
|
137
150
|
minValue: 140,
|
|
138
151
|
maxValue: 500,
|
|
@@ -145,7 +158,7 @@ export class ColorBulb {
|
|
|
145
158
|
|
|
146
159
|
// handle Hue events using the Hue characteristic
|
|
147
160
|
this.lightBulbService
|
|
148
|
-
.getCharacteristic(this.
|
|
161
|
+
.getCharacteristic(this.hap.Characteristic.Hue)
|
|
149
162
|
.setProps({
|
|
150
163
|
minValue: 0,
|
|
151
164
|
maxValue: 360,
|
|
@@ -158,7 +171,7 @@ export class ColorBulb {
|
|
|
158
171
|
|
|
159
172
|
// handle Hue events using the Hue characteristic
|
|
160
173
|
this.lightBulbService
|
|
161
|
-
.getCharacteristic(this.
|
|
174
|
+
.getCharacteristic(this.hap.Characteristic.Saturation)
|
|
162
175
|
.setProps({
|
|
163
176
|
minValue: 0,
|
|
164
177
|
maxValue: 100,
|
|
@@ -971,8 +984,8 @@ export class ColorBulb {
|
|
|
971
984
|
|
|
972
985
|
// Updating the hue/sat to the corresponding values mimics native adaptive lighting
|
|
973
986
|
const hs = m2hs(value);
|
|
974
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
975
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
987
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Hue, hs[0]);
|
|
988
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Saturation, hs[1]);
|
|
976
989
|
|
|
977
990
|
this.ColorTemperature = value;
|
|
978
991
|
this.doColorBulbUpdate.next();
|
|
@@ -990,7 +1003,7 @@ export class ColorBulb {
|
|
|
990
1003
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Hue: ${value}`);
|
|
991
1004
|
}
|
|
992
1005
|
|
|
993
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
1006
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
|
|
994
1007
|
|
|
995
1008
|
this.Hue = value;
|
|
996
1009
|
this.doColorBulbUpdate.next();
|
|
@@ -1008,7 +1021,7 @@ export class ColorBulb {
|
|
|
1008
1021
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Saturation: ${value}`);
|
|
1009
1022
|
}
|
|
1010
1023
|
|
|
1011
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
1024
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
|
|
1012
1025
|
|
|
1013
1026
|
this.Saturation = value;
|
|
1014
1027
|
this.doColorBulbUpdate.next();
|
|
@@ -1020,7 +1033,7 @@ export class ColorBulb {
|
|
|
1020
1033
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
1021
1034
|
} else {
|
|
1022
1035
|
this.accessory.context.On = this.On;
|
|
1023
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
1036
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.On, this.On);
|
|
1024
1037
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
1025
1038
|
}
|
|
1026
1039
|
// Brightness
|
|
@@ -1028,7 +1041,7 @@ export class ColorBulb {
|
|
|
1028
1041
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
1029
1042
|
} else {
|
|
1030
1043
|
this.accessory.context.Brightness = this.Brightness;
|
|
1031
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
1044
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Brightness, this.Brightness);
|
|
1032
1045
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
|
|
1033
1046
|
}
|
|
1034
1047
|
// ColorTemperature
|
|
@@ -1036,7 +1049,7 @@ export class ColorBulb {
|
|
|
1036
1049
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
1037
1050
|
} else {
|
|
1038
1051
|
this.accessory.context.ColorTemperature = this.ColorTemperature;
|
|
1039
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
1052
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.ColorTemperature, this.ColorTemperature);
|
|
1040
1053
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
|
|
1041
1054
|
}
|
|
1042
1055
|
// Hue
|
|
@@ -1044,7 +1057,7 @@ export class ColorBulb {
|
|
|
1044
1057
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
1045
1058
|
} else {
|
|
1046
1059
|
this.accessory.context.Hue = this.Hue;
|
|
1047
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
1060
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Hue, this.Hue);
|
|
1048
1061
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
|
|
1049
1062
|
}
|
|
1050
1063
|
// Saturation
|
|
@@ -1052,7 +1065,7 @@ export class ColorBulb {
|
|
|
1052
1065
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
1053
1066
|
} else {
|
|
1054
1067
|
this.accessory.context.Saturation = this.Saturation;
|
|
1055
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
1068
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Saturation, this.Saturation);
|
|
1056
1069
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
|
|
1057
1070
|
}
|
|
1058
1071
|
}
|
|
@@ -1204,11 +1217,11 @@ export class ColorBulb {
|
|
|
1204
1217
|
}
|
|
1205
1218
|
|
|
1206
1219
|
apiError(e: any): void {
|
|
1207
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
1208
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
1209
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
1210
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
1211
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
1220
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
1221
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Hue, e);
|
|
1222
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Brightness, e);
|
|
1223
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Saturation, e);
|
|
1224
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.ColorTemperature, e);
|
|
1212
1225
|
}
|
|
1213
1226
|
|
|
1214
1227
|
async context() {
|
|
@@ -1255,7 +1268,7 @@ export class ColorBulb {
|
|
|
1255
1268
|
}
|
|
1256
1269
|
}
|
|
1257
1270
|
|
|
1258
|
-
async
|
|
1271
|
+
async deviceConfig(device: device & devicesConfig): Promise<void> {
|
|
1259
1272
|
let config = {};
|
|
1260
1273
|
if (device.colorbulb) {
|
|
1261
1274
|
config = device.colorbulb;
|
|
@@ -1286,7 +1299,7 @@ export class ColorBulb {
|
|
|
1286
1299
|
}
|
|
1287
1300
|
}
|
|
1288
1301
|
|
|
1289
|
-
async
|
|
1302
|
+
async deviceLogs(device: device & devicesConfig): Promise<void> {
|
|
1290
1303
|
if (this.platform.debugMode) {
|
|
1291
1304
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
1292
1305
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|