homebridge-smartsystem 6.7.3 → 6.7.4
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/README.md +2 -0
- package/config.json +12 -16
- package/duotecno/logger.js +1 -1
- package/duotecno/logger.ts +1 -1
- package/duotecno/types.ts +2 -2
- package/package.json +1 -1
- package/server/HB.js +39 -11
- package/server/HB.ts +39 -10
- package/server/smartapp.js +17 -31
- package/server/smartapp.ts +20 -27
- package/server/views/link-details.ejs +1 -1
package/README.md
CHANGED
|
@@ -298,6 +298,8 @@ Homebridge UI version
|
|
|
298
298
|
- 1: updated the readme file
|
|
299
299
|
- 2: use HB Accessory characteristics in set/get, ignore status for the moment
|
|
300
300
|
- 2: remember/show username in login screen + set focus to password
|
|
301
|
+
- 3: do dimmers/up-downs
|
|
302
|
+
- 4: better up-down values to and from HB
|
|
301
303
|
|
|
302
304
|
## Hardware
|
|
303
305
|
A Raspberry Pi that connects to a Duotecno IP Node
|
package/config.json
CHANGED
|
@@ -270,22 +270,6 @@
|
|
|
270
270
|
"ObstructionDetected"
|
|
271
271
|
],
|
|
272
272
|
"type": "accessory"
|
|
273
|
-
},
|
|
274
|
-
{
|
|
275
|
-
"logicalNodeAddress": 3,
|
|
276
|
-
"logicalAddress": 30,
|
|
277
|
-
"masterAddress": "192.168.0.97",
|
|
278
|
-
"masterPort": 5001,
|
|
279
|
-
"name": "dimmers",
|
|
280
|
-
"displayName": "dimmers",
|
|
281
|
-
"extendedType": 0,
|
|
282
|
-
"accId": "da32bb657ad68d3fd63004015406e0cbde28355fc950204cec2fcd90d835e044",
|
|
283
|
-
"accName": "Somfy Dimmer",
|
|
284
|
-
"accService": [
|
|
285
|
-
"On",
|
|
286
|
-
"Brightness"
|
|
287
|
-
],
|
|
288
|
-
"type": "accessory"
|
|
289
273
|
}
|
|
290
274
|
]
|
|
291
275
|
},
|
|
@@ -373,6 +357,18 @@
|
|
|
373
357
|
"used": "Y",
|
|
374
358
|
"group": 0
|
|
375
359
|
},
|
|
360
|
+
{
|
|
361
|
+
"logicalNodeAddress": 3,
|
|
362
|
+
"logicalAddress": 28,
|
|
363
|
+
"masterAddress": "192.168.0.97",
|
|
364
|
+
"masterPort": 5001,
|
|
365
|
+
"name": "Garage $",
|
|
366
|
+
"displayName": "Garage ",
|
|
367
|
+
"extendedType": 8,
|
|
368
|
+
"active": "N",
|
|
369
|
+
"used": "Y",
|
|
370
|
+
"group": 0
|
|
371
|
+
},
|
|
376
372
|
{
|
|
377
373
|
"logicalNodeAddress": 3,
|
|
378
374
|
"logicalAddress": 31,
|
package/duotecno/logger.js
CHANGED
package/duotecno/logger.ts
CHANGED
|
@@ -10,7 +10,7 @@ export enum LogLevel { noLog = 0, log = 1, debug = 2 };
|
|
|
10
10
|
export const logSettings = {
|
|
11
11
|
"*": LogLevel.log,
|
|
12
12
|
"master": LogLevel.log,
|
|
13
|
-
"protocol": LogLevel.
|
|
13
|
+
"protocol": LogLevel.debug,
|
|
14
14
|
"webapp": LogLevel.log,
|
|
15
15
|
"p1": LogLevel.log,
|
|
16
16
|
"shelly": LogLevel.log,
|
package/duotecno/types.ts
CHANGED
|
@@ -269,8 +269,8 @@ export interface Link extends UnitDef{
|
|
|
269
269
|
accService: Array<string>; // e.g. ["On", "Brightness"], ["TargetPosition", "CurrentPosition", ...]
|
|
270
270
|
type: LinkType;
|
|
271
271
|
unit?: Unit;
|
|
272
|
-
|
|
273
|
-
|
|
272
|
+
dtValue?: number | boolean | string;
|
|
273
|
+
hbValue?: number | boolean | string
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
export const kEmptyLink: Link = {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-smartsystem",
|
|
3
3
|
"displayname": "Duotecno Bridge",
|
|
4
|
-
"version": "6.7.
|
|
4
|
+
"version": "6.7.4",
|
|
5
5
|
"description": "SmartServer (Proxy Websockets to TCP sockets, Smappee MQTT, Duotecno IP Nodes, Homekit interface)",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"author": "Johan Coppieters",
|
package/server/HB.js
CHANGED
|
@@ -9,7 +9,7 @@ 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.
|
|
12
|
+
exports.hbUnsubscribe = exports.hbSubscribe = exports.hbGetValue = exports.hbSetState = exports.dt2hbvalue = exports.hb2dtvalue = exports.hbLogin = exports.hbAccessories = exports.hbService = exports.hbName = void 0;
|
|
13
13
|
const logger_1 = require("../duotecno/logger");
|
|
14
14
|
const HA_API_1 = require("./HA-API");
|
|
15
15
|
let gAccessories = [];
|
|
@@ -200,21 +200,49 @@ function hbLoad(value, service) {
|
|
|
200
200
|
;
|
|
201
201
|
return data;
|
|
202
202
|
}
|
|
203
|
+
function hb2dtvalue(unit, value) {
|
|
204
|
+
let dtTarget;
|
|
205
|
+
let dtValue;
|
|
206
|
+
if (typeof value === "boolean")
|
|
207
|
+
value = (value) ? 99 : 1;
|
|
208
|
+
value = Math.round(value);
|
|
209
|
+
if (unit.isUpDown()) {
|
|
210
|
+
dtTarget = (value >= 50) ? 4 : 5; // 4 = up, 5 = down
|
|
211
|
+
dtValue = (value >= 50) ? 2 : 1; // 2 = idle-up, 1 = idle-down
|
|
212
|
+
}
|
|
213
|
+
if (unit.isDimmer())
|
|
214
|
+
dtTarget = dtValue = (value <= 1) ? 1 : (value >= 99) ? 100 : value;
|
|
215
|
+
if (unit.isSwitch() || unit.isMood())
|
|
216
|
+
dtTarget = dtValue = (value > 50) ? 1 : 0;
|
|
217
|
+
return { dtTarget, dtValue };
|
|
218
|
+
}
|
|
219
|
+
exports.hb2dtvalue = hb2dtvalue;
|
|
220
|
+
function dt2hbvalue(unit, dontChangeValue) {
|
|
221
|
+
let value = (typeof unit.value === "boolean") ? (unit.value ? 100 : 0) : Math.round(unit.value);
|
|
222
|
+
// status Motor: 0 = stopped, 1 stopped/down, 2 = stopped/up, 3 = busy/down, 4 = busy/up
|
|
223
|
+
if (unit.isUpDown())
|
|
224
|
+
return ((value === 1) || (value === 3)) ? 0 : ((value === 2) || (value === 4)) ? 100 : dontChangeValue;
|
|
225
|
+
if (unit.isDimmer())
|
|
226
|
+
return (value <= 2) ? 0 : (value >= 99) ? 100 : value;
|
|
227
|
+
if (unit.isSwitch() || unit.isMood())
|
|
228
|
+
return (value) ? 1 : 0;
|
|
229
|
+
return value;
|
|
230
|
+
}
|
|
231
|
+
exports.dt2hbvalue = dt2hbvalue;
|
|
203
232
|
function hbValue(data, service) {
|
|
204
|
-
const values = {};
|
|
205
233
|
if (service.includes("Brightness")) {
|
|
206
|
-
|
|
234
|
+
return parseInt(data["Brightness"]);
|
|
207
235
|
}
|
|
208
236
|
if (service.includes("On")) {
|
|
209
|
-
|
|
237
|
+
return parseInt(data["On"]);
|
|
210
238
|
}
|
|
211
239
|
if (service.includes("TargetPosition")) {
|
|
212
|
-
|
|
240
|
+
return parseInt(data["TargetPosition"]);
|
|
213
241
|
}
|
|
214
|
-
return
|
|
242
|
+
return undefined;
|
|
215
243
|
}
|
|
216
244
|
// send a status change to HB Accessory
|
|
217
|
-
function hbSetState(server, id, service, value,
|
|
245
|
+
function hbSetState(server, id, service, value, token) {
|
|
218
246
|
return __awaiter(this, void 0, void 0, function* () {
|
|
219
247
|
const data = hbLoad(value, service);
|
|
220
248
|
(0, logger_1.log)("HB", "hbSetState: " + id + " -> " + JSON.stringify(data));
|
|
@@ -228,26 +256,26 @@ function hbSetState(server, id, service, value, state, token) {
|
|
|
228
256
|
}
|
|
229
257
|
exports.hbSetState = hbSetState;
|
|
230
258
|
// send a status change to HB Accessory
|
|
231
|
-
function
|
|
259
|
+
function hbGetValue(server, id, service, token) {
|
|
232
260
|
return __awaiter(this, void 0, void 0, function* () {
|
|
233
261
|
const respBody = yield (0, HA_API_1.httpRequest)(server + "/api/accessories/" + id, 'GET', "", HA_API_1.ContentType.json, {
|
|
234
262
|
Authorization: 'Bearer ' + token
|
|
235
263
|
});
|
|
236
264
|
if (respBody && respBody.error) {
|
|
237
265
|
(0, logger_1.log)("HB", "hbGetState: " + id + " -> error: " + JSON.stringify(respBody));
|
|
238
|
-
return
|
|
266
|
+
return undefined;
|
|
239
267
|
}
|
|
240
268
|
else if (respBody && respBody.values) {
|
|
241
269
|
return hbValue(respBody.values, service);
|
|
242
270
|
}
|
|
243
271
|
else {
|
|
244
272
|
(0, logger_1.log)("HB", "hbGetState: " + id + " -> no values?? : " + JSON.stringify(respBody));
|
|
245
|
-
return
|
|
273
|
+
return undefined;
|
|
246
274
|
}
|
|
247
275
|
;
|
|
248
276
|
});
|
|
249
277
|
}
|
|
250
|
-
exports.
|
|
278
|
+
exports.hbGetValue = hbGetValue;
|
|
251
279
|
function hbSubscribe(callback) {
|
|
252
280
|
if (timer) {
|
|
253
281
|
clearInterval(timer);
|
package/server/HB.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { err, log } from "../duotecno/logger";
|
|
2
|
+
import { Unit } from "../duotecno/protocol";
|
|
2
3
|
import { ContentType, httpRequest } from "./HA-API";
|
|
3
4
|
|
|
4
5
|
export interface HBAccessory {
|
|
@@ -205,24 +206,52 @@ function hbLoad(value: number | boolean, service: Array<string>): Record<string,
|
|
|
205
206
|
return data;
|
|
206
207
|
}
|
|
207
208
|
|
|
208
|
-
function
|
|
209
|
-
|
|
209
|
+
export function hb2dtvalue(unit: Unit, value: number | boolean): {dtValue: number, dtTarget: number} {
|
|
210
|
+
let dtTarget;
|
|
211
|
+
let dtValue;
|
|
212
|
+
|
|
213
|
+
if (typeof value === "boolean") value = (value) ? 99 : 1;
|
|
214
|
+
value = Math.round(value);
|
|
215
|
+
|
|
216
|
+
if (unit.isUpDown()) {
|
|
217
|
+
dtTarget = (value >= 50) ? 4 : 5; // 4 = up, 5 = down
|
|
218
|
+
dtValue = (value >= 50) ? 2 : 1; // 2 = idle-up, 1 = idle-down
|
|
219
|
+
}
|
|
220
|
+
if (unit.isDimmer()) dtTarget = dtValue = (value <= 1) ? 1 : (value >= 99) ? 100 : value;
|
|
221
|
+
if (unit.isSwitch() || unit.isMood()) dtTarget = dtValue = (value > 50) ? 1 : 0;
|
|
222
|
+
|
|
223
|
+
return {dtTarget, dtValue};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function dt2hbvalue(unit: Unit, dontChangeValue: number): number {
|
|
227
|
+
let value = (typeof unit.value === "boolean") ? (unit.value ? 100 : 0) : Math.round(unit.value);
|
|
228
|
+
|
|
229
|
+
// status Motor: 0 = stopped, 1 stopped/down, 2 = stopped/up, 3 = busy/down, 4 = busy/up
|
|
230
|
+
if (unit.isUpDown()) return ((value === 1) || (value === 3)) ? 0 : ((value === 2) || (value === 4)) ? 100 : dontChangeValue;
|
|
231
|
+
|
|
232
|
+
if (unit.isDimmer()) return (value <= 2) ? 0 : (value >= 99) ? 100 : value;
|
|
233
|
+
if (unit.isSwitch() || unit.isMood()) return (value) ? 1 : 0;
|
|
234
|
+
|
|
235
|
+
return value;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function hbValue(data: Record<string, any>, service: Array<string>): number {
|
|
210
239
|
if (service.includes("Brightness")) {
|
|
211
|
-
|
|
240
|
+
return parseInt(data["Brightness"]);
|
|
212
241
|
}
|
|
213
242
|
|
|
214
243
|
if (service.includes("On")) {
|
|
215
|
-
|
|
244
|
+
return parseInt(data["On"])
|
|
216
245
|
}
|
|
217
246
|
|
|
218
247
|
if (service.includes("TargetPosition")) {
|
|
219
|
-
|
|
248
|
+
return parseInt(data["TargetPosition"]);
|
|
220
249
|
}
|
|
221
|
-
return
|
|
250
|
+
return undefined
|
|
222
251
|
}
|
|
223
252
|
|
|
224
253
|
// send a status change to HB Accessory
|
|
225
|
-
export async function hbSetState(server: string, id: string, service: Array<string>, value: number | boolean,
|
|
254
|
+
export async function hbSetState(server: string, id: string, service: Array<string>, value: number | boolean, token: string) : Promise<void> {
|
|
226
255
|
const data = hbLoad(value, service);
|
|
227
256
|
|
|
228
257
|
log("HB", "hbSetState: " + id + " -> " + JSON.stringify(data));
|
|
@@ -236,20 +265,20 @@ export async function hbSetState(server: string, id: string, service: Array<stri
|
|
|
236
265
|
}
|
|
237
266
|
|
|
238
267
|
// send a status change to HB Accessory
|
|
239
|
-
export async function
|
|
268
|
+
export async function hbGetValue(server: string, id: string, service: Array<string>, token: string) : Promise<number> {
|
|
240
269
|
const respBody = await httpRequest(server + "/api/accessories/"+id, 'GET', "", ContentType.json, {
|
|
241
270
|
Authorization: 'Bearer ' + token
|
|
242
271
|
});
|
|
243
272
|
if (respBody && respBody.error) {
|
|
244
273
|
log("HB", "hbGetState: " + id + " -> error: " + JSON.stringify(respBody));
|
|
245
|
-
return
|
|
274
|
+
return undefined;
|
|
246
275
|
|
|
247
276
|
} else if (respBody && respBody.values) {
|
|
248
277
|
return hbValue(respBody.values, service);
|
|
249
278
|
|
|
250
279
|
} else {
|
|
251
280
|
log("HB", "hbGetState: " + id + " -> no values?? : " + JSON.stringify(respBody));
|
|
252
|
-
return
|
|
281
|
+
return undefined;
|
|
253
282
|
};
|
|
254
283
|
}
|
|
255
284
|
|
package/server/smartapp.js
CHANGED
|
@@ -396,8 +396,7 @@ class SmartApp extends webapp_1.WebApp {
|
|
|
396
396
|
this.links.forEach(link => {
|
|
397
397
|
link.unit || (link.unit = this.system.findUnit(this.system.findMaster(link.masterAddress, link.masterPort), link.logicalNodeAddress, link.logicalAddress));
|
|
398
398
|
if (link.unit) {
|
|
399
|
-
link.
|
|
400
|
-
link.status = link.unit.status;
|
|
399
|
+
link.dtValue = link.unit.value;
|
|
401
400
|
}
|
|
402
401
|
else {
|
|
403
402
|
(0, logger_1.log)("smartapp", "** error ** missing unit: " + (0, types_1.hex)(link.logicalNodeAddress) + "/" + (0, types_1.hex)(link.logicalAddress) + " **");
|
|
@@ -408,23 +407,17 @@ class SmartApp extends webapp_1.WebApp {
|
|
|
408
407
|
if (this.links.length && (yield this.checkToken())) {
|
|
409
408
|
for (const link of this.links) {
|
|
410
409
|
if ((link.type === types_1.LinkType.kAccessory) && link.unit) {
|
|
411
|
-
|
|
412
|
-
(0, logger_1.debug)("smartapp", "Received HB value for accessory: " + link.accName + " -> " +
|
|
413
|
-
if (typeof
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
value = (value > 50) ? 1 : 0;
|
|
420
|
-
if (value !== link.value) { // || state !== link.status
|
|
421
|
-
(0, logger_1.log)("smartapp", " -> Setting value of Duotecno unit: " + link.unit.getDisplayName() + " to " + value + " of HB accessory: " + link.accName);
|
|
422
|
-
link.value = value;
|
|
423
|
-
// link.status = state;
|
|
424
|
-
link.unit.setState(value);
|
|
410
|
+
const hbValue = yield (0, HB_1.hbGetValue)(this.config.apiHost + ":" + this.config.apiPort, link.accId, link.accService, this.token);
|
|
411
|
+
(0, logger_1.debug)("smartapp", "Received HB value for accessory: " + link.accName + " -> " + hbValue + " from accessory");
|
|
412
|
+
if (typeof hbValue != "undefined") {
|
|
413
|
+
const { dtValue, dtTarget } = (0, HB_1.hb2dtvalue)(link.unit, hbValue);
|
|
414
|
+
if (dtValue !== link.dtValue) { // || state !== link.status
|
|
415
|
+
(0, logger_1.log)("smartapp", "-> Setting value of Duotecno unit: " + link.unit.getDisplayName() + " to " + dtTarget + " of HB accessory: " + link.accName + " with value " + hbValue);
|
|
416
|
+
link.dtValue = dtValue;
|
|
417
|
+
link.unit.setState(dtTarget);
|
|
425
418
|
}
|
|
426
419
|
else {
|
|
427
|
-
(0, logger_1.debug)("smartapp", "
|
|
420
|
+
(0, logger_1.debug)("smartapp", "-> No change for unit: " + link.unit.getDisplayName() + " to " + dtValue);
|
|
428
421
|
}
|
|
429
422
|
}
|
|
430
423
|
}
|
|
@@ -437,21 +430,14 @@ class SmartApp extends webapp_1.WebApp {
|
|
|
437
430
|
(0, logger_1.debug)("smartapp", "Received DT value from unit: " + u.getDisplayName() + " -> " + u.value + " / " + u.status + " from unit");
|
|
438
431
|
for (const link of this.links) {
|
|
439
432
|
if (u.isUnit(link.masterAddress, link.masterPort, link.logicalNodeAddress, link.logicalAddress)) {
|
|
440
|
-
|
|
441
|
-
if (
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
if (u.isSwitch() || link.unit.isMood())
|
|
446
|
-
value = (value) ? 1 : 0;
|
|
447
|
-
if (link.value !== value) { // || link.status !== u.status
|
|
448
|
-
(0, logger_1.log)("smartapp", " -> Setting HB value for accessory: " + link.accName + " to " + value + " / " + u.status + " of Duotecno unit: " + u.getDisplayName());
|
|
449
|
-
link.value = value;
|
|
450
|
-
link.status = u.status;
|
|
451
|
-
yield (0, HB_1.hbSetState)(this.config.apiHost + ":" + this.config.apiPort, link.accId, link.accService, u.value, u.status, this.token);
|
|
433
|
+
const hbValue = (0, HB_1.dt2hbvalue)(u, link.hbValue);
|
|
434
|
+
if ((typeof hbValue != "undefined") && (hbValue !== link.hbValue)) {
|
|
435
|
+
(0, logger_1.log)("smartapp", "-> Setting HB value for accessory: " + link.accName + " to " + hbValue + " of Duotecno unit: " + u.getDisplayName() + " with value " + u.value);
|
|
436
|
+
link.hbValue = hbValue;
|
|
437
|
+
yield (0, HB_1.hbSetState)(this.config.apiHost + ":" + this.config.apiPort, link.accId, link.accService, hbValue, this.token);
|
|
452
438
|
}
|
|
453
439
|
else {
|
|
454
|
-
(0, logger_1.debug)("smartapp", "
|
|
440
|
+
(0, logger_1.debug)("smartapp", "-> No change for accessory: " + link.accName + " to " + u.value + " / " + u.status);
|
|
455
441
|
}
|
|
456
442
|
}
|
|
457
443
|
}
|
|
@@ -569,7 +555,7 @@ class SmartApp extends webapp_1.WebApp {
|
|
|
569
555
|
else {
|
|
570
556
|
if (link.type == types_1.LinkType.kAccessory) {
|
|
571
557
|
if (yield this.checkToken())
|
|
572
|
-
yield (0, HB_1.hbSetState)(this.config.apiHost + ":" + this.config.apiPort, link.id, link.service, link.unit.value,
|
|
558
|
+
yield (0, HB_1.hbSetState)(this.config.apiHost + ":" + this.config.apiPort, link.id, link.service, link.unit.value, this.token);
|
|
573
559
|
}
|
|
574
560
|
else {
|
|
575
561
|
(0, logger_1.err)("smartapp", "Don't know how to set a link of type " + link.type);
|
package/server/smartapp.ts
CHANGED
|
@@ -22,7 +22,7 @@ import { Shelly } from './shelly';
|
|
|
22
22
|
import { P1 } from './p1';
|
|
23
23
|
import { setToken } from "../duotecno/config";
|
|
24
24
|
import { PowerBase } from "./powerbase";
|
|
25
|
-
import { hbAccessories,
|
|
25
|
+
import { dt2hbvalue, hb2dtvalue, hbAccessories, hbGetValue, hbLogin, hbName, hbService, hbSetState, hbSubscribe } from "./HB";
|
|
26
26
|
import { httpRequest, ContentType } from "./HA-API";
|
|
27
27
|
|
|
28
28
|
const kMaster = {name: "master", type: "string", default: "0.0.0.0:5001"} as const;
|
|
@@ -447,8 +447,7 @@ export class SmartApp extends WebApp {
|
|
|
447
447
|
link.unit ||= this.system.findUnit(this.system.findMaster(link.masterAddress, link.masterPort),
|
|
448
448
|
link.logicalNodeAddress, link.logicalAddress);
|
|
449
449
|
if (link.unit) {
|
|
450
|
-
link.
|
|
451
|
-
link.status = link.unit.status;
|
|
450
|
+
link.dtValue = link.unit.value;
|
|
452
451
|
} else {
|
|
453
452
|
log("smartapp", "** error ** missing unit: " + hex(link.logicalNodeAddress)+"/"+hex(link.logicalAddress) + " **");
|
|
454
453
|
}
|
|
@@ -459,20 +458,18 @@ export class SmartApp extends WebApp {
|
|
|
459
458
|
if (this.links.length && await this.checkToken()) {
|
|
460
459
|
for (const link of this.links) {
|
|
461
460
|
if ((link.type === LinkType.kAccessory) && link.unit) {
|
|
462
|
-
|
|
463
|
-
debug("smartapp", "Received HB value for accessory: " + link.accName + " -> " +
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
link.
|
|
472
|
-
// link.status = state;
|
|
473
|
-
link.unit.setState(value);
|
|
461
|
+
const hbValue = await hbGetValue(this.config.apiHost +":"+ this.config.apiPort, link.accId, link.accService, this.token);
|
|
462
|
+
debug("smartapp", "Received HB value for accessory: " + link.accName + " -> " + hbValue + " from accessory");
|
|
463
|
+
|
|
464
|
+
if (typeof hbValue != "undefined") {
|
|
465
|
+
const {dtValue, dtTarget} = hb2dtvalue(link.unit, hbValue);
|
|
466
|
+
|
|
467
|
+
if (dtValue !== link.dtValue) { // || state !== link.status
|
|
468
|
+
log("smartapp", "-> Setting value of Duotecno unit: " + link.unit.getDisplayName() + " to " + dtTarget + " of HB accessory: " + link.accName + " with value " + hbValue);
|
|
469
|
+
link.dtValue = dtValue;
|
|
470
|
+
link.unit.setState(dtTarget);
|
|
474
471
|
} else {
|
|
475
|
-
debug("smartapp", "
|
|
472
|
+
debug("smartapp", "-> No change for unit: " + link.unit.getDisplayName() + " to " + dtValue);
|
|
476
473
|
}
|
|
477
474
|
}
|
|
478
475
|
}
|
|
@@ -486,19 +483,15 @@ export class SmartApp extends WebApp {
|
|
|
486
483
|
debug("smartapp", "Received DT value from unit: " + u.getDisplayName() + " -> " + u.value + " / " + u.status + " from unit");
|
|
487
484
|
for (const link of this.links) {
|
|
488
485
|
if (u.isUnit(link.masterAddress, link.masterPort, link.logicalNodeAddress, link.logicalAddress)) {
|
|
489
|
-
|
|
490
|
-
if (u.isUpDown()) value = ((value === 1) || (value === 3)) ? 100 : 0;
|
|
491
|
-
if (u.isDimmer) value = (value <= 2) ? 0 : (value >= 99) ? 100 : value;
|
|
492
|
-
if (u.isSwitch() || link.unit.isMood()) value = (value) ? 1 : 0;
|
|
486
|
+
const hbValue = dt2hbvalue(u, link.hbValue as number);
|
|
493
487
|
|
|
494
|
-
if (
|
|
495
|
-
log("smartapp", "
|
|
496
|
-
link.
|
|
497
|
-
link.
|
|
498
|
-
await hbSetState(this.config.apiHost +":"+ this.config.apiPort, link.accId, link.accService, u.value, u.status, this.token);
|
|
488
|
+
if ((typeof hbValue != "undefined") && (hbValue !== link.hbValue)) {
|
|
489
|
+
log("smartapp", "-> Setting HB value for accessory: " + link.accName + " to " + hbValue + " of Duotecno unit: " + u.getDisplayName() + " with value " + u.value);
|
|
490
|
+
link.hbValue = hbValue;
|
|
491
|
+
await hbSetState(this.config.apiHost +":"+ this.config.apiPort, link.accId, link.accService, hbValue, this.token);
|
|
499
492
|
|
|
500
493
|
} else {
|
|
501
|
-
debug("smartapp", "
|
|
494
|
+
debug("smartapp", "-> No change for accessory: " + link.accName + " to " + u.value + " / " + u.status);
|
|
502
495
|
}
|
|
503
496
|
}
|
|
504
497
|
};
|
|
@@ -626,7 +619,7 @@ export class SmartApp extends WebApp {
|
|
|
626
619
|
} else {
|
|
627
620
|
if (link.type == LinkType.kAccessory) {
|
|
628
621
|
if (await this.checkToken())
|
|
629
|
-
await hbSetState(this.config.apiHost +":"+ this.config.apiPort, link.id, link.service, link.unit.value,
|
|
622
|
+
await hbSetState(this.config.apiHost +":"+ this.config.apiPort, link.id, link.service, link.unit.value, this.token)
|
|
630
623
|
|
|
631
624
|
} else {
|
|
632
625
|
err("smartapp", "Don't know how to set a link of type " + link.type);
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
<option value="">Select a unit</option>
|
|
61
61
|
<% for (let u of units) { %>
|
|
62
62
|
<option value="<%= u.node.master.getURL()+"-"+u.logicalNodeAddress+"/"+u.logicalAddress %>"
|
|
63
|
-
<%= ((u.
|
|
63
|
+
<%= ((u.node.master.config.address == link.masterAddress) && (u.node.master.config.port == link.masterPort) && (u.logicalNodeAddress == link.logicalNodeAddress) && (u.logicalAddress == link.logicalAddress)) ? "selected" : "" %>
|
|
64
64
|
><%= u.name %></option>
|
|
65
65
|
<% } %>
|
|
66
66
|
</select>
|