node-red-contrib-ccu 4.13.0 → 4.14.0
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/CHANGELOG.md +25 -0
- package/README.md +12 -2
- package/nodes/ccu-connection.js +609 -47
- package/nodes/ccu-poll.js +4 -3
- package/nodes/ccu-program.js +1 -1
- package/nodes/ccu-sysvar.js +1 -1
- package/nodes/lib/lite.js +15 -2
- package/nodes/lib/logic.js +178 -0
- package/nodes/lib/status.js +31 -0
- package/nodes/locales/de/ccu-poll.html +2 -0
- package/nodes/locales/de/ccu-program.html +5 -0
- package/nodes/locales/de/ccu-sysvar.html +7 -0
- package/nodes/locales/en-US/ccu-poll.html +2 -0
- package/nodes/locales/en-US/ccu-program.html +5 -0
- package/nodes/locales/en-US/ccu-sysvar.html +7 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,31 @@ Notable changes to node-red-contrib-ccu. Format follows
|
|
|
5
5
|
user-visible symptom and the cause, not the commit list (the release notes
|
|
6
6
|
append commits automatically).
|
|
7
7
|
|
|
8
|
+
## 4.14.0 (2026-11-25)
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **openccu-lite: system variables and programs from the Logic addon.** On
|
|
13
|
+
openccu-lite the `ccu-sysvar` and `ccu-program` nodes stayed
|
|
14
|
+
_disconnected_ and answered every message with an error, because the system
|
|
15
|
+
has no ReGaHSS. The Logic addon now offers the variables and programs as
|
|
16
|
+
devices of its interface `Logic` through the system's lite-rpc, and the nodes
|
|
17
|
+
use it: a variable or program is found by its name, as on a CCU, so flows
|
|
18
|
+
written for a CCU keep working after the switch once the variables and
|
|
19
|
+
programs were imported into Logic. Values arrive at every write (with
|
|
20
|
+
_Emit changed values only_, changes only), writes take a list entry or a
|
|
21
|
+
logic value also by its text, a program is switched by `true`/`false` and
|
|
22
|
+
started (the first _Then_, as the CCU's _Start_) by anything else. The
|
|
23
|
+
editor lists the variables and programs; `ccu-get-value`, `ccu-switch` and
|
|
24
|
+
`ccu-mqtt` find them as well. Without the addon the nodes show _Logic addon
|
|
25
|
+
not installed_, and the addon installed while Node-RED runs is taken
|
|
26
|
+
without a deploy.
|
|
27
|
+
- **openccu-lite: every interface the system lists.** The connection
|
|
28
|
+
followed only the radio interfaces it knows; an addon's interface (such as
|
|
29
|
+
Logic's) was never seen. It now follows every interface lite-rpc lists, an
|
|
30
|
+
addon's without a checkbox; its devices and datapoints can be used with the
|
|
31
|
+
value, event and rpc nodes like those of any interface.
|
|
32
|
+
|
|
8
33
|
## 4.13.0 (2026-11-22)
|
|
9
34
|
|
|
10
35
|
### Added
|
package/README.md
CHANGED
|
@@ -55,8 +55,18 @@ CCU-Jack keep their own connections.
|
|
|
55
55
|
(`rpc:read` for events and reads, `rpc:operate` for `setValue`, `rpc:configure` for paramsets and links,
|
|
56
56
|
`rpc:admin` for the rest). A token without `rpc:read` (one made for the names alone) keeps the direct connection
|
|
57
57
|
with callbacks under _auto_, and the log says what lite-rpc would need.
|
|
58
|
-
- **System variables
|
|
59
|
-
`
|
|
58
|
+
- **System variables and programs come from the Logic addon** (4.14.0). Logic offers them as devices of an interface
|
|
59
|
+
of its own, `Logic`, which lite-rpc carries like the radio interfaces; the connection follows every interface the
|
|
60
|
+
system lists, an addon's without a checkbox. The `ccu-sysvar` and `ccu-program` nodes find a variable or a program
|
|
61
|
+
by its name, as on a CCU, so a flow written for a CCU keeps working once the variables and programs were imported
|
|
62
|
+
into Logic: a variable is read, written (a list entry or a logic value also by its text) and reported at every
|
|
63
|
+
write (_Emit changed values only_ leaves out a write of the same value); a program is switched by `true`/`false`
|
|
64
|
+
and started by anything else - the first _Then_ without the conditions, as the CCU's _Start_ does. The editor lists
|
|
65
|
+
them, and `ccu-get-value`, `ccu-switch` and `ccu-mqtt` find them too. Messages keep the CCU's shape, with
|
|
66
|
+
`iface: "Logic"`, `key` and `address` (the Logic channel) in place of the ReGa `id`. This needs lite-rpc (RedMatic
|
|
67
|
+
on the system, or a paired connection); without the addon the nodes show _Logic addon not installed_ and a write
|
|
68
|
+
is refused with that reason. `ccu-poll` has nothing to poll there (the values are events). **HM-Script does not
|
|
69
|
+
exist there**: the `ccu-script` node stays in the flows and answers every message with an error.
|
|
60
70
|
|
|
61
71
|
## Topics
|
|
62
72
|
|
package/nodes/ccu-connection.js
CHANGED
|
@@ -19,6 +19,7 @@ const {Rega} = require('homematic-rega'); // ES module - require(esm) needs Node
|
|
|
19
19
|
const metaProvider = require('./lib/metaprovider.js');
|
|
20
20
|
const {InitRetry, retryDelay, RETRY_INTERVAL} = require('./lib/initretry.js');
|
|
21
21
|
const lite = require('./lib/lite.js');
|
|
22
|
+
const logic = require('./lib/logic.js');
|
|
22
23
|
const {Pairings} = require('./lib/pairing.js');
|
|
23
24
|
const {
|
|
24
25
|
writeJsonAtomic,
|
|
@@ -775,6 +776,13 @@ module.exports = function (RED) {
|
|
|
775
776
|
// and, per interface, why it cannot be reached (the nodes show it)
|
|
776
777
|
this.liteScopes = undefined;
|
|
777
778
|
this.ifaceError = {};
|
|
779
|
+
// task 32: Logic (lite-addon-logic), the interface of the system variables and programs on
|
|
780
|
+
// openccu-lite - its name once lite-rpc listed it, whether the list was read, the objects by
|
|
781
|
+
// their value channel, and the writes waiting for the first picture
|
|
782
|
+
this.logicIface = null;
|
|
783
|
+
this.liteListed = false;
|
|
784
|
+
this.logicObjects = {};
|
|
785
|
+
this.logicWaiters = [];
|
|
778
786
|
this.metaMode = false;
|
|
779
787
|
this.meta = null;
|
|
780
788
|
// #167: minutes between re-reads of channel names, rooms and
|
|
@@ -1883,7 +1891,7 @@ module.exports = function (RED) {
|
|
|
1883
1891
|
') - names, rooms and functions come from its metadata api',
|
|
1884
1892
|
);
|
|
1885
1893
|
this.logger.info(
|
|
1886
|
-
'this system has no ReGaHSS: system variables
|
|
1894
|
+
'this system has no ReGaHSS: system variables and programs come from the Logic addon through lite-rpc where it is installed, HM-Script is not available (the script node stays idle)',
|
|
1887
1895
|
);
|
|
1888
1896
|
if (!this.regaEnabled) {
|
|
1889
1897
|
// B-46: the checkbox has nothing to switch here - the names are the metadata api's
|
|
@@ -2066,6 +2074,7 @@ module.exports = function (RED) {
|
|
|
2066
2074
|
' functions',
|
|
2067
2075
|
);
|
|
2068
2076
|
this.saveRegadata();
|
|
2077
|
+
this.relabelLogic();
|
|
2069
2078
|
}
|
|
2070
2079
|
|
|
2071
2080
|
/**
|
|
@@ -2265,12 +2274,11 @@ module.exports = function (RED) {
|
|
|
2265
2274
|
* @returns {Promise}
|
|
2266
2275
|
*/
|
|
2267
2276
|
programActive(name, active) {
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
return;
|
|
2272
|
-
}
|
|
2277
|
+
if (this.metaMode) {
|
|
2278
|
+
return this.logicProgramCall(name, 'ACTIVE', Boolean(active));
|
|
2279
|
+
}
|
|
2273
2280
|
|
|
2281
|
+
return new Promise((resolve, reject) => {
|
|
2274
2282
|
const program = this.program[name];
|
|
2275
2283
|
if (program) {
|
|
2276
2284
|
const script = `dom.GetObject(${program.id}).Active(${active});`;
|
|
@@ -2297,12 +2305,11 @@ module.exports = function (RED) {
|
|
|
2297
2305
|
* @returns {Promise}
|
|
2298
2306
|
*/
|
|
2299
2307
|
programExecute(name) {
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
return;
|
|
2304
|
-
}
|
|
2308
|
+
if (this.metaMode) {
|
|
2309
|
+
return this.logicProgramCall(name, 'RUN_THEN', true);
|
|
2310
|
+
}
|
|
2305
2311
|
|
|
2312
|
+
return new Promise((resolve, reject) => {
|
|
2306
2313
|
const program = this.program[name];
|
|
2307
2314
|
if (program) {
|
|
2308
2315
|
const d = new Date();
|
|
@@ -2336,12 +2343,11 @@ module.exports = function (RED) {
|
|
|
2336
2343
|
* @returns {Promise}
|
|
2337
2344
|
*/
|
|
2338
2345
|
setVariable(name, value) {
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
return;
|
|
2343
|
-
}
|
|
2346
|
+
if (this.metaMode) {
|
|
2347
|
+
return this.setLogicVariable(name, value);
|
|
2348
|
+
}
|
|
2344
2349
|
|
|
2350
|
+
return new Promise((resolve, reject) => {
|
|
2345
2351
|
if (!this.hasRegaVariables) {
|
|
2346
2352
|
this.logger.debug('variables not yet known. defer setVariable ' + name);
|
|
2347
2353
|
clearTimeout(this.setVariableQueueTimeout[name]);
|
|
@@ -2550,29 +2556,57 @@ module.exports = function (RED) {
|
|
|
2550
2556
|
cache: isNew,
|
|
2551
2557
|
});
|
|
2552
2558
|
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2559
|
+
this.dispatchSysvar(sysvar.name);
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
|
|
2563
|
+
/**
|
|
2564
|
+
* A system variable's state to the sysvar subscriptions whose filter takes it: its name, a
|
|
2565
|
+
* value from the start (cache) only where the filter asks for one, a value that did not
|
|
2566
|
+
* change only where the filter does not ask for changes alone.
|
|
2567
|
+
* @param {string} name
|
|
2568
|
+
*/
|
|
2569
|
+
dispatchSysvar(name) {
|
|
2570
|
+
const sysvar = this.sysvar[name];
|
|
2571
|
+
if (!sysvar) {
|
|
2572
|
+
return;
|
|
2573
|
+
}
|
|
2574
|
+
|
|
2575
|
+
Object.keys(this.sysvarCallbacks).forEach((key) => {
|
|
2576
|
+
const {filter, callback} = this.sysvarCallbacks[key];
|
|
2577
|
+
let match = !filter.name || filter.name === name;
|
|
2578
|
+
if (sysvar.cache && !filter.cache) {
|
|
2579
|
+
match = false;
|
|
2580
|
+
} else if (filter.change && !sysvar.change) {
|
|
2581
|
+
if (!(sysvar.cache && filter.cache)) {
|
|
2557
2582
|
match = false;
|
|
2558
|
-
} else if (filter.change && !this.sysvar[sysvar.name].change) {
|
|
2559
|
-
if (!(this.sysvar[sysvar.name].cache && filter.cache)) {
|
|
2560
|
-
match = false;
|
|
2561
|
-
}
|
|
2562
2583
|
}
|
|
2584
|
+
}
|
|
2563
2585
|
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
});
|
|
2569
|
-
}
|
|
2586
|
+
if (match) {
|
|
2587
|
+
callback(RED.util.cloneMessage(sysvar));
|
|
2588
|
+
}
|
|
2589
|
+
});
|
|
2570
2590
|
}
|
|
2571
2591
|
|
|
2572
2592
|
/**
|
|
2573
|
-
*
|
|
2574
|
-
* @
|
|
2593
|
+
* A program's state to the program subscriptions of its name (or of every program).
|
|
2594
|
+
* @param {string} name
|
|
2575
2595
|
*/
|
|
2596
|
+
dispatchProgram(name) {
|
|
2597
|
+
const program = this.program[name];
|
|
2598
|
+
if (!program) {
|
|
2599
|
+
return;
|
|
2600
|
+
}
|
|
2601
|
+
|
|
2602
|
+
Object.keys(this.programCallbacks).forEach((key) => {
|
|
2603
|
+
const {filter, callback} = this.programCallbacks[key];
|
|
2604
|
+
if (!filter.name || filter.name === name) {
|
|
2605
|
+
callback(program);
|
|
2606
|
+
}
|
|
2607
|
+
});
|
|
2608
|
+
}
|
|
2609
|
+
|
|
2576
2610
|
/**
|
|
2577
2611
|
* Re-read the ReGa metadata that only ever got fetched once, in the
|
|
2578
2612
|
* constructor: channel names, rooms and functions. A room or function
|
|
@@ -2695,12 +2729,7 @@ module.exports = function (RED) {
|
|
|
2695
2729
|
ts: prg.ts,
|
|
2696
2730
|
tsPrevious: this.program[prg.name].ts,
|
|
2697
2731
|
};
|
|
2698
|
-
|
|
2699
|
-
const {filter, callback} = this.programCallbacks[key];
|
|
2700
|
-
if (!filter.name || filter.name === prg.name) {
|
|
2701
|
-
callback(this.program[prg.name]);
|
|
2702
|
-
}
|
|
2703
|
-
});
|
|
2732
|
+
this.dispatchProgram(prg.name);
|
|
2704
2733
|
}
|
|
2705
2734
|
});
|
|
2706
2735
|
resolve();
|
|
@@ -2882,7 +2911,9 @@ module.exports = function (RED) {
|
|
|
2882
2911
|
this.meta.attach(box);
|
|
2883
2912
|
}
|
|
2884
2913
|
},
|
|
2885
|
-
|
|
2914
|
+
// task 32: the client follows every interface the system lists; the stream's calls of an
|
|
2915
|
+
// interface this connection does not use (unticked) get an id no handler takes
|
|
2916
|
+
initId: (iface) => (this.liteWants(iface) ? this.liteInitId(iface) : 'nr_ignored'),
|
|
2886
2917
|
logger: this.logger,
|
|
2887
2918
|
createClient: this.liteCreateClient,
|
|
2888
2919
|
onCallback: (method, err, parameters, callback) => {
|
|
@@ -2907,7 +2938,20 @@ module.exports = function (RED) {
|
|
|
2907
2938
|
}
|
|
2908
2939
|
},
|
|
2909
2940
|
onInterface: (iface, state) => {
|
|
2910
|
-
if (
|
|
2941
|
+
if (this.closing) {
|
|
2942
|
+
return;
|
|
2943
|
+
}
|
|
2944
|
+
|
|
2945
|
+
if (state === 'removed' && iface === this.logicIface) {
|
|
2946
|
+
this.logicGone();
|
|
2947
|
+
return;
|
|
2948
|
+
}
|
|
2949
|
+
|
|
2950
|
+
if (state !== 'removed' && !this.liteWants(iface)) {
|
|
2951
|
+
return;
|
|
2952
|
+
}
|
|
2953
|
+
|
|
2954
|
+
if (!this.liteIfaces.includes(iface)) {
|
|
2911
2955
|
return;
|
|
2912
2956
|
}
|
|
2913
2957
|
|
|
@@ -2928,12 +2972,13 @@ module.exports = function (RED) {
|
|
|
2928
2972
|
}
|
|
2929
2973
|
|
|
2930
2974
|
this.logger.debug('lite-rpc client', state);
|
|
2975
|
+
const followed = this.liteIfaces.slice();
|
|
2931
2976
|
if (state === 'ready') {
|
|
2932
|
-
|
|
2977
|
+
followed.forEach((iface) => this.setIfaceStatus(iface, running(iface), !running(iface)));
|
|
2933
2978
|
} else if (state === 'degraded' || state === 'offline' || state === 'connecting') {
|
|
2934
|
-
|
|
2979
|
+
followed.forEach((iface) => this.setIfaceStatus(iface, false, true));
|
|
2935
2980
|
} else if (state === 'closed') {
|
|
2936
|
-
|
|
2981
|
+
followed.forEach((iface) => this.setIfaceStatus(iface, false));
|
|
2937
2982
|
}
|
|
2938
2983
|
},
|
|
2939
2984
|
onValues: (values) => this.applyLiteValues(values),
|
|
@@ -2949,7 +2994,9 @@ module.exports = function (RED) {
|
|
|
2949
2994
|
return;
|
|
2950
2995
|
}
|
|
2951
2996
|
|
|
2952
|
-
|
|
2997
|
+
// task 32: the addon interfaces the system lists (Logic), followed without a checkbox
|
|
2998
|
+
this.liteAddonsListed();
|
|
2999
|
+
const up = this.liteIfaces.filter((iface) => running(iface));
|
|
2953
3000
|
this.logger.info('lite-rpc connected: ' + (up.join(', ') || 'no interface running'));
|
|
2954
3001
|
if (!this.lite.may('rpc:operate')) {
|
|
2955
3002
|
// B-44: events and device lists, but every command refused
|
|
@@ -3005,6 +3052,7 @@ module.exports = function (RED) {
|
|
|
3005
3052
|
this.ifaceStatus[iface] = null;
|
|
3006
3053
|
this.setIfaceStatus(iface, false);
|
|
3007
3054
|
});
|
|
3055
|
+
this.logicSettled();
|
|
3008
3056
|
return;
|
|
3009
3057
|
}
|
|
3010
3058
|
|
|
@@ -3026,7 +3074,7 @@ module.exports = function (RED) {
|
|
|
3026
3074
|
let count = 0;
|
|
3027
3075
|
values.forEach((entry, ref) => {
|
|
3028
3076
|
const [iface, channel, datapoint] = String(ref).split('.');
|
|
3029
|
-
if (!
|
|
3077
|
+
if (!channel || !datapoint || !this.liteWants(iface)) {
|
|
3030
3078
|
return;
|
|
3031
3079
|
}
|
|
3032
3080
|
|
|
@@ -3041,10 +3089,15 @@ module.exports = function (RED) {
|
|
|
3041
3089
|
});
|
|
3042
3090
|
this.values[message.datapointName] = message;
|
|
3043
3091
|
count += 1;
|
|
3092
|
+
if (iface === this.logicIface) {
|
|
3093
|
+
this.logicValue(iface, channel, datapoint, entry.value, {ts: ts || now(), picture: true});
|
|
3094
|
+
}
|
|
3095
|
+
|
|
3044
3096
|
if (!datapoint.startsWith('PRESS_')) {
|
|
3045
3097
|
this.callCallbacks(message);
|
|
3046
3098
|
}
|
|
3047
3099
|
});
|
|
3100
|
+
this.logicPictureDone();
|
|
3048
3101
|
this.logger.debug('lite-rpc: ' + count + ' values from the state store');
|
|
3049
3102
|
this.cachedValuesReceived = true;
|
|
3050
3103
|
this.saveValues();
|
|
@@ -3060,6 +3113,504 @@ module.exports = function (RED) {
|
|
|
3060
3113
|
}
|
|
3061
3114
|
}
|
|
3062
3115
|
|
|
3116
|
+
/**
|
|
3117
|
+
* task 32: whether this connection uses an interface the system's lite-rpc carries - one whose
|
|
3118
|
+
* checkbox put it on lite-rpc, or an addon's interface (Logic), which needs no checkbox: it is
|
|
3119
|
+
* taken the first time the stream or the system's list names it. An interface this package
|
|
3120
|
+
* knows by name (CUxD, CCU-Jack, an unticked one) keeps what its checkbox says.
|
|
3121
|
+
* @param {string} iface
|
|
3122
|
+
* @returns {boolean}
|
|
3123
|
+
*/
|
|
3124
|
+
liteWants(iface) {
|
|
3125
|
+
if (typeof iface !== 'string' || iface === '') {
|
|
3126
|
+
return false;
|
|
3127
|
+
}
|
|
3128
|
+
|
|
3129
|
+
if (this.liteIfaces.includes(iface)) {
|
|
3130
|
+
return true;
|
|
3131
|
+
}
|
|
3132
|
+
|
|
3133
|
+
if (this.ifaceTypes[iface] || iface === META_IFACE || !this.lite || this.closing) {
|
|
3134
|
+
return false;
|
|
3135
|
+
}
|
|
3136
|
+
|
|
3137
|
+
return this.liteAddonIface(iface);
|
|
3138
|
+
}
|
|
3139
|
+
|
|
3140
|
+
/**
|
|
3141
|
+
* task 32: an addon's interface the system lists, followed through lite-rpc from now on: its
|
|
3142
|
+
* devices, datapoints and events are those of any interface (the value and event nodes can
|
|
3143
|
+
* address them), and Logic's are the system variables and programs as well.
|
|
3144
|
+
* @param {string} iface
|
|
3145
|
+
* @returns {boolean} whether it is followed
|
|
3146
|
+
*/
|
|
3147
|
+
liteAddonIface(iface) {
|
|
3148
|
+
if (!/^[\w.-]+$/.test(iface)) {
|
|
3149
|
+
this.logger.warn('lite-rpc: the interface "' + iface + '" has a name this package cannot follow');
|
|
3150
|
+
return false;
|
|
3151
|
+
}
|
|
3152
|
+
|
|
3153
|
+
const info =
|
|
3154
|
+
(this.lite &&
|
|
3155
|
+
this.lite.box &&
|
|
3156
|
+
Array.isArray(this.lite.box.interfaces) &&
|
|
3157
|
+
this.lite.box.interfaces.find((entry) => entry.name === iface)) ||
|
|
3158
|
+
{};
|
|
3159
|
+
this.ifaceTypes[iface] = {
|
|
3160
|
+
conf: 'addon',
|
|
3161
|
+
addonIface: true,
|
|
3162
|
+
addon: info.addon || '',
|
|
3163
|
+
protocol: 'lite-rpc',
|
|
3164
|
+
init: false,
|
|
3165
|
+
ping: false,
|
|
3166
|
+
enabled: true,
|
|
3167
|
+
};
|
|
3168
|
+
this.liteIfaces.push(iface);
|
|
3169
|
+
this.lite.follow(iface);
|
|
3170
|
+
if (!this.enabledIfaces.includes(iface)) {
|
|
3171
|
+
this.enabledIfaces.push(iface);
|
|
3172
|
+
}
|
|
3173
|
+
|
|
3174
|
+
this.ifaceStatus[iface] = null;
|
|
3175
|
+
const isLogic = logic.isLogicIface(iface, info);
|
|
3176
|
+
if (isLogic) {
|
|
3177
|
+
this.logicIface = iface;
|
|
3178
|
+
}
|
|
3179
|
+
|
|
3180
|
+
this.logger.info(
|
|
3181
|
+
'lite-rpc: the interface ' +
|
|
3182
|
+
iface +
|
|
3183
|
+
(info.addon ? ' of the addon ' + info.addon : '') +
|
|
3184
|
+
' is followed as well' +
|
|
3185
|
+
(isLogic ? ' - the system variables and programs' : ''),
|
|
3186
|
+
);
|
|
3187
|
+
this.pushStatus();
|
|
3188
|
+
return true;
|
|
3189
|
+
}
|
|
3190
|
+
|
|
3191
|
+
/**
|
|
3192
|
+
* task 32: the system's list of interfaces, read by the client at connect: every addon
|
|
3193
|
+
* interface in it is followed. Then it is known whether Logic is installed.
|
|
3194
|
+
*/
|
|
3195
|
+
liteAddonsListed() {
|
|
3196
|
+
const list = this.lite && this.lite.box && this.lite.box.interfaces;
|
|
3197
|
+
if (Array.isArray(list)) {
|
|
3198
|
+
list.forEach((entry) => this.liteWants(entry && entry.name));
|
|
3199
|
+
}
|
|
3200
|
+
|
|
3201
|
+
this.liteListed = true;
|
|
3202
|
+
if (!this.logicIface) {
|
|
3203
|
+
this.logger.info(
|
|
3204
|
+
'openccu-lite: the Logic addon is not installed - the sysvar and program nodes have nothing to reach until it is',
|
|
3205
|
+
);
|
|
3206
|
+
}
|
|
3207
|
+
|
|
3208
|
+
this.logicSettled();
|
|
3209
|
+
this.pushStatus();
|
|
3210
|
+
}
|
|
3211
|
+
|
|
3212
|
+
/**
|
|
3213
|
+
* task 32: the Logic interface was removed (the addon uninstalled): its variables and programs
|
|
3214
|
+
* are gone, the nodes say so.
|
|
3215
|
+
*/
|
|
3216
|
+
logicGone() {
|
|
3217
|
+
const iface = this.logicIface;
|
|
3218
|
+
this.logger.warn('lite-rpc: the interface ' + iface + ' was removed - the Logic addon is gone');
|
|
3219
|
+
Object.keys(this.logicObjects).forEach((channel) => this.forgetLogicObject(channel));
|
|
3220
|
+
this.setIfaceStatus(iface, false);
|
|
3221
|
+
this.logicIface = null;
|
|
3222
|
+
this.pushStatus();
|
|
3223
|
+
}
|
|
3224
|
+
|
|
3225
|
+
/** task 32: whether Logic is installed is known now (or cannot be known): waiting writes go on */
|
|
3226
|
+
logicSettled() {
|
|
3227
|
+
const waiters = this.logicWaiters;
|
|
3228
|
+
this.logicWaiters = [];
|
|
3229
|
+
waiters.forEach((resolve) => resolve());
|
|
3230
|
+
}
|
|
3231
|
+
|
|
3232
|
+
/**
|
|
3233
|
+
* task 32: resolves once it is known whether Logic is installed and its picture is loaded, or
|
|
3234
|
+
* after `timeout` - a write in the first seconds after a deploy waits for it, as the CCU path
|
|
3235
|
+
* waits for the first poll of the ReGa.
|
|
3236
|
+
* @param {number} [timeout] ms
|
|
3237
|
+
* @returns {Promise<void>}
|
|
3238
|
+
*/
|
|
3239
|
+
whenLogicKnown(timeout = 30000) {
|
|
3240
|
+
if (this.liteListed || !this.lite) {
|
|
3241
|
+
return Promise.resolve();
|
|
3242
|
+
}
|
|
3243
|
+
|
|
3244
|
+
return new Promise((resolve) => {
|
|
3245
|
+
const timer = setTimeout(resolve, timeout);
|
|
3246
|
+
this.logicWaiters.push(() => {
|
|
3247
|
+
clearTimeout(timer);
|
|
3248
|
+
resolve();
|
|
3249
|
+
});
|
|
3250
|
+
});
|
|
3251
|
+
}
|
|
3252
|
+
|
|
3253
|
+
/**
|
|
3254
|
+
* task 32: why system variables and programs cannot be reached on this openccu-lite system, or
|
|
3255
|
+
* null when they can (or it is not known yet).
|
|
3256
|
+
* @param {string} feature for the message, e.g. "system variables"
|
|
3257
|
+
* @returns {Error|null}
|
|
3258
|
+
*/
|
|
3259
|
+
logicUnavailable(feature) {
|
|
3260
|
+
if (this.logicIface) {
|
|
3261
|
+
return null;
|
|
3262
|
+
}
|
|
3263
|
+
|
|
3264
|
+
if (!this.lite) {
|
|
3265
|
+
return new Error(
|
|
3266
|
+
feature +
|
|
3267
|
+
" are reached through the system's lite-rpc (the Logic addon's interface), which this connection does not use - see the log for why",
|
|
3268
|
+
);
|
|
3269
|
+
}
|
|
3270
|
+
|
|
3271
|
+
if (this.liteListed) {
|
|
3272
|
+
return new Error(feature + ' are not available: the Logic addon is not installed on this system');
|
|
3273
|
+
}
|
|
3274
|
+
|
|
3275
|
+
return null;
|
|
3276
|
+
}
|
|
3277
|
+
|
|
3278
|
+
/**
|
|
3279
|
+
* task 32: what the sysvar, program and poll nodes show: the ReGaHSS's state on a CCU; on
|
|
3280
|
+
* openccu-lite the Logic interface's, or why there is none.
|
|
3281
|
+
* @returns {{iface: string, error?: string, waiting?: boolean}}
|
|
3282
|
+
*/
|
|
3283
|
+
sysvarSource() {
|
|
3284
|
+
if (!this.metaMode) {
|
|
3285
|
+
return {iface: 'ReGaHSS'};
|
|
3286
|
+
}
|
|
3287
|
+
|
|
3288
|
+
if (this.logicIface) {
|
|
3289
|
+
return {iface: this.logicIface};
|
|
3290
|
+
}
|
|
3291
|
+
|
|
3292
|
+
if (!this.lite) {
|
|
3293
|
+
return {iface: logic.LOGIC_IFACE, error: 'needs lite-rpc'};
|
|
3294
|
+
}
|
|
3295
|
+
|
|
3296
|
+
if (this.liteListed) {
|
|
3297
|
+
return {iface: logic.LOGIC_IFACE, error: 'Logic addon not installed'};
|
|
3298
|
+
}
|
|
3299
|
+
|
|
3300
|
+
return {iface: logic.LOGIC_IFACE, waiting: true};
|
|
3301
|
+
}
|
|
3302
|
+
|
|
3303
|
+
/**
|
|
3304
|
+
* task 32: the description of a datapoint of a Logic channel, where it was fetched.
|
|
3305
|
+
* @param {string} channel
|
|
3306
|
+
* @param {string} datapoint
|
|
3307
|
+
* @returns {object|undefined}
|
|
3308
|
+
*/
|
|
3309
|
+
logicDescription(channel, datapoint) {
|
|
3310
|
+
const devices = this.metadata.devices[this.logicIface];
|
|
3311
|
+
const description = devices && devices[channel];
|
|
3312
|
+
if (!description) {
|
|
3313
|
+
return undefined;
|
|
3314
|
+
}
|
|
3315
|
+
|
|
3316
|
+
const psKey = this.paramsetName(this.logicIface, description, 'VALUES');
|
|
3317
|
+
const paramset = psKey && this.paramsetDescriptions[psKey];
|
|
3318
|
+
return paramset ? paramset[datapoint] : undefined;
|
|
3319
|
+
}
|
|
3320
|
+
|
|
3321
|
+
/**
|
|
3322
|
+
* task 32: a datapoint of Logic's interface - a variable's VALUE, a program's ACTIVE or
|
|
3323
|
+
* LAST_RUN - into the tables the sysvar and program nodes read (this.sysvar, this.program).
|
|
3324
|
+
* @param {string} iface
|
|
3325
|
+
* @param {string} channel
|
|
3326
|
+
* @param {string} datapoint
|
|
3327
|
+
* @param {*} value
|
|
3328
|
+
* @param {{ts: number, picture?: boolean}} options picture: from the state store at connect
|
|
3329
|
+
*/
|
|
3330
|
+
logicValue(iface, channel, datapoint, value, {ts, picture = false}) {
|
|
3331
|
+
const ref = logic.parseAddress(channel);
|
|
3332
|
+
if (!ref) {
|
|
3333
|
+
return;
|
|
3334
|
+
}
|
|
3335
|
+
|
|
3336
|
+
if (ref.kind === 'variable') {
|
|
3337
|
+
if (datapoint === 'VALUE') {
|
|
3338
|
+
this.updateLogicVariable(ref, value, ts, picture);
|
|
3339
|
+
}
|
|
3340
|
+
} else if (datapoint === 'ACTIVE') {
|
|
3341
|
+
this.updateLogicProgram(ref, {active: Boolean(value)}, ts, picture);
|
|
3342
|
+
} else if (datapoint === 'LAST_RUN') {
|
|
3343
|
+
this.updateLogicProgram(ref, {ran: true}, ts, picture);
|
|
3344
|
+
}
|
|
3345
|
+
}
|
|
3346
|
+
|
|
3347
|
+
/**
|
|
3348
|
+
* task 32: the entry of a Logic object under its current name in `table` (this.sysvar or
|
|
3349
|
+
* this.program): a rename moves it, a name another object holds is not taken over.
|
|
3350
|
+
* @param {object} table
|
|
3351
|
+
* @param {object} ref from logic.parseAddress()
|
|
3352
|
+
* @returns {{entry: object|undefined, name: string}}
|
|
3353
|
+
*/
|
|
3354
|
+
logicEntry(table, ref) {
|
|
3355
|
+
const name = logic.nameOf(this.channelNames, ref);
|
|
3356
|
+
const entry = this.logicObjects[ref.channel];
|
|
3357
|
+
if (entry && entry.name !== name) {
|
|
3358
|
+
if (table[entry.name] === entry) {
|
|
3359
|
+
delete table[entry.name];
|
|
3360
|
+
}
|
|
3361
|
+
|
|
3362
|
+
entry.name = name;
|
|
3363
|
+
}
|
|
3364
|
+
|
|
3365
|
+
if (entry) {
|
|
3366
|
+
table[name] = entry;
|
|
3367
|
+
}
|
|
3368
|
+
|
|
3369
|
+
return {entry, name};
|
|
3370
|
+
}
|
|
3371
|
+
|
|
3372
|
+
/**
|
|
3373
|
+
* task 32: a system variable's value. A write is an event at every write, so a value that did
|
|
3374
|
+
* not change is an update (change false), as the CCU's poll reported a new timestamp.
|
|
3375
|
+
* @param {object} ref
|
|
3376
|
+
* @param {*} value
|
|
3377
|
+
* @param {number} ts
|
|
3378
|
+
* @param {boolean} picture
|
|
3379
|
+
*/
|
|
3380
|
+
updateLogicVariable(ref, value, ts, picture) {
|
|
3381
|
+
const {entry, name} = this.logicEntry(this.sysvar, ref);
|
|
3382
|
+
const shape = logic.variableShape(this.logicDescription(ref.channel, 'VALUE'), value);
|
|
3383
|
+
if (entry && picture && entry.ts >= ts) {
|
|
3384
|
+
// the picture again (a resync): nothing new
|
|
3385
|
+
return;
|
|
3386
|
+
}
|
|
3387
|
+
|
|
3388
|
+
const isNew = !entry;
|
|
3389
|
+
const sysvar = entry || {
|
|
3390
|
+
topic: '',
|
|
3391
|
+
ccu: this.host,
|
|
3392
|
+
iface: this.logicIface,
|
|
3393
|
+
type: 'SYSVAR',
|
|
3394
|
+
name,
|
|
3395
|
+
info: '',
|
|
3396
|
+
key: ref.key,
|
|
3397
|
+
address: ref.channel,
|
|
3398
|
+
};
|
|
3399
|
+
Object.assign(sysvar, {
|
|
3400
|
+
payload: value,
|
|
3401
|
+
value,
|
|
3402
|
+
valueType: shape.valueType,
|
|
3403
|
+
enum: shape.enum,
|
|
3404
|
+
unit: shape.unit,
|
|
3405
|
+
valueEnum: shape.enum[Number(value)],
|
|
3406
|
+
valuePrevious: isNew ? undefined : sysvar.value,
|
|
3407
|
+
valueEnumPrevious: isNew ? undefined : sysvar.valueEnum,
|
|
3408
|
+
ts,
|
|
3409
|
+
tsPrevious: isNew ? undefined : sysvar.ts,
|
|
3410
|
+
lc: isNew || sysvar.value !== value ? ts : sysvar.lc,
|
|
3411
|
+
lcPrevious: isNew ? undefined : sysvar.lc,
|
|
3412
|
+
change: isNew ? false : sysvar.value !== value,
|
|
3413
|
+
// a value from the start is the cache; the first event of a variable made later is an event
|
|
3414
|
+
cache: isNew && picture,
|
|
3415
|
+
});
|
|
3416
|
+
if (shape.min !== undefined) {
|
|
3417
|
+
sysvar.min = shape.min;
|
|
3418
|
+
}
|
|
3419
|
+
|
|
3420
|
+
if (shape.max !== undefined) {
|
|
3421
|
+
sysvar.max = shape.max;
|
|
3422
|
+
}
|
|
3423
|
+
|
|
3424
|
+
if (isNew) {
|
|
3425
|
+
this.logicObjects[ref.channel] = sysvar;
|
|
3426
|
+
this.sysvar[name] = sysvar;
|
|
3427
|
+
}
|
|
3428
|
+
|
|
3429
|
+
this.dispatchSysvar(name);
|
|
3430
|
+
}
|
|
3431
|
+
|
|
3432
|
+
/**
|
|
3433
|
+
* task 32: a program's state: ACTIVE, and LAST_RUN as the time it last ran (the CCU's
|
|
3434
|
+
* ProgramLastExecuteTime, `ts`). The state store's picture is said once per program, after
|
|
3435
|
+
* both datapoints are in (logicPictureDone).
|
|
3436
|
+
* @param {object} ref
|
|
3437
|
+
* @param {{active?: boolean, ran?: boolean}} change
|
|
3438
|
+
* @param {number} ts
|
|
3439
|
+
* @param {boolean} picture
|
|
3440
|
+
*/
|
|
3441
|
+
updateLogicProgram(ref, change, ts, picture) {
|
|
3442
|
+
const {entry, name} = this.logicEntry(this.program, ref);
|
|
3443
|
+
const program = entry || {
|
|
3444
|
+
ccu: this.host,
|
|
3445
|
+
iface: this.logicIface,
|
|
3446
|
+
type: 'PROGRAM',
|
|
3447
|
+
name,
|
|
3448
|
+
key: ref.key,
|
|
3449
|
+
address: ref.channel,
|
|
3450
|
+
};
|
|
3451
|
+
const previous = {active: program.active, ts: program.ts};
|
|
3452
|
+
if (change.active !== undefined) {
|
|
3453
|
+
program.active = change.active;
|
|
3454
|
+
program.payload = change.active;
|
|
3455
|
+
program.value = change.active;
|
|
3456
|
+
}
|
|
3457
|
+
|
|
3458
|
+
if (change.ran) {
|
|
3459
|
+
program.ts = ts;
|
|
3460
|
+
}
|
|
3461
|
+
|
|
3462
|
+
if (!entry) {
|
|
3463
|
+
this.logicObjects[ref.channel] = program;
|
|
3464
|
+
this.program[name] = program;
|
|
3465
|
+
program.pictured = picture;
|
|
3466
|
+
}
|
|
3467
|
+
|
|
3468
|
+
if (picture) {
|
|
3469
|
+
program.pictured = true;
|
|
3470
|
+
return;
|
|
3471
|
+
}
|
|
3472
|
+
|
|
3473
|
+
if (previous.active === program.active && previous.ts === program.ts) {
|
|
3474
|
+
return;
|
|
3475
|
+
}
|
|
3476
|
+
|
|
3477
|
+
program.activePrevious = previous.active;
|
|
3478
|
+
program.tsPrevious = previous.ts;
|
|
3479
|
+
this.dispatchProgram(name);
|
|
3480
|
+
}
|
|
3481
|
+
|
|
3482
|
+
/**
|
|
3483
|
+
* task 32: the state store's picture is in: each program once to its nodes, as the CCU's
|
|
3484
|
+
* first poll does.
|
|
3485
|
+
*/
|
|
3486
|
+
logicPictureDone() {
|
|
3487
|
+
Object.keys(this.program).forEach((name) => {
|
|
3488
|
+
const program = this.program[name];
|
|
3489
|
+
if (program.pictured) {
|
|
3490
|
+
delete program.pictured;
|
|
3491
|
+
this.dispatchProgram(name);
|
|
3492
|
+
}
|
|
3493
|
+
});
|
|
3494
|
+
}
|
|
3495
|
+
|
|
3496
|
+
/**
|
|
3497
|
+
* task 32: the names changed - a variable or program that was renamed (or whose name came
|
|
3498
|
+
* after its value) is found by its new name; a node waiting for it gets the value it would
|
|
3499
|
+
* have got at the start.
|
|
3500
|
+
*/
|
|
3501
|
+
relabelLogic() {
|
|
3502
|
+
Object.keys(this.logicObjects).forEach((channel) => {
|
|
3503
|
+
const entry = this.logicObjects[channel];
|
|
3504
|
+
const ref = logic.parseAddress(channel);
|
|
3505
|
+
const before = entry.name;
|
|
3506
|
+
const {name} = this.logicEntry(entry.type === 'SYSVAR' ? this.sysvar : this.program, ref);
|
|
3507
|
+
if (name === before) {
|
|
3508
|
+
return;
|
|
3509
|
+
}
|
|
3510
|
+
|
|
3511
|
+
this.logger.debug(
|
|
3512
|
+
'Logic',
|
|
3513
|
+
channel,
|
|
3514
|
+
'is',
|
|
3515
|
+
JSON.stringify(name),
|
|
3516
|
+
'now (was',
|
|
3517
|
+
JSON.stringify(before) + ')',
|
|
3518
|
+
);
|
|
3519
|
+
if (entry.type === 'SYSVAR') {
|
|
3520
|
+
const {cache, change} = entry;
|
|
3521
|
+
entry.cache = true;
|
|
3522
|
+
entry.change = false;
|
|
3523
|
+
this.dispatchSysvar(name);
|
|
3524
|
+
entry.cache = cache;
|
|
3525
|
+
entry.change = change;
|
|
3526
|
+
} else {
|
|
3527
|
+
this.dispatchProgram(name);
|
|
3528
|
+
}
|
|
3529
|
+
});
|
|
3530
|
+
}
|
|
3531
|
+
|
|
3532
|
+
/**
|
|
3533
|
+
* task 32: a variable or program deleted in Logic (its device, or its value channel).
|
|
3534
|
+
* @param {string} address
|
|
3535
|
+
*/
|
|
3536
|
+
forgetLogicObject(address) {
|
|
3537
|
+
const channel = String(address).includes(':') ? address : address + ':1';
|
|
3538
|
+
const entry = this.logicObjects[channel];
|
|
3539
|
+
if (!entry) {
|
|
3540
|
+
return;
|
|
3541
|
+
}
|
|
3542
|
+
|
|
3543
|
+
delete this.logicObjects[channel];
|
|
3544
|
+
const table = entry.type === 'SYSVAR' ? this.sysvar : this.program;
|
|
3545
|
+
if (table[entry.name] === entry) {
|
|
3546
|
+
delete table[entry.name];
|
|
3547
|
+
}
|
|
3548
|
+
}
|
|
3549
|
+
|
|
3550
|
+
/**
|
|
3551
|
+
* task 32: a write to a system variable on openccu-lite - setValue of VALUE on Logic's
|
|
3552
|
+
* interface, cast as the CCU path casts it; the addon refuses what the variable does not take.
|
|
3553
|
+
* @param {string} name
|
|
3554
|
+
* @param {*} value
|
|
3555
|
+
* @returns {Promise<object>} the variable
|
|
3556
|
+
*/
|
|
3557
|
+
setLogicVariable(name, value) {
|
|
3558
|
+
return this.whenLogicKnown().then(() => {
|
|
3559
|
+
const unavailable = this.logicUnavailable('system variables');
|
|
3560
|
+
if (unavailable) {
|
|
3561
|
+
throw unavailable;
|
|
3562
|
+
}
|
|
3563
|
+
|
|
3564
|
+
const sysvar = this.sysvar[name];
|
|
3565
|
+
if (!sysvar || sysvar.iface !== this.logicIface) {
|
|
3566
|
+
throw new Error('setVariable ' + name + ' unknown');
|
|
3567
|
+
}
|
|
3568
|
+
|
|
3569
|
+
const shape = logic.variableShape(this.logicDescription(sysvar.address, 'VALUE'), sysvar.value);
|
|
3570
|
+
const cast = logic.castVariable(value, shape);
|
|
3571
|
+
this.logger.debug('setVariable', name, sysvar.address, JSON.stringify(cast));
|
|
3572
|
+
return this.methodCall(this.logicIface, 'setValue', [sysvar.address, 'VALUE', cast]).then(() => sysvar);
|
|
3573
|
+
});
|
|
3574
|
+
}
|
|
3575
|
+
|
|
3576
|
+
/**
|
|
3577
|
+
* task 32: a program on openccu-lite: ACTIVE, or RUN_THEN - what the CCU's ProgramExecute()
|
|
3578
|
+
* does, the first "Then" without the conditions (the addon's interface calls it the CCU's
|
|
3579
|
+
* "Start"); RUN would evaluate the conditions first.
|
|
3580
|
+
* @param {string} name
|
|
3581
|
+
* @param {string} datapoint ACTIVE | RUN_THEN
|
|
3582
|
+
* @param {boolean} value
|
|
3583
|
+
* @returns {Promise<object>} the program
|
|
3584
|
+
*/
|
|
3585
|
+
logicProgramCall(name, datapoint, value) {
|
|
3586
|
+
return this.whenLogicKnown().then(() => {
|
|
3587
|
+
const unavailable = this.logicUnavailable('programs');
|
|
3588
|
+
if (unavailable) {
|
|
3589
|
+
throw unavailable;
|
|
3590
|
+
}
|
|
3591
|
+
|
|
3592
|
+
const program = this.program[name];
|
|
3593
|
+
if (!program || program.iface !== this.logicIface) {
|
|
3594
|
+
throw new Error(
|
|
3595
|
+
(datapoint === 'ACTIVE' ? 'programActive ' : 'programExecute ') + name + ' not found',
|
|
3596
|
+
);
|
|
3597
|
+
}
|
|
3598
|
+
|
|
3599
|
+
return this.methodCall(this.logicIface, 'setValue', [program.address, datapoint, value]).then(() => {
|
|
3600
|
+
if (datapoint === 'ACTIVE') {
|
|
3601
|
+
program.activePrevious = program.active;
|
|
3602
|
+
program.active = value;
|
|
3603
|
+
program.payload = value;
|
|
3604
|
+
program.value = value;
|
|
3605
|
+
} else {
|
|
3606
|
+
program.ts = now();
|
|
3607
|
+
}
|
|
3608
|
+
|
|
3609
|
+
return program;
|
|
3610
|
+
});
|
|
3611
|
+
});
|
|
3612
|
+
}
|
|
3613
|
+
|
|
3063
3614
|
/**
|
|
3064
3615
|
*
|
|
3065
3616
|
* @param iface
|
|
@@ -3328,7 +3879,10 @@ module.exports = function (RED) {
|
|
|
3328
3879
|
*/
|
|
3329
3880
|
rereadDevices() {
|
|
3330
3881
|
const ifaces = Object.keys(this.ifaceTypes).filter(
|
|
3331
|
-
(iface) =>
|
|
3882
|
+
(iface) =>
|
|
3883
|
+
this.ifaceTypes[iface].enabled &&
|
|
3884
|
+
(this.ifaceTypes[iface].init || this.ifaceTypes[iface].addonIface) &&
|
|
3885
|
+
iface !== 'CUxD',
|
|
3332
3886
|
);
|
|
3333
3887
|
this.logger.info('re-reading device data:', ifaces.join(', '));
|
|
3334
3888
|
return Promise.all(
|
|
@@ -4012,6 +4566,9 @@ module.exports = function (RED) {
|
|
|
4012
4566
|
*/
|
|
4013
4567
|
deleteDevice(iface, device) {
|
|
4014
4568
|
this.logger.debug('deleteDevice', iface, device);
|
|
4569
|
+
if (iface === this.logicIface) {
|
|
4570
|
+
this.forgetLogicObject(device);
|
|
4571
|
+
}
|
|
4015
4572
|
const known = this.metadata.devices[iface] && this.metadata.devices[iface][device];
|
|
4016
4573
|
if (this.metadata.devices[iface]) {
|
|
4017
4574
|
delete this.metadata.devices[iface][device];
|
|
@@ -4220,7 +4777,7 @@ module.exports = function (RED) {
|
|
|
4220
4777
|
return idInit;
|
|
4221
4778
|
}
|
|
4222
4779
|
|
|
4223
|
-
const match = idInit.match(/^nr_[\da-zA-Z]{6}_([
|
|
4780
|
+
const match = idInit.match(/^nr_[\da-zA-Z]{6}_([\w.-]+)$/);
|
|
4224
4781
|
return match && this.ifaceTypes[match[1]] ? match[1] : null;
|
|
4225
4782
|
}
|
|
4226
4783
|
|
|
@@ -4725,6 +5282,11 @@ module.exports = function (RED) {
|
|
|
4725
5282
|
return;
|
|
4726
5283
|
}
|
|
4727
5284
|
|
|
5285
|
+
if (iface === this.logicIface) {
|
|
5286
|
+
// task 32: a variable's or a program's datapoint is the sysvar or program nodes' event too
|
|
5287
|
+
this.logicValue(iface, channel, datapoint, payload, {ts: now()});
|
|
5288
|
+
}
|
|
5289
|
+
|
|
4728
5290
|
//this.logger.trace('publishEvent', JSON.stringify(params));
|
|
4729
5291
|
|
|
4730
5292
|
const message = this.createMessage(iface, channel, datapoint, payload, {
|
package/nodes/ccu-poll.js
CHANGED
|
@@ -18,8 +18,9 @@ module.exports = function (RED) {
|
|
|
18
18
|
|
|
19
19
|
this.on('input', (message, send, done) => {
|
|
20
20
|
if (this.ccu.metaMode) {
|
|
21
|
-
// openccu-lite has no ReGaHSS -
|
|
22
|
-
|
|
21
|
+
// openccu-lite has no ReGaHSS (B-17); the Logic addon's variables and programs
|
|
22
|
+
// arrive as events, there is nothing to poll (task 32)
|
|
23
|
+
done(this.ccu.logicUnavailable('system variables and programs') || undefined);
|
|
23
24
|
return;
|
|
24
25
|
}
|
|
25
26
|
|
|
@@ -30,7 +31,7 @@ module.exports = function (RED) {
|
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
setStatus(data) {
|
|
33
|
-
statusHelper(this, data);
|
|
34
|
+
statusHelper.sysvar(this, data);
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
|
package/nodes/ccu-program.js
CHANGED
package/nodes/ccu-sysvar.js
CHANGED
package/nodes/lib/lite.js
CHANGED
|
@@ -277,7 +277,8 @@ class LiteConnection {
|
|
|
277
277
|
* @param {string} options.token the credential
|
|
278
278
|
* @param {boolean} [options.insecure] accept any certificate
|
|
279
279
|
* @param {string} [options.fingerprint256] accept exactly this certificate (pinned at pairing; wins over insecure)
|
|
280
|
-
* @param {string[]} options.interfaces the interfaces
|
|
280
|
+
* @param {string[]} options.interfaces the interfaces the connection uses (the enabled ones lite-rpc carries;
|
|
281
|
+
* addon interfaces are added with follow()); the client itself follows all the system lists
|
|
281
282
|
* @param {function(string): string} options.initId the init id the connection's callback table expects per interface
|
|
282
283
|
* @param {function(string, *, Array, Function)} options.onCallback (method, err, params, answer): a callback server's call
|
|
283
284
|
* @param {function(string, string)} options.onInterface (iface, state): up | down | restarted | added | removed
|
|
@@ -312,6 +313,16 @@ class LiteConnection {
|
|
|
312
313
|
return this.interfaces.includes(iface);
|
|
313
314
|
}
|
|
314
315
|
|
|
316
|
+
/**
|
|
317
|
+
* task 32: an interface the connection uses from now on (an addon's, named by the system).
|
|
318
|
+
* @param {string} iface
|
|
319
|
+
*/
|
|
320
|
+
follow(iface) {
|
|
321
|
+
if (!this.interfaces.includes(iface)) {
|
|
322
|
+
this.interfaces.push(iface);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
315
326
|
/**
|
|
316
327
|
* Opens the client. Resolves once the first picture is loaded. occulite-client (0.4) does not
|
|
317
328
|
* try a failed connect again (its streams only reconnect once connected), so a system that
|
|
@@ -364,7 +375,9 @@ class LiteConnection {
|
|
|
364
375
|
url: this.options.url,
|
|
365
376
|
auth: {token: this.options.token},
|
|
366
377
|
transport: nodeTransport(trustOf(this.options)),
|
|
367
|
-
|
|
378
|
+
// task 32: no interface filter - the client follows every interface the system lists, so
|
|
379
|
+
// an addon's interface (Logic) is seen, also one installed later (a filter would hide its
|
|
380
|
+
// `interface added`); the connection takes what it uses (initId)
|
|
368
381
|
values: true,
|
|
369
382
|
meta: Boolean(this.options.meta),
|
|
370
383
|
devices: true,
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* task 32: system variables and programs on openccu-lite. The system has no ReGaHSS; the addon
|
|
3
|
+
* Logic (lite-addon-logic) offers them as devices of an interface of its own, which the system's
|
|
4
|
+
* lite-rpc carries like the radio interfaces:
|
|
5
|
+
*
|
|
6
|
+
* system variable `regen` device var-regen (LOGIC-VARIABLE), channel var-regen:1, VALUE
|
|
7
|
+
* (an alarm variable also ACKNOWLEDGE, COUNT, FIRST, LAST)
|
|
8
|
+
* program `markise` device prg-markise (LOGIC-PROGRAM), channel prg-markise:1,
|
|
9
|
+
* ACTIVE, RUN (with the conditions), RUN_THEN (the CCU's "Start"),
|
|
10
|
+
* LAST_RUN (an event at every run)
|
|
11
|
+
*
|
|
12
|
+
* The address is the object's key and stays across a rename; the name is the system's metadata
|
|
13
|
+
* name of the channel (or the device), which the addon writes. The sysvar and program nodes find
|
|
14
|
+
* an object by that name, as they did by the ReGa name on a CCU, so a flow written for a CCU
|
|
15
|
+
* keeps working after the switch once the variables and programs were imported.
|
|
16
|
+
*
|
|
17
|
+
* Pure helpers, no connection state: the connection (ccu-connection.js) keeps the tables.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** the interface's name as lite-addon-logic registers it */
|
|
21
|
+
const LOGIC_IFACE = 'Logic';
|
|
22
|
+
|
|
23
|
+
/** the addon's id, `addon` in GET /api/rpc/v1/interfaces */
|
|
24
|
+
const LOGIC_ADDON = 'logic';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Whether an interface the system lists is Logic's: by its addon id, else by its name.
|
|
28
|
+
* @param {string} name
|
|
29
|
+
* @param {{addon?: string}} [info] the entry of GET /api/rpc/v1/interfaces
|
|
30
|
+
* @returns {boolean}
|
|
31
|
+
*/
|
|
32
|
+
function isLogicIface(name, info) {
|
|
33
|
+
if (info && info.addon) {
|
|
34
|
+
return info.addon === LOGIC_ADDON;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return name === LOGIC_IFACE;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* What a Logic address stands for: a variable's or a program's value channel (`:1`), else null.
|
|
42
|
+
* @param {string} channel e.g. var-regen:1
|
|
43
|
+
* @returns {{kind: 'variable'|'program', key: string, device: string, channel: string}|null}
|
|
44
|
+
*/
|
|
45
|
+
function parseAddress(channel) {
|
|
46
|
+
const match = /^(var|prg)-(.+):1$/.exec(String(channel || ''));
|
|
47
|
+
if (!match) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
kind: match[1] === 'var' ? 'variable' : 'program',
|
|
53
|
+
key: match[2],
|
|
54
|
+
device: match[1] + '-' + match[2],
|
|
55
|
+
channel: match[1] + '-' + match[2] + ':1',
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The name a node finds an object by: the channel's metadata name, else the device's, else its key
|
|
61
|
+
* (a connection without a credential for the names).
|
|
62
|
+
* @param {object} names channelNames, by address
|
|
63
|
+
* @param {{key: string, device: string, channel: string}} ref from parseAddress()
|
|
64
|
+
* @returns {string}
|
|
65
|
+
*/
|
|
66
|
+
function nameOf(names, ref) {
|
|
67
|
+
const map = names || {};
|
|
68
|
+
return map[ref.channel] || map[ref.device] || ref.key;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The CCU's shape of a system variable (homematic-rega's getVariables) from the description of
|
|
73
|
+
* Logic's VALUE datapoint: `valueType` boolean | number | string, `enum` (the texts for false and
|
|
74
|
+
* true of a logic value, the entries of a value list), `unit`, and the Homematic type.
|
|
75
|
+
* Without a description (not fetched yet) the type follows the value.
|
|
76
|
+
* @param {object} [description] the paramset description of VALUE
|
|
77
|
+
* @param {*} [value] the current value, for the fallback
|
|
78
|
+
* @returns {{valueType: string, enum: string[], unit: string, type: string|undefined, min?: number, max?: number}}
|
|
79
|
+
*/
|
|
80
|
+
function variableShape(description, value) {
|
|
81
|
+
const list = description && Array.isArray(description.VALUE_LIST) ? description.VALUE_LIST.map(String) : [];
|
|
82
|
+
const unit = (description && typeof description.UNIT === 'string' && description.UNIT) || '';
|
|
83
|
+
const type = description && description.TYPE;
|
|
84
|
+
const shape = {valueType: 'number', enum: [], unit, type};
|
|
85
|
+
switch (type) {
|
|
86
|
+
case 'BOOL':
|
|
87
|
+
case 'ACTION':
|
|
88
|
+
shape.valueType = 'boolean';
|
|
89
|
+
shape.enum = list;
|
|
90
|
+
break;
|
|
91
|
+
case 'STRING':
|
|
92
|
+
shape.valueType = 'string';
|
|
93
|
+
break;
|
|
94
|
+
case 'ENUM':
|
|
95
|
+
shape.enum = list;
|
|
96
|
+
break;
|
|
97
|
+
case 'FLOAT':
|
|
98
|
+
case 'INTEGER':
|
|
99
|
+
break;
|
|
100
|
+
default:
|
|
101
|
+
if (typeof value === 'boolean') {
|
|
102
|
+
shape.valueType = 'boolean';
|
|
103
|
+
} else if (typeof value === 'string') {
|
|
104
|
+
shape.valueType = 'string';
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (description && typeof description.MIN === 'number' && shape.valueType === 'number' && type !== 'ENUM') {
|
|
109
|
+
shape.min = description.MIN;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (description && typeof description.MAX === 'number' && shape.valueType === 'number' && type !== 'ENUM') {
|
|
113
|
+
shape.max = description.MAX;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return shape;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* A value for Logic's VALUE, cast the way the CCU path casts a variable (castSysvar): a logic
|
|
121
|
+
* value takes true/false, a number, or one of its two texts; a value list its entry's number or
|
|
122
|
+
* text; a number a number; a string a string. A FLOAT goes out as homematic-xmlrpc's
|
|
123
|
+
* `{explicitDouble}`, which lite.js turns into lite-rpc's double. Limits are the addon's to check:
|
|
124
|
+
* it refuses a number outside them and an entry the list does not have, and the refusal is said.
|
|
125
|
+
* @param {*} value
|
|
126
|
+
* @param {{valueType: string, enum: string[], type?: string}} shape from variableShape()
|
|
127
|
+
* @returns {*}
|
|
128
|
+
*/
|
|
129
|
+
function castVariable(value, shape) {
|
|
130
|
+
const list = shape.enum || [];
|
|
131
|
+
switch (shape.valueType) {
|
|
132
|
+
case 'boolean':
|
|
133
|
+
if (typeof value === 'string') {
|
|
134
|
+
if (list.includes(value)) {
|
|
135
|
+
return list.indexOf(value) === 1;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (value === 'false' || value === '0') {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return Boolean(value);
|
|
144
|
+
case 'string':
|
|
145
|
+
return value === null || value === undefined ? '' : String(value);
|
|
146
|
+
default: {
|
|
147
|
+
if (typeof value === 'string' && list.includes(value)) {
|
|
148
|
+
return list.indexOf(value);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (typeof value === 'boolean') {
|
|
152
|
+
value = value ? 1 : 0;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const number = Number.parseFloat(value);
|
|
156
|
+
const safe = Number.isFinite(number) ? number : 0;
|
|
157
|
+
if (shape.type === 'ENUM' || shape.type === 'INTEGER') {
|
|
158
|
+
return Math.round(safe);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (shape.type === 'FLOAT') {
|
|
162
|
+
return {explicitDouble: safe};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return safe;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
module.exports = {
|
|
171
|
+
LOGIC_IFACE,
|
|
172
|
+
LOGIC_ADDON,
|
|
173
|
+
isLogicIface,
|
|
174
|
+
parseAddress,
|
|
175
|
+
nameOf,
|
|
176
|
+
variableShape,
|
|
177
|
+
castVariable,
|
|
178
|
+
};
|
package/nodes/lib/status.js
CHANGED
|
@@ -63,3 +63,34 @@ module.exports = (that, data) => {
|
|
|
63
63
|
that.currentStatus = 'red';
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* task 32: the status of a node of system variables or programs (sysvar, program, poll): on a CCU
|
|
69
|
+
* the ReGaHSS's, on openccu-lite the Logic interface's - or why there is none (the addon is not
|
|
70
|
+
* installed, the connection does not use lite-rpc).
|
|
71
|
+
* @param {object} that the node; `that.ccu.sysvarSource()` decides
|
|
72
|
+
* @param {object} data what the connection pushes
|
|
73
|
+
*/
|
|
74
|
+
module.exports.sysvar = (that, data) => {
|
|
75
|
+
const source = that.ccu && typeof that.ccu.sysvarSource === 'function' ? that.ccu.sysvarSource() : {};
|
|
76
|
+
if (source.iface) {
|
|
77
|
+
that.iface = source.iface;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (source.error) {
|
|
81
|
+
if (that.currentStatus !== 'error:' + source.error) {
|
|
82
|
+
that.status({fill: 'red', shape: 'ring', text: source.error});
|
|
83
|
+
that.currentStatus = 'error:' + source.error;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (source.waiting) {
|
|
90
|
+
that.status(WAITING);
|
|
91
|
+
that.currentStatus = 'waiting';
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
module.exports(that, data);
|
|
96
|
+
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
<script type="text/html" data-help-name="ccu-poll">
|
|
2
2
|
<p>Führt einen sofortigen Poll von ReGaHSS Systemvariablen durch.</p>
|
|
3
|
+
<p><b>openccu-lite:</b> die Variablen und Programme des Addons <i>Logic</i> kommen als Ereignisse; es gibt nichts
|
|
4
|
+
zu pollen, eine Nachricht bewirkt nichts.</p>
|
|
3
5
|
<p>Dieser Node ist dazu vorgesehen die Änderung von Systemvariablen mit möglichst geringer Verzögerung zu empfangen.
|
|
4
6
|
Hierzu kann man ein Programm auf der CCU anlegen dass bei Änderung von Variablen einen virtuellen Taster betätigt.
|
|
5
7
|
In Node-RED wird dann ein <i>rpc event</i> oder <i>value</i> Node so konfiguriert dass er diese
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
<script type="text/html" data-help-name="ccu-program">
|
|
2
2
|
<p>Führt ein ReGaHSS Programm aus.</p>
|
|
3
|
+
<p><b>openccu-lite:</b> die Programme kommen vom Addon <i>Logic</i> über die lite-rpc des Systems (Schnittstelle
|
|
4
|
+
<code>Logic</code>). Ein boolean schaltet <code>ACTIVE</code> des Programms; alles andere startet es wie auf der
|
|
5
|
+
CCU - das erste <i>Dann</i>, ohne die Bedingungen zu prüfen (<code>RUN_THEN</code>). Der Ausgang folgt
|
|
6
|
+
<code>ACTIVE</code> und jedem Lauf des Programms. Ohne das Addon zeigt der Node <i>Logic addon not
|
|
7
|
+
installed</i>.</p>
|
|
3
8
|
<h3>Inputs</h3>
|
|
4
9
|
<dl class="message-properties">
|
|
5
10
|
<dt>payload
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
<script type="text/html" data-help-name="ccu-sysvar">
|
|
2
2
|
<p>Setzen und lesen von ReGaHSS Systemvariablen.</p>
|
|
3
|
+
<p><b>openccu-lite:</b> das System hat keine ReGaHSS; die Systemvariablen kommen vom Addon <i>Logic</i>, das sie
|
|
4
|
+
als Geräte seiner Schnittstelle <code>Logic</code> über die lite-rpc des Systems anbietet. Der Node findet eine
|
|
5
|
+
Variable wie auf der CCU über ihren Namen und bekommt bei jedem Schreiben ein Ereignis (<i>Nur geänderte Werte ausgeben</i>
|
|
6
|
+
lässt das Schreiben desselben Werts weg). Die Verbindung braucht lite-rpc (ein Token mit <code>rpc:read</code>
|
|
7
|
+
und <code>rpc:operate</code>, oder RedMatic auf dem System selbst); ohne das Addon zeigt der Node
|
|
8
|
+
<i>Logic addon not installed</i>. <code>msg.iface</code> ist <code>Logic</code>, <code>msg.key</code> der
|
|
9
|
+
Schlüssel der Variablen und <code>msg.address</code> ihr Kanal (<code>var-<key>:1</code>).</p>
|
|
3
10
|
<h3>Inputs</h3>
|
|
4
11
|
<dl class="message-properties">
|
|
5
12
|
<dt>payload
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
<script type="text/html" data-help-name="ccu-poll">
|
|
2
2
|
<p>Triggers an immediate polling of Sysvars from ReGaHSS.</p>
|
|
3
|
+
<p><b>openccu-lite:</b> the <i>Logic</i> addon's variables and programs arrive as events; there is nothing to
|
|
4
|
+
poll, a message does nothing.</p>
|
|
3
5
|
<p>This node is intended to receive changes of variables with lower latency. You can create a CCU Program that
|
|
4
6
|
reacts to variable changes by pressing a virtual button, this virtual button presses can then be received by a
|
|
5
7
|
<i>value</i> or <i>rpc event</i> node that triggers an update of the variables through the <i>ccu poll</i>
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
<script type="text/html" data-help-name="ccu-program">
|
|
2
2
|
<p>Executes a ReGaHSS program.</p>
|
|
3
|
+
<p><b>openccu-lite:</b> the programs come from the <i>Logic</i> addon through the system's lite-rpc (interface
|
|
4
|
+
<code>Logic</code>). A boolean switches the program's <code>ACTIVE</code>; anything else starts it as on a CCU -
|
|
5
|
+
the first <i>Then</i> without looking at the conditions (<code>RUN_THEN</code>). The output follows
|
|
6
|
+
<code>ACTIVE</code> and every run of the program. Without the addon the node shows <i>Logic addon not
|
|
7
|
+
installed</i>.</p>
|
|
3
8
|
<h3>Inputs</h3>
|
|
4
9
|
<dl class="message-properties">
|
|
5
10
|
<dt>payload
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
<script type="text/html" data-help-name="ccu-sysvar">
|
|
2
2
|
<p>Set and read ReGaHSS system variables.</p>
|
|
3
|
+
<p><b>openccu-lite:</b> the system has no ReGaHSS; the system variables come from the <i>Logic</i> addon,
|
|
4
|
+
which offers them as devices of its interface <code>Logic</code> through the system's lite-rpc. The node finds a
|
|
5
|
+
variable by its name, as on a CCU, and gets an event at every write (<i>Emit changed values only</i> leaves out a write of
|
|
6
|
+
the same value). The connection needs lite-rpc (a token with <code>rpc:read</code> and <code>rpc:operate</code>,
|
|
7
|
+
or RedMatic on the system itself); without the addon the node shows <i>Logic addon not installed</i>.
|
|
8
|
+
<code>msg.iface</code> is <code>Logic</code>, <code>msg.key</code> the variable's key and
|
|
9
|
+
<code>msg.address</code> its channel (<code>var-<key>:1</code>).</p>
|
|
3
10
|
<h3>Inputs</h3>
|
|
4
11
|
<dl class="message-properties">
|
|
5
12
|
<dt>payload
|