@switchbot/homebridge-switchbot 1.9.0 → 1.10.1
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 +13 -1
- package/CHANGELOG.md +16 -0
- package/README.md +100 -99
- package/SECURITY.md +2 -2
- package/config.schema.json +8 -0
- package/dist/devices/bots.d.ts +2 -2
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +91 -86
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +15 -15
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +60 -71
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +2 -2
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +33 -31
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +2 -2
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +71 -71
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +2 -2
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +74 -76
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +2 -2
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +29 -27
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +2 -2
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +34 -32
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +7 -7
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +18 -23
- package/dist/devices/plugs.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +5 -2
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +61 -56
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +2 -2
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +12 -17
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +2 -2
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +10 -13
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +2 -2
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +15 -17
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +2 -2
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +10 -13
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +2 -2
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +10 -13
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +2 -2
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +22 -30
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +2 -2
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +11 -13
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +2 -2
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +10 -13
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +3 -3
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +13 -14
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -0
- package/dist/settings.d.ts.map +1 -1
- 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 +15 -9
- package/src/devices/bots.ts +217 -186
- package/src/devices/colorbulb.ts +90 -84
- package/src/devices/contact.ts +85 -78
- package/src/devices/curtains.ts +152 -135
- package/src/devices/humidifiers.ts +162 -137
- package/src/devices/meters.ts +76 -73
- package/src/devices/motion.ts +87 -78
- package/src/devices/plugs.ts +27 -31
- package/src/irdevices/airconditioners.ts +91 -59
- package/src/irdevices/airpurifiers.ts +22 -23
- package/src/irdevices/cameras.ts +18 -19
- package/src/irdevices/fans.ts +27 -25
- package/src/irdevices/lights.ts +18 -20
- package/src/irdevices/others.ts +18 -19
- package/src/irdevices/tvs.ts +33 -41
- package/src/irdevices/vacuumcleaners.ts +19 -19
- package/src/irdevices/waterheaters.ts +21 -31
- package/src/platform.ts +32 -33
- package/src/settings.ts +9 -19
- package/tsconfig.json +5 -14
- package/.github/PULL_REQUEST_TEMPLATE/pull_requests.md +0 -27
package/dist/devices/bots.js
CHANGED
|
@@ -61,9 +61,8 @@ class Bot {
|
|
|
61
61
|
this.removeWindowCoveringService(accessory);
|
|
62
62
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
63
63
|
// Add switchService
|
|
64
|
-
(this.switchService =
|
|
65
|
-
accessory.
|
|
66
|
-
accessory.addService(this.platform.Service.Switch)), `${accessory.displayName} Switch`;
|
|
64
|
+
(this.switchService = accessory.getService(this.platform.Service.Switch) || accessory.addService(this.platform.Service.Switch)),
|
|
65
|
+
`${accessory.displayName} Switch`;
|
|
67
66
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Switch`);
|
|
68
67
|
this.switchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
69
68
|
this.switchService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
|
|
@@ -80,8 +79,8 @@ class Bot {
|
|
|
80
79
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
81
80
|
// Add switchService
|
|
82
81
|
(this.garageDoorService =
|
|
83
|
-
accessory.getService(this.platform.Service.GarageDoorOpener) ||
|
|
84
|
-
|
|
82
|
+
accessory.getService(this.platform.Service.GarageDoorOpener) || accessory.addService(this.platform.Service.GarageDoorOpener)),
|
|
83
|
+
`${accessory.displayName} Garage Door Opener`;
|
|
85
84
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Garage Door Opener`);
|
|
86
85
|
this.garageDoorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
87
86
|
this.garageDoorService.getCharacteristic(this.platform.Characteristic.TargetDoorState).onSet(this.handleOnSet.bind(this));
|
|
@@ -98,18 +97,19 @@ class Bot {
|
|
|
98
97
|
this.removeWindowCoveringService(accessory);
|
|
99
98
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
100
99
|
// Add switchService
|
|
101
|
-
(this.doorService =
|
|
102
|
-
accessory.
|
|
103
|
-
accessory.addService(this.platform.Service.Door)), `${accessory.displayName} Door`;
|
|
100
|
+
(this.doorService = accessory.getService(this.platform.Service.Door) || accessory.addService(this.platform.Service.Door)),
|
|
101
|
+
`${accessory.displayName} Door`;
|
|
104
102
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Door`);
|
|
105
103
|
this.doorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
106
|
-
this.doorService
|
|
104
|
+
this.doorService
|
|
105
|
+
.getCharacteristic(this.platform.Characteristic.TargetPosition)
|
|
107
106
|
.setProps({
|
|
108
107
|
validValues: [0, 100],
|
|
109
108
|
minValue: 0,
|
|
110
109
|
maxValue: 100,
|
|
111
110
|
minStep: 100,
|
|
112
|
-
})
|
|
111
|
+
})
|
|
112
|
+
.onSet(this.handleOnSet.bind(this));
|
|
113
113
|
this.doorService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
|
|
114
114
|
}
|
|
115
115
|
else if (device.bot?.deviceType === 'window') {
|
|
@@ -123,18 +123,19 @@ class Bot {
|
|
|
123
123
|
this.removeWindowCoveringService(accessory);
|
|
124
124
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
125
125
|
// Add switchService
|
|
126
|
-
(this.windowService =
|
|
127
|
-
accessory.
|
|
128
|
-
accessory.addService(this.platform.Service.Window)), `${accessory.displayName} Window`;
|
|
126
|
+
(this.windowService = accessory.getService(this.platform.Service.Window) || accessory.addService(this.platform.Service.Window)),
|
|
127
|
+
`${accessory.displayName} Window`;
|
|
129
128
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Window`);
|
|
130
129
|
this.windowService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
131
|
-
this.windowService
|
|
130
|
+
this.windowService
|
|
131
|
+
.getCharacteristic(this.platform.Characteristic.TargetPosition)
|
|
132
132
|
.setProps({
|
|
133
133
|
validValues: [0, 100],
|
|
134
134
|
minValue: 0,
|
|
135
135
|
maxValue: 100,
|
|
136
136
|
minStep: 100,
|
|
137
|
-
})
|
|
137
|
+
})
|
|
138
|
+
.onSet(this.handleOnSet.bind(this));
|
|
138
139
|
this.windowService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
|
|
139
140
|
}
|
|
140
141
|
else if (device.bot?.deviceType === 'windowcovering') {
|
|
@@ -149,17 +150,19 @@ class Bot {
|
|
|
149
150
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
150
151
|
// Add switchService
|
|
151
152
|
(this.windowCoveringService =
|
|
152
|
-
accessory.getService(this.platform.Service.WindowCovering) ||
|
|
153
|
-
|
|
153
|
+
accessory.getService(this.platform.Service.WindowCovering) || accessory.addService(this.platform.Service.WindowCovering)),
|
|
154
|
+
`${accessory.displayName} Window Covering`;
|
|
154
155
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Window Covering`);
|
|
155
156
|
this.windowCoveringService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
156
|
-
this.windowCoveringService
|
|
157
|
+
this.windowCoveringService
|
|
158
|
+
.getCharacteristic(this.platform.Characteristic.TargetPosition)
|
|
157
159
|
.setProps({
|
|
158
160
|
validValues: [0, 100],
|
|
159
161
|
minValue: 0,
|
|
160
162
|
maxValue: 100,
|
|
161
163
|
minStep: 100,
|
|
162
|
-
})
|
|
164
|
+
})
|
|
165
|
+
.onSet(this.handleOnSet.bind(this));
|
|
163
166
|
this.windowCoveringService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
|
|
164
167
|
}
|
|
165
168
|
else if (device.bot?.deviceType === 'lock') {
|
|
@@ -173,9 +176,8 @@ class Bot {
|
|
|
173
176
|
this.removeWindowCoveringService(accessory);
|
|
174
177
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
175
178
|
// Add switchService
|
|
176
|
-
(this.lockService =
|
|
177
|
-
accessory.
|
|
178
|
-
accessory.addService(this.platform.Service.LockMechanism)), `${accessory.displayName} Lock`;
|
|
179
|
+
(this.lockService = accessory.getService(this.platform.Service.LockMechanism) || accessory.addService(this.platform.Service.LockMechanism)),
|
|
180
|
+
`${accessory.displayName} Lock`;
|
|
179
181
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Lock`);
|
|
180
182
|
this.lockService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
181
183
|
this.lockService.getCharacteristic(this.platform.Characteristic.LockTargetState).onSet(this.handleOnSet.bind(this));
|
|
@@ -191,9 +193,8 @@ class Bot {
|
|
|
191
193
|
this.removeWindowCoveringService(accessory);
|
|
192
194
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
193
195
|
// Add switchService
|
|
194
|
-
(this.faucetService =
|
|
195
|
-
accessory.
|
|
196
|
-
accessory.addService(this.platform.Service.Faucet)), `${accessory.displayName} Faucet`;
|
|
196
|
+
(this.faucetService = accessory.getService(this.platform.Service.Faucet) || accessory.addService(this.platform.Service.Faucet)),
|
|
197
|
+
`${accessory.displayName} Faucet`;
|
|
197
198
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Faucet`);
|
|
198
199
|
this.faucetService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
199
200
|
this.faucetService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.handleOnSet.bind(this));
|
|
@@ -209,9 +210,8 @@ class Bot {
|
|
|
209
210
|
this.removeWindowCoveringService(accessory);
|
|
210
211
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
211
212
|
// Add switchService
|
|
212
|
-
(this.fanService =
|
|
213
|
-
accessory.
|
|
214
|
-
accessory.addService(this.platform.Service.Fan)), `${accessory.displayName} Fan`;
|
|
213
|
+
(this.fanService = accessory.getService(this.platform.Service.Fan) || accessory.addService(this.platform.Service.Fan)),
|
|
214
|
+
`${accessory.displayName} Fan`;
|
|
215
215
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Fan`);
|
|
216
216
|
this.fanService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
217
217
|
this.fanService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
|
|
@@ -229,10 +229,12 @@ class Bot {
|
|
|
229
229
|
// Add switchService
|
|
230
230
|
(this.statefulProgrammableSwitchService =
|
|
231
231
|
accessory.getService(this.platform.Service.StatefulProgrammableSwitch) ||
|
|
232
|
-
accessory.addService(this.platform.Service.StatefulProgrammableSwitch)),
|
|
232
|
+
accessory.addService(this.platform.Service.StatefulProgrammableSwitch)),
|
|
233
|
+
`${accessory.displayName} Stateful Programmable Switch`;
|
|
233
234
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
|
|
234
235
|
this.statefulProgrammableSwitchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
235
|
-
this.statefulProgrammableSwitchService
|
|
236
|
+
this.statefulProgrammableSwitchService
|
|
237
|
+
.getCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState)
|
|
236
238
|
.onSet(this.handleOnSet.bind(this));
|
|
237
239
|
}
|
|
238
240
|
else {
|
|
@@ -246,9 +248,8 @@ class Bot {
|
|
|
246
248
|
this.removeWindowCoveringService(accessory);
|
|
247
249
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
248
250
|
// Add outletService
|
|
249
|
-
(this.outletService =
|
|
250
|
-
accessory.
|
|
251
|
-
accessory.addService(this.platform.Service.Outlet)), `${accessory.displayName} Outlet`;
|
|
251
|
+
(this.outletService = accessory.getService(this.platform.Service.Outlet) || accessory.addService(this.platform.Service.Outlet)),
|
|
252
|
+
`${accessory.displayName} Outlet`;
|
|
252
253
|
this.infoLog(`Bot: ${accessory.displayName} Displaying as Outlet`);
|
|
253
254
|
this.outletService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
254
255
|
this.outletService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
|
|
@@ -261,9 +262,8 @@ class Bot {
|
|
|
261
262
|
}
|
|
262
263
|
else if (device.ble && !this.batteryService) {
|
|
263
264
|
this.debugLog(`Bot: ${accessory.displayName} Add Battery Service`);
|
|
264
|
-
(this.batteryService =
|
|
265
|
-
|
|
266
|
-
this.accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
|
|
265
|
+
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
|
|
266
|
+
`${accessory.displayName} Battery`;
|
|
267
267
|
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
268
268
|
}
|
|
269
269
|
else {
|
|
@@ -294,12 +294,10 @@ class Bot {
|
|
|
294
294
|
catch (e) {
|
|
295
295
|
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges`);
|
|
296
296
|
if (this.deviceLogging === 'debug') {
|
|
297
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,`
|
|
298
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
297
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
299
298
|
}
|
|
300
299
|
if (this.platform.debugMode) {
|
|
301
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,`
|
|
302
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
300
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,` + ` Error: ${JSON.stringify(e)}`);
|
|
303
301
|
}
|
|
304
302
|
}
|
|
305
303
|
this.botUpdateInProgress = false;
|
|
@@ -390,16 +388,21 @@ class Bot {
|
|
|
390
388
|
this.debugLog(`Bot: ${this.accessory.displayName} BLE refreshStatus`);
|
|
391
389
|
const switchbot = await this.platform.connectBLE();
|
|
392
390
|
// Convert to BLE Address
|
|
393
|
-
this.device.bleMac =
|
|
391
|
+
this.device.bleMac = this.device
|
|
392
|
+
.deviceId.match(/.{1,2}/g)
|
|
393
|
+
.join(':')
|
|
394
|
+
.toLowerCase();
|
|
394
395
|
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
395
396
|
// Start to monitor advertisement packets
|
|
396
397
|
if (switchbot === false) {
|
|
397
398
|
this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection: ${switchbot}`);
|
|
398
399
|
}
|
|
399
|
-
switchbot
|
|
400
|
+
switchbot
|
|
401
|
+
.startScan({
|
|
400
402
|
model: 'H',
|
|
401
403
|
id: this.device.bleMac,
|
|
402
|
-
})
|
|
404
|
+
})
|
|
405
|
+
.then(() => {
|
|
403
406
|
// Set an event hander
|
|
404
407
|
switchbot.onadvertisement = (ad) => {
|
|
405
408
|
this.serviceData = ad.serviceData;
|
|
@@ -407,8 +410,8 @@ class Bot {
|
|
|
407
410
|
this.state = ad.serviceData.state;
|
|
408
411
|
this.battery = ad.serviceData.battery;
|
|
409
412
|
this.debugLog(`Bot: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
410
|
-
this.debugLog(`Bot: ${this.accessory.displayName}, model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},`
|
|
411
|
-
|
|
413
|
+
this.debugLog(`Bot: ${this.accessory.displayName}, model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
|
|
414
|
+
` mode: ${ad.serviceData.mode}, state: ${ad.serviceData.state}, battery: ${ad.serviceData.battery}`);
|
|
412
415
|
if (this.serviceData) {
|
|
413
416
|
this.connected = true;
|
|
414
417
|
this.debugLog(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
@@ -420,7 +423,8 @@ class Bot {
|
|
|
420
423
|
};
|
|
421
424
|
// Wait 2 seconds
|
|
422
425
|
return switchbot.wait(this.scanDuration * 1000);
|
|
423
|
-
})
|
|
426
|
+
})
|
|
427
|
+
.then(async () => {
|
|
424
428
|
// Stop to monitor
|
|
425
429
|
switchbot.stopScan();
|
|
426
430
|
if (this.connected) {
|
|
@@ -435,15 +439,14 @@ class Bot {
|
|
|
435
439
|
await this.openAPIRefreshStatus();
|
|
436
440
|
}
|
|
437
441
|
}
|
|
438
|
-
})
|
|
442
|
+
})
|
|
443
|
+
.catch(async (e) => {
|
|
439
444
|
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
440
445
|
if (this.deviceLogging === 'debug') {
|
|
441
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
442
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
446
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
443
447
|
}
|
|
444
448
|
if (this.platform.debugMode) {
|
|
445
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
446
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
449
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
447
450
|
}
|
|
448
451
|
if (this.platform.config.credentials?.openToken) {
|
|
449
452
|
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
@@ -466,12 +469,10 @@ class Bot {
|
|
|
466
469
|
catch (e) {
|
|
467
470
|
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
468
471
|
if (this.deviceLogging === 'debug') {
|
|
469
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
470
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
472
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
471
473
|
}
|
|
472
474
|
if (this.platform.debugMode) {
|
|
473
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
474
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
475
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
475
476
|
}
|
|
476
477
|
this.apiError(e);
|
|
477
478
|
}
|
|
@@ -500,20 +501,25 @@ class Bot {
|
|
|
500
501
|
}
|
|
501
502
|
async BLEpushChanges() {
|
|
502
503
|
this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges On: ${this.On} OnCached: ${this.OnCached}`);
|
|
503
|
-
if (
|
|
504
|
+
if (this.On !== this.OnCached || this.allowPush) {
|
|
504
505
|
this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges`);
|
|
505
506
|
const switchbot = await this.platform.connectBLE();
|
|
506
507
|
// Convert to BLE Address
|
|
507
|
-
this.device.bleMac =
|
|
508
|
+
this.device.bleMac = this.device
|
|
509
|
+
.deviceId.match(/.{1,2}/g)
|
|
510
|
+
.join(':')
|
|
511
|
+
.toLowerCase();
|
|
508
512
|
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
509
513
|
//if (switchbot !== false) {
|
|
510
514
|
if (this.botMode === 'press') {
|
|
511
515
|
this.debugLog(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
|
|
512
|
-
switchbot
|
|
516
|
+
switchbot
|
|
517
|
+
.discover({ model: 'H', quick: true, id: this.device.bleMac })
|
|
513
518
|
.then((device_list) => {
|
|
514
519
|
this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
515
520
|
return device_list[0].press({ id: this.device.bleMac });
|
|
516
|
-
})
|
|
521
|
+
})
|
|
522
|
+
.then(() => {
|
|
517
523
|
this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
|
|
518
524
|
this.On = false;
|
|
519
525
|
this.OnCached = this.On;
|
|
@@ -527,15 +533,14 @@ class Bot {
|
|
|
527
533
|
}
|
|
528
534
|
this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}, Switch Timeout`);
|
|
529
535
|
}, 500);
|
|
530
|
-
})
|
|
536
|
+
})
|
|
537
|
+
.catch(async (e) => {
|
|
531
538
|
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
532
539
|
if (this.deviceLogging === 'debug') {
|
|
533
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
534
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
540
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
535
541
|
}
|
|
536
542
|
if (this.platform.debugMode) {
|
|
537
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
538
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
543
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
539
544
|
}
|
|
540
545
|
if (this.platform.config.credentials?.openToken) {
|
|
541
546
|
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
@@ -546,22 +551,24 @@ class Bot {
|
|
|
546
551
|
}
|
|
547
552
|
else if (this.botMode === 'switch') {
|
|
548
553
|
this.debugLog(`Bot: ${this.accessory.displayName} Press Mode: ${this.botMode}`);
|
|
549
|
-
switchbot
|
|
554
|
+
switchbot
|
|
555
|
+
.discover({ model: 'H', quick: true, id: this.device.bleMac })
|
|
556
|
+
.then((device_list) => {
|
|
550
557
|
this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
|
|
551
558
|
return this.turnOnOff(device_list);
|
|
552
|
-
})
|
|
559
|
+
})
|
|
560
|
+
.then(() => {
|
|
553
561
|
this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
|
|
554
562
|
this.OnCached = this.On;
|
|
555
563
|
this.accessory.context.On = this.OnCached;
|
|
556
|
-
})
|
|
564
|
+
})
|
|
565
|
+
.catch(async (e) => {
|
|
557
566
|
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
558
567
|
if (this.deviceLogging === 'debug') {
|
|
559
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
560
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
568
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
561
569
|
}
|
|
562
570
|
if (this.platform.debugMode) {
|
|
563
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
564
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
571
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
565
572
|
}
|
|
566
573
|
if (this.platform.config.credentials?.openToken) {
|
|
567
574
|
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
@@ -595,7 +602,7 @@ class Bot {
|
|
|
595
602
|
async openAPIpushChanges() {
|
|
596
603
|
if (this.platform.config.credentials?.openToken) {
|
|
597
604
|
try {
|
|
598
|
-
if (
|
|
605
|
+
if (this.On !== this.OnCached || this.allowPush) {
|
|
599
606
|
this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI pushChanges`);
|
|
600
607
|
const payload = {
|
|
601
608
|
commandType: 'command',
|
|
@@ -619,10 +626,10 @@ class Bot {
|
|
|
619
626
|
else {
|
|
620
627
|
throw new Error(`Bot: ${this.accessory.displayName} Device Paramters not set for this Bot.`);
|
|
621
628
|
}
|
|
622
|
-
this.infoLog(`Bot: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
623
|
-
|
|
629
|
+
this.infoLog(`Bot: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
630
|
+
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
624
631
|
// Make the API request
|
|
625
|
-
const push =
|
|
632
|
+
const push = await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
626
633
|
this.debugLog(`Bot: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
|
|
627
634
|
this.statusCode(push);
|
|
628
635
|
this.OnCached = this.On;
|
|
@@ -632,12 +639,10 @@ class Bot {
|
|
|
632
639
|
catch (e) {
|
|
633
640
|
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
634
641
|
if (this.deviceLogging === 'debug') {
|
|
635
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
636
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
642
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
637
643
|
}
|
|
638
644
|
if (this.platform.debugMode) {
|
|
639
|
-
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
640
|
-
+ ` Error: ${JSON.stringify(e)}`);
|
|
645
|
+
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
641
646
|
}
|
|
642
647
|
this.apiError(e);
|
|
643
648
|
}
|
|
@@ -895,8 +900,8 @@ class Bot {
|
|
|
895
900
|
this.offlineOff();
|
|
896
901
|
break;
|
|
897
902
|
case 190:
|
|
898
|
-
this.errorLog(`Bot: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
|
|
899
|
-
|
|
903
|
+
this.errorLog(`Bot: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
904
|
+
` Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
900
905
|
break;
|
|
901
906
|
case 100:
|
|
902
907
|
this.debugLog(`Bot: ${this.accessory.displayName} Command successfully sent.`);
|
|
@@ -929,9 +934,9 @@ class Bot {
|
|
|
929
934
|
this.On = true;
|
|
930
935
|
}
|
|
931
936
|
}
|
|
932
|
-
else if (this.device.bot?.deviceType === 'door'
|
|
933
|
-
|
|
934
|
-
|
|
937
|
+
else if (this.device.bot?.deviceType === 'door' ||
|
|
938
|
+
this.device.bot?.deviceType === 'window' ||
|
|
939
|
+
this.device.bot?.deviceType === 'windowcovering') {
|
|
935
940
|
this.debugLog(`Bot: ${this.accessory.displayName} TargetPosition: ${value}`);
|
|
936
941
|
if (value === 0) {
|
|
937
942
|
this.On = false;
|
|
@@ -1144,8 +1149,8 @@ class Bot {
|
|
|
1144
1149
|
accessory.removeService(this.switchService);
|
|
1145
1150
|
}
|
|
1146
1151
|
/**
|
|
1147
|
-
|
|
1148
|
-
|
|
1152
|
+
* Logging for Device
|
|
1153
|
+
*/
|
|
1149
1154
|
infoLog(...log) {
|
|
1150
1155
|
if (this.enablingDeviceLogging()) {
|
|
1151
1156
|
this.platform.log.info(String(...log));
|