@switchbot/homebridge-switchbot 1.6.4-beta.5 → 1.7.1-beta.10
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/CHANGELOG.md +23 -2
- package/config.schema.json +125 -33
- package/dist/devices/bots.d.ts +21 -9
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +352 -48
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +6 -1
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +18 -11
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +10 -2
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +92 -51
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +10 -3
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +52 -34
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +8 -2
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +28 -35
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +14 -12
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +63 -103
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +10 -3
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +114 -68
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +3 -1
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +8 -1
- package/dist/devices/plugs.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +1 -0
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +6 -0
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +1 -0
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +6 -0
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +1 -0
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +6 -0
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +1 -0
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +6 -0
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +1 -0
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +6 -0
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +1 -0
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +6 -0
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +1 -0
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +6 -0
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +1 -0
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +6 -0
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +1 -0
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +6 -0
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +2 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +14 -1
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +14 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +5 -5
- package/src/devices/bots.ts +355 -52
- package/src/devices/colorbulb.ts +24 -14
- package/src/devices/contact.ts +99 -55
- package/src/devices/curtains.ts +60 -36
- package/src/devices/humidifiers.ts +36 -36
- package/src/devices/meters.ts +79 -113
- package/src/devices/motion.ts +125 -74
- package/src/devices/plugs.ts +11 -2
- package/src/irdevices/airconditioners.ts +7 -0
- package/src/irdevices/airpurifiers.ts +7 -0
- package/src/irdevices/cameras.ts +7 -0
- package/src/irdevices/fans.ts +7 -0
- package/src/irdevices/lights.ts +7 -0
- package/src/irdevices/others.ts +7 -0
- package/src/irdevices/tvs.ts +7 -0
- package/src/irdevices/vacuumcleaners.ts +7 -0
- package/src/irdevices/waterheaters.ts +7 -0
- package/src/platform.ts +14 -1
- package/src/settings.ts +15 -0
package/src/devices/motion.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { interval, Subject } from 'rxjs';
|
|
|
2
2
|
import { skipWhile } from 'rxjs/operators';
|
|
3
3
|
import { SwitchBotPlatform } from '../platform';
|
|
4
4
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
5
|
-
import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse } from '../settings';
|
|
5
|
+
import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse, deviceStatus } from '../settings';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Platform Accessory
|
|
@@ -17,22 +17,27 @@ export class Motion {
|
|
|
17
17
|
|
|
18
18
|
// Characteristic Values
|
|
19
19
|
MotionDetected!: CharacteristicValue;
|
|
20
|
+
CurrentAmbientLightLevel!: CharacteristicValue;
|
|
20
21
|
BatteryLevel?: CharacteristicValue;
|
|
21
22
|
StatusLowBattery?: CharacteristicValue;
|
|
22
|
-
CurrentAmbientLightLevel?: CharacteristicValue;
|
|
23
23
|
|
|
24
24
|
// OpenAPI Others
|
|
25
25
|
deviceStatus!: deviceStatusResponse;
|
|
26
|
+
moveDetected: deviceStatus['moveDetected'];
|
|
27
|
+
brightness: deviceStatus['brightness'];
|
|
26
28
|
|
|
27
29
|
// BLE Others
|
|
28
30
|
connected?: boolean;
|
|
29
31
|
switchbot!: switchbot;
|
|
32
|
+
SwitchToOpenAPI?: boolean;
|
|
30
33
|
serviceData!: serviceData;
|
|
31
34
|
battery!: serviceData['battery'];
|
|
32
35
|
movement!: serviceData['movement'];
|
|
33
36
|
lightLevel!: serviceData['lightLevel'];
|
|
34
37
|
|
|
35
38
|
// Config
|
|
39
|
+
set_minLux!: number;
|
|
40
|
+
set_maxLux!: number;
|
|
36
41
|
scanDuration!: number;
|
|
37
42
|
deviceLogging!: string;
|
|
38
43
|
deviceRefreshRate!: number;
|
|
@@ -50,8 +55,14 @@ export class Motion {
|
|
|
50
55
|
this.logs();
|
|
51
56
|
this.scan();
|
|
52
57
|
this.refreshRate();
|
|
58
|
+
this.config(device);
|
|
53
59
|
this.MotionDetected = false;
|
|
54
60
|
|
|
61
|
+
// Motion Config
|
|
62
|
+
this.debugLog(`Motion Sensor: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline},`
|
|
63
|
+
+ ` hide_lightsensor: ${device.motion?.hide_lightsensor},`
|
|
64
|
+
+ ` set_minLux: ${this.device.motion?.set_minLux}, set_maxLux: ${this.device.motion?.set_maxLux})`);
|
|
65
|
+
|
|
55
66
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
56
67
|
this.doMotionUpdate = new Subject();
|
|
57
68
|
this.motionUbpdateInProgress = false;
|
|
@@ -72,21 +83,6 @@ export class Motion {
|
|
|
72
83
|
accessory.getService(this.platform.Service.MotionSensor) ||
|
|
73
84
|
accessory.addService(this.platform.Service.MotionSensor)), `${accessory.displayName} Motion Sensor`;
|
|
74
85
|
|
|
75
|
-
if (device.ble) {
|
|
76
|
-
(this.lightSensorService =
|
|
77
|
-
accessory.getService(this.platform.Service.LightSensor) ||
|
|
78
|
-
accessory.addService(this.platform.Service.LightSensor)), `${accessory.displayName} Light Sensor`;
|
|
79
|
-
|
|
80
|
-
this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
(this.batteryService =
|
|
84
|
-
accessory.getService(this.platform.Service.Battery) ||
|
|
85
|
-
accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
|
|
86
|
-
|
|
87
|
-
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
86
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
91
87
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
92
88
|
// accessory.getService('NAME') ?? accessory.addService(this.platform.Service.Motion, 'NAME', 'USER_DEFINED_SUBTYPE');
|
|
@@ -98,8 +94,39 @@ export class Motion {
|
|
|
98
94
|
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
99
95
|
// see https://developers.homebridge.io/#/service/MotionSensor
|
|
100
96
|
|
|
101
|
-
//
|
|
102
|
-
|
|
97
|
+
// Light Sensor Service
|
|
98
|
+
if (device.motion?.hide_lightsensor) {
|
|
99
|
+
this.debugLog(`Motion Sensor: ${accessory.displayName} Removing Light Sensor Service`);
|
|
100
|
+
this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor);
|
|
101
|
+
accessory.removeService(this.lightSensorService!);
|
|
102
|
+
} else if (!this.lightSensorService) {
|
|
103
|
+
this.debugLog(`Motion Sensor: ${accessory.displayName} Add Light Sensor Service`);
|
|
104
|
+
(this.lightSensorService =
|
|
105
|
+
this.accessory.getService(this.platform.Service.LightSensor) ||
|
|
106
|
+
this.accessory.addService(this.platform.Service.LightSensor)), `${accessory.displayName} Light Sensor`;
|
|
107
|
+
|
|
108
|
+
this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
|
|
109
|
+
|
|
110
|
+
} else {
|
|
111
|
+
this.debugLog(`Motion Sensor: ${accessory.displayName} Light Sensor Service Not Added`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Battery Service
|
|
115
|
+
if (!device.ble) {
|
|
116
|
+
this.debugLog(`Motion Sensor: ${accessory.displayName} Removing Battery Service`);
|
|
117
|
+
this.batteryService = this.accessory.getService(this.platform.Service.Battery);
|
|
118
|
+
accessory.removeService(this.batteryService!);
|
|
119
|
+
} else if (device.ble && !this.batteryService) {
|
|
120
|
+
this.debugLog(`Motion Sensor: ${accessory.displayName} Add Battery Service`);
|
|
121
|
+
(this.batteryService =
|
|
122
|
+
this.accessory.getService(this.platform.Service.Battery) ||
|
|
123
|
+
this.accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
|
|
124
|
+
|
|
125
|
+
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
126
|
+
|
|
127
|
+
} else {
|
|
128
|
+
this.debugLog(`Motion Sensor: ${accessory.displayName} Battery Service Not Added`);
|
|
129
|
+
}
|
|
103
130
|
|
|
104
131
|
// Retrieve initial values and updateHomekit
|
|
105
132
|
this.updateHomeKitCharacteristics();
|
|
@@ -112,6 +139,12 @@ export class Motion {
|
|
|
112
139
|
});
|
|
113
140
|
}
|
|
114
141
|
|
|
142
|
+
config(device: device & devicesConfig) {
|
|
143
|
+
if (device.motion !== undefined) {
|
|
144
|
+
this.warnLog(`Motion Sensor: ${this.accessory.displayName} Config: ${JSON.stringify(device.motion)}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
115
148
|
refreshRate() {
|
|
116
149
|
if (this.device.refreshRate) {
|
|
117
150
|
this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
|
|
@@ -159,59 +192,92 @@ export class Motion {
|
|
|
159
192
|
}
|
|
160
193
|
}
|
|
161
194
|
|
|
195
|
+
private minLux(): number {
|
|
196
|
+
if (this.device.motion?.set_minLux) {
|
|
197
|
+
this.set_minLux = this.device.motion!.set_minLux!;
|
|
198
|
+
} else {
|
|
199
|
+
this.set_minLux = 1;
|
|
200
|
+
}
|
|
201
|
+
return this.set_minLux;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
private maxLux(): number {
|
|
205
|
+
if (this.device.motion?.set_maxLux) {
|
|
206
|
+
this.set_maxLux = this.device.motion!.set_maxLux!;
|
|
207
|
+
} else {
|
|
208
|
+
this.set_maxLux = 6001;
|
|
209
|
+
}
|
|
210
|
+
return this.set_maxLux;
|
|
211
|
+
}
|
|
212
|
+
|
|
162
213
|
/**
|
|
163
214
|
* Parse the device status from the SwitchBot api
|
|
164
215
|
*/
|
|
165
216
|
async parseStatus() {
|
|
166
|
-
if (this.device.ble) {
|
|
167
|
-
await this.BLEparseStatus();
|
|
168
|
-
} else {
|
|
217
|
+
if (this.SwitchToOpenAPI || !this.device.ble) {
|
|
169
218
|
await this.openAPIparseStatus();
|
|
219
|
+
} else {
|
|
220
|
+
await this.BLEparseStatus();
|
|
170
221
|
}
|
|
171
222
|
}
|
|
172
223
|
|
|
173
224
|
private async BLEparseStatus() {
|
|
174
225
|
this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE parseStatus`);
|
|
175
|
-
|
|
226
|
+
// Movement
|
|
227
|
+
this.MotionDetected = this.movement!;
|
|
176
228
|
this.debugLog(`Motion Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
177
229
|
// Light Level
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
230
|
+
if (!this.device.motion?.hide_lightsensor) {
|
|
231
|
+
this.set_minLux = this.minLux();
|
|
232
|
+
this.set_maxLux = this.maxLux();
|
|
233
|
+
switch (this.lightLevel) {
|
|
234
|
+
case 'dark':
|
|
235
|
+
case 1:
|
|
236
|
+
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
237
|
+
break;
|
|
238
|
+
default:
|
|
239
|
+
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
240
|
+
}
|
|
241
|
+
this.debugLog(`Motion Sensor: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
|
|
242
|
+
+ ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
185
243
|
}
|
|
186
244
|
// Battery
|
|
187
|
-
|
|
245
|
+
if (this.battery === undefined) {
|
|
246
|
+
this.battery = 100;
|
|
247
|
+
}
|
|
248
|
+
this.BatteryLevel = this.battery!;
|
|
188
249
|
if (this.BatteryLevel < 10) {
|
|
189
250
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
190
251
|
} else {
|
|
191
252
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
192
253
|
}
|
|
254
|
+
this.debugLog(`Motion Sensor: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
|
|
193
255
|
}
|
|
194
256
|
|
|
195
257
|
private async openAPIparseStatus() {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
258
|
+
if (this.device.ble) {
|
|
259
|
+
this.SwitchToOpenAPI = false;
|
|
260
|
+
}
|
|
261
|
+
if (this.platform.config.credentials?.openToken) {
|
|
262
|
+
this.debugLog(`Motion Sensor: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
263
|
+
// Motion State
|
|
264
|
+
this.MotionDetected = this.moveDetected!;
|
|
265
|
+
this.debugLog(`Motion Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
266
|
+
// Light Level
|
|
267
|
+
if (!this.device.motion?.hide_lightsensor) {
|
|
268
|
+
this.set_minLux = this.minLux();
|
|
269
|
+
this.set_maxLux = this.maxLux();
|
|
270
|
+
switch (this.brightness) {
|
|
271
|
+
case 'dim':
|
|
272
|
+
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
273
|
+
break;
|
|
274
|
+
case 'bright':
|
|
275
|
+
default:
|
|
276
|
+
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
201
277
|
}
|
|
202
|
-
this.debugLog(`Motion Sensor: ${this.accessory.displayName}
|
|
203
|
-
|
|
204
|
-
} catch (e: any) {
|
|
205
|
-
this.errorLog(`Motion Sensor: ${this.accessory.displayName} failed parseStatus with OpenAPI Connection`);
|
|
206
|
-
if (this.deviceLogging === 'debug') {
|
|
207
|
-
this.errorLog(`Motion Sensor: ${this.accessory.displayName} failed parseStatus with OpenAPI Connection,`
|
|
208
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
209
|
-
}
|
|
210
|
-
if (this.platform.debugMode) {
|
|
211
|
-
this.errorLog(`Motion Sensor: ${this.accessory.displayName} failed parseStatus with OpenAPI Connection,`
|
|
212
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
278
|
+
this.debugLog(`Motion Sensor: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
279
|
+
|
|
213
280
|
}
|
|
214
|
-
this.apiError(e);
|
|
215
281
|
}
|
|
216
282
|
}
|
|
217
283
|
|
|
@@ -226,34 +292,12 @@ export class Motion {
|
|
|
226
292
|
}
|
|
227
293
|
}
|
|
228
294
|
|
|
229
|
-
public async connectBLE() {
|
|
230
|
-
let switchbot: any;
|
|
231
|
-
try {
|
|
232
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
233
|
-
const Switchbot = require('node-switchbot');
|
|
234
|
-
switchbot = new Switchbot();
|
|
235
|
-
// Convert to BLE Address
|
|
236
|
-
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
237
|
-
this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
238
|
-
} catch (e: any) {
|
|
239
|
-
switchbot = false;
|
|
240
|
-
this.errorLog(`Motion Sensor: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot}`);
|
|
241
|
-
if (this.deviceLogging === 'debug') {
|
|
242
|
-
this.errorLog(`Motion Sensor: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
243
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
244
|
-
}
|
|
245
|
-
if (this.platform.debugMode) {
|
|
246
|
-
this.errorLog(`Motion Sensor: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
247
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return switchbot;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
295
|
private async BLERefreshStatus() {
|
|
254
296
|
this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE RefreshStatus`);
|
|
255
|
-
|
|
256
|
-
|
|
297
|
+
const switchbot = await this.platform.connectBLE();
|
|
298
|
+
// Convert to BLE Address
|
|
299
|
+
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
300
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
257
301
|
// Start to monitor advertisement packets
|
|
258
302
|
if (switchbot !== false) {
|
|
259
303
|
switchbot.startScan({
|
|
@@ -301,6 +345,7 @@ export class Motion {
|
|
|
301
345
|
}
|
|
302
346
|
if (this.platform.config.credentials?.openToken) {
|
|
303
347
|
this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
348
|
+
this.SwitchToOpenAPI = true;
|
|
304
349
|
await this.openAPIRefreshStatus();
|
|
305
350
|
}
|
|
306
351
|
this.apiError(e);
|
|
@@ -314,6 +359,7 @@ export class Motion {
|
|
|
314
359
|
this.errorLog(`Motion Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
315
360
|
if (this.platform.config.credentials?.openToken) {
|
|
316
361
|
this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
362
|
+
this.SwitchToOpenAPI = true;
|
|
317
363
|
await this.openAPIRefreshStatus();
|
|
318
364
|
}
|
|
319
365
|
}
|
|
@@ -324,6 +370,11 @@ export class Motion {
|
|
|
324
370
|
try {
|
|
325
371
|
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
326
372
|
this.debugLog(`Motion Sensor: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
373
|
+
if (this.deviceStatus.body.moveDetected === undefined) {
|
|
374
|
+
this.errorLog(`Motion Sensor: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
375
|
+
}
|
|
376
|
+
this.moveDetected = this.deviceStatus.body.moveDetected;
|
|
377
|
+
this.brightness = this.deviceStatus.body.brightness;
|
|
327
378
|
this.parseStatus();
|
|
328
379
|
this.updateHomeKitCharacteristics();
|
|
329
380
|
} catch (e: any) {
|
package/src/devices/plugs.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { interval, Subject } from 'rxjs';
|
|
|
4
4
|
import { SwitchBotPlatform } from '../platform';
|
|
5
5
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
6
6
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
7
|
-
import { DeviceURL, device, devicesConfig, deviceStatusResponse, payload } from '../settings';
|
|
7
|
+
import { DeviceURL, device, devicesConfig, deviceStatusResponse, payload, deviceStatus } from '../settings';
|
|
8
8
|
|
|
9
9
|
export class Plug {
|
|
10
10
|
// Services
|
|
@@ -15,6 +15,7 @@ export class Plug {
|
|
|
15
15
|
OnCached!: CharacteristicValue;
|
|
16
16
|
|
|
17
17
|
// OpenAPI Others
|
|
18
|
+
power: deviceStatus['power'];
|
|
18
19
|
deviceStatus!: deviceStatusResponse;
|
|
19
20
|
|
|
20
21
|
// Config
|
|
@@ -35,6 +36,7 @@ export class Plug {
|
|
|
35
36
|
this.logs();
|
|
36
37
|
this.scan();
|
|
37
38
|
this.refreshRate();
|
|
39
|
+
this.config(device);
|
|
38
40
|
if (this.On === undefined) {
|
|
39
41
|
this.On = false;
|
|
40
42
|
} else {
|
|
@@ -116,6 +118,12 @@ export class Plug {
|
|
|
116
118
|
});
|
|
117
119
|
}
|
|
118
120
|
|
|
121
|
+
config(device: device & devicesConfig) {
|
|
122
|
+
if (device.plug !== undefined) {
|
|
123
|
+
this.warnLog(`Plug: ${this.accessory.displayName} Config: ${JSON.stringify(device.plug)}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
119
127
|
refreshRate() {
|
|
120
128
|
if (this.device.refreshRate) {
|
|
121
129
|
this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
|
|
@@ -164,7 +172,7 @@ export class Plug {
|
|
|
164
172
|
}
|
|
165
173
|
|
|
166
174
|
parseStatus() {
|
|
167
|
-
switch (this.
|
|
175
|
+
switch (this.power) {
|
|
168
176
|
case 'on':
|
|
169
177
|
this.On = true;
|
|
170
178
|
break;
|
|
@@ -178,6 +186,7 @@ export class Plug {
|
|
|
178
186
|
try {
|
|
179
187
|
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
180
188
|
this.debugLog(`Plug: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
189
|
+
this.power = this.deviceStatus.body.power;
|
|
181
190
|
this.parseStatus();
|
|
182
191
|
this.updateHomeKitCharacteristics();
|
|
183
192
|
} catch (e: any) {
|
|
@@ -50,6 +50,7 @@ export class AirConditioner {
|
|
|
50
50
|
) {
|
|
51
51
|
// default placeholders
|
|
52
52
|
this.logs();
|
|
53
|
+
this.config(device);
|
|
53
54
|
if (this.Active === undefined) {
|
|
54
55
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
55
56
|
} else {
|
|
@@ -166,6 +167,12 @@ export class AirConditioner {
|
|
|
166
167
|
.onSet(this.RotationSpeedSet.bind(this));
|
|
167
168
|
}
|
|
168
169
|
|
|
170
|
+
config(device: irdevice & irDevicesConfig) {
|
|
171
|
+
if (device.irair !== undefined) {
|
|
172
|
+
this.warnLog(`Air Conditioner: ${this.accessory.displayName} Config: ${JSON.stringify(device.irair)}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
169
176
|
logs() {
|
|
170
177
|
if (this.platform.debugMode) {
|
|
171
178
|
this.deviceLogging = this.accessory.context.logging = 'debug';
|
|
@@ -45,6 +45,7 @@ export class AirPurifier {
|
|
|
45
45
|
) {
|
|
46
46
|
// default placeholders
|
|
47
47
|
this.logs();
|
|
48
|
+
this.config(device);
|
|
48
49
|
if (this.Active === undefined) {
|
|
49
50
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
50
51
|
} else {
|
|
@@ -87,6 +88,12 @@ export class AirPurifier {
|
|
|
87
88
|
this.service.getCharacteristic(this.platform.Characteristic.TargetAirPurifierState).onSet(this.TargetAirPurifierStateSet.bind(this));
|
|
88
89
|
}
|
|
89
90
|
|
|
91
|
+
config(device: irdevice & irDevicesConfig) {
|
|
92
|
+
if (device.irpur !== undefined) {
|
|
93
|
+
this.warnLog(`Air Purifier: ${this.accessory.displayName} Config: ${JSON.stringify(device.irpur)}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
90
97
|
logs() {
|
|
91
98
|
if (this.platform.debugMode) {
|
|
92
99
|
this.deviceLogging = this.accessory.context.logging = 'debug';
|
package/src/irdevices/cameras.ts
CHANGED
|
@@ -26,6 +26,7 @@ export class Camera {
|
|
|
26
26
|
) {
|
|
27
27
|
// default placeholders
|
|
28
28
|
this.logs();
|
|
29
|
+
this.config(device);
|
|
29
30
|
if (this.On === undefined) {
|
|
30
31
|
this.On = false;
|
|
31
32
|
} else {
|
|
@@ -57,6 +58,12 @@ export class Camera {
|
|
|
57
58
|
this.service.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
58
59
|
}
|
|
59
60
|
|
|
61
|
+
config(device: irdevice & irDevicesConfig) {
|
|
62
|
+
if (device.ircam !== undefined && (this.deviceLogging === 'debug' || this.deviceLogging === 'standard')) {
|
|
63
|
+
this.warnLog(`Camera: ${this.accessory.displayName} Config: ${JSON.stringify(device.ircam)}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
60
67
|
logs() {
|
|
61
68
|
if (this.platform.debugMode) {
|
|
62
69
|
this.deviceLogging = this.accessory.context.logging = 'debug';
|
package/src/irdevices/fans.ts
CHANGED
|
@@ -36,6 +36,7 @@ export class Fan {
|
|
|
36
36
|
) {
|
|
37
37
|
// default placeholders
|
|
38
38
|
this.logs();
|
|
39
|
+
this.config(device);
|
|
39
40
|
if (this.Active === undefined) {
|
|
40
41
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
41
42
|
} else {
|
|
@@ -116,6 +117,12 @@ export class Fan {
|
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
119
|
|
|
120
|
+
config(device: irdevice & irDevicesConfig) {
|
|
121
|
+
if (device.irfan !== undefined && (this.deviceLogging === 'debug' || this.deviceLogging === 'standard')) {
|
|
122
|
+
this.warnLog(`Fan: ${this.accessory.displayName} Config: ${JSON.stringify(device.irfan)}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
119
126
|
logs() {
|
|
120
127
|
if (this.platform.debugMode) {
|
|
121
128
|
this.deviceLogging = this.accessory.context.logging = 'debug';
|
package/src/irdevices/lights.ts
CHANGED
|
@@ -26,6 +26,7 @@ export class Light {
|
|
|
26
26
|
) {
|
|
27
27
|
// default placeholders
|
|
28
28
|
this.logs();
|
|
29
|
+
this.config(device);
|
|
29
30
|
if (this.On === undefined) {
|
|
30
31
|
this.On = false;
|
|
31
32
|
} else {
|
|
@@ -72,6 +73,12 @@ export class Light {
|
|
|
72
73
|
});*/
|
|
73
74
|
}
|
|
74
75
|
|
|
76
|
+
config(device: irdevice & irDevicesConfig) {
|
|
77
|
+
if (device.irlight !== undefined) {
|
|
78
|
+
this.warnLog(`Light: ${this.accessory.displayName} Config: ${JSON.stringify(device.irlight)}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
75
82
|
logs() {
|
|
76
83
|
if (this.platform.debugMode) {
|
|
77
84
|
this.deviceLogging = this.accessory.context.logging = 'debug';
|
package/src/irdevices/others.ts
CHANGED
|
@@ -28,6 +28,7 @@ export class Others {
|
|
|
28
28
|
// default placeholders
|
|
29
29
|
this.logs();
|
|
30
30
|
this.deviceType();
|
|
31
|
+
this.config(device);
|
|
31
32
|
if (this.Active === undefined) {
|
|
32
33
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
33
34
|
} else {
|
|
@@ -76,6 +77,12 @@ export class Others {
|
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
|
|
80
|
+
config(device: irdevice & irDevicesConfig) {
|
|
81
|
+
if (device.other !== undefined) {
|
|
82
|
+
this.warnLog(`Other: ${this.accessory.displayName} Config: ${JSON.stringify(device.other)}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
79
86
|
logs() {
|
|
80
87
|
if (this.platform.debugMode) {
|
|
81
88
|
this.deviceLogging = this.accessory.context.logging = 'debug';
|
package/src/irdevices/tvs.ts
CHANGED
|
@@ -31,6 +31,7 @@ export class TV {
|
|
|
31
31
|
) {
|
|
32
32
|
// default placeholders
|
|
33
33
|
this.logs();
|
|
34
|
+
this.config(device);
|
|
34
35
|
if (this.Active === undefined) {
|
|
35
36
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
36
37
|
} else {
|
|
@@ -128,6 +129,12 @@ export class TV {
|
|
|
128
129
|
.onSet(this.VolumeSelectorSet.bind(this));
|
|
129
130
|
}
|
|
130
131
|
|
|
132
|
+
config(device: irdevice & irDevicesConfig) {
|
|
133
|
+
if (device.irtv !== undefined) {
|
|
134
|
+
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(device.irtv)}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
131
138
|
logs() {
|
|
132
139
|
if (this.platform.debugMode) {
|
|
133
140
|
this.deviceLogging = this.accessory.context.logging = 'debug';
|
|
@@ -26,6 +26,7 @@ export class VacuumCleaner {
|
|
|
26
26
|
) {
|
|
27
27
|
// default placeholders
|
|
28
28
|
this.logs();
|
|
29
|
+
this.config(device);
|
|
29
30
|
if (this.On === undefined) {
|
|
30
31
|
this.On = false;
|
|
31
32
|
} else {
|
|
@@ -57,6 +58,12 @@ export class VacuumCleaner {
|
|
|
57
58
|
this.service.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
58
59
|
}
|
|
59
60
|
|
|
61
|
+
config(device: irdevice & irDevicesConfig) {
|
|
62
|
+
if (device.irvc !== undefined) {
|
|
63
|
+
this.warnLog(`Vacuum Cleaner: ${this.accessory.displayName} Config: ${JSON.stringify(device.irvc)}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
60
67
|
logs() {
|
|
61
68
|
if (this.platform.debugMode) {
|
|
62
69
|
this.deviceLogging = this.accessory.context.logging = 'debug';
|
|
@@ -26,6 +26,7 @@ export class WaterHeater {
|
|
|
26
26
|
) {
|
|
27
27
|
// default placeholders
|
|
28
28
|
this.logs();
|
|
29
|
+
this.config(device);
|
|
29
30
|
if (this.Active === undefined) {
|
|
30
31
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
31
32
|
} else {
|
|
@@ -66,6 +67,12 @@ export class WaterHeater {
|
|
|
66
67
|
this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
67
68
|
}
|
|
68
69
|
|
|
70
|
+
config(device: irdevice & irDevicesConfig) {
|
|
71
|
+
if (device.irwh !== undefined) {
|
|
72
|
+
this.warnLog(`Water Heater: ${this.accessory.displayName} Config: ${JSON.stringify(device.irwh)}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
69
76
|
logs() {
|
|
70
77
|
if (this.platform.debugMode) {
|
|
71
78
|
this.deviceLogging = this.accessory.context.logging = 'debug';
|
package/src/platform.ts
CHANGED
|
@@ -192,8 +192,21 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
connectBLE() {
|
|
196
|
+
let Switchbot: new () => any;
|
|
197
|
+
let switchbot: any;
|
|
198
|
+
try {
|
|
199
|
+
Switchbot = require('node-switchbot');
|
|
200
|
+
switchbot = new Switchbot();
|
|
201
|
+
} catch (e) {
|
|
202
|
+
switchbot = false;
|
|
203
|
+
this.errorLog(`Was 'node-switchbot' found: ${switchbot}`);
|
|
204
|
+
}
|
|
205
|
+
return switchbot;
|
|
206
|
+
}
|
|
207
|
+
|
|
195
208
|
/**
|
|
196
|
-
* this method discovers
|
|
209
|
+
* this method discovers devices
|
|
197
210
|
*/
|
|
198
211
|
async discoverDevices() {
|
|
199
212
|
try {
|
package/src/settings.ts
CHANGED
|
@@ -48,7 +48,9 @@ export interface devicesConfig extends device {
|
|
|
48
48
|
humidifier?: humidifier;
|
|
49
49
|
curtain?: curtain;
|
|
50
50
|
contact?: contact;
|
|
51
|
+
motion?: motion;
|
|
51
52
|
colorbulb?: colorbulb;
|
|
53
|
+
plug?: undefined;
|
|
52
54
|
ble?: string;
|
|
53
55
|
scanDuration?: number;
|
|
54
56
|
hide_device?: boolean;
|
|
@@ -84,9 +86,17 @@ export type curtain = {
|
|
|
84
86
|
|
|
85
87
|
export type contact = {
|
|
86
88
|
hide_lightsensor?: boolean;
|
|
89
|
+
set_minLux?: number;
|
|
90
|
+
set_maxLux?: number;
|
|
87
91
|
hide_motionsensor?: boolean;
|
|
88
92
|
};
|
|
89
93
|
|
|
94
|
+
export type motion = {
|
|
95
|
+
hide_lightsensor?: boolean;
|
|
96
|
+
set_minLux?: number;
|
|
97
|
+
set_maxLux?: number;
|
|
98
|
+
};
|
|
99
|
+
|
|
90
100
|
export type colorbulb = {
|
|
91
101
|
set_minStep?: number;
|
|
92
102
|
adaptiveLightingShift?: number;
|
|
@@ -98,6 +108,11 @@ export interface irDevicesConfig extends irdevice {
|
|
|
98
108
|
logging?: string;
|
|
99
109
|
irfan?: irfan;
|
|
100
110
|
irair?: irair;
|
|
111
|
+
irpur?: undefined;
|
|
112
|
+
ircam?: undefined;
|
|
113
|
+
irlight?: undefined;
|
|
114
|
+
irvc?: undefined;
|
|
115
|
+
irwh?: undefined;
|
|
101
116
|
irtv?: irtv;
|
|
102
117
|
other?: other;
|
|
103
118
|
hide_device?: boolean;
|