Skip to content

Commit

Permalink
feat(get-history): Add flatten option
Browse files Browse the repository at this point in the history
Instead of returning the data from home assistant ( array for each
entity_id ) return one flattened array of one item per history entry
  • Loading branch information
zachowj committed Mar 8, 2019
1 parent 44f75c0 commit b46a4d5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
22 changes: 17 additions & 5 deletions nodes/get-history/get-history.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
entityidtype: { value: "" },
useRelativeTime: { value: false },
relativeTime: { value: "" },
flatten: { value: true },
output_type: { value: "array" },
output_location_type: { value: "msg" },
output_location: { value: "payload" }
Expand Down Expand Up @@ -125,7 +126,9 @@
.trigger("change");
},
oneditsave: function() {
this.entityid = $("#entity_id").val();
this.entityid = $("#entity_id")
.val()
.trim();
}
});
</script>
Expand Down Expand Up @@ -154,7 +157,7 @@
</div>

<div class="form-row">
<input type="checkbox" id="node-input-useRelativeTime" checked style="display: inline-block; width: auto; vertical-align: top;margin-left: 105px;">&nbsp;
<input type="checkbox" id="node-input-useRelativeTime" style="display: inline-block; width: auto; vertical-align: top;margin-left: 105px;">&nbsp;
<label for="node-input-useRelativeTime" style="width: auto;">Use Relative Time</label>
</div>

Expand Down Expand Up @@ -194,6 +197,11 @@
</ol>
</div>

<div class="form-row">
<input type="checkbox" id="node-input-flatten" style="display: inline-block; width: auto; vertical-align: top;margin-left: 105px;">&nbsp;
<label for="node-input-flatten" style="width: auto;">Flatten Results</label>
</div>

<div class="form-row">
<label for="node-input-output_type">Output Type</label>
<select id="node-input-output_type">
Expand All @@ -214,7 +222,10 @@

<h3>Inputs</h3>
<dl class="message-properties">
<dt class="optional">startdate <span class="property-type">string | date</span></dt>
<dt class="optional">entityid <span class="property-type">string</span></dt>
<dd>Exact entity_id to fetch history for, must be an exact match as is passed directly to the home-assistant api</dd>

<dt class="optional">startdate <span class="property-type">string | date</span></dt>
<dd>Date to start fetching history from. Will override the nodes configuration if passed in</dd>

<dt class="optional">enddate <span class="property-type">string | date</span></dt>
Expand All @@ -223,8 +234,9 @@ <h3>Inputs</h3>
<dt class="optional">relativetime <span class="property-type">string</span></dt>
<dd>A timestring to be parsed into datetime string</dd>

<dt class="optional">entityid <span class="property-type">string</span></dt>
<dd>Exact entity_id to fetch history for, must be an exact match as is passed directly to the home-assistant api</dd>
<dt>Flatten</dt>
<dd>Instead of returning the data from home assistant ( array for each entity_id ) return one flattened array of one item per history entry</dd>

</dl>

<h3>Outputs</h3>
Expand Down
15 changes: 13 additions & 2 deletions nodes/get-history/get-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = function(RED) {
entityidtype: {},
useRelativeTime: {},
relativeTime: {},
flatten: {},
output_type: {},
output_location_type: {},
output_location: {}
Expand Down Expand Up @@ -53,6 +54,10 @@ module.exports = function(RED) {
relativeTime: {
messageProp: 'relativetime',
configProp: 'relativeTime'
},
flatten: {
messageProp: 'flatten',
configProp: 'flatten'
}
}
};
Expand All @@ -68,12 +73,14 @@ module.exports = function(RED) {
enddate,
entityid,
entityidtype,
relativeTime
relativeTime,
flatten
} = parsedMessage;
startdate = startdate.value;
enddate = enddate.value;
entityid = entityid.value;
relativeTime = relativeTime.value;
flatten = flatten.value;
let useRelativeTime = this.nodeConfig.useRelativeTime;

if (this.nodeConfig.server === null) {
Expand All @@ -97,13 +104,17 @@ module.exports = function(RED) {
null,
enddate,
{
flatten: flatten,
include: new RegExp(entityid)
}
)
: this.nodeConfig.server.http.getHistory(
startdate,
entityid,
enddate
enddate,
{
flatten: flatten
}
);

this.setStatusSending('Requesting');
Expand Down

0 comments on commit b46a4d5

Please sign in to comment.