diff --git a/CHANGELOG.md b/CHANGELOG.md index 8118b23..bb874a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ -# V0.3.1 +# v0.3.2 +* Feat: History node now supports end date and entityid filtering +* Fix: Nodered configuration value userDir is fetched correctly now +# v0.3.1 * Fix/Feat: Current State Node: Preserve original message with options to override topic and payload (Thanks @declankenny) * Fix: Added try/catch in onHaEventsStateChanged (Thanks @oskargronqvist) * Docs: Added quotes to 'Call Service' placeholder text (Thanks @brubaked) diff --git a/docker/home-assistant/root-fs/config/configuration.yaml b/docker/home-assistant/root-fs/config/configuration.yaml index c4f9951..3799c3c 100644 --- a/docker/home-assistant/root-fs/config/configuration.yaml +++ b/docker/home-assistant/root-fs/config/configuration.yaml @@ -14,25 +14,18 @@ logger: default: !env_var HA_LOGGER_DEFAULT recorder: - purge_interval: 2 - purge_keep_days: 1 - +logbook: frontend: config: history: map: sun: -weblink: - entities: - - name: Node Red - url: !env_var NODE_RED_URL - panel_iframe: node_red: title: Node Red url: !env_var NODE_RED_URL - icon: mdi:grid-on + icon: mdi:sitemap alarm_control_panel: diff --git a/lib/base-node.js b/lib/base-node.js index cfc84cb..4c94b80 100644 --- a/lib/base-node.js +++ b/lib/base-node.js @@ -69,7 +69,7 @@ class BaseNode { try { if (DB) return DB; - let dbLocation = this.RED.settings.get('userDir'); + let dbLocation = this.RED.settings.userDir; if (!dbLocation) throw new Error('Could not find userDir to use for database store'); dbLocation += '/node-red-contrib-home-assistant.json'; diff --git a/nodes/api_get-history/api_get-history.html b/nodes/api_get-history/api_get-history.html index 8364b2a..d83d9d0 100644 --- a/nodes/api_get-history/api_get-history.html +++ b/nodes/api_get-history/api_get-history.html @@ -3,9 +3,12 @@ category: 'home_assistant', color: '#52C0F2', defaults: { - name: { value: '' }, + name: { value: '' }, server: { value: '', type: 'server', required: true }, - startdate: { value: '' } + startdate: { value: '' }, + enddate: { value: '' }, + entityid: { value: '' }, + entityidtype: { value: '' } }, inputs: 1, outputs: 1, @@ -22,6 +25,9 @@ oneditprepare: function() { const NODE = this; const $server = $('#node-input-server'); + NODE.entityidtype = NODE.entityidtype || 'is'; + $('#node-input-entityidtype').val(NODE.entityidtype); + const utils = { setDefaultServerSelection: function () { let defaultServer; @@ -40,7 +46,7 @@ - - diff --git a/nodes/api_get-history/api_get-history.js b/nodes/api_get-history/api_get-history.js index 5668cc8..4b87899 100644 --- a/nodes/api_get-history/api_get-history.js +++ b/nodes/api_get-history/api_get-history.js @@ -5,20 +5,36 @@ module.exports = function(RED) { const nodeOptions = { debug: true, config: { - startdate: {}, - name: {}, - server: { isNode: true } + name: {}, + server: { isNode: true }, + startdate: {}, + enddate: {}, + entityid: {}, + entityidtype: {} }, input: { startdate: { messageProp: 'startdate', - configProp: 'startdate', + configProp: 'startdate', default: () => { const yesterday = new Date(); yesterday.setDate(yesterday.getDate() - 1); return yesterday.toISOString(); }, validation: { haltOnFail: true, schema: Joi.date().optional().allow('') } + }, + enddate: { + messageProp: 'enddate', + configProp: 'enddate', + validation: { haltOnFail: true, schema: Joi.date().optional().allow('') } + }, + entityid: { + messageProp: 'entityid', + configProp: 'entityid' + }, + entityidtype: { + messageProp: 'entityidtype', + configProp: 'entityidtype' } } }; @@ -29,13 +45,21 @@ module.exports = function(RED) { } onInput({ parsedMessage, message }) { - let { startdate } = parsedMessage; - startdate = startdate.value; + let { startdate, enddate, entityid, entityidtype } = parsedMessage; + startdate = startdate.value; + enddate = enddate.value; + entityid = entityid.value; + + let apiRequest = (entityidtype.value === 'includes' && entityid) + ? this.nodeConfig.server.api.getHistory(startdate, null, enddate, { include: new RegExp(entityid) }) + : this.nodeConfig.server.api.getHistory(startdate, entityid, enddate); - return this.nodeConfig.server.api.getHistory(startdate) + return apiRequest .then(res => { message.startdate = startdate; - message.payload = res; + message.enddate = enddate || null; + message.entityid = entityid || null; + message.payload = res; this.send(message); }) .catch(err => { diff --git a/package.json b/package.json index ffb76db..f345055 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "node-red-contrib-home-assistant", "description": "node-red nodes to visually construct home automation with home assistant", - "version": "0.3.1", + "version": "0.3.2", "homepage": "https://github.com/AYapejian/node-red-contrib-home-assistant", "bugs": { "url": "https://github.com/AYapejian/node-red-contrib-home-assistant/issues"