homebridge-smartsystem 6.7.2 → 6.7.3

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.
@@ -41,13 +41,15 @@ var Cmd;
41
41
  Cmd[Cmd["Heartbeat"] = 215] = "Heartbeat";
42
42
  Cmd[Cmd["DatabaseInfo"] = 209] = "DatabaseInfo";
43
43
  Cmd[Cmd["SetSchedule"] = 217] = "SetSchedule";
44
+ Cmd[Cmd["reqSchedule"] = 218] = "reqSchedule";
45
+ Cmd[Cmd["reqNodeManagement"] = 220] = "reqNodeManagement";
44
46
  Cmd[Cmd["Register"] = 224] = "Register";
45
47
  })(Cmd || (Cmd = {}));
46
- // for Set Switch/Dimmer/Control
48
+ // for Set Switch/Dimmer/Control/Motor/Sensor = 162, 163, 168, 182, 136
47
49
  const reqDim = 3;
48
50
  const reqOff = 9;
49
51
  const reqOn = 10;
50
- // for Login
52
+ // for Login = 214
51
53
  const reqDisconnect = 0;
52
54
  const reqConnect = 3;
53
55
  // for DatabaseInfo = 209;
@@ -55,10 +57,7 @@ const reqDBInfo = 0;
55
57
  const reqNodeInfo = 1;
56
58
  const reqUnitInfo = 2;
57
59
  const reqUnitStatus = 3;
58
- // for Schedule
59
- const reqSchedule = 218;
60
- // for versions et al
61
- const reqNodeManagement = 220;
60
+ // for reqNodeMgt, versions et al
62
61
  var reqNodeAttributes;
