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