homebridge-smartsystem 7.1.20 → 7.1.21
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/package.json +3 -2
- package/server/HB.js +19 -1
- package/server/smartapp.js +34 -10
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-smartsystem",
|
|
3
3
|
"displayname": "Duotecno Bridge",
|
|
4
|
-
"version": "7.1.
|
|
4
|
+
"version": "7.1.21",
|
|
5
5
|
"description": "SmartServer (Proxy TCP sockets to the cloud, Smappee MQTT, Duotecno IP Nodes, Homekit interface)",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"author": "Johan Coppieters",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"check-published": "npm view homebridge-smartsystem version",
|
|
17
17
|
"release:patch": "echo 'npm login !!' && git add -A && git commit -m 'pre-release' --allow-empty && npm version patch && npm publish && git push && git push --tags && echo 'Waiting for npm to propagate...' && sleep 5 && npm run check-published",
|
|
18
18
|
"release:minor": "echo 'npm login !!' && git add -A && git commit -m 'pre-release' --allow-empty && npm version minor && npm publish && git push && git push --tags && echo 'Waiting for npm to propagate...' && sleep 5 && npm run check-published",
|
|
19
|
-
"release:major": "git add -A && git commit -m 'pre-release' --allow-empty && npm version major && npm publish && git push && git push --tags && echo 'Waiting for npm to propagate...' && sleep 5 && npm run check-published"
|
|
19
|
+
"release:major": "git add -A && git commit -m 'pre-release' --allow-empty && npm version major && npm publish && git push && git push --tags && echo 'Waiting for npm to propagate...' && sleep 5 && npm run check-published",
|
|
20
|
+
"push:azure": "bash scripts/push-azure.sh master"
|
|
20
21
|
},
|
|
21
22
|
"engines": {
|
|
22
23
|
"node": "^18.20.4 || ^20.15.1 || ^22",
|
package/server/HB.js
CHANGED
|
@@ -9,11 +9,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.hbUnsubscribe = exports.hbSubscribe = exports.hbStop = exports.hbGetValue = exports.hbSetState = exports.dt2hbvalue = exports.hb2dtvalue = exports.hbLogin = exports.hbAccessories = exports.hbService = exports.hbName = void 0;
|
|
12
|
+
exports.hbUnsubscribe = exports.hbSubscribe = exports.hbStop = exports.hbGetValue = exports.hbSetState = exports.dt2hbvalue = exports.hb2dtvalue = exports.hbLogin = exports.hbAccessories = exports.hbService = exports.hbName = exports.HbAuthError = void 0;
|
|
13
13
|
const logger_1 = require("../duotecno/logger");
|
|
14
14
|
const HA_API_1 = require("./HA-API");
|
|
15
15
|
let gAccessories = [];
|
|
16
16
|
let timer = null;
|
|
17
|
+
// Thrown when the Homebridge API rejects a request because the access token is
|
|
18
|
+
// missing/expired, so callers can force a fresh hbLogin() instead of silently
|
|
19
|
+
// failing forever with the same stale token.
|
|
20
|
+
class HbAuthError extends Error {
|
|
21
|
+
constructor(message = "Homebridge API rejected the request: token expired?") {
|
|
22
|
+
super(message);
|
|
23
|
+
this.name = "HbAuthError";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.HbAuthError = HbAuthError;
|
|
27
|
+
function checkHbAuth(respBody) {
|
|
28
|
+
if (respBody && (respBody.statusCode === 401 || /unauthorized/i.test(respBody.message || respBody.error || ""))) {
|
|
29
|
+
throw new HbAuthError();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
17
32
|
function hbName(id) {
|
|
18
33
|
var _a;
|
|
19
34
|
return ((_a = gAccessories.find(item => item.id === id)) === null || _a === void 0 ? void 0 : _a.name) || "Unknown";
|
|
@@ -265,6 +280,7 @@ function hbSetState(server, id, service, value, token) {
|
|
|
265
280
|
const respBody = yield (0, HA_API_1.httpRequest)(server + "/api/accessories/" + id, 'PUT', JSON.stringify(data), HA_API_1.ContentType.json, {
|
|
266
281
|
Authorization: 'Bearer ' + token
|
|
267
282
|
});
|
|
283
|
+
checkHbAuth(respBody);
|
|
268
284
|
if (respBody && respBody.error) {
|
|
269
285
|
(0, logger_1.log)("HB", "hbSetState: " + id + " -> error: " + JSON.stringify(respBody));
|
|
270
286
|
}
|
|
@@ -277,6 +293,7 @@ function hbGetValue(server, id, service, token) {
|
|
|
277
293
|
const respBody = yield (0, HA_API_1.httpRequest)(server + "/api/accessories/" + id, 'GET', "", HA_API_1.ContentType.json, {
|
|
278
294
|
Authorization: 'Bearer ' + token
|
|
279
295
|
});
|
|
296
|
+
checkHbAuth(respBody);
|
|
280
297
|
if (respBody && respBody.error) {
|
|
281
298
|
(0, logger_1.log)("HB", "hbGetState: " + id + " -> error: " + JSON.stringify(respBody));
|
|
282
299
|
return undefined;
|
|
@@ -298,6 +315,7 @@ function hbStop(server, id, service, token) {
|
|
|
298
315
|
const respBody = yield (0, HA_API_1.httpRequest)(server + "/api/accessories/" + id, 'GET', "", HA_API_1.ContentType.json, {
|
|
299
316
|
Authorization: 'Bearer ' + token
|
|
300
317
|
});
|
|
318
|
+
checkHbAuth(respBody);
|
|
301
319
|
if (respBody && respBody.error) {
|
|
302
320
|
(0, logger_1.log)("HB", "hbGetState: " + id + " -> error: " + JSON.stringify(respBody));
|
|
303
321
|
return undefined;
|
package/server/smartapp.js
CHANGED
|
@@ -532,17 +532,30 @@ class SmartApp extends webapp_1.WebApp {
|
|
|
532
532
|
if (this.links.length && (yield this.checkToken())) {
|
|
533
533
|
for (const link of this.links) {
|
|
534
534
|
if ((link.type === types_1.LinkType.kAccessory) && link.unit) {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
535
|
+
try {
|
|
536
|
+
const hbValue = yield (0, HB_1.hbGetValue)(this.config.apiHost + ":" + this.config.apiPort, link.accId, link.accService, this.token);
|
|
537
|
+
(0, logger_1.debug)("smartapp", "Received HB value for accessory: " + link.accName + " -> " + hbValue + " from accessory");
|
|
538
|
+
if (typeof hbValue != "undefined") {
|
|
539
|
+
const { dtValue, dtTarget } = (0, HB_1.hb2dtvalue)(link.unit, hbValue);
|
|
540
|
+
if (dtValue !== link.dtValue) { // || state !== link.status
|
|
541
|
+
(0, logger_1.log)("smartapp", "-> Setting value of Duotecno unit: " + link.unit.getDisplayName() + " to " + dtTarget + " of HB accessory: " + link.accName + " with value " + hbValue);
|
|
542
|
+
link.dtValue = dtValue;
|
|
543
|
+
link.unit.setState(dtTarget);
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
(0, logger_1.debug)("smartapp", "-> No change for unit: " + link.unit.getDisplayName() + " to " + dtValue);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
catch (e) {
|
|
551
|
+
if (e instanceof HB_1.HbAuthError) {
|
|
552
|
+
(0, logger_1.err)("smartapp", "initLinks: Homebridge API token expired -> forcing re-login on next round");
|
|
553
|
+
this.token = "";
|
|
554
|
+
(0, config_1.setToken)("");
|
|
555
|
+
break;
|
|
543
556
|
}
|
|
544
557
|
else {
|
|
545
|
-
(0, logger_1.
|
|
558
|
+
(0, logger_1.err)("smartapp", "initLinks: failed to get HB value for accessory " + link.accName + " -> " + e.toString());
|
|
546
559
|
}
|
|
547
560
|
}
|
|
548
561
|
}
|
|
@@ -553,6 +566,10 @@ class SmartApp extends webapp_1.WebApp {
|
|
|
553
566
|
informLinks(u, kind) {
|
|
554
567
|
return __awaiter(this, void 0, void 0, function* () {
|
|
555
568
|
(0, logger_1.debug)("smartapp", "Received DT value from unit: " + u.getDisplayName() + " -> " + u.value + " / " + u.status + " from unit");
|
|
569
|
+
if (!this.links.length)
|
|
570
|
+
return;
|
|
571
|
+
if (!(yield this.checkToken()))
|
|
572
|
+
return;
|
|
556
573
|
for (const link of this.links) {
|
|
557
574
|
if (u.isUnit(link.masterAddress, link.masterPort, link.logicalNodeAddress, link.logicalAddress)) {
|
|
558
575
|
const hbValue = (0, HB_1.dt2hbvalue)(u, link.hbValue, link.min, link.max);
|
|
@@ -574,7 +591,14 @@ class SmartApp extends webapp_1.WebApp {
|
|
|
574
591
|
}
|
|
575
592
|
}
|
|
576
593
|
catch (e) {
|
|
577
|
-
|
|
594
|
+
if (e instanceof HB_1.HbAuthError) {
|
|
595
|
+
(0, logger_1.err)("smartapp", "informLinks: Homebridge API token expired for accessory " + link.accName + " -> forcing re-login on next update");
|
|
596
|
+
this.token = "";
|
|
597
|
+
(0, config_1.setToken)("");
|
|
598
|
+
}
|
|
599
|
+
else {
|
|
600
|
+
(0, logger_1.err)("smartapp", "informLinks: failed to set HB value for accessory " + link.accName + " -> " + e.toString());
|
|
601
|
+
}
|
|
578
602
|
}
|
|
579
603
|
}
|
|
580
604
|
}
|