@switchbot/homebridge-switchbot 1.8.2 → 1.8.3-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/.eslintrc +1 -1
- package/.vscode/extensions.json +5 -0
- package/.vscode/settings.json +15 -0
- package/dist/devices/bots.d.ts +34 -35
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +241 -184
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +50 -50
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +145 -131
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +27 -29
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +138 -115
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +29 -31
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +211 -176
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +33 -33
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +214 -189
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +30 -31
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +124 -100
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +25 -26
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +120 -102
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +23 -23
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +81 -63
- package/dist/devices/plugs.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -3
- package/dist/index.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +6 -6
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +105 -79
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +5 -5
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +56 -42
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +5 -5
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +31 -27
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +5 -5
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +45 -38
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +5 -5
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +37 -33
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +5 -5
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +34 -29
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +5 -5
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +91 -76
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +5 -5
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +31 -27
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +5 -5
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +31 -27
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +12 -12
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +241 -172
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +4 -4
- package/dist/settings.js.map +1 -1
- package/package.json +72 -71
- package/src/devices/bots.ts +927 -442
- package/src/devices/colorbulb.ts +473 -246
- package/src/devices/contact.ts +381 -208
- package/src/devices/curtains.ts +613 -321
- package/src/devices/humidifiers.ts +594 -323
- package/src/devices/meters.ts +331 -186
- package/src/devices/motion.ts +327 -184
- package/src/devices/plugs.ts +175 -107
- package/src/index.ts +5 -5
- package/src/irdevices/airconditioners.ts +360 -149
- package/src/irdevices/airpurifiers.ts +178 -80
- package/src/irdevices/cameras.ts +109 -51
- package/src/irdevices/fans.ts +174 -77
- package/src/irdevices/lights.ts +110 -57
- package/src/irdevices/others.ts +137 -62
- package/src/irdevices/tvs.ts +249 -124
- package/src/irdevices/vacuumcleaners.ts +112 -52
- package/src/irdevices/waterheaters.ts +115 -53
- package/src/platform.ts +768 -357
- package/src/settings.ts +17 -23
package/src/devices/bots.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { DeviceURL, device, devicesConfig, serviceData, ad, switchbot, deviceStatusResponse, payload, deviceStatus } from '../settings';
|
|
1
|
+
import * as axios from "axios";
|
|
2
|
+
import * as homebridge from "homebridge";
|
|
3
|
+
import * as rxjs from "rxjs";
|
|
4
|
+
import * as operators from "rxjs/operators";
|
|
5
|
+
import * as platform from "../platform";
|
|
6
|
+
import * as settings from "../settings";
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Platform Accessory
|
|
@@ -13,37 +12,35 @@ import { DeviceURL, device, devicesConfig, serviceData, ad, switchbot, deviceSta
|
|
|
13
12
|
*/
|
|
14
13
|
export class Bot {
|
|
15
14
|
// Services
|
|
16
|
-
private fanService?: Service;
|
|
17
|
-
private doorService?: Service;
|
|
18
|
-
private lockService?: Service;
|
|
19
|
-
private faucetService?: Service;
|
|
20
|
-
private windowService?: Service;
|
|
21
|
-
private switchService?: Service;
|
|
22
|
-
private outletService?: Service;
|
|
23
|
-
private batteryService?: Service;
|
|
24
|
-
private garageDoorService?: Service;
|
|
25
|
-
private windowCoveringService?: Service;
|
|
26
|
-
private statefulProgrammableSwitchService?: Service;
|
|
27
|
-
|
|
15
|
+
private fanService?: homebridge.Service;
|
|
16
|
+
private doorService?: homebridge.Service;
|
|
17
|
+
private lockService?: homebridge.Service;
|
|
18
|
+
private faucetService?: homebridge.Service;
|
|
19
|
+
private windowService?: homebridge.Service;
|
|
20
|
+
private switchService?: homebridge.Service;
|
|
21
|
+
private outletService?: homebridge.Service;
|
|
22
|
+
private batteryService?: homebridge.Service;
|
|
23
|
+
private garageDoorService?: homebridge.Service;
|
|
24
|
+
private windowCoveringService?: homebridge.Service;
|
|
25
|
+
private statefulProgrammableSwitchService?: homebridge.Service;
|
|
28
26
|
|
|
29
27
|
// Characteristic Values
|
|
30
|
-
On!: CharacteristicValue;
|
|
31
|
-
OnCached!: CharacteristicValue;
|
|
32
|
-
BatteryLevel!: CharacteristicValue;
|
|
33
|
-
StatusLowBattery!: CharacteristicValue;
|
|
28
|
+
On!: homebridge.CharacteristicValue;
|
|
29
|
+
OnCached!: homebridge.CharacteristicValue;
|
|
30
|
+
BatteryLevel!: homebridge.CharacteristicValue;
|
|
31
|
+
StatusLowBattery!: homebridge.CharacteristicValue;
|
|
34
32
|
|
|
35
33
|
// OpenAPI Others
|
|
36
|
-
power: deviceStatus[
|
|
37
|
-
deviceStatus!: deviceStatusResponse;
|
|
34
|
+
power: settings.deviceStatus["power"];
|
|
35
|
+
deviceStatus!: settings.deviceStatusResponse;
|
|
38
36
|
|
|
39
37
|
// BLE Others
|
|
40
38
|
connected?: boolean;
|
|
41
|
-
switchbot!: switchbot;
|
|
42
39
|
SwitchToOpenAPI?: boolean;
|
|
43
|
-
serviceData!: serviceData;
|
|
44
|
-
mode!: serviceData[
|
|
45
|
-
state!: serviceData[
|
|
46
|
-
battery!: serviceData[
|
|
40
|
+
serviceData!: settings.serviceData;
|
|
41
|
+
mode!: settings.serviceData["mode"];
|
|
42
|
+
state!: settings.serviceData["state"];
|
|
43
|
+
battery!: settings.serviceData["battery"];
|
|
47
44
|
|
|
48
45
|
// Config
|
|
49
46
|
botMode!: string;
|
|
@@ -56,12 +53,12 @@ export class Bot {
|
|
|
56
53
|
|
|
57
54
|
// Updates
|
|
58
55
|
botUpdateInProgress!: boolean;
|
|
59
|
-
doBotUpdate!: Subject<void>;
|
|
56
|
+
doBotUpdate!: rxjs.Subject<void>;
|
|
60
57
|
|
|
61
58
|
constructor(
|
|
62
|
-
private readonly platform: SwitchBotPlatform,
|
|
63
|
-
private accessory: PlatformAccessory,
|
|
64
|
-
public device: device & devicesConfig,
|
|
59
|
+
private readonly platform: platform.SwitchBotPlatform,
|
|
60
|
+
private accessory: homebridge.PlatformAccessory,
|
|
61
|
+
public device: settings.device & settings.devicesConfig,
|
|
65
62
|
) {
|
|
66
63
|
// default placeholders
|
|
67
64
|
this.logs(device);
|
|
@@ -85,7 +82,7 @@ export class Bot {
|
|
|
85
82
|
this.StatusLowBattery = 0;
|
|
86
83
|
|
|
87
84
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
88
|
-
this.doBotUpdate = new Subject();
|
|
85
|
+
this.doBotUpdate = new rxjs.Subject();
|
|
89
86
|
this.botUpdateInProgress = false;
|
|
90
87
|
|
|
91
88
|
// Retrieve initial values and updateHomekit
|
|
@@ -94,13 +91,16 @@ export class Bot {
|
|
|
94
91
|
// set accessory information
|
|
95
92
|
accessory
|
|
96
93
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
97
|
-
.setCharacteristic(this.platform.Characteristic.Manufacturer,
|
|
98
|
-
.setCharacteristic(this.platform.Characteristic.Model,
|
|
99
|
-
.setCharacteristic(
|
|
94
|
+
.setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
|
|
95
|
+
.setCharacteristic(this.platform.Characteristic.Model, "SWITCHBOT-BOT-S1")
|
|
96
|
+
.setCharacteristic(
|
|
97
|
+
this.platform.Characteristic.SerialNumber,
|
|
98
|
+
device.deviceId!,
|
|
99
|
+
);
|
|
100
100
|
|
|
101
101
|
// get the LightBulb service if it exists, otherwise create a new LightBulb service
|
|
102
102
|
// you can create multiple services for each accessory
|
|
103
|
-
if (device.bot?.deviceType ===
|
|
103
|
+
if (device.bot?.deviceType === "switch") {
|
|
104
104
|
this.removeFanService(accessory);
|
|
105
105
|
this.removeLockService(accessory);
|
|
106
106
|
this.removeDoorService(accessory);
|
|
@@ -114,12 +114,18 @@ export class Bot {
|
|
|
114
114
|
// Add switchService
|
|
115
115
|
(this.switchService =
|
|
116
116
|
accessory.getService(this.platform.Service.Switch) ||
|
|
117
|
-
accessory.addService(this.platform.Service.Switch)),
|
|
117
|
+
accessory.addService(this.platform.Service.Switch)),
|
|
118
|
+
`${accessory.displayName} Switch`;
|
|
118
119
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Switch`);
|
|
119
120
|
|
|
120
|
-
this.switchService.setCharacteristic(
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
this.switchService.setCharacteristic(
|
|
122
|
+
this.platform.Characteristic.Name,
|
|
123
|
+
accessory.displayName,
|
|
124
|
+
);
|
|
125
|
+
this.switchService
|
|
126
|
+
.getCharacteristic(this.platform.Characteristic.On)
|
|
127
|
+
.onSet(this.handleOnSet.bind(this));
|
|
128
|
+
} else if (device.bot?.deviceType === "garagedoor") {
|
|
123
129
|
this.removeFanService(accessory);
|
|
124
130
|
this.removeLockService(accessory);
|
|
125
131
|
this.removeDoorService(accessory);
|
|
@@ -133,13 +139,24 @@ export class Bot {
|
|
|
133
139
|
// Add switchService
|
|
134
140
|
(this.garageDoorService =
|
|
135
141
|
accessory.getService(this.platform.Service.GarageDoorOpener) ||
|
|
136
|
-
accessory.addService(this.platform.Service.GarageDoorOpener)),
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
142
|
+
accessory.addService(this.platform.Service.GarageDoorOpener)),
|
|
143
|
+
`${accessory.displayName} Garage Door Opener`;
|
|
144
|
+
this.infoLog(
|
|
145
|
+
`Bot: ${accessory.displayName} Displaying as Garage Door Opener`,
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
this.garageDoorService.setCharacteristic(
|
|
149
|
+
this.platform.Characteristic.Name,
|
|
150
|
+
accessory.displayName,
|
|
151
|
+
);
|
|
152
|
+
this.garageDoorService
|
|
153
|
+
.getCharacteristic(this.platform.Characteristic.TargetDoorState)
|
|
154
|
+
.onSet(this.handleOnSet.bind(this));
|
|
155
|
+
this.garageDoorService.setCharacteristic(
|
|
156
|
+
this.platform.Characteristic.ObstructionDetected,
|
|
157
|
+
false,
|
|
158
|
+
);
|
|
159
|
+
} else if (device.bot?.deviceType === "door") {
|
|
143
160
|
this.removeFanService(accessory);
|
|
144
161
|
this.removeLockService(accessory);
|
|
145
162
|
this.removeOutletService(accessory);
|
|
@@ -153,19 +170,28 @@ export class Bot {
|
|
|
153
170
|
// Add switchService
|
|
154
171
|
(this.doorService =
|
|
155
172
|
accessory.getService(this.platform.Service.Door) ||
|
|
156
|
-
accessory.addService(this.platform.Service.Door)),
|
|
173
|
+
accessory.addService(this.platform.Service.Door)),
|
|
174
|
+
`${accessory.displayName} Door`;
|
|
157
175
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Door`);
|
|
158
176
|
|
|
159
|
-
this.doorService.setCharacteristic(
|
|
160
|
-
|
|
177
|
+
this.doorService.setCharacteristic(
|
|
178
|
+
this.platform.Characteristic.Name,
|
|
179
|
+
accessory.displayName,
|
|
180
|
+
);
|
|
181
|
+
this.doorService
|
|
182
|
+
.getCharacteristic(this.platform.Characteristic.TargetPosition)
|
|
161
183
|
.setProps({
|
|
162
184
|
validValues: [0, 100],
|
|
163
185
|
minValue: 0,
|
|
164
186
|
maxValue: 100,
|
|
165
187
|
minStep: 100,
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
|
|
188
|
+
})
|
|
189
|
+
.onSet(this.handleOnSet.bind(this));
|
|
190
|
+
this.doorService.setCharacteristic(
|
|
191
|
+
this.platform.Characteristic.PositionState,
|
|
192
|
+
this.platform.Characteristic.PositionState.STOPPED,
|
|
193
|
+
);
|
|
194
|
+
} else if (device.bot?.deviceType === "window") {
|
|
169
195
|
this.removeFanService(accessory);
|
|
170
196
|
this.removeLockService(accessory);
|
|
171
197
|
this.removeDoorService(accessory);
|
|
@@ -179,19 +205,28 @@ export class Bot {
|
|
|
179
205
|
// Add switchService
|
|
180
206
|
(this.windowService =
|
|
181
207
|
accessory.getService(this.platform.Service.Window) ||
|
|
182
|
-
accessory.addService(this.platform.Service.Window)),
|
|
208
|
+
accessory.addService(this.platform.Service.Window)),
|
|
209
|
+
`${accessory.displayName} Window`;
|
|
183
210
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Window`);
|
|
184
211
|
|
|
185
|
-
this.windowService.setCharacteristic(
|
|
186
|
-
|
|
212
|
+
this.windowService.setCharacteristic(
|
|
213
|
+
this.platform.Characteristic.Name,
|
|
214
|
+
accessory.displayName,
|
|
215
|
+
);
|
|
216
|
+
this.windowService
|
|
217
|
+
.getCharacteristic(this.platform.Characteristic.TargetPosition)
|
|
187
218
|
.setProps({
|
|
188
219
|
validValues: [0, 100],
|
|
189
220
|
minValue: 0,
|
|
190
221
|
maxValue: 100,
|
|
191
222
|
minStep: 100,
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
|
|
223
|
+
})
|
|
224
|
+
.onSet(this.handleOnSet.bind(this));
|
|
225
|
+
this.windowService.setCharacteristic(
|
|
226
|
+
this.platform.Characteristic.PositionState,
|
|
227
|
+
this.platform.Characteristic.PositionState.STOPPED,
|
|
228
|
+
);
|
|
229
|
+
} else if (device.bot?.deviceType === "windowcovering") {
|
|
195
230
|
this.removeFanService(accessory);
|
|
196
231
|
this.removeLockService(accessory);
|
|
197
232
|
this.removeDoorService(accessory);
|
|
@@ -205,19 +240,30 @@ export class Bot {
|
|
|
205
240
|
// Add switchService
|
|
206
241
|
(this.windowCoveringService =
|
|
207
242
|
accessory.getService(this.platform.Service.WindowCovering) ||
|
|
208
|
-
accessory.addService(this.platform.Service.WindowCovering)),
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
243
|
+
accessory.addService(this.platform.Service.WindowCovering)),
|
|
244
|
+
`${accessory.displayName} Window Covering`;
|
|
245
|
+
this.infoLog(
|
|
246
|
+
`Bot: ${accessory.displayName} Displaying as Window Covering`,
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
this.windowCoveringService.setCharacteristic(
|
|
250
|
+
this.platform.Characteristic.Name,
|
|
251
|
+
accessory.displayName,
|
|
252
|
+
);
|
|
253
|
+
this.windowCoveringService
|
|
254
|
+
.getCharacteristic(this.platform.Characteristic.TargetPosition)
|
|
213
255
|
.setProps({
|
|
214
256
|
validValues: [0, 100],
|
|
215
257
|
minValue: 0,
|
|
216
258
|
maxValue: 100,
|
|
217
259
|
minStep: 100,
|
|
218
|
-
})
|
|
219
|
-
|
|
220
|
-
|
|
260
|
+
})
|
|
261
|
+
.onSet(this.handleOnSet.bind(this));
|
|
262
|
+
this.windowCoveringService.setCharacteristic(
|
|
263
|
+
this.platform.Characteristic.PositionState,
|
|
264
|
+
this.platform.Characteristic.PositionState.STOPPED,
|
|
265
|
+
);
|
|
266
|
+
} else if (device.bot?.deviceType === "lock") {
|
|
221
267
|
this.removeFanService(accessory);
|
|
222
268
|
this.removeDoorService(accessory);
|
|
223
269
|
this.removeOutletService(accessory);
|
|
@@ -231,12 +277,18 @@ export class Bot {
|
|
|
231
277
|
// Add switchService
|
|
232
278
|
(this.lockService =
|
|
233
279
|
accessory.getService(this.platform.Service.LockMechanism) ||
|
|
234
|
-
accessory.addService(this.platform.Service.LockMechanism)),
|
|
280
|
+
accessory.addService(this.platform.Service.LockMechanism)),
|
|
281
|
+
`${accessory.displayName} Lock`;
|
|
235
282
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Lock`);
|
|
236
283
|
|
|
237
|
-
this.lockService.setCharacteristic(
|
|
238
|
-
|
|
239
|
-
|
|
284
|
+
this.lockService.setCharacteristic(
|
|
285
|
+
this.platform.Characteristic.Name,
|
|
286
|
+
accessory.displayName,
|
|
287
|
+
);
|
|
288
|
+
this.lockService
|
|
289
|
+
.getCharacteristic(this.platform.Characteristic.LockTargetState)
|
|
290
|
+
.onSet(this.handleOnSet.bind(this));
|
|
291
|
+
} else if (device.bot?.deviceType === "faucet") {
|
|
240
292
|
this.removeFanService(accessory);
|
|
241
293
|
this.removeLockService(accessory);
|
|
242
294
|
this.removeDoorService(accessory);
|
|
@@ -250,12 +302,18 @@ export class Bot {
|
|
|
250
302
|
// Add switchService
|
|
251
303
|
(this.faucetService =
|
|
252
304
|
accessory.getService(this.platform.Service.Faucet) ||
|
|
253
|
-
accessory.addService(this.platform.Service.Faucet)),
|
|
305
|
+
accessory.addService(this.platform.Service.Faucet)),
|
|
306
|
+
`${accessory.displayName} Faucet`;
|
|
254
307
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Faucet`);
|
|
255
308
|
|
|
256
|
-
this.faucetService.setCharacteristic(
|
|
257
|
-
|
|
258
|
-
|
|
309
|
+
this.faucetService.setCharacteristic(
|
|
310
|
+
this.platform.Characteristic.Name,
|
|
311
|
+
accessory.displayName,
|
|
312
|
+
);
|
|
313
|
+
this.faucetService
|
|
314
|
+
.getCharacteristic(this.platform.Characteristic.Active)
|
|
315
|
+
.onSet(this.handleOnSet.bind(this));
|
|
316
|
+
} else if (device.bot?.deviceType === "fan") {
|
|
259
317
|
this.removeLockService(accessory);
|
|
260
318
|
this.removeDoorService(accessory);
|
|
261
319
|
this.removeFaucetService(accessory);
|
|
@@ -269,12 +327,18 @@ export class Bot {
|
|
|
269
327
|
// Add switchService
|
|
270
328
|
(this.fanService =
|
|
271
329
|
accessory.getService(this.platform.Service.Fan) ||
|
|
272
|
-
accessory.addService(this.platform.Service.Fan)),
|
|
330
|
+
accessory.addService(this.platform.Service.Fan)),
|
|
331
|
+
`${accessory.displayName} Fan`;
|
|
273
332
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Fan`);
|
|
274
333
|
|
|
275
|
-
this.fanService.setCharacteristic(
|
|
276
|
-
|
|
277
|
-
|
|
334
|
+
this.fanService.setCharacteristic(
|
|
335
|
+
this.platform.Characteristic.Name,
|
|
336
|
+
accessory.displayName,
|
|
337
|
+
);
|
|
338
|
+
this.fanService
|
|
339
|
+
.getCharacteristic(this.platform.Characteristic.On)
|
|
340
|
+
.onSet(this.handleOnSet.bind(this));
|
|
341
|
+
} else if (device.bot?.deviceType === "stateful") {
|
|
278
342
|
this.removeFanService(accessory);
|
|
279
343
|
this.removeLockService(accessory);
|
|
280
344
|
this.removeDoorService(accessory);
|
|
@@ -287,12 +351,23 @@ export class Bot {
|
|
|
287
351
|
|
|
288
352
|
// Add switchService
|
|
289
353
|
(this.statefulProgrammableSwitchService =
|
|
290
|
-
accessory.getService(
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
this.
|
|
354
|
+
accessory.getService(
|
|
355
|
+
this.platform.Service.StatefulProgrammableSwitch,
|
|
356
|
+
) ||
|
|
357
|
+
accessory.addService(this.platform.Service.StatefulProgrammableSwitch)),
|
|
358
|
+
`${accessory.displayName} Stateful Programmable Switch`;
|
|
359
|
+
this.infoLog(
|
|
360
|
+
`Bot: ${accessory.displayName} Displaying as Stateful Programmable Switch`,
|
|
361
|
+
);
|
|
362
|
+
|
|
363
|
+
this.statefulProgrammableSwitchService.setCharacteristic(
|
|
364
|
+
this.platform.Characteristic.Name,
|
|
365
|
+
accessory.displayName,
|
|
366
|
+
);
|
|
367
|
+
this.statefulProgrammableSwitchService
|
|
368
|
+
.getCharacteristic(
|
|
369
|
+
this.platform.Characteristic.ProgrammableSwitchOutputState,
|
|
370
|
+
)
|
|
296
371
|
.onSet(this.handleOnSet.bind(this));
|
|
297
372
|
} else {
|
|
298
373
|
this.removeFanService(accessory);
|
|
@@ -308,26 +383,37 @@ export class Bot {
|
|
|
308
383
|
// Add outletService
|
|
309
384
|
(this.outletService =
|
|
310
385
|
accessory.getService(this.platform.Service.Outlet) ||
|
|
311
|
-
accessory.addService(this.platform.Service.Outlet)),
|
|
386
|
+
accessory.addService(this.platform.Service.Outlet)),
|
|
387
|
+
`${accessory.displayName} Outlet`;
|
|
312
388
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Outlet`);
|
|
313
389
|
|
|
314
|
-
this.outletService.setCharacteristic(
|
|
315
|
-
|
|
390
|
+
this.outletService.setCharacteristic(
|
|
391
|
+
this.platform.Characteristic.Name,
|
|
392
|
+
accessory.displayName,
|
|
393
|
+
);
|
|
394
|
+
this.outletService
|
|
395
|
+
.getCharacteristic(this.platform.Characteristic.On)
|
|
396
|
+
.onSet(this.handleOnSet.bind(this));
|
|
316
397
|
}
|
|
317
398
|
|
|
318
399
|
// Battery Service
|
|
319
400
|
if (!device.ble) {
|
|
320
401
|
this.debugLog(`Bot: ${accessory.displayName} Removing Battery Service`);
|
|
321
|
-
this.batteryService = this.accessory.getService(
|
|
402
|
+
this.batteryService = this.accessory.getService(
|
|
403
|
+
this.platform.Service.Battery,
|
|
404
|
+
);
|
|
322
405
|
accessory.removeService(this.batteryService!);
|
|
323
406
|
} else if (device.ble && !this.batteryService) {
|
|
324
407
|
this.debugLog(`Bot: ${accessory.displayName} Add Battery Service`);
|
|
325
408
|
(this.batteryService =
|
|
326
409
|
this.accessory.getService(this.platform.Service.Battery) ||
|
|
327
|
-
this.accessory.addService(this.platform.Service.Battery)),
|
|
328
|
-
|
|
329
|
-
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
410
|
+
this.accessory.addService(this.platform.Service.Battery)),
|
|
411
|
+
`${accessory.displayName} Battery`;
|
|
330
412
|
|
|
413
|
+
this.batteryService.setCharacteristic(
|
|
414
|
+
this.platform.Characteristic.Name,
|
|
415
|
+
`${accessory.displayName} Battery`,
|
|
416
|
+
);
|
|
331
417
|
} else {
|
|
332
418
|
this.debugLog(`Bot: ${accessory.displayName} Battery Service Not Added`);
|
|
333
419
|
}
|
|
@@ -336,8 +422,9 @@ export class Bot {
|
|
|
336
422
|
this.updateHomeKitCharacteristics();
|
|
337
423
|
|
|
338
424
|
// Start an update interval
|
|
339
|
-
|
|
340
|
-
.
|
|
425
|
+
rxjs
|
|
426
|
+
.interval(this.deviceRefreshRate * 1000)
|
|
427
|
+
.pipe(operators.skipWhile(() => this.botUpdateInProgress))
|
|
341
428
|
.subscribe(() => {
|
|
342
429
|
this.refreshStatus();
|
|
343
430
|
});
|
|
@@ -346,27 +433,28 @@ export class Bot {
|
|
|
346
433
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
347
434
|
this.doBotUpdate
|
|
348
435
|
.pipe(
|
|
349
|
-
tap(() => {
|
|
436
|
+
operators.tap(() => {
|
|
350
437
|
this.botUpdateInProgress = true;
|
|
351
438
|
}),
|
|
352
|
-
debounceTime(100),
|
|
439
|
+
operators.debounceTime(100),
|
|
353
440
|
)
|
|
354
441
|
.subscribe(async () => {
|
|
355
442
|
try {
|
|
356
|
-
|
|
357
|
-
.
|
|
443
|
+
rxjs
|
|
444
|
+
.interval(100)
|
|
445
|
+
.pipe(operators.take(this.doublePress!))
|
|
358
446
|
.subscribe(async () => {
|
|
359
447
|
await this.pushChanges();
|
|
360
448
|
});
|
|
361
449
|
} catch (e: any) {
|
|
362
|
-
this.errorLog(
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
450
|
+
this.errorLog(
|
|
451
|
+
`Bot: ${this.accessory.displayName} failed pushChanges`,
|
|
452
|
+
);
|
|
453
|
+
if (this.deviceLogging.includes("debug")) {
|
|
454
|
+
this.errorLog(
|
|
455
|
+
`Bot: ${this.accessory.displayName} failed pushChanges,` +
|
|
456
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
457
|
+
);
|
|
370
458
|
}
|
|
371
459
|
}
|
|
372
460
|
this.botUpdateInProgress = false;
|
|
@@ -393,24 +481,32 @@ export class Bot {
|
|
|
393
481
|
if (this.On === undefined) {
|
|
394
482
|
this.On = Boolean(this.state);
|
|
395
483
|
}
|
|
396
|
-
this.debugLog(
|
|
484
|
+
this.debugLog(
|
|
485
|
+
`Bot: ${this.accessory.displayName} Switch Mode, mode: ${this.mode}, On: ${this.On}`,
|
|
486
|
+
);
|
|
397
487
|
} else {
|
|
398
488
|
this.On = false;
|
|
399
489
|
this.OnCached = this.On;
|
|
400
490
|
this.accessory.context.On = this.OnCached;
|
|
401
|
-
this.debugLog(
|
|
491
|
+
this.debugLog(
|
|
492
|
+
`Bot: ${this.accessory.displayName} Press Mode, mode: ${this.mode}, On: ${this.On}`,
|
|
493
|
+
);
|
|
402
494
|
}
|
|
403
495
|
|
|
404
496
|
this.BatteryLevel = Number(this.battery);
|
|
405
497
|
if (this.BatteryLevel < 10) {
|
|
406
|
-
this.StatusLowBattery =
|
|
498
|
+
this.StatusLowBattery =
|
|
499
|
+
this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
407
500
|
} else {
|
|
408
|
-
this.StatusLowBattery =
|
|
501
|
+
this.StatusLowBattery =
|
|
502
|
+
this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
409
503
|
}
|
|
410
504
|
if (Number.isNaN(this.BatteryLevel)) {
|
|
411
505
|
this.BatteryLevel = 100;
|
|
412
506
|
}
|
|
413
|
-
this.debugLog(
|
|
507
|
+
this.debugLog(
|
|
508
|
+
`Bot: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`,
|
|
509
|
+
);
|
|
414
510
|
}
|
|
415
511
|
|
|
416
512
|
private async openAPIparseStatus() {
|
|
@@ -419,7 +515,7 @@ export class Bot {
|
|
|
419
515
|
}
|
|
420
516
|
if (this.platform.config.credentials?.openToken) {
|
|
421
517
|
this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
422
|
-
if (this.botMode ===
|
|
518
|
+
if (this.botMode === "press") {
|
|
423
519
|
this.On = false;
|
|
424
520
|
this.OnCached = this.On;
|
|
425
521
|
this.accessory.context.On = this.OnCached;
|
|
@@ -458,87 +554,117 @@ export class Bot {
|
|
|
458
554
|
this.debugLog(`Bot: ${this.accessory.displayName} BLE refreshStatus`);
|
|
459
555
|
const switchbot = await this.platform.connectBLE();
|
|
460
556
|
// Convert to BLE Address
|
|
461
|
-
this.device.bleMac =
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
557
|
+
this.device.bleMac = this.device
|
|
558
|
+
.deviceId!.match(/.{1,2}/g)!
|
|
559
|
+
.join(":")
|
|
560
|
+
.toLowerCase();
|
|
561
|
+
this.debugLog(
|
|
562
|
+
`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`,
|
|
563
|
+
);
|
|
564
|
+
try {
|
|
565
|
+
await switchbot.discover({
|
|
566
|
+
model: "H",
|
|
567
|
+
quick: false,
|
|
568
|
+
});
|
|
569
|
+
// Start to monitor advertisement packets
|
|
570
|
+
await switchbot.startScan({
|
|
571
|
+
model: "H",
|
|
572
|
+
id: this.device.bleMac,
|
|
573
|
+
});
|
|
471
574
|
// Set an event hander
|
|
472
|
-
switchbot.onadvertisement = (ad: ad) => {
|
|
575
|
+
switchbot.onadvertisement = (ad: settings.ad) => {
|
|
473
576
|
this.serviceData = ad.serviceData;
|
|
474
577
|
this.mode = ad.serviceData.mode;
|
|
475
578
|
this.state = ad.serviceData.state;
|
|
476
579
|
this.battery = ad.serviceData.battery;
|
|
477
|
-
this.debugLog(
|
|
478
|
-
|
|
479
|
-
|
|
580
|
+
this.debugLog(
|
|
581
|
+
`Bot: ${this.accessory.displayName} serviceData: ${JSON.stringify(
|
|
582
|
+
ad.serviceData,
|
|
583
|
+
)}`,
|
|
584
|
+
);
|
|
585
|
+
this.debugLog(
|
|
586
|
+
`Bot: ${this.accessory.displayName}, model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
|
|
587
|
+
` mode: ${ad.serviceData.mode}, state: ${ad.serviceData.state}, battery: ${ad.serviceData.battery}`,
|
|
588
|
+
);
|
|
480
589
|
|
|
481
590
|
if (this.serviceData) {
|
|
482
591
|
this.connected = true;
|
|
483
|
-
this.debugLog(
|
|
592
|
+
this.debugLog(
|
|
593
|
+
`Bot: ${this.accessory.displayName} connected: ${this.connected}`,
|
|
594
|
+
);
|
|
484
595
|
} else {
|
|
485
596
|
this.connected = false;
|
|
486
|
-
this.debugLog(
|
|
597
|
+
this.debugLog(
|
|
598
|
+
`Bot: ${this.accessory.displayName} connected: ${this.connected}`,
|
|
599
|
+
);
|
|
487
600
|
}
|
|
488
601
|
};
|
|
489
602
|
// Wait 2 seconds
|
|
490
|
-
|
|
491
|
-
}).then(async () => {
|
|
603
|
+
await switchbot.wait(this.scanDuration * 1000);
|
|
492
604
|
// Stop to monitor
|
|
493
605
|
switchbot.stopScan();
|
|
494
606
|
if (this.connected) {
|
|
495
607
|
this.parseStatus();
|
|
496
608
|
this.updateHomeKitCharacteristics();
|
|
497
609
|
} else {
|
|
498
|
-
this.errorLog(
|
|
610
|
+
this.errorLog(
|
|
611
|
+
`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection`,
|
|
612
|
+
);
|
|
499
613
|
if (this.platform.config.credentials?.openToken) {
|
|
500
|
-
this.warnLog(
|
|
614
|
+
this.warnLog(
|
|
615
|
+
`Bot: ${this.accessory.displayName} Using OpenAPI Connection`,
|
|
616
|
+
);
|
|
501
617
|
this.SwitchToOpenAPI = true;
|
|
502
618
|
await this.openAPIRefreshStatus();
|
|
503
619
|
}
|
|
504
620
|
}
|
|
505
|
-
}
|
|
506
|
-
this.errorLog(
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
621
|
+
} catch (e: any) {
|
|
622
|
+
this.errorLog(
|
|
623
|
+
`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection`,
|
|
624
|
+
);
|
|
625
|
+
if (this.deviceLogging.includes("debug")) {
|
|
626
|
+
this.errorLog(
|
|
627
|
+
`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` +
|
|
628
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
629
|
+
);
|
|
514
630
|
}
|
|
515
631
|
if (this.platform.config.credentials?.openToken) {
|
|
516
|
-
this.warnLog(
|
|
632
|
+
this.warnLog(
|
|
633
|
+
`Bot: ${this.accessory.displayName} Using OpenAPI Connection`,
|
|
634
|
+
);
|
|
517
635
|
this.SwitchToOpenAPI = true;
|
|
518
636
|
await this.openAPIRefreshStatus();
|
|
519
637
|
}
|
|
520
638
|
this.apiError(e);
|
|
521
|
-
}
|
|
639
|
+
}
|
|
522
640
|
}
|
|
523
641
|
|
|
524
642
|
private async openAPIRefreshStatus() {
|
|
525
643
|
if (this.platform.config.credentials?.openToken) {
|
|
526
644
|
this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI refreshStatus`);
|
|
527
645
|
try {
|
|
528
|
-
this.deviceStatus = (
|
|
529
|
-
|
|
646
|
+
this.deviceStatus = (
|
|
647
|
+
await this.platform.axios.get(
|
|
648
|
+
`${settings.DeviceURL}/${this.device.deviceId}/status`,
|
|
649
|
+
)
|
|
650
|
+
).data;
|
|
651
|
+
this.debugLog(
|
|
652
|
+
`Bot: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(
|
|
653
|
+
this.deviceStatus,
|
|
654
|
+
)}`,
|
|
655
|
+
);
|
|
530
656
|
this.power = this.deviceStatus.body.power;
|
|
531
657
|
this.parseStatus();
|
|
532
658
|
this.updateHomeKitCharacteristics();
|
|
533
659
|
} catch (e: any) {
|
|
534
|
-
this.errorLog(
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
660
|
+
this.errorLog(
|
|
661
|
+
`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`,
|
|
662
|
+
);
|
|
663
|
+
if (this.deviceLogging.includes("debug")) {
|
|
664
|
+
this.errorLog(
|
|
665
|
+
`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
|
|
666
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
667
|
+
);
|
|
542
668
|
}
|
|
543
669
|
this.apiError(e);
|
|
544
670
|
}
|
|
@@ -558,85 +684,122 @@ export class Bot {
|
|
|
558
684
|
} else {
|
|
559
685
|
await this.openAPIpushChanges();
|
|
560
686
|
}
|
|
561
|
-
|
|
562
|
-
.
|
|
563
|
-
.pipe(
|
|
687
|
+
rxjs
|
|
688
|
+
.interval(5000)
|
|
689
|
+
.pipe(operators.skipWhile(() => this.botUpdateInProgress))
|
|
690
|
+
.pipe(operators.take(1))
|
|
564
691
|
.subscribe(() => {
|
|
565
692
|
this.refreshStatus();
|
|
566
693
|
});
|
|
567
694
|
}
|
|
568
695
|
|
|
569
696
|
private async BLEpushChanges() {
|
|
570
|
-
this.debugLog(
|
|
697
|
+
this.debugLog(
|
|
698
|
+
`Bot: ${this.accessory.displayName} BLE pushChanges On: ${this.On} OnCached: ${this.OnCached}`,
|
|
699
|
+
);
|
|
571
700
|
if (this.On !== this.OnCached) {
|
|
572
701
|
this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges`);
|
|
573
702
|
const switchbot = await this.platform.connectBLE();
|
|
574
703
|
// Convert to BLE Address
|
|
575
|
-
this.device.bleMac =
|
|
576
|
-
|
|
704
|
+
this.device.bleMac = this.device
|
|
705
|
+
.deviceId!.match(/.{1,2}/g)!
|
|
706
|
+
.join(":")
|
|
707
|
+
.toLowerCase();
|
|
708
|
+
this.debugLog(
|
|
709
|
+
`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`,
|
|
710
|
+
);
|
|
577
711
|
//if (switchbot !== false) {
|
|
578
|
-
if (this.botMode ===
|
|
579
|
-
this.debugLog(
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
712
|
+
if (this.botMode === "press") {
|
|
713
|
+
this.debugLog(
|
|
714
|
+
`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`,
|
|
715
|
+
);
|
|
716
|
+
switchbot
|
|
717
|
+
.discover({ model: "H", quick: true, id: this.device.bleMac })
|
|
718
|
+
.then(
|
|
719
|
+
(
|
|
720
|
+
device_list: {
|
|
721
|
+
press: (arg0: { id: string | undefined }) => any;
|
|
722
|
+
}[],
|
|
723
|
+
) => {
|
|
724
|
+
this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
725
|
+
return device_list[0].press({ id: this.device.bleMac });
|
|
726
|
+
},
|
|
727
|
+
)
|
|
728
|
+
.then(() => {
|
|
585
729
|
this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
|
|
586
730
|
this.On = false;
|
|
587
731
|
this.OnCached = this.On;
|
|
588
732
|
this.accessory.context.On = this.OnCached;
|
|
589
733
|
setTimeout(() => {
|
|
590
|
-
if (this.device.bot?.deviceType ===
|
|
591
|
-
this.switchService
|
|
734
|
+
if (this.device.bot?.deviceType === "switch") {
|
|
735
|
+
this.switchService
|
|
736
|
+
?.getCharacteristic(this.platform.Characteristic.On)
|
|
737
|
+
.updateValue(this.On);
|
|
592
738
|
} else {
|
|
593
|
-
this.outletService
|
|
739
|
+
this.outletService
|
|
740
|
+
?.getCharacteristic(this.platform.Characteristic.On)
|
|
741
|
+
.updateValue(this.On);
|
|
594
742
|
}
|
|
595
|
-
this.debugLog(
|
|
743
|
+
this.debugLog(
|
|
744
|
+
`Bot: ${this.accessory.displayName} On: ${this.On}, Switch Timeout`,
|
|
745
|
+
);
|
|
596
746
|
}, 500);
|
|
597
|
-
})
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
747
|
+
})
|
|
748
|
+
.catch(async (e: any) => {
|
|
749
|
+
this.errorLog(
|
|
750
|
+
`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`,
|
|
751
|
+
);
|
|
752
|
+
if (this.deviceLogging.includes("debug")) {
|
|
753
|
+
this.errorLog(
|
|
754
|
+
`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` +
|
|
755
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
756
|
+
);
|
|
757
|
+
}
|
|
758
|
+
if (this.platform.config.credentials?.openToken) {
|
|
759
|
+
this.warnLog(
|
|
760
|
+
`Bot: ${this.accessory.displayName} Using OpenAPI Connection`,
|
|
761
|
+
);
|
|
762
|
+
await this.openAPIpushChanges();
|
|
602
763
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
764
|
+
this.apiError(e);
|
|
765
|
+
});
|
|
766
|
+
} else if (this.botMode === "switch") {
|
|
767
|
+
this.debugLog(
|
|
768
|
+
`Bot: ${this.accessory.displayName} Press Mode: ${this.botMode}`,
|
|
769
|
+
);
|
|
770
|
+
switchbot
|
|
771
|
+
.discover({ model: "H", quick: true, id: this.device.bleMac })
|
|
772
|
+
.then((device_list: any) => {
|
|
773
|
+
this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
774
|
+
return this.turnOnOff(device_list);
|
|
775
|
+
})
|
|
776
|
+
.then(() => {
|
|
777
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
|
|
778
|
+
this.OnCached = this.On;
|
|
779
|
+
this.accessory.context.On = this.OnCached;
|
|
780
|
+
})
|
|
781
|
+
.catch(async (e: any) => {
|
|
782
|
+
this.errorLog(
|
|
783
|
+
`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`,
|
|
784
|
+
);
|
|
785
|
+
if (this.deviceLogging.includes("debug")) {
|
|
786
|
+
this.errorLog(
|
|
787
|
+
`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` +
|
|
788
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
789
|
+
);
|
|
606
790
|
}
|
|
607
791
|
if (this.platform.config.credentials?.openToken) {
|
|
608
|
-
this.warnLog(
|
|
792
|
+
this.warnLog(
|
|
793
|
+
`Bot: ${this.accessory.displayName} Using OpenAPI Connection`,
|
|
794
|
+
);
|
|
609
795
|
await this.openAPIpushChanges();
|
|
610
796
|
}
|
|
611
797
|
this.apiError(e);
|
|
612
798
|
});
|
|
613
|
-
} else if (this.botMode === 'switch') {
|
|
614
|
-
this.debugLog(`Bot: ${this.accessory.displayName} Press Mode: ${this.botMode}`);
|
|
615
|
-
switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac }).then((device_list: any) => {
|
|
616
|
-
this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
617
|
-
return this.turnOnOff(device_list);
|
|
618
|
-
}).then(() => {
|
|
619
|
-
this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
|
|
620
|
-
this.OnCached = this.On;
|
|
621
|
-
this.accessory.context.On = this.OnCached;
|
|
622
|
-
}).catch(async (e: any) => {
|
|
623
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
624
|
-
if (this.deviceLogging === 'debug') {
|
|
625
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
626
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
627
|
-
}
|
|
628
|
-
if (this.platform.debugMode) {
|
|
629
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
630
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
631
|
-
}
|
|
632
|
-
if (this.platform.config.credentials?.openToken) {
|
|
633
|
-
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
634
|
-
await this.openAPIpushChanges();
|
|
635
|
-
}
|
|
636
|
-
this.apiError(e);
|
|
637
|
-
});
|
|
638
799
|
} else {
|
|
639
|
-
throw new Error(
|
|
800
|
+
throw new Error(
|
|
801
|
+
`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`,
|
|
802
|
+
);
|
|
640
803
|
}
|
|
641
804
|
/* } else {
|
|
642
805
|
this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
@@ -662,47 +825,64 @@ export class Bot {
|
|
|
662
825
|
if (this.platform.config.credentials?.openToken) {
|
|
663
826
|
try {
|
|
664
827
|
if (this.On !== this.OnCached) {
|
|
665
|
-
this.debugLog(
|
|
828
|
+
this.debugLog(
|
|
829
|
+
`Bot: ${this.accessory.displayName} OpenAPI pushChanges`,
|
|
830
|
+
);
|
|
666
831
|
const payload = {
|
|
667
|
-
commandType:
|
|
668
|
-
parameter:
|
|
669
|
-
} as payload;
|
|
832
|
+
commandType: "command",
|
|
833
|
+
parameter: "default",
|
|
834
|
+
} as settings.payload;
|
|
670
835
|
|
|
671
|
-
if (this.botMode ===
|
|
672
|
-
payload.command =
|
|
836
|
+
if (this.botMode === "switch" && this.On) {
|
|
837
|
+
payload.command = "turnOn";
|
|
673
838
|
this.On = true;
|
|
674
|
-
this.debugLog(
|
|
675
|
-
|
|
676
|
-
|
|
839
|
+
this.debugLog(
|
|
840
|
+
`Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`,
|
|
841
|
+
);
|
|
842
|
+
} else if (this.botMode === "switch" && !this.On) {
|
|
843
|
+
payload.command = "turnOff";
|
|
677
844
|
this.On = false;
|
|
678
|
-
this.debugLog(
|
|
679
|
-
|
|
680
|
-
|
|
845
|
+
this.debugLog(
|
|
846
|
+
`Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`,
|
|
847
|
+
);
|
|
848
|
+
} else if (this.botMode === "press") {
|
|
849
|
+
payload.command = "press";
|
|
681
850
|
this.debugLog(`Bot: ${this.accessory.displayName} Press Mode`);
|
|
682
851
|
this.On = false;
|
|
683
852
|
} else {
|
|
684
|
-
throw new Error(
|
|
853
|
+
throw new Error(
|
|
854
|
+
`Bot: ${this.accessory.displayName} Device Paramters not set for this Bot.`,
|
|
855
|
+
);
|
|
685
856
|
}
|
|
686
857
|
|
|
687
|
-
this.infoLog(
|
|
688
|
-
|
|
858
|
+
this.infoLog(
|
|
859
|
+
`Bot: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
860
|
+
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
861
|
+
);
|
|
689
862
|
|
|
690
863
|
// Make the API request
|
|
691
|
-
const push: any =
|
|
692
|
-
|
|
864
|
+
const push: any = await this.platform.axios.post(
|
|
865
|
+
`${settings.DeviceURL}/${this.device.deviceId}/commands`,
|
|
866
|
+
payload,
|
|
867
|
+
);
|
|
868
|
+
this.debugLog(
|
|
869
|
+
`Bot: ${this.accessory.displayName} pushchanges: ${JSON.stringify(
|
|
870
|
+
push.data,
|
|
871
|
+
)}`,
|
|
872
|
+
);
|
|
693
873
|
this.statusCode(push);
|
|
694
874
|
this.OnCached = this.On;
|
|
695
875
|
this.accessory.context.On = this.OnCached;
|
|
696
876
|
}
|
|
697
877
|
} catch (e: any) {
|
|
698
|
-
this.errorLog(
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
878
|
+
this.errorLog(
|
|
879
|
+
`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`,
|
|
880
|
+
);
|
|
881
|
+
if (this.deviceLogging.includes("debug")) {
|
|
882
|
+
this.errorLog(
|
|
883
|
+
`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
884
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
885
|
+
);
|
|
706
886
|
}
|
|
707
887
|
this.apiError(e);
|
|
708
888
|
}
|
|
@@ -713,241 +893,460 @@ export class Bot {
|
|
|
713
893
|
* Updates the status for each of the HomeKit Characteristics
|
|
714
894
|
*/
|
|
715
895
|
updateHomeKitCharacteristics() {
|
|
716
|
-
if (this.device.bot?.deviceType ===
|
|
896
|
+
if (this.device.bot?.deviceType === "garagedoor") {
|
|
717
897
|
if (this.On === undefined) {
|
|
718
898
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
719
899
|
} else {
|
|
720
900
|
if (this.On) {
|
|
721
|
-
this.garageDoorService?.updateCharacteristic(
|
|
722
|
-
this.platform.Characteristic.TargetDoorState
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
this.
|
|
901
|
+
this.garageDoorService?.updateCharacteristic(
|
|
902
|
+
this.platform.Characteristic.TargetDoorState,
|
|
903
|
+
this.platform.Characteristic.TargetDoorState.OPEN,
|
|
904
|
+
);
|
|
905
|
+
this.garageDoorService?.updateCharacteristic(
|
|
906
|
+
this.platform.Characteristic.CurrentDoorState,
|
|
907
|
+
this.platform.Characteristic.CurrentDoorState.OPEN,
|
|
908
|
+
);
|
|
909
|
+
this.debugLog(
|
|
910
|
+
`Bot: ${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`,
|
|
911
|
+
);
|
|
726
912
|
} else {
|
|
727
|
-
this.garageDoorService?.updateCharacteristic(
|
|
728
|
-
this.platform.Characteristic.TargetDoorState
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
this.
|
|
913
|
+
this.garageDoorService?.updateCharacteristic(
|
|
914
|
+
this.platform.Characteristic.TargetDoorState,
|
|
915
|
+
this.platform.Characteristic.TargetDoorState.CLOSED,
|
|
916
|
+
);
|
|
917
|
+
this.garageDoorService?.updateCharacteristic(
|
|
918
|
+
this.platform.Characteristic.CurrentDoorState,
|
|
919
|
+
this.platform.Characteristic.CurrentDoorState.CLOSED,
|
|
920
|
+
);
|
|
921
|
+
this.debugLog(
|
|
922
|
+
`Bot: ${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`,
|
|
923
|
+
);
|
|
732
924
|
}
|
|
733
925
|
}
|
|
734
|
-
this.debugLog(
|
|
735
|
-
|
|
926
|
+
this.debugLog(
|
|
927
|
+
`Bot: ${this.accessory.displayName} Garage Door On: ${this.On}`,
|
|
928
|
+
);
|
|
929
|
+
} else if (this.device.bot?.deviceType === "door") {
|
|
736
930
|
if (this.On === undefined) {
|
|
737
931
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
738
932
|
} else {
|
|
739
933
|
if (this.On) {
|
|
740
|
-
this.doorService?.updateCharacteristic(
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
this.
|
|
934
|
+
this.doorService?.updateCharacteristic(
|
|
935
|
+
this.platform.Characteristic.TargetPosition,
|
|
936
|
+
100,
|
|
937
|
+
);
|
|
938
|
+
this.doorService?.updateCharacteristic(
|
|
939
|
+
this.platform.Characteristic.CurrentPosition,
|
|
940
|
+
100,
|
|
941
|
+
);
|
|
942
|
+
this.doorService?.updateCharacteristic(
|
|
943
|
+
this.platform.Characteristic.PositionState,
|
|
944
|
+
this.platform.Characteristic.PositionState.STOPPED,
|
|
945
|
+
);
|
|
946
|
+
this.debugLog(
|
|
947
|
+
`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`,
|
|
948
|
+
);
|
|
745
949
|
} else {
|
|
746
|
-
this.doorService?.updateCharacteristic(
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
this.
|
|
950
|
+
this.doorService?.updateCharacteristic(
|
|
951
|
+
this.platform.Characteristic.TargetPosition,
|
|
952
|
+
0,
|
|
953
|
+
);
|
|
954
|
+
this.doorService?.updateCharacteristic(
|
|
955
|
+
this.platform.Characteristic.CurrentPosition,
|
|
956
|
+
0,
|
|
957
|
+
);
|
|
958
|
+
this.doorService?.updateCharacteristic(
|
|
959
|
+
this.platform.Characteristic.PositionState,
|
|
960
|
+
this.platform.Characteristic.PositionState.STOPPED,
|
|
961
|
+
);
|
|
962
|
+
this.debugLog(
|
|
963
|
+
`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`,
|
|
964
|
+
);
|
|
751
965
|
}
|
|
752
966
|
}
|
|
753
967
|
this.debugLog(`Bot: ${this.accessory.displayName} Door On: ${this.On}`);
|
|
754
|
-
} else if (this.device.bot?.deviceType ===
|
|
968
|
+
} else if (this.device.bot?.deviceType === "window") {
|
|
755
969
|
if (this.On === undefined) {
|
|
756
970
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
757
971
|
} else {
|
|
758
972
|
if (this.On) {
|
|
759
|
-
this.windowService?.updateCharacteristic(
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
this.
|
|
973
|
+
this.windowService?.updateCharacteristic(
|
|
974
|
+
this.platform.Characteristic.TargetPosition,
|
|
975
|
+
100,
|
|
976
|
+
);
|
|
977
|
+
this.windowService?.updateCharacteristic(
|
|
978
|
+
this.platform.Characteristic.CurrentPosition,
|
|
979
|
+
100,
|
|
980
|
+
);
|
|
981
|
+
this.windowService?.updateCharacteristic(
|
|
982
|
+
this.platform.Characteristic.PositionState,
|
|
983
|
+
this.platform.Characteristic.PositionState.STOPPED,
|
|
984
|
+
);
|
|
985
|
+
this.debugLog(
|
|
986
|
+
`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`,
|
|
987
|
+
);
|
|
764
988
|
} else {
|
|
765
|
-
this.windowService?.updateCharacteristic(
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
this.
|
|
989
|
+
this.windowService?.updateCharacteristic(
|
|
990
|
+
this.platform.Characteristic.TargetPosition,
|
|
991
|
+
0,
|
|
992
|
+
);
|
|
993
|
+
this.windowService?.updateCharacteristic(
|
|
994
|
+
this.platform.Characteristic.CurrentPosition,
|
|
995
|
+
0,
|
|
996
|
+
);
|
|
997
|
+
this.windowService?.updateCharacteristic(
|
|
998
|
+
this.platform.Characteristic.PositionState,
|
|
999
|
+
this.platform.Characteristic.PositionState.STOPPED,
|
|
1000
|
+
);
|
|
1001
|
+
this.debugLog(
|
|
1002
|
+
`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`,
|
|
1003
|
+
);
|
|
770
1004
|
}
|
|
771
1005
|
}
|
|
772
1006
|
this.debugLog(`Bot: ${this.accessory.displayName} Window On: ${this.On}`);
|
|
773
|
-
} else if (this.device.bot?.deviceType ===
|
|
1007
|
+
} else if (this.device.bot?.deviceType === "windowcovering") {
|
|
774
1008
|
if (this.On === undefined) {
|
|
775
1009
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
776
1010
|
} else {
|
|
777
1011
|
if (this.On) {
|
|
778
|
-
this.windowCoveringService?.updateCharacteristic(
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
this.
|
|
1012
|
+
this.windowCoveringService?.updateCharacteristic(
|
|
1013
|
+
this.platform.Characteristic.TargetPosition,
|
|
1014
|
+
100,
|
|
1015
|
+
);
|
|
1016
|
+
this.windowCoveringService?.updateCharacteristic(
|
|
1017
|
+
this.platform.Characteristic.CurrentPosition,
|
|
1018
|
+
100,
|
|
1019
|
+
);
|
|
1020
|
+
this.windowCoveringService?.updateCharacteristic(
|
|
1021
|
+
this.platform.Characteristic.PositionState,
|
|
1022
|
+
this.platform.Characteristic.PositionState.STOPPED,
|
|
1023
|
+
);
|
|
1024
|
+
this.debugLog(
|
|
1025
|
+
`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`,
|
|
1026
|
+
);
|
|
783
1027
|
} else {
|
|
784
|
-
this.windowCoveringService?.updateCharacteristic(
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
this.
|
|
1028
|
+
this.windowCoveringService?.updateCharacteristic(
|
|
1029
|
+
this.platform.Characteristic.TargetPosition,
|
|
1030
|
+
0,
|
|
1031
|
+
);
|
|
1032
|
+
this.windowCoveringService?.updateCharacteristic(
|
|
1033
|
+
this.platform.Characteristic.CurrentPosition,
|
|
1034
|
+
0,
|
|
1035
|
+
);
|
|
1036
|
+
this.windowCoveringService?.updateCharacteristic(
|
|
1037
|
+
this.platform.Characteristic.PositionState,
|
|
1038
|
+
this.platform.Characteristic.PositionState.STOPPED,
|
|
1039
|
+
);
|
|
1040
|
+
this.debugLog(
|
|
1041
|
+
`Bot: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`,
|
|
1042
|
+
);
|
|
789
1043
|
}
|
|
790
1044
|
}
|
|
791
|
-
this.debugLog(
|
|
792
|
-
|
|
1045
|
+
this.debugLog(
|
|
1046
|
+
`Bot: ${this.accessory.displayName} Window Covering On: ${this.On}`,
|
|
1047
|
+
);
|
|
1048
|
+
} else if (this.device.bot?.deviceType === "lock") {
|
|
793
1049
|
if (this.On === undefined) {
|
|
794
1050
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
795
1051
|
} else {
|
|
796
1052
|
if (this.On) {
|
|
797
|
-
this.lockService?.updateCharacteristic(
|
|
798
|
-
this.platform.Characteristic.LockTargetState
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
this.
|
|
1053
|
+
this.lockService?.updateCharacteristic(
|
|
1054
|
+
this.platform.Characteristic.LockTargetState,
|
|
1055
|
+
this.platform.Characteristic.LockTargetState.UNSECURED,
|
|
1056
|
+
);
|
|
1057
|
+
this.lockService?.updateCharacteristic(
|
|
1058
|
+
this.platform.Characteristic.LockCurrentState,
|
|
1059
|
+
this.platform.Characteristic.LockCurrentState.UNSECURED,
|
|
1060
|
+
);
|
|
1061
|
+
this.debugLog(
|
|
1062
|
+
`Bot: ${this.accessory.displayName} updateCharacteristic LockTargetState: UNSECURED, LockCurrentState: UNSECURED`,
|
|
1063
|
+
);
|
|
802
1064
|
} else {
|
|
803
|
-
this.lockService?.updateCharacteristic(
|
|
804
|
-
this.platform.Characteristic.LockTargetState
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
this.
|
|
1065
|
+
this.lockService?.updateCharacteristic(
|
|
1066
|
+
this.platform.Characteristic.LockTargetState,
|
|
1067
|
+
this.platform.Characteristic.LockTargetState.SECURED,
|
|
1068
|
+
);
|
|
1069
|
+
this.lockService?.updateCharacteristic(
|
|
1070
|
+
this.platform.Characteristic.LockCurrentState,
|
|
1071
|
+
this.platform.Characteristic.LockCurrentState.SECURED,
|
|
1072
|
+
);
|
|
1073
|
+
this.debugLog(
|
|
1074
|
+
`Bot: ${this.accessory.displayName} updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED`,
|
|
1075
|
+
);
|
|
808
1076
|
}
|
|
809
1077
|
}
|
|
810
1078
|
this.debugLog(`Bot: ${this.accessory.displayName} Lock On: ${this.On}`);
|
|
811
|
-
} else if (this.device.bot?.deviceType ===
|
|
1079
|
+
} else if (this.device.bot?.deviceType === "faucet") {
|
|
812
1080
|
if (this.On === undefined) {
|
|
813
1081
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
814
1082
|
} else {
|
|
815
1083
|
if (this.On) {
|
|
816
|
-
this.faucetService?.updateCharacteristic(
|
|
817
|
-
this.platform.Characteristic.Active
|
|
818
|
-
|
|
1084
|
+
this.faucetService?.updateCharacteristic(
|
|
1085
|
+
this.platform.Characteristic.Active,
|
|
1086
|
+
this.platform.Characteristic.Active.ACTIVE,
|
|
1087
|
+
);
|
|
1088
|
+
this.debugLog(
|
|
1089
|
+
`Bot: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`,
|
|
1090
|
+
);
|
|
819
1091
|
} else {
|
|
820
|
-
this.faucetService?.updateCharacteristic(
|
|
821
|
-
this.platform.Characteristic.Active
|
|
822
|
-
|
|
1092
|
+
this.faucetService?.updateCharacteristic(
|
|
1093
|
+
this.platform.Characteristic.Active,
|
|
1094
|
+
this.platform.Characteristic.Active.INACTIVE,
|
|
1095
|
+
);
|
|
1096
|
+
this.debugLog(
|
|
1097
|
+
`Bot: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`,
|
|
1098
|
+
);
|
|
823
1099
|
}
|
|
824
1100
|
}
|
|
825
1101
|
this.debugLog(`Bot: ${this.accessory.displayName} Faucet On: ${this.On}`);
|
|
826
|
-
} else if (this.device.bot?.deviceType ===
|
|
1102
|
+
} else if (this.device.bot?.deviceType === "fan") {
|
|
827
1103
|
if (this.On === undefined) {
|
|
828
1104
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
829
1105
|
} else {
|
|
830
1106
|
if (this.On) {
|
|
831
|
-
this.fanService?.updateCharacteristic(
|
|
832
|
-
|
|
1107
|
+
this.fanService?.updateCharacteristic(
|
|
1108
|
+
this.platform.Characteristic.On,
|
|
1109
|
+
this.On,
|
|
1110
|
+
);
|
|
1111
|
+
this.debugLog(
|
|
1112
|
+
`Bot: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`,
|
|
1113
|
+
);
|
|
833
1114
|
} else {
|
|
834
|
-
this.fanService?.updateCharacteristic(
|
|
835
|
-
|
|
1115
|
+
this.fanService?.updateCharacteristic(
|
|
1116
|
+
this.platform.Characteristic.On,
|
|
1117
|
+
this.On,
|
|
1118
|
+
);
|
|
1119
|
+
this.debugLog(
|
|
1120
|
+
`Bot: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`,
|
|
1121
|
+
);
|
|
836
1122
|
}
|
|
837
1123
|
}
|
|
838
1124
|
this.debugLog(`Bot: ${this.accessory.displayName} Fan On: ${this.On}`);
|
|
839
|
-
} else if (this.device.bot?.deviceType ===
|
|
1125
|
+
} else if (this.device.bot?.deviceType === "stateful") {
|
|
840
1126
|
if (this.On === undefined) {
|
|
841
1127
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
842
1128
|
} else {
|
|
843
1129
|
if (this.On) {
|
|
844
|
-
this.statefulProgrammableSwitchService?.updateCharacteristic(
|
|
845
|
-
this.platform.Characteristic.ProgrammableSwitchEvent
|
|
846
|
-
|
|
847
|
-
|
|
1130
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(
|
|
1131
|
+
this.platform.Characteristic.ProgrammableSwitchEvent,
|
|
1132
|
+
this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
|
|
1133
|
+
);
|
|
1134
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(
|
|
1135
|
+
this.platform.Characteristic.ProgrammableSwitchOutputState,
|
|
1136
|
+
1,
|
|
1137
|
+
);
|
|
1138
|
+
this.debugLog(
|
|
1139
|
+
`Bot: ${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1`,
|
|
1140
|
+
);
|
|
848
1141
|
} else {
|
|
849
|
-
this.statefulProgrammableSwitchService?.updateCharacteristic(
|
|
850
|
-
this.platform.Characteristic.ProgrammableSwitchEvent
|
|
851
|
-
|
|
852
|
-
|
|
1142
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(
|
|
1143
|
+
this.platform.Characteristic.ProgrammableSwitchEvent,
|
|
1144
|
+
this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
|
|
1145
|
+
);
|
|
1146
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(
|
|
1147
|
+
this.platform.Characteristic.ProgrammableSwitchOutputState,
|
|
1148
|
+
0,
|
|
1149
|
+
);
|
|
1150
|
+
this.debugLog(
|
|
1151
|
+
`Bot: ${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0`,
|
|
1152
|
+
);
|
|
853
1153
|
}
|
|
854
1154
|
}
|
|
855
|
-
this.debugLog(
|
|
856
|
-
|
|
1155
|
+
this.debugLog(
|
|
1156
|
+
`Bot: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.On}`,
|
|
1157
|
+
);
|
|
1158
|
+
} else if (this.device.bot?.deviceType === "switch") {
|
|
857
1159
|
if (this.On === undefined) {
|
|
858
1160
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
859
1161
|
} else {
|
|
860
|
-
this.switchService?.updateCharacteristic(
|
|
861
|
-
|
|
1162
|
+
this.switchService?.updateCharacteristic(
|
|
1163
|
+
this.platform.Characteristic.On,
|
|
1164
|
+
this.On,
|
|
1165
|
+
);
|
|
1166
|
+
this.debugLog(
|
|
1167
|
+
`Bot: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`,
|
|
1168
|
+
);
|
|
862
1169
|
}
|
|
863
1170
|
} else {
|
|
864
1171
|
if (this.On === undefined) {
|
|
865
1172
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
866
1173
|
} else {
|
|
867
|
-
this.outletService?.updateCharacteristic(
|
|
868
|
-
|
|
1174
|
+
this.outletService?.updateCharacteristic(
|
|
1175
|
+
this.platform.Characteristic.On,
|
|
1176
|
+
this.On,
|
|
1177
|
+
);
|
|
1178
|
+
this.debugLog(
|
|
1179
|
+
`Bot: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`,
|
|
1180
|
+
);
|
|
869
1181
|
}
|
|
870
1182
|
}
|
|
871
1183
|
if (this.device.ble) {
|
|
872
1184
|
if (this.BatteryLevel === undefined) {
|
|
873
|
-
this.debugLog(
|
|
1185
|
+
this.debugLog(
|
|
1186
|
+
`Bot: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`,
|
|
1187
|
+
);
|
|
874
1188
|
} else {
|
|
875
|
-
this.batteryService?.updateCharacteristic(
|
|
876
|
-
|
|
1189
|
+
this.batteryService?.updateCharacteristic(
|
|
1190
|
+
this.platform.Characteristic.BatteryLevel,
|
|
1191
|
+
this.BatteryLevel,
|
|
1192
|
+
);
|
|
1193
|
+
this.debugLog(
|
|
1194
|
+
`Bot: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`,
|
|
1195
|
+
);
|
|
877
1196
|
}
|
|
878
1197
|
if (this.StatusLowBattery === undefined) {
|
|
879
|
-
this.debugLog(
|
|
1198
|
+
this.debugLog(
|
|
1199
|
+
`Bot: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`,
|
|
1200
|
+
);
|
|
880
1201
|
} else {
|
|
881
|
-
this.batteryService?.updateCharacteristic(
|
|
882
|
-
|
|
1202
|
+
this.batteryService?.updateCharacteristic(
|
|
1203
|
+
this.platform.Characteristic.StatusLowBattery,
|
|
1204
|
+
this.StatusLowBattery,
|
|
1205
|
+
);
|
|
1206
|
+
this.debugLog(
|
|
1207
|
+
`Bot: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`,
|
|
1208
|
+
);
|
|
883
1209
|
}
|
|
884
1210
|
}
|
|
885
1211
|
}
|
|
886
1212
|
|
|
887
1213
|
public apiError(e: any) {
|
|
888
|
-
if (this.device.bot?.deviceType ===
|
|
889
|
-
this.garageDoorService?.updateCharacteristic(
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
this.
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
this.
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
this.
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
this.doorService?.updateCharacteristic(
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
1214
|
+
if (this.device.bot?.deviceType === "garagedoor") {
|
|
1215
|
+
this.garageDoorService?.updateCharacteristic(
|
|
1216
|
+
this.platform.Characteristic.TargetDoorState,
|
|
1217
|
+
e,
|
|
1218
|
+
);
|
|
1219
|
+
this.garageDoorService?.updateCharacteristic(
|
|
1220
|
+
this.platform.Characteristic.CurrentDoorState,
|
|
1221
|
+
e,
|
|
1222
|
+
);
|
|
1223
|
+
this.garageDoorService?.updateCharacteristic(
|
|
1224
|
+
this.platform.Characteristic.ObstructionDetected,
|
|
1225
|
+
e,
|
|
1226
|
+
);
|
|
1227
|
+
} else if (this.device.bot?.deviceType === "door") {
|
|
1228
|
+
this.doorService?.updateCharacteristic(
|
|
1229
|
+
this.platform.Characteristic.TargetPosition,
|
|
1230
|
+
e,
|
|
1231
|
+
);
|
|
1232
|
+
this.doorService?.updateCharacteristic(
|
|
1233
|
+
this.platform.Characteristic.CurrentPosition,
|
|
1234
|
+
e,
|
|
1235
|
+
);
|
|
1236
|
+
this.doorService?.updateCharacteristic(
|
|
1237
|
+
this.platform.Characteristic.PositionState,
|
|
1238
|
+
e,
|
|
1239
|
+
);
|
|
1240
|
+
} else if (this.device.bot?.deviceType === "window") {
|
|
1241
|
+
this.windowService?.updateCharacteristic(
|
|
1242
|
+
this.platform.Characteristic.TargetPosition,
|
|
1243
|
+
e,
|
|
1244
|
+
);
|
|
1245
|
+
this.windowService?.updateCharacteristic(
|
|
1246
|
+
this.platform.Characteristic.CurrentPosition,
|
|
1247
|
+
e,
|
|
1248
|
+
);
|
|
1249
|
+
this.windowService?.updateCharacteristic(
|
|
1250
|
+
this.platform.Characteristic.PositionState,
|
|
1251
|
+
e,
|
|
1252
|
+
);
|
|
1253
|
+
} else if (this.device.bot?.deviceType === "windowcovering") {
|
|
1254
|
+
this.windowCoveringService?.updateCharacteristic(
|
|
1255
|
+
this.platform.Characteristic.TargetPosition,
|
|
1256
|
+
e,
|
|
1257
|
+
);
|
|
1258
|
+
this.windowCoveringService?.updateCharacteristic(
|
|
1259
|
+
this.platform.Characteristic.CurrentPosition,
|
|
1260
|
+
e,
|
|
1261
|
+
);
|
|
1262
|
+
this.windowCoveringService?.updateCharacteristic(
|
|
1263
|
+
this.platform.Characteristic.PositionState,
|
|
1264
|
+
e,
|
|
1265
|
+
);
|
|
1266
|
+
} else if (this.device.bot?.deviceType === "lock") {
|
|
1267
|
+
this.doorService?.updateCharacteristic(
|
|
1268
|
+
this.platform.Characteristic.LockTargetState,
|
|
1269
|
+
e,
|
|
1270
|
+
);
|
|
1271
|
+
this.doorService?.updateCharacteristic(
|
|
1272
|
+
this.platform.Characteristic.LockCurrentState,
|
|
1273
|
+
e,
|
|
1274
|
+
);
|
|
1275
|
+
} else if (this.device.bot?.deviceType === "faucet") {
|
|
1276
|
+
this.faucetService?.updateCharacteristic(
|
|
1277
|
+
this.platform.Characteristic.Active,
|
|
1278
|
+
e,
|
|
1279
|
+
);
|
|
1280
|
+
} else if (this.device.bot?.deviceType === "fan") {
|
|
910
1281
|
this.fanService?.updateCharacteristic(this.platform.Characteristic.On, e);
|
|
911
|
-
} else if (this.device.bot?.deviceType ===
|
|
912
|
-
this.statefulProgrammableSwitchService?.updateCharacteristic(
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
1282
|
+
} else if (this.device.bot?.deviceType === "stateful") {
|
|
1283
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(
|
|
1284
|
+
this.platform.Characteristic.ProgrammableSwitchEvent,
|
|
1285
|
+
e,
|
|
1286
|
+
);
|
|
1287
|
+
this.statefulProgrammableSwitchService?.updateCharacteristic(
|
|
1288
|
+
this.platform.Characteristic.ProgrammableSwitchOutputState,
|
|
1289
|
+
e,
|
|
1290
|
+
);
|
|
1291
|
+
} else if (this.device.bot?.deviceType === "switch") {
|
|
1292
|
+
this.switchService?.updateCharacteristic(
|
|
1293
|
+
this.platform.Characteristic.On,
|
|
1294
|
+
e,
|
|
1295
|
+
);
|
|
916
1296
|
} else {
|
|
917
|
-
this.outletService?.updateCharacteristic(
|
|
1297
|
+
this.outletService?.updateCharacteristic(
|
|
1298
|
+
this.platform.Characteristic.On,
|
|
1299
|
+
e,
|
|
1300
|
+
);
|
|
918
1301
|
}
|
|
919
1302
|
if (this.device.ble) {
|
|
920
|
-
this.batteryService?.updateCharacteristic(
|
|
921
|
-
|
|
1303
|
+
this.batteryService?.updateCharacteristic(
|
|
1304
|
+
this.platform.Characteristic.BatteryLevel,
|
|
1305
|
+
e,
|
|
1306
|
+
);
|
|
1307
|
+
this.batteryService?.updateCharacteristic(
|
|
1308
|
+
this.platform.Characteristic.StatusLowBattery,
|
|
1309
|
+
e,
|
|
1310
|
+
);
|
|
922
1311
|
}
|
|
923
1312
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
924
1313
|
}
|
|
925
1314
|
|
|
926
|
-
private statusCode(push: AxiosResponse<{ statusCode: number
|
|
1315
|
+
private statusCode(push: axios.AxiosResponse<{ statusCode: number }>) {
|
|
927
1316
|
switch (push.data.statusCode) {
|
|
928
1317
|
case 151:
|
|
929
|
-
this.errorLog(
|
|
1318
|
+
this.errorLog(
|
|
1319
|
+
`Bot: ${this.accessory.displayName} Command not supported by this device type.`,
|
|
1320
|
+
);
|
|
930
1321
|
break;
|
|
931
1322
|
case 152:
|
|
932
1323
|
this.errorLog(`Bot: ${this.accessory.displayName} Device not found.`);
|
|
933
1324
|
break;
|
|
934
1325
|
case 160:
|
|
935
|
-
this.errorLog(
|
|
1326
|
+
this.errorLog(
|
|
1327
|
+
`Bot: ${this.accessory.displayName} Command is not supported.`,
|
|
1328
|
+
);
|
|
936
1329
|
break;
|
|
937
1330
|
case 161:
|
|
938
1331
|
this.errorLog(`Bot: ${this.accessory.displayName} Device is offline.`);
|
|
939
1332
|
this.offlineOff();
|
|
940
1333
|
break;
|
|
941
1334
|
case 171:
|
|
942
|
-
this.errorLog(
|
|
1335
|
+
this.errorLog(
|
|
1336
|
+
`Bot: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
|
|
1337
|
+
);
|
|
943
1338
|
this.offlineOff();
|
|
944
1339
|
break;
|
|
945
1340
|
case 190:
|
|
946
|
-
this.errorLog(
|
|
947
|
-
|
|
1341
|
+
this.errorLog(
|
|
1342
|
+
`Bot: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
1343
|
+
` Or command: ${JSON.stringify(push.data)} format is invalid`,
|
|
1344
|
+
);
|
|
948
1345
|
break;
|
|
949
1346
|
case 100:
|
|
950
|
-
this.debugLog(
|
|
1347
|
+
this.debugLog(
|
|
1348
|
+
`Bot: ${this.accessory.displayName} Command successfully sent.`,
|
|
1349
|
+
);
|
|
951
1350
|
break;
|
|
952
1351
|
default:
|
|
953
1352
|
this.debugLog(`Bot: ${this.accessory.displayName} Unknown statusCode.`);
|
|
@@ -957,10 +1356,14 @@ export class Bot {
|
|
|
957
1356
|
private offlineOff() {
|
|
958
1357
|
if (this.device.offline) {
|
|
959
1358
|
this.On = false;
|
|
960
|
-
if (this.device.bot?.deviceType ===
|
|
961
|
-
this.switchService
|
|
1359
|
+
if (this.device.bot?.deviceType === "switch") {
|
|
1360
|
+
this.switchService
|
|
1361
|
+
?.getCharacteristic(this.platform.Characteristic.On)
|
|
1362
|
+
.updateValue(this.On);
|
|
962
1363
|
} else {
|
|
963
|
-
this.outletService
|
|
1364
|
+
this.outletService
|
|
1365
|
+
?.getCharacteristic(this.platform.Characteristic.On)
|
|
1366
|
+
.updateValue(this.On);
|
|
964
1367
|
}
|
|
965
1368
|
}
|
|
966
1369
|
}
|
|
@@ -968,39 +1371,49 @@ export class Bot {
|
|
|
968
1371
|
/**
|
|
969
1372
|
* Handle requests to set the "On" characteristic
|
|
970
1373
|
*/
|
|
971
|
-
private handleOnSet(value: CharacteristicValue) {
|
|
972
|
-
if (this.device.bot?.deviceType ===
|
|
973
|
-
this.debugLog(
|
|
1374
|
+
private handleOnSet(value: homebridge.CharacteristicValue) {
|
|
1375
|
+
if (this.device.bot?.deviceType === "garagedoor") {
|
|
1376
|
+
this.debugLog(
|
|
1377
|
+
`Bot: ${this.accessory.displayName} TargetDoorState: ${value}`,
|
|
1378
|
+
);
|
|
974
1379
|
if (value === this.platform.Characteristic.TargetDoorState.CLOSED) {
|
|
975
1380
|
this.On = false;
|
|
976
1381
|
} else {
|
|
977
1382
|
this.On = true;
|
|
978
1383
|
}
|
|
979
|
-
} else if (
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
this.
|
|
1384
|
+
} else if (
|
|
1385
|
+
this.device.bot?.deviceType === "door" ||
|
|
1386
|
+
this.device.bot?.deviceType === "window" ||
|
|
1387
|
+
this.device.bot?.deviceType === "windowcovering"
|
|
1388
|
+
) {
|
|
1389
|
+
this.debugLog(
|
|
1390
|
+
`Bot: ${this.accessory.displayName} TargetPosition: ${value}`,
|
|
1391
|
+
);
|
|
983
1392
|
if (value === 0) {
|
|
984
1393
|
this.On = false;
|
|
985
1394
|
} else {
|
|
986
1395
|
this.On = true;
|
|
987
1396
|
}
|
|
988
|
-
} else if (this.device.bot?.deviceType ===
|
|
989
|
-
this.debugLog(
|
|
1397
|
+
} else if (this.device.bot?.deviceType === "lock") {
|
|
1398
|
+
this.debugLog(
|
|
1399
|
+
`Bot: ${this.accessory.displayName} LockTargetState: ${value}`,
|
|
1400
|
+
);
|
|
990
1401
|
if (value === this.platform.Characteristic.LockTargetState.SECURED) {
|
|
991
1402
|
this.On = false;
|
|
992
1403
|
} else {
|
|
993
1404
|
this.On = true;
|
|
994
1405
|
}
|
|
995
|
-
} else if (this.device.bot?.deviceType ===
|
|
1406
|
+
} else if (this.device.bot?.deviceType === "faucet") {
|
|
996
1407
|
this.debugLog(`Bot: ${this.accessory.displayName} Active: ${value}`);
|
|
997
1408
|
if (value === this.platform.Characteristic.Active.INACTIVE) {
|
|
998
1409
|
this.On = false;
|
|
999
1410
|
} else {
|
|
1000
1411
|
this.On = true;
|
|
1001
1412
|
}
|
|
1002
|
-
} else if (this.device.bot?.deviceType ===
|
|
1003
|
-
this.debugLog(
|
|
1413
|
+
} else if (this.device.bot?.deviceType === "stateful") {
|
|
1414
|
+
this.debugLog(
|
|
1415
|
+
`Bot: ${this.accessory.displayName} ProgrammableSwitchOutputState: ${value}`,
|
|
1416
|
+
);
|
|
1004
1417
|
if (value === 0) {
|
|
1005
1418
|
this.On = false;
|
|
1006
1419
|
} else {
|
|
@@ -1013,177 +1426,247 @@ export class Bot {
|
|
|
1013
1426
|
this.doBotUpdate.next();
|
|
1014
1427
|
}
|
|
1015
1428
|
|
|
1016
|
-
config(device: device & devicesConfig) {
|
|
1429
|
+
config(device: settings.device & settings.devicesConfig) {
|
|
1017
1430
|
let config = {};
|
|
1018
1431
|
if (device.bot) {
|
|
1019
1432
|
config = device.bot;
|
|
1020
1433
|
}
|
|
1021
1434
|
if (device.ble) {
|
|
1022
|
-
config[
|
|
1435
|
+
config["ble"] = device.ble;
|
|
1023
1436
|
}
|
|
1024
1437
|
if (device.logging !== undefined) {
|
|
1025
|
-
config[
|
|
1438
|
+
config["logging"] = device.logging;
|
|
1026
1439
|
}
|
|
1027
1440
|
if (device.refreshRate !== undefined) {
|
|
1028
|
-
config[
|
|
1441
|
+
config["refreshRate"] = device.refreshRate;
|
|
1029
1442
|
}
|
|
1030
1443
|
if (device.scanDuration !== undefined) {
|
|
1031
|
-
config[
|
|
1444
|
+
config["scanDuration"] = device.scanDuration;
|
|
1032
1445
|
}
|
|
1033
1446
|
if (Object.entries(config).length !== 0) {
|
|
1034
|
-
this.warnLog(
|
|
1447
|
+
this.warnLog(
|
|
1448
|
+
`Bot: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`,
|
|
1449
|
+
);
|
|
1035
1450
|
}
|
|
1036
1451
|
}
|
|
1037
1452
|
|
|
1038
|
-
refreshRate(device: device & devicesConfig) {
|
|
1453
|
+
refreshRate(device: settings.device & settings.devicesConfig) {
|
|
1039
1454
|
if (device.refreshRate) {
|
|
1040
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
1041
|
-
|
|
1455
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
1456
|
+
device.refreshRate;
|
|
1457
|
+
this.debugLog(
|
|
1458
|
+
`Bot: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`,
|
|
1459
|
+
);
|
|
1042
1460
|
} else if (this.platform.config.options!.refreshRate) {
|
|
1043
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
1044
|
-
|
|
1461
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
1462
|
+
this.platform.config.options!.refreshRate;
|
|
1463
|
+
this.debugLog(
|
|
1464
|
+
`Bot: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`,
|
|
1465
|
+
);
|
|
1045
1466
|
}
|
|
1046
1467
|
}
|
|
1047
1468
|
|
|
1048
|
-
scan(device: device & devicesConfig) {
|
|
1469
|
+
scan(device: settings.device & settings.devicesConfig) {
|
|
1049
1470
|
if (device.scanDuration) {
|
|
1050
|
-
this.scanDuration = this.accessory.context.scanDuration =
|
|
1471
|
+
this.scanDuration = this.accessory.context.scanDuration =
|
|
1472
|
+
device.scanDuration;
|
|
1051
1473
|
if (device.ble) {
|
|
1052
|
-
this.debugLog(
|
|
1474
|
+
this.debugLog(
|
|
1475
|
+
`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`,
|
|
1476
|
+
);
|
|
1053
1477
|
}
|
|
1054
1478
|
} else {
|
|
1055
1479
|
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
1056
1480
|
if (this.device.ble) {
|
|
1057
|
-
this.debugLog(
|
|
1481
|
+
this.debugLog(
|
|
1482
|
+
`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`,
|
|
1483
|
+
);
|
|
1058
1484
|
}
|
|
1059
1485
|
}
|
|
1060
1486
|
}
|
|
1061
1487
|
|
|
1062
|
-
logs(device: device & devicesConfig) {
|
|
1488
|
+
logs(device: settings.device & settings.devicesConfig) {
|
|
1063
1489
|
if (this.platform.debugMode) {
|
|
1064
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
1065
|
-
this.debugLog(
|
|
1490
|
+
this.deviceLogging = this.accessory.context.logging = "debugMode";
|
|
1491
|
+
this.debugLog(
|
|
1492
|
+
`Bot: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
|
|
1493
|
+
);
|
|
1066
1494
|
} else if (device.logging) {
|
|
1067
1495
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
1068
|
-
this.debugLog(
|
|
1496
|
+
this.debugLog(
|
|
1497
|
+
`Bot: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
|
|
1498
|
+
);
|
|
1069
1499
|
} else if (this.platform.config.options?.logging) {
|
|
1070
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
1071
|
-
|
|
1500
|
+
this.deviceLogging = this.accessory.context.logging =
|
|
1501
|
+
this.platform.config.options?.logging;
|
|
1502
|
+
this.debugLog(
|
|
1503
|
+
`Bot: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
|
|
1504
|
+
);
|
|
1072
1505
|
} else {
|
|
1073
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
1074
|
-
this.debugLog(
|
|
1506
|
+
this.deviceLogging = this.accessory.context.logging = "standard";
|
|
1507
|
+
this.debugLog(
|
|
1508
|
+
`Bot: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
|
|
1509
|
+
);
|
|
1075
1510
|
}
|
|
1076
1511
|
}
|
|
1077
1512
|
|
|
1078
|
-
PressOrSwitch(device: device & devicesConfig) {
|
|
1513
|
+
PressOrSwitch(device: settings.device & settings.devicesConfig) {
|
|
1079
1514
|
if (!device.bot?.mode) {
|
|
1080
|
-
this.botMode =
|
|
1081
|
-
this.warnLog(
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
this.
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
this.
|
|
1515
|
+
this.botMode = "switch";
|
|
1516
|
+
this.warnLog(
|
|
1517
|
+
`Bot: ${this.accessory.displayName} does not have bot mode set in the Plugin's SwitchBot Device Settings,`,
|
|
1518
|
+
);
|
|
1519
|
+
this.warnLog(
|
|
1520
|
+
`Bot: ${this.accessory.displayName} is defaulting to "${this.botMode}" mode, you may experience issues.`,
|
|
1521
|
+
);
|
|
1522
|
+
} else if (device.bot?.mode === "switch") {
|
|
1523
|
+
this.botMode = "switch";
|
|
1524
|
+
this.debugLog(
|
|
1525
|
+
`Bot: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`,
|
|
1526
|
+
);
|
|
1527
|
+
} else if (device.bot?.mode === "press") {
|
|
1528
|
+
this.botMode = "press";
|
|
1529
|
+
this.debugLog(
|
|
1530
|
+
`Bot: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`,
|
|
1531
|
+
);
|
|
1089
1532
|
} else {
|
|
1090
|
-
throw new Error(
|
|
1533
|
+
throw new Error(
|
|
1534
|
+
`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`,
|
|
1535
|
+
);
|
|
1091
1536
|
}
|
|
1092
1537
|
}
|
|
1093
1538
|
|
|
1094
|
-
public removeOutletService(accessory: PlatformAccessory) {
|
|
1539
|
+
public removeOutletService(accessory: homebridge.PlatformAccessory) {
|
|
1095
1540
|
// If outletService still pressent, then remove first
|
|
1096
|
-
this.outletService = this.accessory.getService(
|
|
1541
|
+
this.outletService = this.accessory.getService(
|
|
1542
|
+
this.platform.Service.Outlet,
|
|
1543
|
+
);
|
|
1097
1544
|
if (this.outletService) {
|
|
1098
|
-
this.warnLog(
|
|
1545
|
+
this.warnLog(
|
|
1546
|
+
`Bot: ${accessory.displayName} Removing Leftover Outlet Service`,
|
|
1547
|
+
);
|
|
1099
1548
|
}
|
|
1100
1549
|
accessory.removeService(this.outletService!);
|
|
1101
1550
|
}
|
|
1102
1551
|
|
|
1103
|
-
public removeGarageDoorService(accessory: PlatformAccessory) {
|
|
1552
|
+
public removeGarageDoorService(accessory: homebridge.PlatformAccessory) {
|
|
1104
1553
|
// If garageDoorService still pressent, then remove first
|
|
1105
|
-
this.garageDoorService = this.accessory.getService(
|
|
1554
|
+
this.garageDoorService = this.accessory.getService(
|
|
1555
|
+
this.platform.Service.GarageDoorOpener,
|
|
1556
|
+
);
|
|
1106
1557
|
if (this.garageDoorService) {
|
|
1107
|
-
this.warnLog(
|
|
1558
|
+
this.warnLog(
|
|
1559
|
+
`Bot: ${accessory.displayName} Removing Leftover Garage Door Service`,
|
|
1560
|
+
);
|
|
1108
1561
|
}
|
|
1109
1562
|
accessory.removeService(this.garageDoorService!);
|
|
1110
1563
|
}
|
|
1111
1564
|
|
|
1112
|
-
public removeDoorService(accessory: PlatformAccessory) {
|
|
1565
|
+
public removeDoorService(accessory: homebridge.PlatformAccessory) {
|
|
1113
1566
|
// If doorService still pressent, then remove first
|
|
1114
1567
|
this.doorService = this.accessory.getService(this.platform.Service.Door);
|
|
1115
1568
|
if (this.doorService) {
|
|
1116
|
-
this.warnLog(
|
|
1569
|
+
this.warnLog(
|
|
1570
|
+
`Bot: ${accessory.displayName} Removing Leftover Door Service`,
|
|
1571
|
+
);
|
|
1117
1572
|
}
|
|
1118
1573
|
accessory.removeService(this.doorService!);
|
|
1119
1574
|
}
|
|
1120
1575
|
|
|
1121
|
-
public removeLockService(accessory: PlatformAccessory) {
|
|
1576
|
+
public removeLockService(accessory: homebridge.PlatformAccessory) {
|
|
1122
1577
|
// If lockService still pressent, then remove first
|
|
1123
|
-
this.lockService = this.accessory.getService(
|
|
1578
|
+
this.lockService = this.accessory.getService(
|
|
1579
|
+
this.platform.Service.LockMechanism,
|
|
1580
|
+
);
|
|
1124
1581
|
if (this.lockService) {
|
|
1125
|
-
this.warnLog(
|
|
1582
|
+
this.warnLog(
|
|
1583
|
+
`Bot: ${accessory.displayName} Removing Leftover Lock Service`,
|
|
1584
|
+
);
|
|
1126
1585
|
}
|
|
1127
1586
|
accessory.removeService(this.lockService!);
|
|
1128
1587
|
}
|
|
1129
1588
|
|
|
1130
|
-
public removeFaucetService(accessory: PlatformAccessory) {
|
|
1589
|
+
public removeFaucetService(accessory: homebridge.PlatformAccessory) {
|
|
1131
1590
|
// If faucetService still pressent, then remove first
|
|
1132
|
-
this.faucetService = this.accessory.getService(
|
|
1591
|
+
this.faucetService = this.accessory.getService(
|
|
1592
|
+
this.platform.Service.Faucet,
|
|
1593
|
+
);
|
|
1133
1594
|
if (this.faucetService) {
|
|
1134
|
-
this.warnLog(
|
|
1595
|
+
this.warnLog(
|
|
1596
|
+
`Bot: ${accessory.displayName} Removing Leftover Faucet Service`,
|
|
1597
|
+
);
|
|
1135
1598
|
}
|
|
1136
1599
|
accessory.removeService(this.faucetService!);
|
|
1137
1600
|
}
|
|
1138
1601
|
|
|
1139
|
-
public removeFanService(accessory: PlatformAccessory) {
|
|
1602
|
+
public removeFanService(accessory: homebridge.PlatformAccessory) {
|
|
1140
1603
|
// If fanService still pressent, then remove first
|
|
1141
1604
|
this.fanService = this.accessory.getService(this.platform.Service.Fan);
|
|
1142
1605
|
if (this.fanService) {
|
|
1143
|
-
this.warnLog(
|
|
1606
|
+
this.warnLog(
|
|
1607
|
+
`Bot: ${accessory.displayName} Removing Leftover Fan Service`,
|
|
1608
|
+
);
|
|
1144
1609
|
}
|
|
1145
1610
|
accessory.removeService(this.fanService!);
|
|
1146
1611
|
}
|
|
1147
1612
|
|
|
1148
|
-
public removeWindowService(accessory: PlatformAccessory) {
|
|
1613
|
+
public removeWindowService(accessory: homebridge.PlatformAccessory) {
|
|
1149
1614
|
// If windowService still pressent, then remove first
|
|
1150
|
-
this.windowService = this.accessory.getService(
|
|
1615
|
+
this.windowService = this.accessory.getService(
|
|
1616
|
+
this.platform.Service.Window,
|
|
1617
|
+
);
|
|
1151
1618
|
if (this.windowService) {
|
|
1152
|
-
this.warnLog(
|
|
1619
|
+
this.warnLog(
|
|
1620
|
+
`Bot: ${accessory.displayName} Removing Leftover Window Service`,
|
|
1621
|
+
);
|
|
1153
1622
|
}
|
|
1154
1623
|
accessory.removeService(this.windowService!);
|
|
1155
1624
|
}
|
|
1156
1625
|
|
|
1157
|
-
public removeWindowCoveringService(accessory: PlatformAccessory) {
|
|
1626
|
+
public removeWindowCoveringService(accessory: homebridge.PlatformAccessory) {
|
|
1158
1627
|
// If windowCoveringService still pressent, then remove first
|
|
1159
|
-
this.windowCoveringService = this.accessory.getService(
|
|
1628
|
+
this.windowCoveringService = this.accessory.getService(
|
|
1629
|
+
this.platform.Service.WindowCovering,
|
|
1630
|
+
);
|
|
1160
1631
|
if (this.windowCoveringService) {
|
|
1161
|
-
this.warnLog(
|
|
1632
|
+
this.warnLog(
|
|
1633
|
+
`Bot: ${accessory.displayName} Removing Leftover Window Covering Service`,
|
|
1634
|
+
);
|
|
1162
1635
|
}
|
|
1163
1636
|
accessory.removeService(this.windowCoveringService!);
|
|
1164
1637
|
}
|
|
1165
1638
|
|
|
1166
|
-
public removeStatefulProgrammableSwitchService(
|
|
1639
|
+
public removeStatefulProgrammableSwitchService(
|
|
1640
|
+
accessory: homebridge.PlatformAccessory,
|
|
1641
|
+
) {
|
|
1167
1642
|
// If statefulProgrammableSwitchService still pressent, then remove first
|
|
1168
|
-
this.statefulProgrammableSwitchService = this.accessory.getService(
|
|
1643
|
+
this.statefulProgrammableSwitchService = this.accessory.getService(
|
|
1644
|
+
this.platform.Service.StatefulProgrammableSwitch,
|
|
1645
|
+
);
|
|
1169
1646
|
if (this.statefulProgrammableSwitchService) {
|
|
1170
|
-
this.warnLog(
|
|
1647
|
+
this.warnLog(
|
|
1648
|
+
`Bot: ${accessory.displayName} Removing Leftover Stateful Programmable Switch Service`,
|
|
1649
|
+
);
|
|
1171
1650
|
}
|
|
1172
1651
|
accessory.removeService(this.statefulProgrammableSwitchService!);
|
|
1173
1652
|
}
|
|
1174
1653
|
|
|
1175
|
-
public removeSwitchService(accessory: PlatformAccessory) {
|
|
1654
|
+
public removeSwitchService(accessory: homebridge.PlatformAccessory) {
|
|
1176
1655
|
// If switchService still pressent, then remove first
|
|
1177
|
-
this.switchService = this.accessory.getService(
|
|
1656
|
+
this.switchService = this.accessory.getService(
|
|
1657
|
+
this.platform.Service.Switch,
|
|
1658
|
+
);
|
|
1178
1659
|
if (this.switchService) {
|
|
1179
|
-
this.warnLog(
|
|
1660
|
+
this.warnLog(
|
|
1661
|
+
`Bot: ${accessory.displayName} Removing Leftover Switch Service`,
|
|
1662
|
+
);
|
|
1180
1663
|
}
|
|
1181
1664
|
accessory.removeService(this.switchService!);
|
|
1182
1665
|
}
|
|
1183
1666
|
|
|
1184
1667
|
/**
|
|
1185
|
-
|
|
1186
|
-
|
|
1668
|
+
* Logging for Device
|
|
1669
|
+
*/
|
|
1187
1670
|
infoLog(...log: any[]) {
|
|
1188
1671
|
if (this.enablingDeviceLogging()) {
|
|
1189
1672
|
this.platform.log.info(String(...log));
|
|
@@ -1204,8 +1687,8 @@ export class Bot {
|
|
|
1204
1687
|
|
|
1205
1688
|
debugLog(...log: any[]) {
|
|
1206
1689
|
if (this.enablingDeviceLogging()) {
|
|
1207
|
-
if (this.deviceLogging ===
|
|
1208
|
-
this.platform.log.info(
|
|
1690
|
+
if (this.deviceLogging === "debug") {
|
|
1691
|
+
this.platform.log.info("[DEBUG]", String(...log));
|
|
1209
1692
|
} else {
|
|
1210
1693
|
this.platform.log.debug(String(...log));
|
|
1211
1694
|
}
|
|
@@ -1213,6 +1696,8 @@ export class Bot {
|
|
|
1213
1696
|
}
|
|
1214
1697
|
|
|
1215
1698
|
enablingDeviceLogging(): boolean {
|
|
1216
|
-
return
|
|
1699
|
+
return (
|
|
1700
|
+
this.deviceLogging.includes("debug") || this.deviceLogging === "standard"
|
|
1701
|
+
);
|
|
1217
1702
|
}
|
|
1218
1703
|
}
|