Skip to content

Commit

Permalink
feat(virtual-device): Add ability to define custom metadata to be inc…
Browse files Browse the repository at this point in the history
…luded in outgoing msg payload
  • Loading branch information
csuermann committed Jan 20, 2024
1 parent 37d0d00 commit 8099d2b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions virtual-device.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
function vshOnEditPrepare() {
$('#node-input-deviceId').val('vshd-' + this.id.replace('.', ''))

$('#node-input-metadata').typedInput({
type: 'json',
types: ['json'],
})

const vshConnectionNodeId = $('#node-input-connection')[0].value

if (vshConnectionNodeId === '_ADD_') {
Expand Down Expand Up @@ -33,6 +38,7 @@
name: { value: '', required: true },
//deviceId: { value: 'vshd-xxx', required: false },
topic: { value: '', required: false },
metadata: { value: {}, required: false },
connection: { type: 'vsh-connection', required: true },
template: { value: 'SWITCH', required: true },
retrievable: { value: false },
Expand Down Expand Up @@ -121,6 +127,15 @@
<input type="text" id="node-input-topic" placeholder="Topic" />
</div>

<div class="form-row">
<label for="node-input-metadata"><i class="fa fa-code"></i> Metadata</label>
<input
type="text"
id="node-input-metadata"
placeholder="arbitrary optional metadata"
/>
</div>

<div class="form-row">
<label for="node-input-deviceId"
><i class="fa fa-hashtag"></i> Device ID</label
Expand Down Expand Up @@ -296,6 +311,13 @@ <h3>Outputs</h3>
</dt>
<dd>topic string as configured in the virtual device node</dd>
</dl>
<dl class="message-properties">
<dt>
metadata
<span class="property-type">object</span>
</dt>
<dd>metadata as configured in the virtual device node</dd>
</dl>
<dl class="message-properties">
<dt>
payload
Expand Down
1 change: 1 addition & 0 deletions virtual-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module.exports = function (RED) {
if (Object.keys(payload).length > 0) {
const msg = {
topic: topic ? topic : config.topic,
metadata: config.metadata,
payload,
}

Expand Down

0 comments on commit 8099d2b

Please sign in to comment.