homebridge-smartsystem 6.3.4 → 6.4.2
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 +39 -34
- package/config.json +48 -56
- package/duotecno/master.js +85 -3
- package/duotecno/master.ts +88 -6
- package/duotecno/protocol.js +97 -25
- package/duotecno/protocol.ts +103 -27
- package/duotecno/types.js +8 -4
- package/duotecno/types.ts +12 -6
- package/index.spec.js +1 -0
- package/index.spec.ts +1 -0
- package/package.json +1 -1
- package/server/powerbase.js +15 -16
- package/server/powerbase.ts +19 -18
- package/server/smartapp.js +11 -6
- package/server/smartapp.ts +15 -8
- package/server/somfy.ts +4 -2
- package/server/views/master-detail.ejs +16 -0
- package/server/views/master-list.ejs +2 -0
- package/server/views/power-binding.ejs +3 -3
- package/server/views/power.ejs +3 -3
package/server/powerbase.ts
CHANGED
|
@@ -136,37 +136,38 @@ export class PowerBase extends Base {
|
|
|
136
136
|
// for all bindings
|
|
137
137
|
this.bindings.forEach( b => {
|
|
138
138
|
const power = this.evalPower(b.channel);
|
|
139
|
-
if (this.significant(power, b.
|
|
140
|
-
debug("power", "APPLY to " + b.channel + " = " + b.
|
|
141
|
-
"
|
|
142
|
-
" > threshold: 5% =" + Math.abs(b.
|
|
139
|
+
if (this.significant(power, b.value)) {
|
|
140
|
+
debug("power", "APPLY to " + b.channel + " = " + b.value + " -> " + power + " for " + b.register +
|
|
141
|
+
"): difference: " + Math.abs(b.value - power) +
|
|
142
|
+
" > threshold: 5% =" + Math.abs(b.value * 0.05) + " > threshold: 2% =" + Math.abs(b.value * 0.02));
|
|
143
143
|
this.applyBinding(b, power)
|
|
144
|
-
.then(
|
|
145
|
-
b.
|
|
146
|
-
|
|
144
|
+
.then(power => {
|
|
145
|
+
b.value = power;
|
|
146
|
+
debug("power", "set register " + b.register + " to " + power);
|
|
147
147
|
})
|
|
148
148
|
.catch((e) => err(this.type, e.message || e));
|
|
149
149
|
|
|
150
150
|
// } else {
|
|
151
|
-
// debug("power", "DONT to " + b.channel + " = " + b.power + " -> " + power + " for " + b.
|
|
152
|
-
// "
|
|
151
|
+
// debug("power", "DONT to " + b.channel + " = " + b.power + " -> " + power + " for " + b.register +
|
|
152
|
+
// " : difference: " + Math.abs(b.power - power) +
|
|
153
153
|
// " > threshold: 5% =" + Math.abs(b.power * 0.05) + " > threshold: 2% =" + Math.abs(b.power * 0.02));
|
|
154
154
|
}
|
|
155
155
|
});
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
+
|
|
159
160
|
async applyBinding(binding: Binding, value: number): Promise<number> {
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (!isNaN(value))
|
|
164
|
-
await unit.setSensorValue(Math.abs(value));
|
|
161
|
+
const master = this.system.findMaster(binding.masterAddress, binding.masterPort);
|
|
162
|
+
if (master) {
|
|
163
|
+
await master.setRegisterValue(binding.register, value);
|
|
165
164
|
return value;
|
|
166
165
|
|
|
167
|
-
} else if ((binding.
|
|
168
|
-
throw new Error("*****
|
|
169
|
-
|
|
166
|
+
} else if ((!binding.masterAddress) || (binding.register)) {
|
|
167
|
+
throw new Error("***** MASTER NOT FOUND for binding for value " + value + " to " + binding.masterAddress + ":" + binding.masterPort + " - register = " + binding.register + " *****");
|
|
168
|
+
|
|
169
|
+
} // else empty binding -> no error
|
|
170
|
+
|
|
170
171
|
}
|
|
171
172
|
|
|
172
173
|
|
|
@@ -284,7 +285,7 @@ export class PowerBase extends Base {
|
|
|
284
285
|
//
|
|
285
286
|
updateBindings() {
|
|
286
287
|
// sort on channel.
|
|
287
|
-
this.bindings.sort((a,b) =>
|
|
288
|
+
this.bindings.sort((a,b) => a.register-b.register);
|
|
288
289
|
|
|
289
290
|
// sanitize and copy all rules into the config
|
|
290
291
|
this.config.bindings = this.bindings.map(b => Sanitizers.bindingConfig(b));
|
package/server/smartapp.js
CHANGED
|
@@ -112,6 +112,8 @@ class SmartApp extends webapp_1.WebApp {
|
|
|
112
112
|
//////////////
|
|
113
113
|
pwOK(context, user, pw) {
|
|
114
114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
// to bypass user/pw ->
|
|
116
|
+
//return true;
|
|
115
117
|
this.token = "";
|
|
116
118
|
(0, config_1.setToken)("");
|
|
117
119
|
try {
|
|
@@ -329,7 +331,7 @@ class SmartApp extends webapp_1.WebApp {
|
|
|
329
331
|
power.updateRule(id, this.scrapeRule(context));
|
|
330
332
|
}
|
|
331
333
|
else if (context.action === "save") {
|
|
332
|
-
power.updateConfig({ address: context.getParam(kAddress), uid: context.getParam(kUID), addresses: context.getParam(kAddresses)
|
|
334
|
+
power.updateConfig({ address: context.getParam(kAddress), uid: context.getParam(kUID), addresses: context.getParam(kAddresses) });
|
|
333
335
|
}
|
|
334
336
|
else if (context.action === "badd") {
|
|
335
337
|
const binding = power.newBinding();
|
|
@@ -357,9 +359,12 @@ class SmartApp extends webapp_1.WebApp {
|
|
|
357
359
|
});
|
|
358
360
|
}
|
|
359
361
|
scrapeBinding(context) {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
362
|
+
context.getMaster("action");
|
|
363
|
+
const master = this.system.findMaster(context["masterAddress"], context["masterPort"]);
|
|
364
|
+
const register = context.getParam({ name: "register", type: "integer", default: 0 });
|
|
365
|
+
const channel = context.getParam({ name: "channel", type: "string", default: "0" });
|
|
366
|
+
return { masterAddress: context["masterAddress"], masterPort: context["masterPort"],
|
|
367
|
+
register, channel };
|
|
363
368
|
}
|
|
364
369
|
scrapeAction(context, boundary) {
|
|
365
370
|
const { name, value, masterAddress, masterPort, logicalAddress, logicalNodeAddress } = this.scrapeUnit(context, boundary);
|
|
@@ -761,7 +766,7 @@ class SmartApp extends webapp_1.WebApp {
|
|
|
761
766
|
let message;
|
|
762
767
|
try {
|
|
763
768
|
if (context.action === "new") {
|
|
764
|
-
return this.ejs("masterDetail", context, { config: types_1.Sanitizers.masterConfig(null) });
|
|
769
|
+
return this.ejs("masterDetail", context, { config: types_1.Sanitizers.masterConfig(null), registers: [], nodes: [] });
|
|
765
770
|
}
|
|
766
771
|
else if (context.action === "list") {
|
|
767
772
|
return this.ejs("unitList", context, { masters: this.system.masters });
|
|
@@ -773,7 +778,7 @@ class SmartApp extends webapp_1.WebApp {
|
|
|
773
778
|
context.getMaster("id");
|
|
774
779
|
const master = this.system.findMaster(context["masterAddress"], context["masterPort"]);
|
|
775
780
|
if (master)
|
|
776
|
-
return this.ejs("masterDetail", context, { nodes: master.nodes, config: master.getConfig() });
|
|
781
|
+
return this.ejs("masterDetail", context, { nodes: master.nodes, config: master.getConfig(), registers: master.registers });
|
|
777
782
|
else
|
|
778
783
|
message = "Error: Master not found";
|
|
779
784
|
}
|
package/server/smartapp.ts
CHANGED
|
@@ -23,6 +23,7 @@ import { Shelly } from './shelly';
|
|
|
23
23
|
import { P1 } from './p1';
|
|
24
24
|
import { post } from "../duotecno/api";
|
|
25
25
|
import { setToken } from "../duotecno/config";
|
|
26
|
+
import { PowerBase } from "./powerbase";
|
|
26
27
|
|
|
27
28
|
const kMaster = {name: "master", type: "string", default: "0.0.0.0:5001"} as const;
|
|
28
29
|
const kAddress = {name: "address", type: "string", default: "0.0.0.0"} as const;
|
|
@@ -130,6 +131,9 @@ export class SmartApp extends WebApp {
|
|
|
130
131
|
// password //
|
|
131
132
|
//////////////
|
|
132
133
|
async pwOK(context: Context, user: string, pw: string): Promise<boolean> {
|
|
134
|
+
// to bypass user/pw ->
|
|
135
|
+
//return true;
|
|
136
|
+
|
|
133
137
|
this.token = "";
|
|
134
138
|
setToken("");
|
|
135
139
|
try {
|
|
@@ -331,7 +335,7 @@ export class SmartApp extends WebApp {
|
|
|
331
335
|
let message: string;
|
|
332
336
|
const id: number = parseInt(context.id);
|
|
333
337
|
const type = context.getParam({name: "type", type: "string", default: "smappee"});
|
|
334
|
-
const power = this.power[type];
|
|
338
|
+
const power: PowerBase = this.power[type];
|
|
335
339
|
|
|
336
340
|
if (!power) {
|
|
337
341
|
return this.error(context, "Power type not implemented", false);
|
|
@@ -358,7 +362,7 @@ export class SmartApp extends WebApp {
|
|
|
358
362
|
power.updateRule( id, this.scrapeRule(context) );
|
|
359
363
|
|
|
360
364
|
} else if (context.action === "save") {
|
|
361
|
-
power.updateConfig({address: context.getParam(kAddress), uid: context.getParam(kUID), addresses: context.getParam(kAddresses)
|
|
365
|
+
power.updateConfig({address: context.getParam(kAddress), uid: context.getParam(kUID), addresses: context.getParam(kAddresses)});
|
|
362
366
|
|
|
363
367
|
|
|
364
368
|
} else if (context.action === "badd") {
|
|
@@ -387,11 +391,14 @@ export class SmartApp extends WebApp {
|
|
|
387
391
|
return this.ejs("power", context, await power.getData(context, ""));
|
|
388
392
|
}
|
|
389
393
|
|
|
390
|
-
|
|
391
394
|
scrapeBinding(context: Context): Binding {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
+
context.getMaster("action");
|
|
396
|
+
const master = this.system.findMaster(context["masterAddress"], context["masterPort"]);
|
|
397
|
+
const register = context.getParam({ name: "register", type: "integer", default: 0 });
|
|
398
|
+
const channel = context.getParam({name: "channel", type: "string", default: "0"})
|
|
399
|
+
|
|
400
|
+
return { masterAddress: context["masterAddress"], masterPort: context["masterPort"],
|
|
401
|
+
register, channel };
|
|
395
402
|
}
|
|
396
403
|
|
|
397
404
|
scrapeAction(context: Context, boundary: string): Action {
|
|
@@ -824,7 +831,7 @@ export class SmartApp extends WebApp {
|
|
|
824
831
|
try {
|
|
825
832
|
|
|
826
833
|
if (context.action === "new") {
|
|
827
|
-
return this.ejs("masterDetail", context, { config: Sanitizers.masterConfig(null) });
|
|
834
|
+
return this.ejs("masterDetail", context, { config: Sanitizers.masterConfig(null), registers: [], nodes: [] });
|
|
828
835
|
|
|
829
836
|
} else if (context.action === "list") {
|
|
830
837
|
return this.ejs("unitList", context, { masters: this.system.masters });
|
|
@@ -836,7 +843,7 @@ export class SmartApp extends WebApp {
|
|
|
836
843
|
context.getMaster("id");
|
|
837
844
|
const master = this.system.findMaster(context["masterAddress"], context["masterPort"]);
|
|
838
845
|
if (master)
|
|
839
|
-
return this.ejs("masterDetail", context, { nodes: master.nodes, config: master.getConfig() });
|
|
846
|
+
return this.ejs("masterDetail", context, { nodes: master.nodes, config: master.getConfig(), registers: master.registers });
|
|
840
847
|
else
|
|
841
848
|
message = "Error: Master not found";
|
|
842
849
|
|
package/server/somfy.ts
CHANGED
|
@@ -160,13 +160,15 @@ export async function stop(screen: number): Promise<boolean> {
|
|
|
160
160
|
// }
|
|
161
161
|
|
|
162
162
|
busy = true;
|
|
163
|
+
|
|
163
164
|
setup().then(() => {
|
|
164
165
|
debug("somfy", "gpio package initialized");
|
|
165
166
|
init = true;
|
|
166
167
|
busy = false;
|
|
168
|
+
|
|
167
169
|
}).catch((e) => {
|
|
168
|
-
debug("somfy", "
|
|
169
|
-
debug("somfy", e);
|
|
170
|
+
debug("somfy", "gpio package not initialized");
|
|
171
|
+
if (e.code != "EACCES") debug("somfy", e);
|
|
170
172
|
init = false;
|
|
171
173
|
busy = false;
|
|
172
174
|
});
|
|
@@ -96,6 +96,22 @@
|
|
|
96
96
|
</tbody>
|
|
97
97
|
</table>
|
|
98
98
|
<% } %>
|
|
99
|
+
|
|
100
|
+
<h1>Registers</h1>
|
|
101
|
+
<% if (Object.keys(registers).length) { %>
|
|
102
|
+
<table>
|
|
103
|
+
<thead>
|
|
104
|
+
<tr><th>Nr</th><th>Value</th></tr>
|
|
105
|
+
</thead>
|
|
106
|
+
<tbody>
|
|
107
|
+
<% for (let ix in registers) { %>
|
|
108
|
+
<tr><td><%= ix %></td><td><%= registers[ix] %></td></tr>
|
|
109
|
+
<% } %>
|
|
110
|
+
</tbody>
|
|
111
|
+
</table>
|
|
112
|
+
<% } else { %>
|
|
113
|
+
<p>No registers yet</p>
|
|
114
|
+
<% } %>
|
|
99
115
|
</form>
|
|
100
116
|
<%- include('/views/footer'); -%>
|
|
101
117
|
</body>
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
<th>Address:port</th>
|
|
27
27
|
<th>Nodes</th>
|
|
28
28
|
<th>Action</th>
|
|
29
|
+
<th>Protocol</th>
|
|
29
30
|
</tr>
|
|
30
31
|
</thead>
|
|
31
32
|
|
|
@@ -36,6 +37,7 @@
|
|
|
36
37
|
<td><a href="/masters/edit/<%= master.config.address %>:<%= master.config.port %>"><%= master.config.address %></a></td>
|
|
37
38
|
<td><a href="/masters/edit/<%= master.config.address %>:<%= master.config.port %>"><%= master.nodes.length %></a></td>
|
|
38
39
|
<td><a href="/masters/close/<%= master.config.address %>:<%= master.config.port %>">close connection</a></td>
|
|
40
|
+
<td><a href="/masters/edit/<%= master.config.address %>:<%= master.config.port %>"><%= master.protocol %></a></td>
|
|
39
41
|
</tr>
|
|
40
42
|
<% }} %>
|
|
41
43
|
</tbody>
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
|
|
47
47
|
<div class="row">
|
|
48
48
|
<div class="input-field col s12">
|
|
49
|
-
<input placeholder="0" id="
|
|
50
|
-
value="<%=
|
|
51
|
-
<label for="unit">
|
|
49
|
+
<input placeholder="0" id="register" name="register" type="text"
|
|
50
|
+
value="<%= binding.register %>">
|
|
51
|
+
<label for="unit">Register</label>
|
|
52
52
|
</div>
|
|
53
53
|
</div>
|
|
54
54
|
|
package/server/views/power.ejs
CHANGED
|
@@ -87,11 +87,11 @@
|
|
|
87
87
|
<button class="right btn waves-effect waves-light" type="submit" name="action" value="badd">Add Binding</button>
|
|
88
88
|
</h1>
|
|
89
89
|
<table style="width: 75%; min-width: 350px">
|
|
90
|
-
<tr><th>Id</th><th>Channels</th><th>
|
|
90
|
+
<tr><th>Id</th><th>Channels</th><th>Value</th><th>Register</th></tr>
|
|
91
91
|
<% for (let inx in bindings) { const b = bindings[inx] %>
|
|
92
92
|
<tr><th><a href="/power/binding/<%= inx %>?type=<%= type%>">Binding <%= inx %></a></th>
|
|
93
|
-
<td><%= b.channel %></td><td><%= b.
|
|
94
|
-
<td><%=
|
|
93
|
+
<td><%= b.channel %></td><td><%= b.value %></td>
|
|
94
|
+
<td><%= b.register %></td></tr>
|
|
95
95
|
<% } %>
|
|
96
96
|
</table>
|
|
97
97
|
|