hm2mqtt 3.0.0 → 3.1.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/README.md +5 -4
- package/config.js +8 -1
- package/index.js +27 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -66,7 +66,7 @@ so the CCU can call back. `--restart unless-stopped` brings it back after `maint
|
|
|
66
66
|
| `-m, --name-file` | — | JSON `{address: name}` overriding ReGa names ([example-names.json](example-names.json)) |
|
|
67
67
|
| `--item-template`, `--sysvar-item-template`, `--program-item-template` | `${channelName\|channel}/${datapoint}`, `${name}` | how items (topic parts) are built, see [Item templates](#item-templates) |
|
|
68
68
|
| `--rega-names-interval` | 3600 | seconds between re-reads of names/rooms/functions (0 = only at start and on `set/rega/sync`) |
|
|
69
|
-
| `--
|
|
69
|
+
| `--payload` | `mqsh-extended` | status payload format: `mqsh-extended`, `mqsh-basic` or `plain` ([Payloads](#payloads)) |
|
|
70
70
|
| `--plain-tree <level>` | — | additionally publish plain payloads under `<name>/<level>/…` (the second `ccu-mqtt` node of the Node-RED flow) |
|
|
71
71
|
| `--publish-cache` | off | publish every datapoint value known to the ReGa at start (thousands of retained messages) |
|
|
72
72
|
| `--publish-counters`, `--duty-cycle-interval` | on, 90 | rpc rx/tx counters and `listBidcosInterfaces` duty cycle polling (0 = off) |
|
|
@@ -165,9 +165,10 @@ meta data block of node-red-contrib-ccu's messages, field for field:
|
|
|
165
165
|
`ENUM` datapoints carry `datapointEnum` (the value list) and `valueEnum` (the name of the current
|
|
166
166
|
value). Variables have `type: "SYSVAR"` with `valueType`, `unit`, `enum`, `valueEnum`, `id` and —
|
|
167
167
|
when bound to a channel — the channel fields; programs `type: "PROGRAM"` with `active`,
|
|
168
|
-
`activePrevious`, `ts` (last execution). `--
|
|
169
|
-
|
|
170
|
-
|
|
168
|
+
`activePrevious`, `ts` (last execution). `--payload` selects the format the way the `ccu-mqtt` node did:
|
|
169
|
+
`mqsh-extended` (default, as above), `mqsh-basic` (`{val, ts, lc}`) or `plain` (the bare value,
|
|
170
|
+
booleans as `0`/`1`). `--plain-tree state` additionally mirrors every item to `<name>/state/…` in
|
|
171
|
+
the plain format (the second `ccu-mqtt` node of a flow).
|
|
171
172
|
|
|
172
173
|
## Names
|
|
173
174
|
|
package/config.js
CHANGED
|
@@ -76,7 +76,14 @@ export const OPTIONS = {
|
|
|
76
76
|
default: DEFAULT_SYSVAR_ITEM_TEMPLATE,
|
|
77
77
|
},
|
|
78
78
|
'program-item-template': {type: 'string', describe: 'item of a program', default: DEFAULT_PROGRAM_ITEM_TEMPLATE},
|
|
79
|
-
|
|
79
|
+
payload: {
|
|
80
|
+
type: 'string',
|
|
81
|
+
describe:
|
|
82
|
+
'status payload format: mqsh-extended ({val, ts, lc, hm}), mqsh-basic ({val, ts, lc}) or plain (value only, booleans as 0/1)',
|
|
83
|
+
choices: ['plain', 'mqsh-basic', 'mqsh-extended'],
|
|
84
|
+
default: 'mqsh-extended',
|
|
85
|
+
},
|
|
86
|
+
'hm-payload': {type: 'boolean', describe: 'deprecated: --no-hm-payload = --payload mqsh-basic', hidden: true},
|
|
80
87
|
'plain-tree': {
|
|
81
88
|
type: 'string',
|
|
82
89
|
describe: 'additionally publish plain payloads under <name>/<level>/... (e.g. "state")',
|
package/index.js
CHANGED
|
@@ -77,11 +77,32 @@ if (config.nameFile) {
|
|
|
77
77
|
nameFile = JSON.parse(fs.readFileSync(path.resolve(config.nameFile), 'utf8'));
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
/*
|
|
81
|
+
* payload format (node-red-contrib-ccu's mqsh-extended / mqsh-basic / plain)
|
|
82
|
+
*/
|
|
83
|
+
let payloadFormat = config.payload;
|
|
84
|
+
if (config.hmPayload === false && payloadFormat === 'mqsh-extended') {
|
|
85
|
+
payloadFormat = 'mqsh-basic';
|
|
86
|
+
}
|
|
87
|
+
if (!config.jsonPayloads) {
|
|
88
|
+
payloadFormat = 'plain';
|
|
89
|
+
}
|
|
90
|
+
config.jsonPayloads = payloadFormat !== 'plain';
|
|
91
|
+
const withHm = payloadFormat === 'mqsh-extended';
|
|
92
|
+
/** the value as published: plain format uses node-red's 0/1 for booleans */
|
|
93
|
+
const outValue = (value) => (payloadFormat === 'plain' ? plainValue(value) : value);
|
|
94
|
+
|
|
80
95
|
const adapter = createAdapter({
|
|
81
96
|
pkg,
|
|
82
97
|
config,
|
|
83
98
|
deviceLabel: 'ccu',
|
|
84
|
-
info: () => ({
|
|
99
|
+
info: () => ({
|
|
100
|
+
ccu: host,
|
|
101
|
+
interfaces: enabled,
|
|
102
|
+
devices: metadata.count(),
|
|
103
|
+
rega: Boolean(regaSync),
|
|
104
|
+
payload: payloadFormat,
|
|
105
|
+
}),
|
|
85
106
|
onSet: handleSet,
|
|
86
107
|
subscriptions: {
|
|
87
108
|
'paramset/#': handleParamset,
|
|
@@ -212,8 +233,8 @@ function publishPlain(item, value, retain) {
|
|
|
212
233
|
|
|
213
234
|
function publishMessage(message, {retain = true} = {}) {
|
|
214
235
|
const item = rendered(renderItem, message, message.datapointName);
|
|
215
|
-
const extra =
|
|
216
|
-
pubStatus(item, message.value, {retain, extra, ts: message.ts, lc: message.lc});
|
|
236
|
+
const extra = withHm ? {hm: hmBlock(message)} : undefined;
|
|
237
|
+
pubStatus(item, outValue(message.value), {retain, extra, ts: message.ts, lc: message.lc});
|
|
217
238
|
publishPlain(item, message.value, retain);
|
|
218
239
|
}
|
|
219
240
|
|
|
@@ -221,13 +242,13 @@ function publishRega(message) {
|
|
|
221
242
|
const render = message.type === 'PROGRAM' ? renderProgramItem : renderSysvarItem;
|
|
222
243
|
const item = rendered(render, message, `${message.type} ${message.name}`);
|
|
223
244
|
itemIndex.add(item, {kind: message.type === 'PROGRAM' ? 'program' : 'sysvar', name: message.name});
|
|
224
|
-
const extra =
|
|
225
|
-
pubStatus(item, message.value, {retain: true, extra, ts: message.ts, lc: message.lc});
|
|
245
|
+
const extra = withHm ? {hm: hmBlock(message)} : undefined;
|
|
246
|
+
pubStatus(item, outValue(message.value), {retain: true, extra, ts: message.ts, lc: message.lc});
|
|
226
247
|
publishPlain(item, message.value, true);
|
|
227
248
|
}
|
|
228
249
|
|
|
229
250
|
function publishItem(item, value, {retain = true} = {}) {
|
|
230
|
-
pubStatus(item, value, {retain});
|
|
251
|
+
pubStatus(item, outValue(value), {retain});
|
|
231
252
|
publishPlain(item, value, retain);
|
|
232
253
|
}
|
|
233
254
|
|