63
62
  (function (reqNodeAttributes) {
64
63
  reqNodeAttributes[reqNodeAttributes["masterSupported"] = 0] = "masterSupported";
@@ -671,10 +670,10 @@ exports.Protocol = {
671
670
  return [Cmd.DatabaseInfo, reqUnitStatus, node.logicalAddress, unit.logicalAddress, unit.type];
672
671
  },
673
672
  buildRequestSchedule() {
674
- return [reqSchedule, 0];
673
+ return [Cmd.reqSchedule, 0];
675
674
  },
676
675
  buildRequestNodeMgt(method = reqNodeAttributes.nodeProtocol) {
677
- return [reqNodeManagement, method];
676
+ return [Cmd.reqNodeManagement, method];
678
677
  },
679
678
  getCmdAndMethod: function (unit, value) {
680
679
  switch (unit.type) {
@@ -38,15 +38,17 @@ enum Cmd {
38
38
  Heartbeat = 215,
39
39
  DatabaseInfo = 209,
40
40
  SetSchedule = 217,
41
+ reqSchedule = 218,
42
+ reqNodeManagement = 220,
41
43
  Register = 224
42
44
  }
43
45
 
44
- // for Set Switch/Dimmer/Control
46
+ // for Set Switch/Dimmer/Control/Motor/Sensor = 162, 163, 168, 182, 136
45
47
  const reqDim = 3;
46
48
  const reqOff = 9;
47
49
  const reqOn = 10;
48
50
 
49
- // for Login
51
+ // for Login = 214
50
52
  const reqDisconnect = 0;
51
53
  const reqConnect = 3;
52
54
 
@@ -56,11 +58,7 @@ const reqNodeInfo = 1;
56
58
  const reqUnitInfo = 2;
57
59
  const reqUnitStatus = 3;
58
60
 
59
- // for Schedule
60
- const reqSchedule = 218;
61
-
62
- // for versions et al
63
- const reqNodeManagement = 220;
61
+ // for reqNodeMgt, versions et al
64
62
  export enum reqNodeAttributes {
65
63
  masterSupported = 0,
66
64
  isMaster = 4,
@@ -782,10 +780,10 @@ export const Protocol = {
782
780
  },
783
781
 
784
782
  buildRequestSchedule(): Message {
785
- return [reqSchedule, 0];
783
+ return [Cmd.reqSchedule, 0];
786
784
  },
787
785
  buildRequestNodeMgt(method = reqNodeAttributes.nodeProtocol): Message {
788
- return [reqNodeManagement, method];
786
+ return [Cmd.reqNodeManagement, method];
789
787
  },
790
788
 
791
789
  getCmdAndMethod: function(unit: Unit, value: number | boolean): CmdSet {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "homebridge-smartsystem",
3
3
  "displayname": "Duotecno Bridge",
4
- "version": "6.7.2",
4
+ "version": "6.7.3",
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
@@ -168,17 +168,33 @@ function hbLogin(server, username, password) {
168
168
  }
169
169
  exports.hbLogin = hbLogin;
170
170
  function hbLoad(value, service) {
171
+ function hbvalue(value) {
172
+ if (typeof value === "boolean") {
173
+ return (value) ? 100 : 0;
174
+ }
175
+ else if (typeof value === "number") {
176
+ if (value <= 2) {
177
+ return 0;
178
+ }
179
+ else if (value >= 98) {
180
+ return 100;
181
+ }
182
+ else {
183
+ return Math.round(value);
184
+ }
185
+ }
186
+ }
171
187
  const data = {};
172
188
  if (service.includes("On")) {
173
189
  data["value"] = value;
174
190
  data["characteristicType"] = "On";
175
191
  }
176
192
  if (service.includes("Brightness")) {
177
- data["value"] = value;
193
+ data["value"] = hbvalue(value);
178
194
  data["characteristicType"] = "Brightness";
179
195
  }
180
196
  if (service.includes("TargetPosition")) {
181
- data["value"] = value;
197
+ data["value"] = hbvalue(value);
182
198
  data["characteristicType"] = "TargetPosition";
183
199
  }
184
200
  ;
@@ -221,7 +237,14 @@ function hbGetState(server, id, service, token) {
221
237
  (0, logger_1.log)("HB", "hbGetState: " + id + " -> error: " + JSON.stringify(respBody));
222
238
  return {};
223
239
  }
224
- return hbValue(respBody.values, service);
240
+ else if (respBody && respBody.values) {
241
+ return hbValue(respBody.values, service);
242
+ }
243
+ else {
244
+ (0, logger_1.log)("HB", "hbGetState: " + id + " -> no values?? : " + JSON.stringify(respBody));
245
+ return {};
246
+ }
247
+ ;
225
248
  });
226
249
  }
227
250
  exports.hbGetState = hbGetState;
package/server/HB.ts CHANGED
@@ -170,19 +170,36 @@ export async function hbLogin(server: string, username: string, password: string
170
170
  }
171
171
  }
172
172
 
173
+
173
174
  function hbLoad(value: number | boolean, service: Array<string>): Record<string, number | boolean> {
175
+ function hbvalue(value: number | boolean): number {
176
+ if (typeof value === "boolean") {
177
+ return (value) ? 100 : 0;
178
+ } else if (typeof value === "number") {
179
+ if (value <= 2) {
180
+ return 0;
181
+ } else if (value >= 98) {
182
+ return 100;
183
+ } else {
184
+ return Math.round(value);
185
+ }
186
+ }
187
+ }
188
+
174
189
  const data = {};
175
190
 
176
191
  if (service.includes("On")) {
177
192
  data["value"] = value;
178
193
  data["characteristicType"] = "On";
179
194
  }
195
+
180
196
  if (service.includes("Brightness")) {
181
- data["value"] = value;
197
+ data["value"] = hbvalue(value);
182
198
  data["characteristicType"] = "Brightness";
183
199
  }
200
+
184
201
  if (service.includes("TargetPosition")) {
185
- data["value"] = value;
202
+ data["value"] = hbvalue(value);
186
203
  data["characteristicType"] = "TargetPosition";
187
204
  };
188
205
  return data;
@@ -226,9 +243,14 @@ export async function hbGetState(server: string, id: string, service: Array<stri
226
243
  if (respBody && respBody.error) {
227
244
  log("HB", "hbGetState: " + id + " -> error: " + JSON.stringify(respBody));
228
245
  return {};
229
- }
230
246
 
231
- return hbValue(respBody.values, service);
247
+ } else if (respBody && respBody.values) {
248
+ return hbValue(respBody.values, service);
249
+
250
+ } else {
251
+ log("HB", "hbGetState: " + id + " -> no values?? : " + JSON.stringify(respBody));
252
+ return {};
253
+ };
232
254
  }
233
255
 
234
256
  export function hbSubscribe(callback) {
@@ -408,16 +408,24 @@ class SmartApp extends webapp_1.WebApp {
408
408
  if (this.links.length && (yield this.checkToken())) {
409
409
  for (const link of this.links) {
410
410
  if ((link.type === types_1.LinkType.kAccessory) && link.unit) {
411
- const { value, state } = yield (0, HB_1.hbGetState)(this.config.apiHost + ":" + this.config.apiPort, link.accId, link.accService, this.token);
411
+ let { value, state } = yield (0, HB_1.hbGetState)(this.config.apiHost + ":" + this.config.apiPort, link.accId, link.accService, this.token);
412
412
  (0, logger_1.debug)("smartapp", "Received HB value for accessory: " + link.accName + " -> " + value + " / " + state + " from accessory");
413
- if ((typeof value != "undefined") && (value !== link.value)) { // || state !== link.status
414
- (0, logger_1.log)("smartapp", " -> Setting value of Duotecno unit: " + link.unit.getDisplayName() + " to " + value + " of HB accessory: " + link.accName);
415
- link.value = value;
416
- // link.status = state;
417
- link.unit.setState(value);
418
- }
419
- else {
420
- (0, logger_1.debug)("smartapp", " -> No change for unit: " + link.unit.getDisplayName() + " to " + value);
413
+ if (typeof value != "undefined") {
414
+ if (link.unit.isUpDown())
415
+ value = (value >= 50) ? 4 : 5;
416
+ if (link.unit.isDimmer)
417
+ value = (value <= 1) ? 1 : (value >= 99) ? 100 : value;
418
+ if (link.unit.isSwitch() || link.unit.isMood())
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);
425
+ }
426
+ else {
427
+ (0, logger_1.debug)("smartapp", " -> No change for unit: " + link.unit.getDisplayName() + " to " + value);
428
+ }
421
429
  }
422
430
  }
423
431
  }
@@ -429,9 +437,16 @@ class SmartApp extends webapp_1.WebApp {
429
437
  (0, logger_1.debug)("smartapp", "Received DT value from unit: " + u.getDisplayName() + " -> " + u.value + " / " + u.status + " from unit");
430
438
  for (const link of this.links) {
431
439
  if (u.isUnit(link.masterAddress, link.masterPort, link.logicalNodeAddress, link.logicalAddress)) {
432
- if (link.value !== u.value) { // || link.status !== u.status
433
- (0, logger_1.log)("smartapp", " -> Setting HB value for accessory: " + link.accName + " to " + u.value + " / " + u.status + " of Duotecno unit: " + u.getDisplayName());
434
- link.value = u.value;
440
+ let value = (typeof u.value === "boolean") ? (u.value ? 100 : 0) : u.value;
441
+ if (u.isUpDown())
442
+ value = ((value === 1) || (value === 3)) ? 100 : 0;
443
+ if (u.isDimmer)
444
+ value = (value <= 2) ? 0 : (value >= 99) ? 100 : value;
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;
435
450
  link.status = u.status;
436
451
  yield (0, HB_1.hbSetState)(this.config.apiHost + ":" + this.config.apiPort, link.accId, link.accService, u.value, u.status, this.token);
437
452
  }
@@ -459,15 +459,21 @@ export class SmartApp extends WebApp {
459
459
  if (this.links.length && await this.checkToken()) {
460
460
  for (const link of this.links) {
461
461
  if ((link.type === LinkType.kAccessory) && link.unit) {
462
- const {value, state} = await hbGetState(this.config.apiHost +":"+ this.config.apiPort, link.accId, link.accService, this.token);
462
+ let {value, state} = await hbGetState(this.config.apiHost +":"+ this.config.apiPort, link.accId, link.accService, this.token);
463
463
  debug("smartapp", "Received HB value for accessory: " + link.accName + " -> " + value + " / " + state + " from accessory");
464
- if ((typeof value != "undefined") && (value !== link.value)) { // || state !== link.status
465
- log("smartapp", " -> Setting value of Duotecno unit: " + link.unit.getDisplayName() + " to " + value + " of HB accessory: " + link.accName);
466
- link.value = value;
467
- // link.status = state;
468
- link.unit.setState(value);
469
- } else {
470
- debug("smartapp", " -> No change for unit: " + link.unit.getDisplayName() + " to " + value);
464
+ if (typeof value != "undefined") {
465
+ if (link.unit.isUpDown()) value = (value >= 50) ? 4 : 5;
466
+ if (link.unit.isDimmer) value = (value <= 1) ? 1 : (value >= 99) ? 100 : value;
467
+ if (link.unit.isSwitch() || link.unit.isMood()) value = (value > 50) ? 1 : 0;
468
+
469
+ if (value !== link.value) { // || state !== link.status
470
+ log("smartapp", " -> Setting value of Duotecno unit: " + link.unit.getDisplayName() + " to " + value + " of HB accessory: " + link.accName);
471
+ link.value = value;
472
+ // link.status = state;
473
+ link.unit.setState(value);
474
+ } else {
475
+ debug("smartapp", " -> No change for unit: " + link.unit.getDisplayName() + " to " + value);
476
+ }
471
477
  }
472
478
  }
473
479
  }
@@ -480,9 +486,14 @@ export class SmartApp extends WebApp {
480
486
  debug("smartapp", "Received DT value from unit: " + u.getDisplayName() + " -> " + u.value + " / " + u.status + " from unit");
481
487
  for (const link of this.links) {
482
488
  if (u.isUnit(link.masterAddress, link.masterPort, link.logicalNodeAddress, link.logicalAddress)) {
483
- if (link.value !== u.value) { // || link.status !== u.status
484
- log("smartapp", " -> Setting HB value for accessory: " + link.accName + " to " + u.value + " / " + u.status + " of Duotecno unit: " + u.getDisplayName());
485
- link.value = u.value;
489
+ let value = (typeof u.value === "boolean") ? (u.value ? 100 : 0) : u.value;
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;
493
+
494
+ if (link.value !== value) { // || link.status !== u.status
495
+ log("smartapp", " -> Setting HB value for accessory: " + link.accName + " to " + value + " / " + u.status + " of Duotecno unit: " + u.getDisplayName());
496
+ link.value = value;
486
497
  link.status = u.status;
487
498
  await hbSetState(this.config.apiHost +":"+ this.config.apiPort, link.accId, link.accService, u.value, u.status, this.token);
488
499