@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/dist/devices/bots.js
CHANGED
|
@@ -19,6 +19,7 @@ class Bot {
|
|
|
19
19
|
this.scan();
|
|
20
20
|
this.refreshRate();
|
|
21
21
|
this.PressOrSwitch();
|
|
22
|
+
this.config(device);
|
|
22
23
|
if (this.On === undefined) {
|
|
23
24
|
this.On = false;
|
|
24
25
|
this.accessory.context.On = this.On;
|
|
@@ -35,9 +36,6 @@ class Bot {
|
|
|
35
36
|
}
|
|
36
37
|
this.BatteryLevel = 100;
|
|
37
38
|
this.StatusLowBattery = 0;
|
|
38
|
-
// Bot Config
|
|
39
|
-
this.debugLog(`Bot: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline}, mode: ${device.bot?.mode},`
|
|
40
|
-
+ ` deviceType: ${device.bot?.deviceType}, doublePress: ${this.doublePress})`);
|
|
41
39
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
42
40
|
this.doBotUpdate = new rxjs_1.Subject();
|
|
43
41
|
this.botUpdateInProgress = false;
|
|
@@ -52,10 +50,15 @@ class Bot {
|
|
|
52
50
|
// get the LightBulb service if it exists, otherwise create a new LightBulb service
|
|
53
51
|
// you can create multiple services for each accessory
|
|
54
52
|
if (device.bot?.deviceType === 'switch') {
|
|
53
|
+
this.removeFanService(accessory);
|
|
55
54
|
this.removeLockService(accessory);
|
|
56
55
|
this.removeDoorService(accessory);
|
|
56
|
+
this.removeFaucetService(accessory);
|
|
57
57
|
this.removeOutletService(accessory);
|
|
58
|
+
this.removeWindowService(accessory);
|
|
58
59
|
this.removeGarageDoorService(accessory);
|
|
60
|
+
this.removeWindowCoveringService(accessory);
|
|
61
|
+
this.removeStatefulProgrammableSwitchService(accessory);
|
|
59
62
|
// Add switchService
|
|
60
63
|
(this.switchService =
|
|
61
64
|
accessory.getService(this.platform.Service.Switch) ||
|
|
@@ -65,10 +68,15 @@ class Bot {
|
|
|
65
68
|
this.switchService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
|
|
66
69
|
}
|
|
67
70
|
else if (device.bot?.deviceType === 'garagedoor') {
|
|
71
|
+
this.removeFanService(accessory);
|
|
68
72
|
this.removeLockService(accessory);
|
|
69
73
|
this.removeDoorService(accessory);
|
|
74
|
+
this.removeFaucetService(accessory);
|
|
70
75
|
this.removeOutletService(accessory);
|
|
71
76
|
this.removeSwitchService(accessory);
|
|
77
|
+
this.removeWindowService(accessory);
|
|
78
|
+
this.removeWindowCoveringService(accessory);
|
|
79
|
+
this.removeStatefulProgrammableSwitchService(accessory);
|
|
72
80
|
// Add switchService
|
|
73
81
|
(this.garageDoorService =
|
|
74
82
|
accessory.getService(this.platform.Service.GarageDoorOpener) ||
|
|
@@ -79,10 +87,15 @@ class Bot {
|
|
|
79
87
|
this.garageDoorService.setCharacteristic(this.platform.Characteristic.ObstructionDetected, false);
|
|
80
88
|
}
|
|
81
89
|
else if (device.bot?.deviceType === 'door') {
|
|
90
|
+
this.removeFanService(accessory);
|
|
82
91
|
this.removeLockService(accessory);
|
|
83
92
|
this.removeOutletService(accessory);
|
|
93
|
+
this.removeFaucetService(accessory);
|
|
84
94
|
this.removeSwitchService(accessory);
|
|
95
|
+
this.removeWindowService(accessory);
|
|
85
96
|
this.removeGarageDoorService(accessory);
|
|
97
|
+
this.removeWindowCoveringService(accessory);
|
|
98
|
+
this.removeStatefulProgrammableSwitchService(accessory);
|
|
86
99
|
// Add switchService
|
|
87
100
|
(this.doorService =
|
|
88
101
|
accessory.getService(this.platform.Service.Door) ||
|
|
@@ -98,11 +111,66 @@ class Bot {
|
|
|
98
111
|
}).onSet(this.handleOnSet.bind(this));
|
|
99
112
|
this.doorService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
|
|
100
113
|
}
|
|
114
|
+
else if (device.bot?.deviceType === 'window') {
|
|
115
|
+
this.removeFanService(accessory);
|
|
116
|
+
this.removeLockService(accessory);
|
|
117
|
+
this.removeDoorService(accessory);
|
|
118
|
+
this.removeOutletService(accessory);
|
|
119
|
+
this.removeFaucetService(accessory);
|
|
120
|
+
this.removeSwitchService(accessory);
|
|
121
|
+
this.removeGarageDoorService(accessory);
|
|
122
|
+
this.removeWindowCoveringService(accessory);
|
|
123
|
+
this.removeStatefulProgrammableSwitchService(accessory);
|
|
124
|
+
// Add switchService
|
|
125
|
+
(this.windowService =
|
|
126
|
+
accessory.getService(this.platform.Service.Window) ||
|
|
127
|
+
accessory.addService(this.platform.Service.Window)), `${accessory.displayName} Window`;
|
|
128
|
+
this.infoLog(`Bot: ${accessory.displayName} Displaying as Window`);
|
|
129
|
+
this.windowService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
130
|
+
this.windowService.getCharacteristic(this.platform.Characteristic.TargetPosition)
|
|
131
|
+
.setProps({
|
|
132
|
+
validValues: [0, 100],
|
|
133
|
+
minValue: 0,
|
|
134
|
+
maxValue: 100,
|
|
135
|
+
minStep: 100,
|
|
136
|
+
}).onSet(this.handleOnSet.bind(this));
|
|
137
|
+
this.windowService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
|
|
138
|
+
}
|
|
139
|
+
else if (device.bot?.deviceType === 'windowcovering') {
|
|
140
|
+
this.removeFanService(accessory);
|
|
141
|
+
this.removeLockService(accessory);
|
|
142
|
+
this.removeDoorService(accessory);
|
|
143
|
+
this.removeOutletService(accessory);
|
|
144
|
+
this.removeFaucetService(accessory);
|
|
145
|
+
this.removeSwitchService(accessory);
|
|
146
|
+
this.removeWindowService(accessory);
|
|
147
|
+
this.removeGarageDoorService(accessory);
|
|
148
|
+
this.removeStatefulProgrammableSwitchService(accessory);
|
|
149
|
+
// Add switchService
|
|
150
|
+
(this.windowCoveringService =
|
|
151
|
+
accessory.getService(this.platform.Service.WindowCovering) ||
|
|
152
|
+
accessory.addService(this.platform.Service.WindowCovering)), `${accessory.displayName} Window Covering`;
|
|
153
|
+
this.infoLog(`Bot: ${accessory.displayName} Displaying as Window Covering`);
|
|
154
|
+
this.windowCoveringService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
155
|
+
this.windowCoveringService.getCharacteristic(this.platform.Characteristic.TargetPosition)
|
|
156
|
+
.setProps({
|
|
157
|
+
validValues: [0, 100],
|
|
158
|
+
minValue: 0,
|
|
159
|
+
maxValue: 100,
|
|
160
|
+
minStep: 100,
|
|
161
|
+
}).onSet(this.handleOnSet.bind(this));
|
|
162
|
+
this.windowCoveringService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
|
|
163
|
+
}
|
|
101
164
|
else if (device.bot?.deviceType === 'lock') {
|
|
165
|
+
this.removeFanService(accessory);
|
|
102
166
|
this.removeDoorService(accessory);
|
|
103
167
|
this.removeOutletService(accessory);
|
|
104
168
|
this.removeSwitchService(accessory);
|
|
169
|
+
this.removeFaucetService(accessory);
|
|
170
|
+
this.removeWindowService(accessory);
|
|
105
171
|
this.removeGarageDoorService(accessory);
|
|
172
|
+
this.removeWindowCoveringService(accessory);
|
|
173
|
+
this.removeStatefulProgrammableSwitchService(accessory);
|
|
106
174
|
// Add switchService
|
|
107
175
|
(this.lockService =
|
|
108
176
|
accessory.getService(this.platform.Service.LockMechanism) ||
|
|
@@ -111,11 +179,71 @@ class Bot {
|
|
|
111
179
|
this.lockService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
112
180
|
this.lockService.getCharacteristic(this.platform.Characteristic.LockTargetState).onSet(this.handleOnSet.bind(this));
|
|
113
181
|
}
|
|
182
|
+
else if (device.bot?.deviceType === 'faucet') {
|
|
183
|
+
this.removeFanService(accessory);
|
|
184
|
+
this.removeLockService(accessory);
|
|
185
|
+
this.removeDoorService(accessory);
|
|
186
|
+
this.removeOutletService(accessory);
|
|
187
|
+
this.removeSwitchService(accessory);
|
|
188
|
+
this.removeWindowService(accessory);
|
|
189
|
+
this.removeGarageDoorService(accessory);
|
|
190
|
+
this.removeWindowCoveringService(accessory);
|
|
191
|
+
this.removeStatefulProgrammableSwitchService(accessory);
|
|
192
|
+
// Add switchService
|
|
193
|
+
(this.faucetService =
|
|
194
|
+
accessory.getService(this.platform.Service.Faucet) ||
|
|
195
|
+
accessory.addService(this.platform.Service.Faucet)), `${accessory.displayName} Faucet`;
|
|
196
|
+
this.infoLog(`Bot: ${accessory.displayName} Displaying as Faucet`);
|
|
197
|
+
this.faucetService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
198
|
+
this.faucetService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.handleOnSet.bind(this));
|
|
199
|
+
}
|
|
200
|
+
else if (device.bot?.deviceType === 'fan') {
|
|
201
|
+
this.removeLockService(accessory);
|
|
202
|
+
this.removeDoorService(accessory);
|
|
203
|
+
this.removeFaucetService(accessory);
|
|
204
|
+
this.removeOutletService(accessory);
|
|
205
|
+
this.removeSwitchService(accessory);
|
|
206
|
+
this.removeWindowService(accessory);
|
|
207
|
+
this.removeGarageDoorService(accessory);
|
|
208
|
+
this.removeWindowCoveringService(accessory);
|
|
209
|
+
this.removeStatefulProgrammableSwitchService(accessory);
|
|
210
|
+
// Add switchService
|
|
211
|
+
(this.fanService =
|
|
212
|
+
accessory.getService(this.platform.Service.Fan) ||
|
|
213
|
+
accessory.addService(this.platform.Service.Fan)), `${accessory.displayName} Fan`;
|
|
214
|
+
this.infoLog(`Bot: ${accessory.displayName} Displaying as Fan`);
|
|
215
|
+
this.fanService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
216
|
+
this.fanService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
|
|
217
|
+
}
|
|
218
|
+
else if (device.bot?.deviceType === 'stateful') {
|
|
219
|
+
this.removeFanService(accessory);
|
|
220
|
+
this.removeLockService(accessory);
|
|
221
|
+
this.removeDoorService(accessory);
|
|
222
|
+
this.removeFaucetService(accessory);
|
|
223
|
+
this.removeOutletService(accessory);
|
|
224
|
+
this.removeSwitchService(accessory);
|
|
225
|
+
this.removeWindowService(accessory);
|
|
226
|
+
this.removeGarageDoorService(accessory);
|
|
227
|
+
this.removeWindowCoveringService(accessory);
|
|
228
|
+
// Add switchService
|
|
229
|
+
(this.statefulProgrammableSwitchService =
|
|
230
|
+
accessory.getService(this.platform.Service.StatefulProgrammableSwitch) ||
|
|
231
|
+
accessory.addService(this.platform.Service.StatefulProgrammableSwitch)), `${accessory.displayName} Stateful Programmable Switch`;
|
|
232
|
+
this.infoLog(`Bot: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
|
|
233
|
+
this.statefulProgrammableSwitchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
234
|
+
this.statefulProgrammableSwitchService.getCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState)
|
|
235
|
+
.onSet(this.handleOnSet.bind(this));
|
|
236
|
+
}
|
|
114
237
|
else {
|
|
238
|
+
this.removeFanService(accessory);
|
|
115
239
|
this.removeLockService(accessory);
|
|
116
240
|
this.removeDoorService(accessory);
|
|
241
|
+
this.removeFaucetService(accessory);
|
|
117
242
|
this.removeSwitchService(accessory);
|
|
243
|
+
this.removeWindowService(accessory);
|
|
118
244
|
this.removeGarageDoorService(accessory);
|
|
245
|
+
this.removeWindowCoveringService(accessory);
|
|
246
|
+
this.removeStatefulProgrammableSwitchService(accessory);
|
|
119
247
|
// Add outletService
|
|
120
248
|
(this.outletService =
|
|
121
249
|
accessory.getService(this.platform.Service.Outlet) ||
|
|
@@ -124,12 +252,22 @@ class Bot {
|
|
|
124
252
|
this.outletService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
125
253
|
this.outletService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
|
|
126
254
|
}
|
|
127
|
-
|
|
255
|
+
// Battery Service
|
|
256
|
+
if (!device.ble) {
|
|
257
|
+
this.debugLog(`Bot: ${accessory.displayName} Removing Battery Service`);
|
|
258
|
+
this.batteryService = this.accessory.getService(this.platform.Service.Battery);
|
|
259
|
+
accessory.removeService(this.batteryService);
|
|
260
|
+
}
|
|
261
|
+
else if (device.ble && !this.batteryService) {
|
|
262
|
+
this.debugLog(`Bot: ${accessory.displayName} Add Battery Service`);
|
|
128
263
|
(this.batteryService =
|
|
129
|
-
accessory.getService(this.platform.Service.Battery) ||
|
|
130
|
-
accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
|
|
264
|
+
this.accessory.getService(this.platform.Service.Battery) ||
|
|
265
|
+
this.accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
|
|
131
266
|
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
132
267
|
}
|
|
268
|
+
else {
|
|
269
|
+
this.debugLog(`Bot: ${accessory.displayName} Battery Service Not Added`);
|
|
270
|
+
}
|
|
133
271
|
// Retrieve initial values and updateHomekit
|
|
134
272
|
this.updateHomeKitCharacteristics();
|
|
135
273
|
// Start an update interval
|
|
@@ -166,6 +304,11 @@ class Bot {
|
|
|
166
304
|
this.botUpdateInProgress = false;
|
|
167
305
|
});
|
|
168
306
|
}
|
|
307
|
+
config(device) {
|
|
308
|
+
if (device.bot !== undefined || device.ble !== undefined) {
|
|
309
|
+
this.warnLog(`Bot: ${this.accessory.displayName} Config: ${JSON.stringify(device.bot)}, BLE: ${device.ble}`);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
169
312
|
removeOutletService(accessory) {
|
|
170
313
|
// If outletService still pressent, then remove first
|
|
171
314
|
this.outletService = this.accessory.getService(this.platform.Service.Outlet);
|
|
@@ -198,6 +341,46 @@ class Bot {
|
|
|
198
341
|
}
|
|
199
342
|
accessory.removeService(this.lockService);
|
|
200
343
|
}
|
|
344
|
+
removeFaucetService(accessory) {
|
|
345
|
+
// If faucetService still pressent, then remove first
|
|
346
|
+
this.faucetService = this.accessory.getService(this.platform.Service.Faucet);
|
|
347
|
+
if (this.faucetService) {
|
|
348
|
+
this.warnLog(`Bot: ${accessory.displayName} Removing Leftover Faucet Service`);
|
|
349
|
+
}
|
|
350
|
+
accessory.removeService(this.faucetService);
|
|
351
|
+
}
|
|
352
|
+
removeFanService(accessory) {
|
|
353
|
+
// If fanService still pressent, then remove first
|
|
354
|
+
this.fanService = this.accessory.getService(this.platform.Service.Fan);
|
|
355
|
+
if (this.fanService) {
|
|
356
|
+
this.warnLog(`Bot: ${accessory.displayName} Removing Leftover Fan Service`);
|
|
357
|
+
}
|
|
358
|
+
accessory.removeService(this.fanService);
|
|
359
|
+
}
|
|
360
|
+
removeWindowService(accessory) {
|
|
361
|
+
// If windowService still pressent, then remove first
|
|
362
|
+
this.windowService = this.accessory.getService(this.platform.Service.Window);
|
|
363
|
+
if (this.windowService) {
|
|
364
|
+
this.warnLog(`Bot: ${accessory.displayName} Removing Leftover Window Service`);
|
|
365
|
+
}
|
|
366
|
+
accessory.removeService(this.windowService);
|
|
367
|
+
}
|
|
368
|
+
removeWindowCoveringService(accessory) {
|
|
369
|
+
// If windowCoveringService still pressent, then remove first
|
|
370
|
+
this.windowCoveringService = this.accessory.getService(this.platform.Service.WindowCovering);
|
|
371
|
+
if (this.windowCoveringService) {
|
|
372
|
+
this.warnLog(`Bot: ${accessory.displayName} Removing Leftover Window Covering Service`);
|
|
373
|
+
}
|
|
374
|
+
accessory.removeService(this.windowCoveringService);
|
|
375
|
+
}
|
|
376
|
+
removeStatefulProgrammableSwitchService(accessory) {
|
|
377
|
+
// If statefulProgrammableSwitchService still pressent, then remove first
|
|
378
|
+
this.statefulProgrammableSwitchService = this.accessory.getService(this.platform.Service.StatefulProgrammableSwitch);
|
|
379
|
+
if (this.statefulProgrammableSwitchService) {
|
|
380
|
+
this.warnLog(`Bot: ${accessory.displayName} Removing Leftover Stateful Programmable Switch Service`);
|
|
381
|
+
}
|
|
382
|
+
accessory.removeService(this.statefulProgrammableSwitchService);
|
|
383
|
+
}
|
|
201
384
|
removeSwitchService(accessory) {
|
|
202
385
|
// If switchService still pressent, then remove first
|
|
203
386
|
this.switchService = this.accessory.getService(this.platform.Service.Switch);
|
|
@@ -209,13 +392,13 @@ class Bot {
|
|
|
209
392
|
refreshRate() {
|
|
210
393
|
if (this.device.refreshRate) {
|
|
211
394
|
this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
|
|
212
|
-
if (this.
|
|
395
|
+
if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
|
|
213
396
|
this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
214
397
|
}
|
|
215
398
|
}
|
|
216
399
|
else if (this.platform.config.options.refreshRate) {
|
|
217
400
|
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
218
|
-
if (this.
|
|
401
|
+
if (this.deviceLogging === 'debug') {
|
|
219
402
|
this.warnLog(`Bot: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
220
403
|
}
|
|
221
404
|
}
|
|
@@ -223,13 +406,13 @@ class Bot {
|
|
|
223
406
|
scan() {
|
|
224
407
|
if (this.device.scanDuration) {
|
|
225
408
|
this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
|
|
226
|
-
if (this.
|
|
409
|
+
if (this.device.ble && (this.deviceLogging === 'debug' || this.deviceLogging === 'standard')) {
|
|
227
410
|
this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
228
411
|
}
|
|
229
412
|
}
|
|
230
413
|
else {
|
|
231
414
|
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
232
|
-
if (this.
|
|
415
|
+
if (this.device.ble && this.deviceLogging === 'debug') {
|
|
233
416
|
this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
234
417
|
}
|
|
235
418
|
}
|
|
@@ -277,11 +460,11 @@ class Bot {
|
|
|
277
460
|
* Parse the device status from the SwitchBot api
|
|
278
461
|
*/
|
|
279
462
|
async parseStatus() {
|
|
280
|
-
if (this.device.ble) {
|
|
281
|
-
await this.
|
|
463
|
+
if (this.SwitchToOpenAPI || !this.device.ble) {
|
|
464
|
+
await this.openAPIparseStatus();
|
|
282
465
|
}
|
|
283
466
|
else {
|
|
284
|
-
await this.
|
|
467
|
+
await this.BLEparseStatus();
|
|
285
468
|
}
|
|
286
469
|
}
|
|
287
470
|
async BLEparseStatus() {
|
|
@@ -314,6 +497,9 @@ class Bot {
|
|
|
314
497
|
this.debugLog(`Bot: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
315
498
|
}
|
|
316
499
|
async openAPIparseStatus() {
|
|
500
|
+
if (this.device.ble) {
|
|
501
|
+
this.SwitchToOpenAPI = false;
|
|
502
|
+
}
|
|
317
503
|
if (this.platform.config.credentials?.openToken) {
|
|
318
504
|
this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
319
505
|
if (this.botMode === 'press') {
|
|
@@ -322,15 +508,19 @@ class Bot {
|
|
|
322
508
|
this.accessory.context.On = this.OnCached;
|
|
323
509
|
}
|
|
324
510
|
else {
|
|
325
|
-
if (this.
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
}
|
|
330
|
-
|
|
511
|
+
/*if (this.power === 'on') {
|
|
512
|
+
this.On = true;
|
|
513
|
+
this.OnCached = this.On;
|
|
514
|
+
this.accessory.context.On = this.OnCached;
|
|
515
|
+
} else {
|
|
516
|
+
this.On = false;
|
|
517
|
+
this.OnCached = this.On;
|
|
518
|
+
this.accessory.context.On = this.OnCached;
|
|
519
|
+
}*/
|
|
520
|
+
this.OnCached = this.On;
|
|
521
|
+
this.accessory.context.On = this.OnCached;
|
|
522
|
+
if (this.On === undefined) {
|
|
331
523
|
this.On = false;
|
|
332
|
-
this.OnCached = this.On;
|
|
333
|
-
this.accessory.context.On = this.OnCached;
|
|
334
524
|
}
|
|
335
525
|
}
|
|
336
526
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
@@ -347,34 +537,12 @@ class Bot {
|
|
|
347
537
|
await this.openAPIRefreshStatus();
|
|
348
538
|
}
|
|
349
539
|
}
|
|
350
|
-
async connectBLE() {
|
|
351
|
-
let switchbot;
|
|
352
|
-
try {
|
|
353
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
354
|
-
const Switchbot = require('node-switchbot');
|
|
355
|
-
switchbot = new Switchbot();
|
|
356
|
-
// Convert to BLE Address
|
|
357
|
-
this.device.bleMac = ((this.device.deviceId.match(/.{1,2}/g)).join(':')).toLowerCase();
|
|
358
|
-
this.debugLog(`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
359
|
-
}
|
|
360
|
-
catch (e) {
|
|
361
|
-
switchbot = false;
|
|
362
|
-
this.errorLog(`Bot: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot}`);
|
|
363
|
-
if (this.deviceLogging === 'debug') {
|
|
364
|
-
this.errorLog(`Bot: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
365
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
366
|
-
}
|
|
367
|
-
if (this.platform.debugMode) {
|
|
368
|
-
this.errorLog(`Bot: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
369
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
return switchbot;
|
|
373
|
-
}
|
|
374
540
|
async BLERefreshStatus() {
|
|
375
541
|
this.debugLog(`Bot: ${this.accessory.displayName} BLE refreshStatus`);
|
|
542
|
+
const switchbot = await this.platform.connectBLE();
|
|
376
543
|
// Convert to BLE Address
|
|
377
|
-
|
|
544
|
+
this.device.bleMac = ((this.device.deviceId.match(/.{1,2}/g)).join(':')).toLowerCase();
|
|
545
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
378
546
|
// Start to monitor advertisement packets
|
|
379
547
|
if (switchbot === false) {
|
|
380
548
|
this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection: ${switchbot}`);
|
|
@@ -414,6 +582,7 @@ class Bot {
|
|
|
414
582
|
this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
415
583
|
if (this.platform.config.credentials?.openToken) {
|
|
416
584
|
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
585
|
+
this.SwitchToOpenAPI = true;
|
|
417
586
|
await this.openAPIRefreshStatus();
|
|
418
587
|
}
|
|
419
588
|
}
|
|
@@ -429,6 +598,7 @@ class Bot {
|
|
|
429
598
|
}
|
|
430
599
|
if (this.platform.config.credentials?.openToken) {
|
|
431
600
|
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
601
|
+
this.SwitchToOpenAPI = true;
|
|
432
602
|
await this.openAPIRefreshStatus();
|
|
433
603
|
}
|
|
434
604
|
this.apiError(e);
|
|
@@ -440,6 +610,7 @@ class Bot {
|
|
|
440
610
|
try {
|
|
441
611
|
this.deviceStatus = (await this.platform.axios.get(`${settings_1.DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
442
612
|
this.debugLog(`Bot: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
613
|
+
this.power = this.deviceStatus.body.power;
|
|
443
614
|
this.parseStatus();
|
|
444
615
|
this.updateHomeKitCharacteristics();
|
|
445
616
|
}
|
|
@@ -482,7 +653,10 @@ class Bot {
|
|
|
482
653
|
this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges On: ${this.On} OnCached: ${this.OnCached}`);
|
|
483
654
|
if (this.On !== this.OnCached) {
|
|
484
655
|
this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges`);
|
|
485
|
-
const switchbot = await this.connectBLE();
|
|
656
|
+
const switchbot = await this.platform.connectBLE();
|
|
657
|
+
// Convert to BLE Address
|
|
658
|
+
this.device.bleMac = ((this.device.deviceId.match(/.{1,2}/g)).join(':')).toLowerCase();
|
|
659
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
486
660
|
//if (switchbot !== false) {
|
|
487
661
|
if (this.botMode === 'press') {
|
|
488
662
|
this.debugLog(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
|
|
@@ -662,6 +836,46 @@ class Bot {
|
|
|
662
836
|
}
|
|
663
837
|
this.debugLog(`Bot: ${this.accessory.displayName} Door On: ${this.On}`);
|
|
664
838
|
}
|
|
839
|
+
else if (this.device.bot?.deviceType === 'window') {
|
|
840
|
+
if (this.On === undefined) {
|
|
841
|
+
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
842
|
+
}
|
|
843
|
+
else {
|
|
844
|
+
if (this.On) {
|
|
845
|
+
this.windowService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 100);
|
|
846
|
+
this.windowService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 100);
|
|
847
|
+
this.windowService?.updateCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
|
|
848
|
+
this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
|
|
849
|
+
}
|
|
850
|
+
else {
|
|
851
|
+
this.windowService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 0);
|
|
852
|
+
this.windowService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 0);
|
|
853
|
+
this.windowService?.updateCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
|
|
854
|
+
this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Window On: ${this.On}`);
|
|
858
|
+
}
|
|
859
|
+
else if (this.device.bot?.deviceType === 'windowcovering') {
|
|
860
|
+
if (this.On === undefined) {
|
|
861
|
+
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
862
|
+
}
|
|
863
|
+
else {
|
|
864
|
+
if (this.On) {
|
|
865
|
+
this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 100);
|
|
866
|
+
this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 100);
|
|
867
|
+
this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
|
|
868
|
+
this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
|
|
869
|
+
}
|
|
870
|
+
else {
|
|
871
|
+
this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 0);
|
|
872
|
+
this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 0);
|
|
873
|
+
this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
|
|
874
|
+
this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Window Covering On: ${this.On}`);
|
|
878
|
+
}
|
|
665
879
|
else if (this.device.bot?.deviceType === 'lock') {
|
|
666
880
|
if (this.On === undefined) {
|
|
667
881
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
@@ -680,6 +894,56 @@ class Bot {
|
|
|
680
894
|
}
|
|
681
895
|
this.debugLog(`Bot: ${this.accessory.displayName} Lock On: ${this.On}`);
|
|
682
896
|
}
|
|
897
|
+
else if (this.device.bot?.deviceType === 'faucet') {
|
|
898
|
+
if (this.On === undefined) {
|
|
899
|
+
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
900
|
+
}
|
|
901
|
+
else {
|
|
902
|
+
if (this.On) {
|
|
903
|
+
this.faucetService?.updateCharacteristic(this.platform.Characteristic.Active, this.platform.Characteristic.Active.ACTIVE);
|
|
904
|
+
this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`);
|
|
905
|
+
}
|
|
906
|
+
else {
|
|
907
|
+
this.faucetService?.updateCharacteristic(this.platform.Characteristic.Active, this.platform.Characteristic.Active.INACTIVE);
|
|
908
|
+
this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`);
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Faucet On: ${this.On}`);
|
|
912
|
+
}
|
|
913
|
+
else if (this.device.bot?.deviceType === 'fan') {
|
|
914
|
+
if (this.On === undefined) {
|
|
915
|
+
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
916
|
+
}
|
|
917
|
+
else {
|
|
918
|
+
if (this.On) {
|
|
919
|
+
this.fanService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
920
|
+
this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
921
|
+
}
|
|
922
|
+
else {
|
|
923
|
+
this.fanService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
924
|
+
this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Fan On: ${this.On}`);
|
|
928
|
+
}
|
|
929
|
+
else if (this.device.bot?.deviceType === 'stateful') {
|
|
930
|
+
if (this.On === undefined) {
|
|
931
|
+
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
932
|
+
}
|
|
933
|
+
else {
|
|
934
|
+
if (this.On) {
|
|
935
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent, this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
936
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, 1);
|
|
937
|
+
this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1`);
|
|
938
|
+
}
|
|
939
|
+
else {
|
|
940
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent, this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
941
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, 0);
|
|
942
|
+
this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0`);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
this.debugLog(`Bot: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.On}`);
|
|
946
|
+
}
|
|
683
947
|
else if (this.device.bot?.deviceType === 'switch') {
|
|
684
948
|
if (this.On === undefined) {
|
|
685
949
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
@@ -726,10 +990,30 @@ class Bot {
|
|
|
726
990
|
this.doorService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, e);
|
|
727
991
|
this.doorService?.updateCharacteristic(this.platform.Characteristic.PositionState, e);
|
|
728
992
|
}
|
|
993
|
+
else if (this.device.bot?.deviceType === 'window') {
|
|
994
|
+
this.windowService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
|
|
995
|
+
this.windowService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, e);
|
|
996
|
+
this.windowService?.updateCharacteristic(this.platform.Characteristic.PositionState, e);
|
|
997
|
+
}
|
|
998
|
+
else if (this.device.bot?.deviceType === 'windowcovering') {
|
|
999
|
+
this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
|
|
1000
|
+
this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, e);
|
|
1001
|
+
this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.PositionState, e);
|
|
1002
|
+
}
|
|
729
1003
|
else if (this.device.bot?.deviceType === 'lock') {
|
|
730
1004
|
this.doorService?.updateCharacteristic(this.platform.Characteristic.LockTargetState, e);
|
|
731
1005
|
this.doorService?.updateCharacteristic(this.platform.Characteristic.LockCurrentState, e);
|
|
732
1006
|
}
|
|
1007
|
+
else if (this.device.bot?.deviceType === 'faucet') {
|
|
1008
|
+
this.faucetService?.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
1009
|
+
}
|
|
1010
|
+
else if (this.device.bot?.deviceType === 'fan') {
|
|
1011
|
+
this.fanService?.updateCharacteristic(this.platform.Characteristic.On, e);
|
|
1012
|
+
}
|
|
1013
|
+
else if (this.device.bot?.deviceType === 'stateful') {
|
|
1014
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent, e);
|
|
1015
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, e);
|
|
1016
|
+
}
|
|
733
1017
|
else if (this.device.bot?.deviceType === 'switch') {
|
|
734
1018
|
this.switchService?.updateCharacteristic(this.platform.Characteristic.On, e);
|
|
735
1019
|
}
|
|
@@ -796,7 +1080,9 @@ class Bot {
|
|
|
796
1080
|
this.On = true;
|
|
797
1081
|
}
|
|
798
1082
|
}
|
|
799
|
-
else if (this.device.bot?.deviceType === 'door'
|
|
1083
|
+
else if (this.device.bot?.deviceType === 'door'
|
|
1084
|
+
|| this.device.bot?.deviceType === 'window'
|
|
1085
|
+
|| this.device.bot?.deviceType === 'windowcovering') {
|
|
800
1086
|
this.debugLog(`Bot: ${this.accessory.displayName} TargetPosition: ${value}`);
|
|
801
1087
|
if (value === 0) {
|
|
802
1088
|
this.On = false;
|
|
@@ -814,6 +1100,24 @@ class Bot {
|
|
|
814
1100
|
this.On = true;
|
|
815
1101
|
}
|
|
816
1102
|
}
|
|
1103
|
+
else if (this.device.bot?.deviceType === 'faucet') {
|
|
1104
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Active: ${value}`);
|
|
1105
|
+
if (value === this.platform.Characteristic.Active.INACTIVE) {
|
|
1106
|
+
this.On = false;
|
|
1107
|
+
}
|
|
1108
|
+
else {
|
|
1109
|
+
this.On = true;
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
else if (this.device.bot?.deviceType === 'stateful') {
|
|
1113
|
+
this.debugLog(`Bot: ${this.accessory.displayName} ProgrammableSwitchOutputState: ${value}`);
|
|
1114
|
+
if (value === 0) {
|
|
1115
|
+
this.On = false;
|
|
1116
|
+
}
|
|
1117
|
+
else {
|
|
1118
|
+
this.On = true;
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
817
1121
|
else {
|
|
818
1122
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${value}`);
|
|
819
1123
|
this.On = value;
|