@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
package/src/device/iosensor.ts
CHANGED
|
@@ -6,8 +6,8 @@ import { connectAsync } from 'async-mqtt';
|
|
|
6
6
|
import { interval, Subject } from 'rxjs';
|
|
7
7
|
import { skipWhile } from 'rxjs/operators';
|
|
8
8
|
import { SwitchBotPlatform } from '../platform';
|
|
9
|
-
import { Service, PlatformAccessory, Units, CharacteristicValue } from 'homebridge';
|
|
10
|
-
import { device, devicesConfig, serviceData, ad, temperature, deviceStatus, Devices } from '../settings';
|
|
9
|
+
import { Service, PlatformAccessory, Units, CharacteristicValue, API, Logging, HAP } from 'homebridge';
|
|
10
|
+
import { device, devicesConfig, serviceData, ad, temperature, deviceStatus, Devices, SwitchBotPlatformConfig } from '../settings';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Platform Accessory
|
|
@@ -15,6 +15,10 @@ import { device, devicesConfig, serviceData, ad, temperature, deviceStatus, Devi
|
|
|
15
15
|
* Each accessory may expose multiple services of different service types.
|
|
16
16
|
*/
|
|
17
17
|
export class IOSensor {
|
|
18
|
+
public readonly api: API;
|
|
19
|
+
public readonly log: Logging;
|
|
20
|
+
public readonly config!: SwitchBotPlatformConfig;
|
|
21
|
+
protected readonly hap: HAP;
|
|
18
22
|
// Services
|
|
19
23
|
batteryService: Service;
|
|
20
24
|
humidityservice?: Service;
|
|
@@ -59,22 +63,29 @@ export class IOSensor {
|
|
|
59
63
|
doIOSensorUpdate: Subject<void>;
|
|
60
64
|
|
|
61
65
|
// Connection
|
|
62
|
-
private readonly
|
|
63
|
-
private readonly
|
|
66
|
+
private readonly OpenAPI: boolean;
|
|
67
|
+
private readonly BLE: boolean;
|
|
64
68
|
|
|
65
69
|
constructor(
|
|
66
70
|
private readonly platform: SwitchBotPlatform,
|
|
67
71
|
private accessory: PlatformAccessory,
|
|
68
72
|
public device: device & devicesConfig,
|
|
69
73
|
) {
|
|
74
|
+
this.api = this.platform.api;
|
|
75
|
+
this.log = this.platform.log;
|
|
76
|
+
this.config = this.platform.config;
|
|
77
|
+
this.hap = this.api.hap;
|
|
78
|
+
// Connection
|
|
79
|
+
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
80
|
+
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
70
81
|
// default placeholders
|
|
71
|
-
this.
|
|
82
|
+
this.deviceLogs(device);
|
|
72
83
|
this.scan(device);
|
|
73
84
|
this.refreshRate(device);
|
|
74
85
|
this.context();
|
|
75
86
|
this.setupHistoryService(device);
|
|
76
87
|
this.setupMqtt(device);
|
|
77
|
-
this.
|
|
88
|
+
this.deviceConfig(device);
|
|
78
89
|
|
|
79
90
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
80
91
|
this.doIOSensorUpdate = new Subject();
|
|
@@ -85,29 +96,29 @@ export class IOSensor {
|
|
|
85
96
|
|
|
86
97
|
// set accessory information
|
|
87
98
|
accessory
|
|
88
|
-
.getService(this.
|
|
89
|
-
.setCharacteristic(this.
|
|
90
|
-
.setCharacteristic(this.
|
|
91
|
-
.setCharacteristic(this.
|
|
92
|
-
.setCharacteristic(this.
|
|
99
|
+
.getService(this.hap.Service.AccessoryInformation)!
|
|
100
|
+
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
101
|
+
.setCharacteristic(this.hap.Characteristic.Model, 'WoIOSensor')
|
|
102
|
+
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
103
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
93
104
|
|
|
94
105
|
// Temperature Sensor Service
|
|
95
106
|
if (device.meter?.hide_temperature) {
|
|
96
107
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
97
|
-
this.temperatureservice = this.accessory.getService(this.
|
|
108
|
+
this.temperatureservice = this.accessory.getService(this.hap.Service.TemperatureSensor);
|
|
98
109
|
accessory.removeService(this.temperatureservice!);
|
|
99
110
|
} else if (!this.temperatureservice) {
|
|
100
111
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
101
112
|
const temperatureservice = `${accessory.displayName} Temperature Sensor`;
|
|
102
|
-
(this.temperatureservice = this.accessory.getService(this.
|
|
103
|
-
|
|
113
|
+
(this.temperatureservice = this.accessory.getService(this.hap.Service.TemperatureSensor)
|
|
114
|
+
|| this.accessory.addService(this.hap.Service.TemperatureSensor)), temperatureservice;
|
|
104
115
|
|
|
105
|
-
this.temperatureservice.setCharacteristic(this.
|
|
106
|
-
if (!this.temperatureservice.testCharacteristic(this.
|
|
107
|
-
this.temperatureservice.addCharacteristic(this.
|
|
116
|
+
this.temperatureservice.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Temperature Sensor`);
|
|
117
|
+
if (!this.temperatureservice.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
118
|
+
this.temperatureservice.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Temperature Sensor`);
|
|
108
119
|
}
|
|
109
120
|
this.temperatureservice
|
|
110
|
-
.getCharacteristic(this.
|
|
121
|
+
.getCharacteristic(this.hap.Characteristic.CurrentTemperature)
|
|
111
122
|
.setProps({
|
|
112
123
|
unit: Units['CELSIUS'],
|
|
113
124
|
validValueRanges: [-273.15, 100],
|
|
@@ -125,20 +136,20 @@ export class IOSensor {
|
|
|
125
136
|
// Humidity Sensor Service
|
|
126
137
|
if (device.meter?.hide_humidity) {
|
|
127
138
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Humidity Sensor Service`);
|
|
128
|
-
this.humidityservice = this.accessory.getService(this.
|
|
139
|
+
this.humidityservice = this.accessory.getService(this.hap.Service.HumiditySensor);
|
|
129
140
|
accessory.removeService(this.humidityservice!);
|
|
130
141
|
} else if (!this.humidityservice) {
|
|
131
142
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Humidity Sensor Service`);
|
|
132
143
|
const humidityservice = `${accessory.displayName} Humidity Sensor`;
|
|
133
|
-
(this.humidityservice = this.accessory.getService(this.
|
|
134
|
-
|
|
144
|
+
(this.humidityservice = this.accessory.getService(this.hap.Service.HumiditySensor)
|
|
145
|
+
|| this.accessory.addService(this.hap.Service.HumiditySensor)), humidityservice;
|
|
135
146
|
|
|
136
|
-
this.humidityservice.setCharacteristic(this.
|
|
137
|
-
if (!this.humidityservice.testCharacteristic(this.
|
|
138
|
-
this.humidityservice.addCharacteristic(this.
|
|
147
|
+
this.humidityservice.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Humidity Sensor`);
|
|
148
|
+
if (!this.humidityservice.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
149
|
+
this.humidityservice.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Humidity Sensor`);
|
|
139
150
|
}
|
|
140
151
|
this.humidityservice
|
|
141
|
-
.getCharacteristic(this.
|
|
152
|
+
.getCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity)
|
|
142
153
|
.setProps({
|
|
143
154
|
minStep: 0.1,
|
|
144
155
|
})
|
|
@@ -151,14 +162,14 @@ export class IOSensor {
|
|
|
151
162
|
|
|
152
163
|
// Battery Service
|
|
153
164
|
const batteryService = `${accessory.displayName} Battery`;
|
|
154
|
-
(this.batteryService = this.accessory.getService(this.
|
|
155
|
-
|
|
165
|
+
(this.batteryService = this.accessory.getService(this.hap.Service.Battery)
|
|
166
|
+
|| accessory.addService(this.hap.Service.Battery)), batteryService;
|
|
156
167
|
|
|
157
|
-
this.batteryService.setCharacteristic(this.
|
|
158
|
-
if (!this.batteryService.testCharacteristic(this.
|
|
159
|
-
this.batteryService.addCharacteristic(this.
|
|
168
|
+
this.batteryService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
169
|
+
if (!this.batteryService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
170
|
+
this.batteryService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
160
171
|
}
|
|
161
|
-
this.batteryService.setCharacteristic(this.
|
|
172
|
+
this.batteryService.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
162
173
|
|
|
163
174
|
// Retrieve initial values and updateHomekit
|
|
164
175
|
this.updateHomeKitCharacteristics();
|
|
@@ -180,16 +191,16 @@ export class IOSensor {
|
|
|
180
191
|
const { temperature, humidity } = context;
|
|
181
192
|
const { CurrentTemperature, CurrentRelativeHumidity } = this;
|
|
182
193
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
194
|
+
'(temperature, humidity) = ' +
|
|
195
|
+
`Webhook:(${temperature}, ${humidity}), ` +
|
|
196
|
+
`current:(${CurrentTemperature}, ${CurrentRelativeHumidity})`);
|
|
186
197
|
this.CurrentRelativeHumidity = humidity;
|
|
187
198
|
this.CurrentTemperature = temperature;
|
|
188
199
|
this.updateHomeKitCharacteristics();
|
|
189
200
|
}
|
|
190
201
|
} catch (e: any) {
|
|
191
202
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
192
|
-
|
|
203
|
+
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
193
204
|
}
|
|
194
205
|
};
|
|
195
206
|
}
|
|
@@ -219,9 +230,9 @@ export class IOSensor {
|
|
|
219
230
|
// Battery
|
|
220
231
|
this.BatteryLevel = Number(this.BLE_BatteryLevel);
|
|
221
232
|
if (this.BatteryLevel < 15) {
|
|
222
|
-
this.StatusLowBattery = this.
|
|
233
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
223
234
|
} else {
|
|
224
|
-
this.StatusLowBattery = this.
|
|
235
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
225
236
|
}
|
|
226
237
|
this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
|
|
227
238
|
|
|
@@ -244,9 +255,9 @@ export class IOSensor {
|
|
|
244
255
|
// Battery
|
|
245
256
|
this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
|
|
246
257
|
if (this.BatteryLevel < 15) {
|
|
247
|
-
this.StatusLowBattery = this.
|
|
258
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
248
259
|
} else {
|
|
249
|
-
this.StatusLowBattery = this.
|
|
260
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
250
261
|
}
|
|
251
262
|
this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
|
|
252
263
|
|
|
@@ -265,9 +276,9 @@ export class IOSensor {
|
|
|
265
276
|
// BatteryLevel
|
|
266
277
|
this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
|
|
267
278
|
if (this.BatteryLevel < 10) {
|
|
268
|
-
this.StatusLowBattery = this.
|
|
279
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
269
280
|
} else {
|
|
270
|
-
this.StatusLowBattery = this.
|
|
281
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
271
282
|
}
|
|
272
283
|
if (Number.isNaN(this.BatteryLevel)) {
|
|
273
284
|
this.BatteryLevel = 100;
|
|
@@ -413,7 +424,7 @@ export class IOSensor {
|
|
|
413
424
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
414
425
|
} else {
|
|
415
426
|
this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
|
|
416
|
-
this.humidityservice?.updateCharacteristic(this.
|
|
427
|
+
this.humidityservice?.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
417
428
|
this.debugLog(
|
|
418
429
|
`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
419
430
|
` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
|
|
@@ -437,7 +448,7 @@ export class IOSensor {
|
|
|
437
448
|
entry['temp'] = this.CurrentTemperature;
|
|
438
449
|
}
|
|
439
450
|
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
440
|
-
this.temperatureservice?.updateCharacteristic(this.
|
|
451
|
+
this.temperatureservice?.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
441
452
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
442
453
|
}
|
|
443
454
|
}
|
|
@@ -448,7 +459,7 @@ export class IOSensor {
|
|
|
448
459
|
mqttmessage.push(`"battery": ${this.BatteryLevel}`);
|
|
449
460
|
}
|
|
450
461
|
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
451
|
-
this.batteryService?.updateCharacteristic(this.
|
|
462
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
452
463
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
453
464
|
}
|
|
454
465
|
if (this.StatusLowBattery === undefined) {
|
|
@@ -458,7 +469,7 @@ export class IOSensor {
|
|
|
458
469
|
mqttmessage.push(`"lowBattery": ${this.StatusLowBattery}`);
|
|
459
470
|
}
|
|
460
471
|
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
461
|
-
this.batteryService?.updateCharacteristic(this.
|
|
472
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
462
473
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
463
474
|
}
|
|
464
475
|
if (this.device.mqttURL) {
|
|
@@ -622,13 +633,13 @@ export class IOSensor {
|
|
|
622
633
|
|
|
623
634
|
async apiError(e: any): Promise<void> {
|
|
624
635
|
if (!this.device.meter?.hide_humidity) {
|
|
625
|
-
this.humidityservice?.updateCharacteristic(this.
|
|
636
|
+
this.humidityservice?.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
|
|
626
637
|
}
|
|
627
638
|
if (!this.device.meter?.hide_temperature) {
|
|
628
|
-
this.temperatureservice?.updateCharacteristic(this.
|
|
639
|
+
this.temperatureservice?.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
|
|
629
640
|
}
|
|
630
|
-
this.batteryService?.updateCharacteristic(this.
|
|
631
|
-
this.batteryService?.updateCharacteristic(this.
|
|
641
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
642
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
632
643
|
}
|
|
633
644
|
|
|
634
645
|
async context() {
|
|
@@ -648,7 +659,7 @@ export class IOSensor {
|
|
|
648
659
|
this.BatteryLevel = this.accessory.context.BatteryLevel;
|
|
649
660
|
}
|
|
650
661
|
if (this.StatusLowBattery === undefined) {
|
|
651
|
-
this.StatusLowBattery = this.
|
|
662
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
652
663
|
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
653
664
|
} else {
|
|
654
665
|
this.StatusLowBattery = this.accessory.context.StatusLowBattery;
|
|
@@ -669,7 +680,7 @@ export class IOSensor {
|
|
|
669
680
|
}
|
|
670
681
|
}
|
|
671
682
|
|
|
672
|
-
async
|
|
683
|
+
async deviceConfig(device: device & devicesConfig): Promise<void> {
|
|
673
684
|
let config = {};
|
|
674
685
|
if (device.meter) {
|
|
675
686
|
config = device.meter;
|
|
@@ -697,7 +708,7 @@ export class IOSensor {
|
|
|
697
708
|
}
|
|
698
709
|
}
|
|
699
710
|
|
|
700
|
-
async
|
|
711
|
+
async deviceLogs(device: device & devicesConfig): Promise<void> {
|
|
701
712
|
if (this.platform.debugMode) {
|
|
702
713
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
703
714
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
package/src/device/lightstrip.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 {
|
|
7
|
-
|
|
6
|
+
import {
|
|
7
|
+
Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap, API, Logging, HAP,
|
|
8
|
+
} from 'homebridge';
|
|
9
|
+
import { device, devicesConfig, hs2rgb, rgb2hs, deviceStatus, ad, serviceData, m2hs, Devices, SwitchBotPlatformConfig } from '../settings';
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* Platform Accessory
|
|
@@ -12,6 +14,10 @@ import { device, devicesConfig, hs2rgb, rgb2hs, deviceStatus, ad, serviceData, m
|
|
|
12
14
|
* Each accessory may expose multiple services of different service types.
|
|
13
15
|
*/
|
|
14
16
|
export class StripLight {
|
|
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
|
|
|
@@ -57,20 +63,27 @@ export class StripLight {
|
|
|
57
63
|
doStripLightUpdate!: Subject<void>;
|
|
58
64
|
|
|
59
65
|
// Connection
|
|
60
|
-
private readonly
|
|
61
|
-
private readonly
|
|
66
|
+
private readonly OpenAPI: boolean;
|
|
67
|
+
private readonly BLE: boolean;
|
|
62
68
|
|
|
63
69
|
constructor(
|
|
64
70
|
private readonly platform: SwitchBotPlatform,
|
|
65
71
|
private accessory: PlatformAccessory,
|
|
66
72
|
public device: device & devicesConfig,
|
|
67
73
|
) {
|
|
74
|
+
this.api = this.platform.api;
|
|
75
|
+
this.log = this.platform.log;
|
|
76
|
+
this.config = this.platform.config;
|
|
77
|
+
this.hap = this.api.hap;
|
|
78
|
+
// Connection
|
|
79
|
+
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
80
|
+
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
68
81
|
// default placeholders
|
|
69
|
-
this.
|
|
82
|
+
this.deviceLogs(device);
|
|
70
83
|
this.scan(device);
|
|
71
84
|
this.refreshRate(device);
|
|
72
85
|
this.context();
|
|
73
|
-
this.
|
|
86
|
+
this.deviceConfig(device);
|
|
74
87
|
|
|
75
88
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
76
89
|
this.doStripLightUpdate = new Subject();
|
|
@@ -81,35 +94,35 @@ export class StripLight {
|
|
|
81
94
|
|
|
82
95
|
// set accessory information
|
|
83
96
|
accessory
|
|
84
|
-
.getService(this.
|
|
85
|
-
.setCharacteristic(this.
|
|
86
|
-
.setCharacteristic(this.
|
|
87
|
-
.setCharacteristic(this.
|
|
88
|
-
.setCharacteristic(this.
|
|
97
|
+
.getService(this.hap.Service.AccessoryInformation)!
|
|
98
|
+
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
99
|
+
.setCharacteristic(this.hap.Characteristic.Model, 'W1701100')
|
|
100
|
+
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
101
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
89
102
|
|
|
90
103
|
// get the Lightbulb service if it exists, otherwise create a new Lightbulb service
|
|
91
104
|
// you can create multiple services for each accessory
|
|
92
105
|
const lightBulbService = `${accessory.displayName} ${device.deviceType}`;
|
|
93
|
-
(this.lightBulbService = accessory.getService(this.
|
|
94
|
-
|| accessory.addService(this.
|
|
106
|
+
(this.lightBulbService = accessory.getService(this.hap.Service.Lightbulb)
|
|
107
|
+
|| accessory.addService(this.hap.Service.Lightbulb)), lightBulbService;
|
|
95
108
|
|
|
96
109
|
if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
|
|
97
110
|
this.accessory.removeService(this.lightBulbService);
|
|
98
|
-
this.lightBulbService = this.accessory.addService(this.
|
|
111
|
+
this.lightBulbService = this.accessory.addService(this.hap.Service.Lightbulb);
|
|
99
112
|
this.accessory.context.adaptiveLighting = false;
|
|
100
113
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
|
|
101
114
|
}
|
|
102
115
|
|
|
103
|
-
this.lightBulbService.setCharacteristic(this.
|
|
104
|
-
if (!this.lightBulbService.testCharacteristic(this.
|
|
105
|
-
this.lightBulbService.addCharacteristic(this.
|
|
116
|
+
this.lightBulbService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
117
|
+
if (!this.lightBulbService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
118
|
+
this.lightBulbService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
106
119
|
}
|
|
107
120
|
// handle on / off events using the On characteristic
|
|
108
|
-
this.lightBulbService.getCharacteristic(this.
|
|
121
|
+
this.lightBulbService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
109
122
|
|
|
110
123
|
// handle Brightness events using the Brightness characteristic
|
|
111
124
|
this.lightBulbService
|
|
112
|
-
.getCharacteristic(this.
|
|
125
|
+
.getCharacteristic(this.hap.Characteristic.Brightness)
|
|
113
126
|
.setProps({
|
|
114
127
|
minStep: this.minStep(device),
|
|
115
128
|
minValue: 0,
|
|
@@ -123,7 +136,7 @@ export class StripLight {
|
|
|
123
136
|
|
|
124
137
|
// handle ColorTemperature events using the ColorTemperature characteristic
|
|
125
138
|
this.lightBulbService
|
|
126
|
-
.getCharacteristic(this.
|
|
139
|
+
.getCharacteristic(this.hap.Characteristic.ColorTemperature)
|
|
127
140
|
.setProps({
|
|
128
141
|
minValue: 140,
|
|
129
142
|
maxValue: 500,
|
|
@@ -136,7 +149,7 @@ export class StripLight {
|
|
|
136
149
|
|
|
137
150
|
// handle Hue events using the Hue characteristic
|
|
138
151
|
this.lightBulbService
|
|
139
|
-
.getCharacteristic(this.
|
|
152
|
+
.getCharacteristic(this.hap.Characteristic.Hue)
|
|
140
153
|
.setProps({
|
|
141
154
|
minValue: 0,
|
|
142
155
|
maxValue: 360,
|
|
@@ -149,7 +162,7 @@ export class StripLight {
|
|
|
149
162
|
|
|
150
163
|
// handle Hue events using the Hue characteristic
|
|
151
164
|
this.lightBulbService
|
|
152
|
-
.getCharacteristic(this.
|
|
165
|
+
.getCharacteristic(this.hap.Characteristic.Saturation)
|
|
153
166
|
.setProps({
|
|
154
167
|
minValue: 0,
|
|
155
168
|
maxValue: 100,
|
|
@@ -192,9 +205,9 @@ export class StripLight {
|
|
|
192
205
|
const { powerState, brightness, color, colorTemperature } = context;
|
|
193
206
|
const { On, Brightness, Hue, Saturation, ColorTemperature } = this;
|
|
194
207
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
208
|
+
'(powerState, brightness, color, colorTemperature) = ' +
|
|
209
|
+
`Webhook:(${powerState}, ${brightness}, ${color}, ${colorTemperature}), ` +
|
|
210
|
+
`current:(${On}, ${Brightness}, ${Hue}, ${Saturation}, ${ColorTemperature})`);
|
|
198
211
|
this.On = powerState === 'ON' ? true : false;
|
|
199
212
|
this.Brightness = brightness;
|
|
200
213
|
|
|
@@ -220,7 +233,7 @@ export class StripLight {
|
|
|
220
233
|
this.updateHomeKitCharacteristics();
|
|
221
234
|
} catch (e: any) {
|
|
222
235
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
223
|
-
|
|
236
|
+
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
224
237
|
}
|
|
225
238
|
};
|
|
226
239
|
}
|
|
@@ -816,8 +829,8 @@ export class StripLight {
|
|
|
816
829
|
|
|
817
830
|
// Updating the hue/sat to the corresponding values mimics native adaptive lighting
|
|
818
831
|
const hs = m2hs(value);
|
|
819
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
820
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
832
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Hue, hs[0]);
|
|
833
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Saturation, hs[1]);
|
|
821
834
|
|
|
822
835
|
this.ColorTemperature = value;
|
|
823
836
|
this.doStripLightUpdate.next();
|
|
@@ -835,7 +848,7 @@ export class StripLight {
|
|
|
835
848
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Hue: ${value}`);
|
|
836
849
|
}
|
|
837
850
|
|
|
838
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
851
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
|
|
839
852
|
|
|
840
853
|
this.Hue = value;
|
|
841
854
|
this.doStripLightUpdate.next();
|
|
@@ -853,7 +866,7 @@ export class StripLight {
|
|
|
853
866
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Saturation: ${value}`);
|
|
854
867
|
}
|
|
855
868
|
|
|
856
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
869
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
|
|
857
870
|
|
|
858
871
|
this.Saturation = value;
|
|
859
872
|
this.doStripLightUpdate.next();
|
|
@@ -865,7 +878,7 @@ export class StripLight {
|
|
|
865
878
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
866
879
|
} else {
|
|
867
880
|
this.accessory.context.On = this.On;
|
|
868
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
881
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.On, this.On);
|
|
869
882
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
870
883
|
}
|
|
871
884
|
// Brightness
|
|
@@ -873,7 +886,7 @@ export class StripLight {
|
|
|
873
886
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
874
887
|
} else {
|
|
875
888
|
this.accessory.context.Brightness = this.Brightness;
|
|
876
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
889
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Brightness, this.Brightness);
|
|
877
890
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
|
|
878
891
|
}
|
|
879
892
|
// ColorTemperature
|
|
@@ -881,7 +894,7 @@ export class StripLight {
|
|
|
881
894
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
882
895
|
} else {
|
|
883
896
|
this.accessory.context.ColorTemperature = this.ColorTemperature;
|
|
884
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
897
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.ColorTemperature, this.ColorTemperature);
|
|
885
898
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
|
|
886
899
|
}
|
|
887
900
|
// Hue
|
|
@@ -889,7 +902,7 @@ export class StripLight {
|
|
|
889
902
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
890
903
|
} else {
|
|
891
904
|
this.accessory.context.Hue = this.Hue;
|
|
892
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
905
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Hue, this.Hue);
|
|
893
906
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
|
|
894
907
|
}
|
|
895
908
|
// Saturation
|
|
@@ -897,7 +910,7 @@ export class StripLight {
|
|
|
897
910
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
898
911
|
} else {
|
|
899
912
|
this.accessory.context.Saturation = this.Saturation;
|
|
900
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
913
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Saturation, this.Saturation);
|
|
901
914
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
|
|
902
915
|
}
|
|
903
916
|
}
|
|
@@ -1049,10 +1062,10 @@ export class StripLight {
|
|
|
1049
1062
|
}
|
|
1050
1063
|
|
|
1051
1064
|
apiError(e: any): void {
|
|
1052
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
1053
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
1054
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
1055
|
-
this.lightBulbService.updateCharacteristic(this.
|
|
1065
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
1066
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Hue, e);
|
|
1067
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Brightness, e);
|
|
1068
|
+
this.lightBulbService.updateCharacteristic(this.hap.Characteristic.Saturation, e);
|
|
1056
1069
|
}
|
|
1057
1070
|
|
|
1058
1071
|
async context() {
|
|
@@ -1099,7 +1112,7 @@ export class StripLight {
|
|
|
1099
1112
|
}
|
|
1100
1113
|
}
|
|
1101
1114
|
|
|
1102
|
-
async
|
|
1115
|
+
async deviceConfig(device: device & devicesConfig): Promise<void> {
|
|
1103
1116
|
let config = {};
|
|
1104
1117
|
if (device.striplight) {
|
|
1105
1118
|
config = device.striplight;
|
|
@@ -1130,7 +1143,7 @@ export class StripLight {
|
|
|
1130
1143
|
}
|
|
1131
1144
|
}
|
|
1132
1145
|
|
|
1133
|
-
async
|
|
1146
|
+
async deviceLogs(device: device & devicesConfig): Promise<void> {
|
|
1134
1147
|
if (this.platform.debugMode) {
|
|
1135
1148
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
1136
1149
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|