From 8a2d87c3022130d569424a8b81f93467b960cb32 Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 20 Sep 2018 02:44:42 -0700 Subject: [PATCH] Added ability to filter event type within the 'events: all' node --- nodes/events-all/events-all.html | 42 ++++++++++++++++++++++---------- nodes/events-all/events-all.js | 15 +++++++++--- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/nodes/events-all/events-all.html b/nodes/events-all/events-all.html index 9605bbc765..702dc12388 100644 --- a/nodes/events-all/events-all.html +++ b/nodes/events-all/events-all.html @@ -1,16 +1,17 @@ diff --git a/nodes/events-all/events-all.js b/nodes/events-all/events-all.js index 424c467802..969519a981 100644 --- a/nodes/events-all/events-all.js +++ b/nodes/events-all/events-all.js @@ -1,15 +1,24 @@ const EventsNode = require('../../lib/events-node'); module.exports = function(RED) { + const nodeOptions = { + config: { + event_type: {} + } + }; + class ServerEventsNode extends EventsNode { constructor(nodeDefinition) { - super(nodeDefinition, RED); - this.addEventClientListener({ event: 'ha_events:all', handler: this.onHaEventsAll.bind(this) }); + super(nodeDefinition, RED, nodeOptions); + this.addEventClientListener({ + event: 'ha_events:' + (this.nodeConfig.event_type || 'all'), + handler: this.onHaEventsAll.bind(this) } + ); } onHaEventsAll(evt) { this.send({ event_type: evt.event_type, topic: evt.event_type, payload: evt }); - this.status({fill: 'green', shape: 'dot', text: `${evt.event_type}`}); + this.status({ fill: 'green', shape: 'dot', text: `${evt.event_type} at: ${this.getPrettyDate()}` }); } }