Skip to content

Commit

Permalink
fix(sensor): Fix reading attributes object when received in message o…
Browse files Browse the repository at this point in the history
…bject
  • Loading branch information
zachowj committed Dec 11, 2019
1 parent 695623b commit 18849d9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion nodes/entity/entity.html
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
<p>This nodes requires <a href="https://github.com/zachowj/hass-node-red" target="_blank">Node-RED custom integration <i class="fa fa-external-link external-link"></i></a> to be installed in Home Assistant
</p>

<h3>Inputs</h3>
<h3>Inputs (properties of <code>msg.payload</code>)</h3>
<dl class="message-properties">
<dt>state<span class="property-type">string | number | boolean</span></dt>
<dd>The state the entity should be updated to</dd>
Expand Down
17 changes: 16 additions & 1 deletion nodes/entity/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,23 @@ module.exports = function(RED) {
return;
}

let attributes = [];
if (parsedMessage.attributes.source === 'message') {
for (const [prop, val] of Object.entries(
parsedMessage.attributes.value
)) {
attributes.push({
property: prop,
value: val,
valueType: 'str'
});
}
} else {
attributes = parsedMessage.attributes.value;
}

// Change string to lower-case and remove unwanted characters
parsedMessage.attributes.value.forEach(x => {
attributes.forEach(x => {
const property = slugify(x.property, {
replacement: '_',
remove: /[^A-Za-z0-9-_~ ]/,
Expand Down

0 comments on commit 18849d9

Please sign in to comment.