homebridge-smartsystem 7.1.10 → 7.1.12

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.
@@ -48,18 +48,8 @@ class Accessory {
48
48
  }
49
49
  getState(next) {
50
50
  if (this.unit) {
51
- this.unit.reqState(unit => {
52
- try {
53
- if (!unit) {
54
- return next(new Error("Unit state not available"));
55
- }
56
- next(null, unit.status);
57
- (0, logger_1.log)("accessory", "getState was called for " + this.unit.node.getName() + " - " + this.unit.getName() + " -> " + this.unit.status);
58
- }
59
- catch (err) {
60
- next(err);
61
- }
62
- }).catch(err => next(err));
51
+ (0, logger_1.log)("accessory", "getState was called for " + this.unit.node.getName() + " - " + this.unit.getName() + " -> " + this.unit.status);
52
+ next(null, this.unit.status);
63
53
  }
64
54
  else {
65
55
  next(new Error("accessory - getState needs to be overridden if no unit is provided."));
@@ -67,18 +57,8 @@ class Accessory {
67
57
  }
68
58
  getValue(next) {
69
59
  if (this.unit) {
70
- this.unit.reqState(unit => {
71
- try {
72
- if (!unit) {
73
- return next(new Error("Unit state not available"));
74
- }
75
- next(null, unit.value);
76
- (0, logger_1.log)("accessory", "getValue was called for " + this.unit.node.getName() + " - " + this.unit.getName() + " -> " + this.unit.value);
77
- }
78
- catch (err) {
79
- next(err);
80
- }
81
- }).catch(err => next(err));
60
+ (0, logger_1.log)("accessory", "getValue was called for " + this.unit.node.getName() + " - " + this.unit.getName() + " -> " + this.unit.value);
61
+ next(null, this.unit.value);
82
62
  }
83
63
  else {
84
64
  next(new Error("accessory - getState needs to be overridden if no unit is provided."));
@@ -29,18 +29,8 @@ class Dimmer extends accessory_1.Accessory {
29
29
  }
30
30
  getBrightness(next) {
31
31
  if (this.unit) {
32
- this.unit.reqState(unit => {
33
- try {
34
- if (!unit) {
35
- return next(new Error("Unit state not available"));
36
- }
37
- next(null, unit.value);
38
- (0, logger_1.log)("accessory", "getBrightness was called for " + this.unit.node.getName() + " - " + this.unit.getName() + " -> " + this.unit.value);
39
- }
40
- catch (err) {
41
- next(err);
42
- }
43
- }).catch(err => next(err));
32
+ (0, logger_1.log)("accessory", "getBrightness was called for " + this.unit.node.getName() + " - " + this.unit.getName() + " -> " + this.unit.value);
33
+ next(null, this.unit.value);
44
34
  }
45
35
  else {
46
36
  next(new Error("accessory - getBrightness needs to be overridden if no unit is provided."));
@@ -55,16 +55,9 @@ class GarageDoor extends accessory_1.Accessory {
55
55
  return null;
56
56
  }
57
57
  getDoorState(next) {
58
- try {
59
- this.unit.reqState(unit => {
60
- const hb = this.DT2HB(unit.status);
61
- (0, logger_1.log)("accessory", "Get CurrentDoorState of " + this.name + " = " + unit.status + " -> " + hb);
62
- next(null, hb);
63
- });
64
- }
65
- catch (err) {
66
- next(err);
67
- }
58
+ const hb = this.DT2HB(this.unit.status);
59
+ (0, logger_1.log)("accessory", "Get CurrentDoorState of " + this.name + " = " + this.unit.status + " -> " + hb);
60
+ next(null, hb);
68
61
  }
69
62
  setDoorState(value, next) {
70
63
  // homekit is giving OPEN, .STOPPED, .CLOSED
@@ -22,27 +22,17 @@ class Temperature extends accessory_1.Accessory {
22
22
  }
23
23
  getTemperature(next) {
24
24
  if (this.unit) {
25
- this.unit.reqState(unit => {
26
- try {
27
- if (!unit) {
28
- return next(new Error("Unit state not available"));
29
- }
30
- (0, logger_1.log)("accessory", "reqState/getTemperature returned a value for " + this.unit.node.getName() + " - " + this.unit.getName() + " -> " + this.unit.value);
31
- next(null, unit.value / 10.0);
32
- }
33
- catch (err) {
34
- next(err);
35
- }
36
- })
37
- .catch(err => next(err));
25
+ (0, logger_1.log)("accessory", "getTemperature was called for " + this.unit.node.getName() + " - " + this.unit.getName() + " -> " + this.unit.value);
26
+ next(null, this.unit.value / 10.0);
38
27
  }
39
28
  else {
40
29
  next(new Error("accessory -> getTemperature needs a unit."));
41
30
  }
42
31
  }
43
32
  updateState() {
44
- this.me.getCharacteristic(this.homebridge.Characteristic.CurrentTemperature).updateValue(this.unit.value / 10.0);
45
- (0, logger_1.log)("accessory", "Received updateState -> Homekit Temperature -> " + this.unit.getName() + " -> temp = " + this.unit.value / 10.0);
33
+ const limited = Math.max(-100, Math.min(100, this.unit.value / 10.0));
34
+ this.me.getCharacteristic(this.homebridge.Characteristic.CurrentTemperature).updateValue(limited);
35
+ (0, logger_1.log)("accessory", "Received updateState -> Homekit Temperature -> " + this.unit.getName() + " -> temp = " + limited);
46
36
  }
47
37
  }
48
38
  exports.Temperature = Temperature;
@@ -92,22 +92,12 @@ class WindowCovering extends accessory_1.Accessory {
92
92
  }
93
93
  getCurrentPosition(next) {
94
94
  (0, logger_1.log)("accessory", "get CurrentPosition was called of " + this.name);
95
- this.unit.reqState(unit => {
96
- try {
97
- if (!unit) {
98
- return next(new Error("Unit state not available"));
99
- }
100
- if (unit.status == types_1.UnitState.kOpen)
101
- next(null, 100);
102
- else if (unit.status == types_1.UnitState.kClosed)
103
- next(null, 0);
104
- else
105
- next(null, 50);
106
- }
107
- catch (err) {
108
- next(err);
109
- }
110
- }).catch(err => next(err));
95
+ if (this.unit.status == types_1.UnitState.kOpen)
96
+ next(null, 100);
97
+ else if (this.unit.status == types_1.UnitState.kClosed)
98
+ next(null, 0);
99
+ else
100
+ next(null, 50);
111
101
  }
112
102
  setTargetPosition(value, next) {
113
103
  // homekit is giving 0-100 for windows
@@ -130,22 +120,12 @@ class WindowCovering extends accessory_1.Accessory {
130
120
  }
131
121
  getTargetPosition(next) {
132
122
  (0, logger_1.log)("accessory", "get Characteristic.TargetPosition was called");
133
- this.unit.reqState(unit => {
134
- try {
135
- if (!unit) {
136
- return next(new Error("Unit state not available"));
137
- }
138
- if (this.unit.status == types_1.UnitState.kOpen)
139
- next(null, 100);
140
- else if (this.unit.status == types_1.UnitState.kClosed)
141
- next(null, 0);
142
- else
143
- next(null, 50);
144
- }
145
- catch (err) {
146
- next(err);
147
- }
148
- }).catch(err => next(err));
123
+ if (this.unit.status == types_1.UnitState.kOpen)
124
+ next(null, 100);
125
+ else if (this.unit.status == types_1.UnitState.kClosed)
126
+ next(null, 0);
127
+ else
128
+ next(null, 50);
149
129
  }
150
130
  // called in response to Duotecno status update
151
131
  updateState() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "homebridge-smartsystem",
3
3
  "displayname": "Duotecno Bridge",
4
- "version": "7.1.10",
4
+ "version": "7.1.12",
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",
@@ -13,8 +13,8 @@
13
13
  "build": "npx tsc --build",
14
14
  "unpublish": "npm unpublish --force homebridge-smartsystem@6.8.17",
15
15
  "prepublishOnly": "npm run build",
16
- "release:patch": "git add -A && git commit -m 'pre-release' --allow-empty && npm version patch && npm publish && git push && git push --tags",
17
- "release:minor": "git add -A && git commit -m 'pre-release' --allow-empty && npm version minor && npm publish && git push && git push --tags",
16
+ "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",
17
+ "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",
18
18
  "release:major": "git add -A && git commit -m 'pre-release' --allow-empty && npm version major && npm publish && git push && git push --tags"
19
19
  },
20
20
  "engines": {
@@ -224,7 +224,7 @@ class SmartApp extends webapp_1.WebApp {
224
224
  // Router //
225
225
  //////////////////////////////
226
226
  needsLogin(context) {
227
- const noNeed = ((context.request === "units") || (context.request === "switches")) &&
227
+ const noNeed = ((context.request === "units") || (context.request === "switches")) || (context.request === "register") ||
228
228
  ((context.action == "press") || (context.action == "get") || (context.action == "set"));
229
229
  return super.needsLogin(context) && (context.request != "files") && (!noNeed);
230
230
  }
@@ -256,6 +256,9 @@ class SmartApp extends webapp_1.WebApp {
256
256
  else if (context.request === "units") {
257
257
  return this.doUnits(context);
258
258
  }
259
+ else if (context.request === "register") {
260
+ return this.doRegisters(context);
261
+ }
259
262
  else if (context.request === "services") {
260
263
  return this.doServices(context);
261
264
  }
@@ -1350,6 +1353,22 @@ class SmartApp extends webapp_1.WebApp {
1350
1353
  }
1351
1354
  });
1352
1355
  }
1356
+ ///////////////
1357
+ // registers //
1358
+ ///////////////
1359
+ doRegisters(context) {
1360
+ return __awaiter(this, void 0, void 0, function* () {
1361
+ context.getMaster("id");
1362
+ const master = this.system.findMaster(context["masterAddress"], context["masterPort"]);
1363
+ if (!master) {
1364
+ return this.error(context, "Master not found", true);
1365
+ }
1366
+ const register = context.getParam({ name: "nr", type: "integer", default: 0 });
1367
+ const value = context.getParam(kValue);
1368
+ yield master.setRegisterValue(register, value);
1369
+ return this.json({ register, value });
1370
+ });
1371
+ }
1353
1372
  //////////////////////////////
1354
1373
  // Units //
1355
1374
  //////////////////////////////
@@ -1371,15 +1390,6 @@ class SmartApp extends webapp_1.WebApp {
1371
1390
  context.action = "edit";
1372
1391
  return this.doRequest(context);
1373
1392
  }
1374
- else if (context.action === "register") {
1375
- // master=...&port=...&register=...&value=...
1376
- if (!master)
1377
- return this.error(context, "master not found", true);
1378
- const register = context.getParam({ name: "register", type: "integer", default: 0 });
1379
- const value = context.getParam(kValue);
1380
- yield master.setRegisterValue(register, value);
1381
- return this.json({ register, value });
1382
- }
1383
1393
  else if (context.action === "set") {
1384
1394
  if (!master)
1385
1395
  return this.error(context, "master not found", true);