@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/dist/devices/bots.js
CHANGED
|
@@ -1,28 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
3
|
exports.Bot = void 0;
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const settings_1 = require("../settings");
|
|
26
7
|
/**
|
|
27
8
|
* Platform Accessory
|
|
28
9
|
* An instance of this class is created for each accessory your platform registers
|
|
@@ -38,6 +19,7 @@ class Bot {
|
|
|
38
19
|
this.scan(device);
|
|
39
20
|
this.refreshRate(device);
|
|
40
21
|
this.PressOrSwitch(device);
|
|
22
|
+
this.allowPushChanges(device);
|
|
41
23
|
this.config(device);
|
|
42
24
|
if (this.On === undefined) {
|
|
43
25
|
this.On = false;
|
|
@@ -56,19 +38,19 @@ class Bot {
|
|
|
56
38
|
this.BatteryLevel = 100;
|
|
57
39
|
this.StatusLowBattery = 0;
|
|
58
40
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
59
|
-
this.doBotUpdate = new
|
|
41
|
+
this.doBotUpdate = new rxjs_1.Subject();
|
|
60
42
|
this.botUpdateInProgress = false;
|
|
61
43
|
// Retrieve initial values and updateHomekit
|
|
62
44
|
this.refreshStatus();
|
|
63
45
|
// set accessory information
|
|
64
46
|
accessory
|
|
65
47
|
.getService(this.platform.Service.AccessoryInformation)
|
|
66
|
-
.setCharacteristic(this.platform.Characteristic.Manufacturer,
|
|
67
|
-
.setCharacteristic(this.platform.Characteristic.Model,
|
|
48
|
+
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
49
|
+
.setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-BOT-S1')
|
|
68
50
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId);
|
|
69
51
|
// get the LightBulb service if it exists, otherwise create a new LightBulb service
|
|
70
52
|
// you can create multiple services for each accessory
|
|
71
|
-
if (device.bot?.deviceType ===
|
|
53
|
+
if (device.bot?.deviceType === 'switch') {
|
|
72
54
|
this.removeFanService(accessory);
|
|
73
55
|
this.removeLockService(accessory);
|
|
74
56
|
this.removeDoorService(accessory);
|
|
@@ -79,17 +61,13 @@ class Bot {
|
|
|
79
61
|
this.removeWindowCoveringService(accessory);
|
|
80
62
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
81
63
|
// Add switchService
|
|
82
|
-
(this.switchService =
|
|
83
|
-
accessory.getService(this.platform.Service.Switch) ||
|
|
84
|
-
accessory.addService(this.platform.Service.Switch)),
|
|
64
|
+
(this.switchService = accessory.getService(this.platform.Service.Switch) || accessory.addService(this.platform.Service.Switch)),
|
|
85
65
|
`${accessory.displayName} Switch`;
|
|
86
66
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Switch`);
|
|
87
67
|
this.switchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
88
|
-
this.switchService
|
|
89
|
-
.getCharacteristic(this.platform.Characteristic.On)
|
|
90
|
-
.onSet(this.handleOnSet.bind(this));
|
|
68
|
+
this.switchService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
|
|
91
69
|
}
|
|
92
|
-
else if (device.bot?.deviceType ===
|
|
70
|
+
else if (device.bot?.deviceType === 'garagedoor') {
|
|
93
71
|
this.removeFanService(accessory);
|
|
94
72
|
this.removeLockService(accessory);
|
|
95
73
|
this.removeDoorService(accessory);
|
|
@@ -101,17 +79,14 @@ class Bot {
|
|
|
101
79
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
102
80
|
// Add switchService
|
|
103
81
|
(this.garageDoorService =
|
|
104
|
-
accessory.getService(this.platform.Service.GarageDoorOpener) ||
|
|
105
|
-
accessory.addService(this.platform.Service.GarageDoorOpener)),
|
|
82
|
+
accessory.getService(this.platform.Service.GarageDoorOpener) || accessory.addService(this.platform.Service.GarageDoorOpener)),
|
|
106
83
|
`${accessory.displayName} Garage Door Opener`;
|
|
107
84
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Garage Door Opener`);
|
|
108
85
|
this.garageDoorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
109
|
-
this.garageDoorService
|
|
110
|
-
.getCharacteristic(this.platform.Characteristic.TargetDoorState)
|
|
111
|
-
.onSet(this.handleOnSet.bind(this));
|
|
86
|
+
this.garageDoorService.getCharacteristic(this.platform.Characteristic.TargetDoorState).onSet(this.handleOnSet.bind(this));
|
|
112
87
|
this.garageDoorService.setCharacteristic(this.platform.Characteristic.ObstructionDetected, false);
|
|
113
88
|
}
|
|
114
|
-
else if (device.bot?.deviceType ===
|
|
89
|
+
else if (device.bot?.deviceType === 'door') {
|
|
115
90
|
this.removeFanService(accessory);
|
|
116
91
|
this.removeLockService(accessory);
|
|
117
92
|
this.removeOutletService(accessory);
|
|
@@ -122,9 +97,7 @@ class Bot {
|
|
|
122
97
|
this.removeWindowCoveringService(accessory);
|
|
123
98
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
124
99
|
// Add switchService
|
|
125
|
-
(this.doorService =
|
|
126
|
-
accessory.getService(this.platform.Service.Door) ||
|
|
127
|
-
accessory.addService(this.platform.Service.Door)),
|
|
100
|
+
(this.doorService = accessory.getService(this.platform.Service.Door) || accessory.addService(this.platform.Service.Door)),
|
|
128
101
|
`${accessory.displayName} Door`;
|
|
129
102
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Door`);
|
|
130
103
|
this.doorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
@@ -139,7 +112,7 @@ class Bot {
|
|
|
139
112
|
.onSet(this.handleOnSet.bind(this));
|
|
140
113
|
this.doorService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
|
|
141
114
|
}
|
|
142
|
-
else if (device.bot?.deviceType ===
|
|
115
|
+
else if (device.bot?.deviceType === 'window') {
|
|
143
116
|
this.removeFanService(accessory);
|
|
144
117
|
this.removeLockService(accessory);
|
|
145
118
|
this.removeDoorService(accessory);
|
|
@@ -150,9 +123,7 @@ class Bot {
|
|
|
150
123
|
this.removeWindowCoveringService(accessory);
|
|
151
124
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
152
125
|
// Add switchService
|
|
153
|
-
(this.windowService =
|
|
154
|
-
accessory.getService(this.platform.Service.Window) ||
|
|
155
|
-
accessory.addService(this.platform.Service.Window)),
|
|
126
|
+
(this.windowService = accessory.getService(this.platform.Service.Window) || accessory.addService(this.platform.Service.Window)),
|
|
156
127
|
`${accessory.displayName} Window`;
|
|
157
128
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Window`);
|
|
158
129
|
this.windowService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
@@ -167,7 +138,7 @@ class Bot {
|
|
|
167
138
|
.onSet(this.handleOnSet.bind(this));
|
|
168
139
|
this.windowService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
|
|
169
140
|
}
|
|
170
|
-
else if (device.bot?.deviceType ===
|
|
141
|
+
else if (device.bot?.deviceType === 'windowcovering') {
|
|
171
142
|
this.removeFanService(accessory);
|
|
172
143
|
this.removeLockService(accessory);
|
|
173
144
|
this.removeDoorService(accessory);
|
|
@@ -179,8 +150,7 @@ class Bot {
|
|
|
179
150
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
180
151
|
// Add switchService
|
|
181
152
|
(this.windowCoveringService =
|
|
182
|
-
accessory.getService(this.platform.Service.WindowCovering) ||
|
|
183
|
-
accessory.addService(this.platform.Service.WindowCovering)),
|
|
153
|
+
accessory.getService(this.platform.Service.WindowCovering) || accessory.addService(this.platform.Service.WindowCovering)),
|
|
184
154
|
`${accessory.displayName} Window Covering`;
|
|
185
155
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Window Covering`);
|
|
186
156
|
this.windowCoveringService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
@@ -195,7 +165,7 @@ class Bot {
|
|
|
195
165
|
.onSet(this.handleOnSet.bind(this));
|
|
196
166
|
this.windowCoveringService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
|
|
197
167
|
}
|
|
198
|
-
else if (device.bot?.deviceType ===
|
|
168
|
+
else if (device.bot?.deviceType === 'lock') {
|
|
199
169
|
this.removeFanService(accessory);
|
|
200
170
|
this.removeDoorService(accessory);
|
|
201
171
|
this.removeOutletService(accessory);
|
|
@@ -206,17 +176,13 @@ class Bot {
|
|
|
206
176
|
this.removeWindowCoveringService(accessory);
|
|
207
177
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
208
178
|
// Add switchService
|
|
209
|
-
(this.lockService =
|
|
210
|
-
accessory.getService(this.platform.Service.LockMechanism) ||
|
|
211
|
-
accessory.addService(this.platform.Service.LockMechanism)),
|
|
179
|
+
(this.lockService = accessory.getService(this.platform.Service.LockMechanism) || accessory.addService(this.platform.Service.LockMechanism)),
|
|
212
180
|
`${accessory.displayName} Lock`;
|
|
213
181
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Lock`);
|
|
214
182
|
this.lockService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
215
|
-
this.lockService
|
|
216
|
-
.getCharacteristic(this.platform.Characteristic.LockTargetState)
|
|
217
|
-
.onSet(this.handleOnSet.bind(this));
|
|
183
|
+
this.lockService.getCharacteristic(this.platform.Characteristic.LockTargetState).onSet(this.handleOnSet.bind(this));
|
|
218
184
|
}
|
|
219
|
-
else if (device.bot?.deviceType ===
|
|
185
|
+
else if (device.bot?.deviceType === 'faucet') {
|
|
220
186
|
this.removeFanService(accessory);
|
|
221
187
|
this.removeLockService(accessory);
|
|
222
188
|
this.removeDoorService(accessory);
|
|
@@ -227,17 +193,13 @@ class Bot {
|
|
|
227
193
|
this.removeWindowCoveringService(accessory);
|
|
228
194
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
229
195
|
// Add switchService
|
|
230
|
-
(this.faucetService =
|
|
231
|
-
accessory.getService(this.platform.Service.Faucet) ||
|
|
232
|
-
accessory.addService(this.platform.Service.Faucet)),
|
|
196
|
+
(this.faucetService = accessory.getService(this.platform.Service.Faucet) || accessory.addService(this.platform.Service.Faucet)),
|
|
233
197
|
`${accessory.displayName} Faucet`;
|
|
234
198
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Faucet`);
|
|
235
199
|
this.faucetService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
236
|
-
this.faucetService
|
|
237
|
-
.getCharacteristic(this.platform.Characteristic.Active)
|
|
238
|
-
.onSet(this.handleOnSet.bind(this));
|
|
200
|
+
this.faucetService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.handleOnSet.bind(this));
|
|
239
201
|
}
|
|
240
|
-
else if (device.bot?.deviceType ===
|
|
202
|
+
else if (device.bot?.deviceType === 'fan') {
|
|
241
203
|
this.removeLockService(accessory);
|
|
242
204
|
this.removeDoorService(accessory);
|
|
243
205
|
this.removeFaucetService(accessory);
|
|
@@ -248,17 +210,13 @@ class Bot {
|
|
|
248
210
|
this.removeWindowCoveringService(accessory);
|
|
249
211
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
250
212
|
// Add switchService
|
|
251
|
-
(this.fanService =
|
|
252
|
-
accessory.getService(this.platform.Service.Fan) ||
|
|
253
|
-
accessory.addService(this.platform.Service.Fan)),
|
|
213
|
+
(this.fanService = accessory.getService(this.platform.Service.Fan) || accessory.addService(this.platform.Service.Fan)),
|
|
254
214
|
`${accessory.displayName} Fan`;
|
|
255
215
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Fan`);
|
|
256
216
|
this.fanService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
257
|
-
this.fanService
|
|
258
|
-
.getCharacteristic(this.platform.Characteristic.On)
|
|
259
|
-
.onSet(this.handleOnSet.bind(this));
|
|
217
|
+
this.fanService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
|
|
260
218
|
}
|
|
261
|
-
else if (device.bot?.deviceType ===
|
|
219
|
+
else if (device.bot?.deviceType === 'stateful') {
|
|
262
220
|
this.removeFanService(accessory);
|
|
263
221
|
this.removeLockService(accessory);
|
|
264
222
|
this.removeDoorService(accessory);
|
|
@@ -290,15 +248,11 @@ class Bot {
|
|
|
290
248
|
this.removeWindowCoveringService(accessory);
|
|
291
249
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
292
250
|
// Add outletService
|
|
293
|
-
(this.outletService =
|
|
294
|
-
accessory.getService(this.platform.Service.Outlet) ||
|
|
295
|
-
accessory.addService(this.platform.Service.Outlet)),
|
|
251
|
+
(this.outletService = accessory.getService(this.platform.Service.Outlet) || accessory.addService(this.platform.Service.Outlet)),
|
|
296
252
|
`${accessory.displayName} Outlet`;
|
|
297
253
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Outlet`);
|
|
298
254
|
this.outletService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
299
|
-
this.outletService
|
|
300
|
-
.getCharacteristic(this.platform.Characteristic.On)
|
|
301
|
-
.onSet(this.handleOnSet.bind(this));
|
|
255
|
+
this.outletService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
|
|
302
256
|
}
|
|
303
257
|
// Battery Service
|
|
304
258
|
if (!device.ble) {
|
|
@@ -308,9 +262,7 @@ class Bot {
|
|
|
308
262
|
}
|
|
309
263
|
else if (device.ble && !this.batteryService) {
|
|
310
264
|
this.debugLog(`Bot: ${accessory.displayName} Add Battery Service`);
|
|
311
|
-
(this.batteryService =
|
|
312
|
-
this.accessory.getService(this.platform.Service.Battery) ||
|
|
313
|
-
this.accessory.addService(this.platform.Service.Battery)),
|
|
265
|
+
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
|
|
314
266
|
`${accessory.displayName} Battery`;
|
|
315
267
|
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
316
268
|
}
|
|
@@ -320,32 +272,32 @@ class Bot {
|
|
|
320
272
|
// Retrieve initial values and updateHomekit
|
|
321
273
|
this.updateHomeKitCharacteristics();
|
|
322
274
|
// Start an update interval
|
|
323
|
-
|
|
324
|
-
.
|
|
325
|
-
.pipe(operators.skipWhile(() => this.botUpdateInProgress))
|
|
275
|
+
(0, rxjs_1.interval)(this.deviceRefreshRate * 1000)
|
|
276
|
+
.pipe((0, operators_1.skipWhile)(() => this.botUpdateInProgress))
|
|
326
277
|
.subscribe(() => {
|
|
327
278
|
this.refreshStatus();
|
|
328
279
|
});
|
|
329
280
|
// Watch for Bot change events
|
|
330
281
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
331
282
|
this.doBotUpdate
|
|
332
|
-
.pipe(
|
|
283
|
+
.pipe((0, operators_1.tap)(() => {
|
|
333
284
|
this.botUpdateInProgress = true;
|
|
334
|
-
}),
|
|
285
|
+
}), (0, operators_1.debounceTime)(100))
|
|
335
286
|
.subscribe(async () => {
|
|
336
287
|
try {
|
|
337
|
-
|
|
338
|
-
.
|
|
339
|
-
.pipe(operators.take(this.doublePress))
|
|
288
|
+
(0, rxjs_1.interval)(100)
|
|
289
|
+
.pipe((0, operators_1.take)(this.doublePress))
|
|
340
290
|
.subscribe(async () => {
|
|
341
291
|
await this.pushChanges();
|
|
342
292
|
});
|
|
343
293
|
}
|
|
344
294
|
catch (e) {
|
|
345
295
|
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges`);
|
|
346
|
-
if (this.deviceLogging
|
|
347
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,` +
|
|
348
|
-
|
|
296
|
+
if (this.deviceLogging === 'debug') {
|
|
297
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
298
|
+
}
|
|
299
|
+
if (this.platform.debugMode) {
|
|
300
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,` + ` Error: ${JSON.stringify(e)}`);
|
|
349
301
|
}
|
|
350
302
|
}
|
|
351
303
|
this.botUpdateInProgress = false;
|
|
@@ -381,12 +333,10 @@ class Bot {
|
|
|
381
333
|
}
|
|
382
334
|
this.BatteryLevel = Number(this.battery);
|
|
383
335
|
if (this.BatteryLevel < 10) {
|
|
384
|
-
this.StatusLowBattery =
|
|
385
|
-
this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
336
|
+
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
386
337
|
}
|
|
387
338
|
else {
|
|
388
|
-
this.StatusLowBattery =
|
|
389
|
-
this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
339
|
+
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
390
340
|
}
|
|
391
341
|
if (Number.isNaN(this.BatteryLevel)) {
|
|
392
342
|
this.BatteryLevel = 100;
|
|
@@ -399,7 +349,7 @@ class Bot {
|
|
|
399
349
|
}
|
|
400
350
|
if (this.platform.config.credentials?.openToken) {
|
|
401
351
|
this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
402
|
-
if (this.botMode ===
|
|
352
|
+
if (this.botMode === 'press') {
|
|
403
353
|
this.On = false;
|
|
404
354
|
this.OnCached = this.On;
|
|
405
355
|
this.accessory.context.On = this.OnCached;
|
|
@@ -440,19 +390,19 @@ class Bot {
|
|
|
440
390
|
// Convert to BLE Address
|
|
441
391
|
this.device.bleMac = this.device
|
|
442
392
|
.deviceId.match(/.{1,2}/g)
|
|
443
|
-
.join(
|
|
393
|
+
.join(':')
|
|
444
394
|
.toLowerCase();
|
|
445
|
-
this.debugLog(`
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
395
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
396
|
+
// Start to monitor advertisement packets
|
|
397
|
+
if (switchbot === false) {
|
|
398
|
+
this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection: ${switchbot}`);
|
|
399
|
+
}
|
|
400
|
+
switchbot
|
|
401
|
+
.startScan({
|
|
402
|
+
model: 'H',
|
|
403
|
+
id: this.device.bleMac,
|
|
404
|
+
})
|
|
405
|
+
.then(() => {
|
|
456
406
|
// Set an event hander
|
|
457
407
|
switchbot.onadvertisement = (ad) => {
|
|
458
408
|
this.serviceData = ad.serviceData;
|
|
@@ -472,7 +422,9 @@ class Bot {
|
|
|
472
422
|
}
|
|
473
423
|
};
|
|
474
424
|
// Wait 2 seconds
|
|
475
|
-
|
|
425
|
+
return switchbot.wait(this.scanDuration * 1000);
|
|
426
|
+
})
|
|
427
|
+
.then(async () => {
|
|
476
428
|
// Stop to monitor
|
|
477
429
|
switchbot.stopScan();
|
|
478
430
|
if (this.connected) {
|
|
@@ -487,12 +439,14 @@ class Bot {
|
|
|
487
439
|
await this.openAPIRefreshStatus();
|
|
488
440
|
}
|
|
489
441
|
}
|
|
490
|
-
}
|
|
491
|
-
|
|
442
|
+
})
|
|
443
|
+
.catch(async (e) => {
|
|
492
444
|
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
493
|
-
if (this.deviceLogging
|
|
494
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` +
|
|
495
|
-
|
|
445
|
+
if (this.deviceLogging === 'debug') {
|
|
446
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
447
|
+
}
|
|
448
|
+
if (this.platform.debugMode) {
|
|
449
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
496
450
|
}
|
|
497
451
|
if (this.platform.config.credentials?.openToken) {
|
|
498
452
|
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
@@ -500,13 +454,13 @@ class Bot {
|
|
|
500
454
|
await this.openAPIRefreshStatus();
|
|
501
455
|
}
|
|
502
456
|
this.apiError(e);
|
|
503
|
-
}
|
|
457
|
+
});
|
|
504
458
|
}
|
|
505
459
|
async openAPIRefreshStatus() {
|
|
506
460
|
if (this.platform.config.credentials?.openToken) {
|
|
507
461
|
this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI refreshStatus`);
|
|
508
462
|
try {
|
|
509
|
-
this.deviceStatus = (await this.platform.axios.get(`${
|
|
463
|
+
this.deviceStatus = (await this.platform.axios.get(`${settings_1.DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
510
464
|
this.debugLog(`Bot: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
511
465
|
this.power = this.deviceStatus.body.power;
|
|
512
466
|
this.parseStatus();
|
|
@@ -514,9 +468,11 @@ class Bot {
|
|
|
514
468
|
}
|
|
515
469
|
catch (e) {
|
|
516
470
|
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
517
|
-
if (this.deviceLogging
|
|
518
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
|
|
519
|
-
|
|
471
|
+
if (this.deviceLogging === 'debug') {
|
|
472
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
473
|
+
}
|
|
474
|
+
if (this.platform.debugMode) {
|
|
475
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
520
476
|
}
|
|
521
477
|
this.apiError(e);
|
|
522
478
|
}
|
|
@@ -536,30 +492,29 @@ class Bot {
|
|
|
536
492
|
else {
|
|
537
493
|
await this.openAPIpushChanges();
|
|
538
494
|
}
|
|
539
|
-
|
|
540
|
-
.
|
|
541
|
-
.pipe(
|
|
542
|
-
.pipe(operators.take(1))
|
|
495
|
+
(0, rxjs_1.interval)(5000)
|
|
496
|
+
.pipe((0, operators_1.skipWhile)(() => this.botUpdateInProgress))
|
|
497
|
+
.pipe((0, operators_1.take)(1))
|
|
543
498
|
.subscribe(() => {
|
|
544
499
|
this.refreshStatus();
|
|
545
500
|
});
|
|
546
501
|
}
|
|
547
502
|
async BLEpushChanges() {
|
|
548
503
|
this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges On: ${this.On} OnCached: ${this.OnCached}`);
|
|
549
|
-
if (this.On !== this.OnCached) {
|
|
504
|
+
if (this.On !== this.OnCached || this.allowPush) {
|
|
550
505
|
this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges`);
|
|
551
506
|
const switchbot = await this.platform.connectBLE();
|
|
552
507
|
// Convert to BLE Address
|
|
553
508
|
this.device.bleMac = this.device
|
|
554
509
|
.deviceId.match(/.{1,2}/g)
|
|
555
|
-
.join(
|
|
510
|
+
.join(':')
|
|
556
511
|
.toLowerCase();
|
|
557
|
-
this.debugLog(`
|
|
512
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
558
513
|
//if (switchbot !== false) {
|
|
559
|
-
if (this.botMode ===
|
|
514
|
+
if (this.botMode === 'press') {
|
|
560
515
|
this.debugLog(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
|
|
561
516
|
switchbot
|
|
562
|
-
.discover({ model:
|
|
517
|
+
.discover({ model: 'H', quick: true, id: this.device.bleMac })
|
|
563
518
|
.then((device_list) => {
|
|
564
519
|
this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
565
520
|
return device_list[0].press({ id: this.device.bleMac });
|
|
@@ -570,24 +525,22 @@ class Bot {
|
|
|
570
525
|
this.OnCached = this.On;
|
|
571
526
|
this.accessory.context.On = this.OnCached;
|
|
572
527
|
setTimeout(() => {
|
|
573
|
-
if (this.device.bot?.deviceType ===
|
|
574
|
-
this.switchService
|
|
575
|
-
?.getCharacteristic(this.platform.Characteristic.On)
|
|
576
|
-
.updateValue(this.On);
|
|
528
|
+
if (this.device.bot?.deviceType === 'switch') {
|
|
529
|
+
this.switchService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
|
|
577
530
|
}
|
|
578
531
|
else {
|
|
579
|
-
this.outletService
|
|
580
|
-
?.getCharacteristic(this.platform.Characteristic.On)
|
|
581
|
-
.updateValue(this.On);
|
|
532
|
+
this.outletService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
|
|
582
533
|
}
|
|
583
534
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}, Switch Timeout`);
|
|
584
535
|
}, 500);
|
|
585
536
|
})
|
|
586
537
|
.catch(async (e) => {
|
|
587
538
|
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
588
|
-
if (this.deviceLogging
|
|
589
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` +
|
|
590
|
-
|
|
539
|
+
if (this.deviceLogging === 'debug') {
|
|
540
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
541
|
+
}
|
|
542
|
+
if (this.platform.debugMode) {
|
|
543
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
591
544
|
}
|
|
592
545
|
if (this.platform.config.credentials?.openToken) {
|
|
593
546
|
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
@@ -596,10 +549,10 @@ class Bot {
|
|
|
596
549
|
this.apiError(e);
|
|
597
550
|
});
|
|
598
551
|
}
|
|
599
|
-
else if (this.botMode ===
|
|
552
|
+
else if (this.botMode === 'switch') {
|
|
600
553
|
this.debugLog(`Bot: ${this.accessory.displayName} Press Mode: ${this.botMode}`);
|
|
601
554
|
switchbot
|
|
602
|
-
.discover({ model:
|
|
555
|
+
.discover({ model: 'H', quick: true, id: this.device.bleMac })
|
|
603
556
|
.then((device_list) => {
|
|
604
557
|
this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
605
558
|
return this.turnOnOff(device_list);
|
|
@@ -611,9 +564,11 @@ class Bot {
|
|
|
611
564
|
})
|
|
612
565
|
.catch(async (e) => {
|
|
613
566
|
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
614
|
-
if (this.deviceLogging
|
|
615
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` +
|
|
616
|
-
|
|
567
|
+
if (this.deviceLogging === 'debug') {
|
|
568
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
569
|
+
}
|
|
570
|
+
if (this.platform.debugMode) {
|
|
571
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
617
572
|
}
|
|
618
573
|
if (this.platform.config.credentials?.openToken) {
|
|
619
574
|
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
@@ -647,24 +602,24 @@ class Bot {
|
|
|
647
602
|
async openAPIpushChanges() {
|
|
648
603
|
if (this.platform.config.credentials?.openToken) {
|
|
649
604
|
try {
|
|
650
|
-
if (this.On !== this.OnCached) {
|
|
605
|
+
if (this.On !== this.OnCached || this.allowPush) {
|
|
651
606
|
this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI pushChanges`);
|
|
652
607
|
const payload = {
|
|
653
|
-
commandType:
|
|
654
|
-
parameter:
|
|
608
|
+
commandType: 'command',
|
|
609
|
+
parameter: 'default',
|
|
655
610
|
};
|
|
656
|
-
if (this.botMode ===
|
|
657
|
-
payload.command =
|
|
611
|
+
if (this.botMode === 'switch' && this.On) {
|
|
612
|
+
payload.command = 'turnOn';
|
|
658
613
|
this.On = true;
|
|
659
614
|
this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`);
|
|
660
615
|
}
|
|
661
|
-
else if (this.botMode ===
|
|
662
|
-
payload.command =
|
|
616
|
+
else if (this.botMode === 'switch' && !this.On) {
|
|
617
|
+
payload.command = 'turnOff';
|
|
663
618
|
this.On = false;
|
|
664
619
|
this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`);
|
|
665
620
|
}
|
|
666
|
-
else if (this.botMode ===
|
|
667
|
-
payload.command =
|
|
621
|
+
else if (this.botMode === 'press') {
|
|
622
|
+
payload.command = 'press';
|
|
668
623
|
this.debugLog(`Bot: ${this.accessory.displayName} Press Mode`);
|
|
669
624
|
this.On = false;
|
|
670
625
|
}
|
|
@@ -674,7 +629,7 @@ class Bot {
|
|
|
674
629
|
this.infoLog(`Bot: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
675
630
|
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
676
631
|
// Make the API request
|
|
677
|
-
const push = await this.platform.axios.post(`${
|
|
632
|
+
const push = await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
678
633
|
this.debugLog(`Bot: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
|
|
679
634
|
this.statusCode(push);
|
|
680
635
|
this.OnCached = this.On;
|
|
@@ -683,9 +638,11 @@ class Bot {
|
|
|
683
638
|
}
|
|
684
639
|
catch (e) {
|
|
685
640
|
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
686
|
-
if (this.deviceLogging
|
|
687
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
688
|
-
|
|
641
|
+
if (this.deviceLogging === 'debug') {
|
|
642
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
643
|
+
}
|
|
644
|
+
if (this.platform.debugMode) {
|
|
645
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
689
646
|
}
|
|
690
647
|
this.apiError(e);
|
|
691
648
|
}
|
|
@@ -695,7 +652,7 @@ class Bot {
|
|
|
695
652
|
* Updates the status for each of the HomeKit Characteristics
|
|
696
653
|
*/
|
|
697
654
|
updateHomeKitCharacteristics() {
|
|
698
|
-
if (this.device.bot?.deviceType ===
|
|
655
|
+
if (this.device.bot?.deviceType === 'garagedoor') {
|
|
699
656
|
if (this.On === undefined) {
|
|
700
657
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
701
658
|
}
|
|
@@ -713,7 +670,7 @@ class Bot {
|
|
|
713
670
|
}
|
|
714
671
|
this.debugLog(`Bot: ${this.accessory.displayName} Garage Door On: ${this.On}`);
|
|
715
672
|
}
|
|
716
|
-
else if (this.device.bot?.deviceType ===
|
|
673
|
+
else if (this.device.bot?.deviceType === 'door') {
|
|
717
674
|
if (this.On === undefined) {
|
|
718
675
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
719
676
|
}
|
|
@@ -733,7 +690,7 @@ class Bot {
|
|
|
733
690
|
}
|
|
734
691
|
this.debugLog(`Bot: ${this.accessory.displayName} Door On: ${this.On}`);
|
|
735
692
|
}
|
|
736
|
-
else if (this.device.bot?.deviceType ===
|
|
693
|
+
else if (this.device.bot?.deviceType === 'window') {
|
|
737
694
|
if (this.On === undefined) {
|
|
738
695
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
739
696
|
}
|
|
@@ -753,7 +710,7 @@ class Bot {
|
|
|
753
710
|
}
|
|
754
711
|
this.debugLog(`Bot: ${this.accessory.displayName} Window On: ${this.On}`);
|
|
755
712
|
}
|
|
756
|
-
else if (this.device.bot?.deviceType ===
|
|
713
|
+
else if (this.device.bot?.deviceType === 'windowcovering') {
|
|
757
714
|
if (this.On === undefined) {
|
|
758
715
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
759
716
|
}
|
|
@@ -773,7 +730,7 @@ class Bot {
|
|
|
773
730
|
}
|
|
774
731
|
this.debugLog(`Bot: ${this.accessory.displayName} Window Covering On: ${this.On}`);
|
|
775
732
|
}
|
|
776
|
-
else if (this.device.bot?.deviceType ===
|
|
733
|
+
else if (this.device.bot?.deviceType === 'lock') {
|
|
777
734
|
if (this.On === undefined) {
|
|
778
735
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
779
736
|
}
|
|
@@ -791,7 +748,7 @@ class Bot {
|
|
|
791
748
|
}
|
|
792
749
|
this.debugLog(`Bot: ${this.accessory.displayName} Lock On: ${this.On}`);
|
|
793
750
|
}
|
|
794
|
-
else if (this.device.bot?.deviceType ===
|
|
751
|
+
else if (this.device.bot?.deviceType === 'faucet') {
|
|
795
752
|
if (this.On === undefined) {
|
|
796
753
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
797
754
|
}
|
|
@@ -807,7 +764,7 @@ class Bot {
|
|
|
807
764
|
}
|
|
808
765
|
this.debugLog(`Bot: ${this.accessory.displayName} Faucet On: ${this.On}`);
|
|
809
766
|
}
|
|
810
|
-
else if (this.device.bot?.deviceType ===
|
|
767
|
+
else if (this.device.bot?.deviceType === 'fan') {
|
|
811
768
|
if (this.On === undefined) {
|
|
812
769
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
813
770
|
}
|
|
@@ -823,7 +780,7 @@ class Bot {
|
|
|
823
780
|
}
|
|
824
781
|
this.debugLog(`Bot: ${this.accessory.displayName} Fan On: ${this.On}`);
|
|
825
782
|
}
|
|
826
|
-
else if (this.device.bot?.deviceType ===
|
|
783
|
+
else if (this.device.bot?.deviceType === 'stateful') {
|
|
827
784
|
if (this.On === undefined) {
|
|
828
785
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
829
786
|
}
|
|
@@ -841,7 +798,7 @@ class Bot {
|
|
|
841
798
|
}
|
|
842
799
|
this.debugLog(`Bot: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.On}`);
|
|
843
800
|
}
|
|
844
|
-
else if (this.device.bot?.deviceType ===
|
|
801
|
+
else if (this.device.bot?.deviceType === 'switch') {
|
|
845
802
|
if (this.On === undefined) {
|
|
846
803
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
847
804
|
}
|
|
@@ -877,41 +834,41 @@ class Bot {
|
|
|
877
834
|
}
|
|
878
835
|
}
|
|
879
836
|
apiError(e) {
|
|
880
|
-
if (this.device.bot?.deviceType ===
|
|
837
|
+
if (this.device.bot?.deviceType === 'garagedoor') {
|
|
881
838
|
this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.TargetDoorState, e);
|
|
882
839
|
this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.CurrentDoorState, e);
|
|
883
840
|
this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.ObstructionDetected, e);
|
|
884
841
|
}
|
|
885
|
-
else if (this.device.bot?.deviceType ===
|
|
842
|
+
else if (this.device.bot?.deviceType === 'door') {
|
|
886
843
|
this.doorService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
|
|
887
844
|
this.doorService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, e);
|
|
888
845
|
this.doorService?.updateCharacteristic(this.platform.Characteristic.PositionState, e);
|
|
889
846
|
}
|
|
890
|
-
else if (this.device.bot?.deviceType ===
|
|
847
|
+
else if (this.device.bot?.deviceType === 'window') {
|
|
891
848
|
this.windowService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
|
|
892
849
|
this.windowService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, e);
|
|
893
850
|
this.windowService?.updateCharacteristic(this.platform.Characteristic.PositionState, e);
|
|
894
851
|
}
|
|
895
|
-
else if (this.device.bot?.deviceType ===
|
|
852
|
+
else if (this.device.bot?.deviceType === 'windowcovering') {
|
|
896
853
|
this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
|
|
897
854
|
this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, e);
|
|
898
855
|
this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.PositionState, e);
|
|
899
856
|
}
|
|
900
|
-
else if (this.device.bot?.deviceType ===
|
|
857
|
+
else if (this.device.bot?.deviceType === 'lock') {
|
|
901
858
|
this.doorService?.updateCharacteristic(this.platform.Characteristic.LockTargetState, e);
|
|
902
859
|
this.doorService?.updateCharacteristic(this.platform.Characteristic.LockCurrentState, e);
|
|
903
860
|
}
|
|
904
|
-
else if (this.device.bot?.deviceType ===
|
|
861
|
+
else if (this.device.bot?.deviceType === 'faucet') {
|
|
905
862
|
this.faucetService?.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
906
863
|
}
|
|
907
|
-
else if (this.device.bot?.deviceType ===
|
|
864
|
+
else if (this.device.bot?.deviceType === 'fan') {
|
|
908
865
|
this.fanService?.updateCharacteristic(this.platform.Characteristic.On, e);
|
|
909
866
|
}
|
|
910
|
-
else if (this.device.bot?.deviceType ===
|
|
867
|
+
else if (this.device.bot?.deviceType === 'stateful') {
|
|
911
868
|
this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent, e);
|
|
912
869
|
this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, e);
|
|
913
870
|
}
|
|
914
|
-
else if (this.device.bot?.deviceType ===
|
|
871
|
+
else if (this.device.bot?.deviceType === 'switch') {
|
|
915
872
|
this.switchService?.updateCharacteristic(this.platform.Characteristic.On, e);
|
|
916
873
|
}
|
|
917
874
|
else {
|
|
@@ -956,15 +913,11 @@ class Bot {
|
|
|
956
913
|
offlineOff() {
|
|
957
914
|
if (this.device.offline) {
|
|
958
915
|
this.On = false;
|
|
959
|
-
if (this.device.bot?.deviceType ===
|
|
960
|
-
this.switchService
|
|
961
|
-
?.getCharacteristic(this.platform.Characteristic.On)
|
|
962
|
-
.updateValue(this.On);
|
|
916
|
+
if (this.device.bot?.deviceType === 'switch') {
|
|
917
|
+
this.switchService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
|
|
963
918
|
}
|
|
964
919
|
else {
|
|
965
|
-
this.outletService
|
|
966
|
-
?.getCharacteristic(this.platform.Characteristic.On)
|
|
967
|
-
.updateValue(this.On);
|
|
920
|
+
this.outletService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
|
|
968
921
|
}
|
|
969
922
|
}
|
|
970
923
|
}
|
|
@@ -972,7 +925,7 @@ class Bot {
|
|
|
972
925
|
* Handle requests to set the "On" characteristic
|
|
973
926
|
*/
|
|
974
927
|
handleOnSet(value) {
|
|
975
|
-
if (this.device.bot?.deviceType ===
|
|
928
|
+
if (this.device.bot?.deviceType === 'garagedoor') {
|
|
976
929
|
this.debugLog(`Bot: ${this.accessory.displayName} TargetDoorState: ${value}`);
|
|
977
930
|
if (value === this.platform.Characteristic.TargetDoorState.CLOSED) {
|
|
978
931
|
this.On = false;
|
|
@@ -981,9 +934,9 @@ class Bot {
|
|
|
981
934
|
this.On = true;
|
|
982
935
|
}
|
|
983
936
|
}
|
|
984
|
-
else if (this.device.bot?.deviceType ===
|
|
985
|
-
this.device.bot?.deviceType ===
|
|
986
|
-
this.device.bot?.deviceType ===
|
|
937
|
+
else if (this.device.bot?.deviceType === 'door' ||
|
|
938
|
+
this.device.bot?.deviceType === 'window' ||
|
|
939
|
+
this.device.bot?.deviceType === 'windowcovering') {
|
|
987
940
|
this.debugLog(`Bot: ${this.accessory.displayName} TargetPosition: ${value}`);
|
|
988
941
|
if (value === 0) {
|
|
989
942
|
this.On = false;
|
|
@@ -992,7 +945,7 @@ class Bot {
|
|
|
992
945
|
this.On = true;
|
|
993
946
|
}
|
|
994
947
|
}
|
|
995
|
-
else if (this.device.bot?.deviceType ===
|
|
948
|
+
else if (this.device.bot?.deviceType === 'lock') {
|
|
996
949
|
this.debugLog(`Bot: ${this.accessory.displayName} LockTargetState: ${value}`);
|
|
997
950
|
if (value === this.platform.Characteristic.LockTargetState.SECURED) {
|
|
998
951
|
this.On = false;
|
|
@@ -1001,7 +954,7 @@ class Bot {
|
|
|
1001
954
|
this.On = true;
|
|
1002
955
|
}
|
|
1003
956
|
}
|
|
1004
|
-
else if (this.device.bot?.deviceType ===
|
|
957
|
+
else if (this.device.bot?.deviceType === 'faucet') {
|
|
1005
958
|
this.debugLog(`Bot: ${this.accessory.displayName} Active: ${value}`);
|
|
1006
959
|
if (value === this.platform.Characteristic.Active.INACTIVE) {
|
|
1007
960
|
this.On = false;
|
|
@@ -1010,7 +963,7 @@ class Bot {
|
|
|
1010
963
|
this.On = true;
|
|
1011
964
|
}
|
|
1012
965
|
}
|
|
1013
|
-
else if (this.device.bot?.deviceType ===
|
|
966
|
+
else if (this.device.bot?.deviceType === 'stateful') {
|
|
1014
967
|
this.debugLog(`Bot: ${this.accessory.displayName} ProgrammableSwitchOutputState: ${value}`);
|
|
1015
968
|
if (value === 0) {
|
|
1016
969
|
this.On = false;
|
|
@@ -1031,16 +984,16 @@ class Bot {
|
|
|
1031
984
|
config = device.bot;
|
|
1032
985
|
}
|
|
1033
986
|
if (device.ble) {
|
|
1034
|
-
config[
|
|
987
|
+
config['ble'] = device.ble;
|
|
1035
988
|
}
|
|
1036
989
|
if (device.logging !== undefined) {
|
|
1037
|
-
config[
|
|
990
|
+
config['logging'] = device.logging;
|
|
1038
991
|
}
|
|
1039
992
|
if (device.refreshRate !== undefined) {
|
|
1040
|
-
config[
|
|
993
|
+
config['refreshRate'] = device.refreshRate;
|
|
1041
994
|
}
|
|
1042
995
|
if (device.scanDuration !== undefined) {
|
|
1043
|
-
config[
|
|
996
|
+
config['scanDuration'] = device.scanDuration;
|
|
1044
997
|
}
|
|
1045
998
|
if (Object.entries(config).length !== 0) {
|
|
1046
999
|
this.warnLog(`Bot: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
@@ -1048,20 +1001,17 @@ class Bot {
|
|
|
1048
1001
|
}
|
|
1049
1002
|
refreshRate(device) {
|
|
1050
1003
|
if (device.refreshRate) {
|
|
1051
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
1052
|
-
device.refreshRate;
|
|
1004
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
1053
1005
|
this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
1054
1006
|
}
|
|
1055
1007
|
else if (this.platform.config.options.refreshRate) {
|
|
1056
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
1057
|
-
this.platform.config.options.refreshRate;
|
|
1008
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
1058
1009
|
this.debugLog(`Bot: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
1059
1010
|
}
|
|
1060
1011
|
}
|
|
1061
1012
|
scan(device) {
|
|
1062
1013
|
if (device.scanDuration) {
|
|
1063
|
-
this.scanDuration = this.accessory.context.scanDuration =
|
|
1064
|
-
device.scanDuration;
|
|
1014
|
+
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
1065
1015
|
if (device.ble) {
|
|
1066
1016
|
this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
1067
1017
|
}
|
|
@@ -1075,7 +1025,7 @@ class Bot {
|
|
|
1075
1025
|
}
|
|
1076
1026
|
logs(device) {
|
|
1077
1027
|
if (this.platform.debugMode) {
|
|
1078
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
1028
|
+
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
1079
1029
|
this.debugLog(`Bot: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
1080
1030
|
}
|
|
1081
1031
|
else if (device.logging) {
|
|
@@ -1083,33 +1033,41 @@ class Bot {
|
|
|
1083
1033
|
this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
1084
1034
|
}
|
|
1085
1035
|
else if (this.platform.config.options?.logging) {
|
|
1086
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
1087
|
-
this.platform.config.options?.logging;
|
|
1036
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
1088
1037
|
this.debugLog(`Bot: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
1089
1038
|
}
|
|
1090
1039
|
else {
|
|
1091
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
1040
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
1092
1041
|
this.debugLog(`Bot: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
1093
1042
|
}
|
|
1094
1043
|
}
|
|
1095
1044
|
PressOrSwitch(device) {
|
|
1096
1045
|
if (!device.bot?.mode) {
|
|
1097
|
-
this.botMode =
|
|
1046
|
+
this.botMode = 'switch';
|
|
1098
1047
|
this.warnLog(`Bot: ${this.accessory.displayName} does not have bot mode set in the Plugin's SwitchBot Device Settings,`);
|
|
1099
1048
|
this.warnLog(`Bot: ${this.accessory.displayName} is defaulting to "${this.botMode}" mode, you may experience issues.`);
|
|
1100
1049
|
}
|
|
1101
|
-
else if (device.bot?.mode ===
|
|
1102
|
-
this.botMode =
|
|
1050
|
+
else if (device.bot?.mode === 'switch') {
|
|
1051
|
+
this.botMode = 'switch';
|
|
1103
1052
|
this.debugLog(`Bot: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
|
|
1104
1053
|
}
|
|
1105
|
-
else if (device.bot?.mode ===
|
|
1106
|
-
this.botMode =
|
|
1054
|
+
else if (device.bot?.mode === 'press') {
|
|
1055
|
+
this.botMode = 'press';
|
|
1107
1056
|
this.debugLog(`Bot: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
|
|
1108
1057
|
}
|
|
1109
1058
|
else {
|
|
1110
1059
|
throw new Error(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
|
|
1111
1060
|
}
|
|
1112
1061
|
}
|
|
1062
|
+
allowPushChanges(device) {
|
|
1063
|
+
if (device.bot?.allowPush) {
|
|
1064
|
+
this.allowPush = true;
|
|
1065
|
+
}
|
|
1066
|
+
else {
|
|
1067
|
+
this.allowPush = false;
|
|
1068
|
+
}
|
|
1069
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Allowing Push Changes: ${this.allowPush}`);
|
|
1070
|
+
}
|
|
1113
1071
|
removeOutletService(accessory) {
|
|
1114
1072
|
// If outletService still pressent, then remove first
|
|
1115
1073
|
this.outletService = this.accessory.getService(this.platform.Service.Outlet);
|
|
@@ -1210,8 +1168,8 @@ class Bot {
|
|
|
1210
1168
|
}
|
|
1211
1169
|
debugLog(...log) {
|
|
1212
1170
|
if (this.enablingDeviceLogging()) {
|
|
1213
|
-
if (this.deviceLogging ===
|
|
1214
|
-
this.platform.log.info(
|
|
1171
|
+
if (this.deviceLogging === 'debug') {
|
|
1172
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
1215
1173
|
}
|
|
1216
1174
|
else {
|
|
1217
1175
|
this.platform.log.debug(String(...log));
|
|
@@ -1219,7 +1177,7 @@ class Bot {
|
|
|
1219
1177
|
}
|
|
1220
1178
|
}
|
|
1221
1179
|
enablingDeviceLogging() {
|
|
1222
|
-
return
|
|
1180
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
1223
1181
|
}
|
|
1224
1182
|
}
|
|
1225
1183
|
exports.Bot = Bot;
|