From 67857b5bc3d05e1c5aa91f7bc86f24d5c34128bf Mon Sep 17 00:00:00 2001 From: Jason Date: Sat, 6 Apr 2019 16:53:08 -0700 Subject: [PATCH] fix(events-all): only send home_assistant_client events when needed --- nodes/events-all/events-all.js | 42 +++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/nodes/events-all/events-all.js b/nodes/events-all/events-all.js index e60679746b..6954eb853e 100644 --- a/nodes/events-all/events-all.js +++ b/nodes/events-all/events-all.js @@ -14,14 +14,19 @@ module.exports = function(RED) { event: 'ha_events:' + (this.nodeConfig.event_type || 'all'), handler: this.onHaEventsAll.bind(this) }); - this.addEventClientListener({ - event: 'ha_events:states_loaded', - handler: this.onClientStatesLoaded.bind(this) - }); - this.addEventClientListener({ - event: 'ha_events:services_loaded', - handler: this.onClientServicesLoaded.bind(this) - }); + if ( + !this.nodeConfig.event_type || + this.nodeConfig.event_type === 'home_assistant_client' + ) { + this.addEventClientListener({ + event: 'ha_events:states_loaded', + handler: this.onClientStatesLoaded.bind(this) + }); + this.addEventClientListener({ + event: 'ha_events:services_loaded', + handler: this.onClientServicesLoaded.bind(this) + }); + } } onHaEventsAll(evt) { @@ -34,15 +39,20 @@ module.exports = function(RED) { } clientEvent(type, data) { - this.send({ - event_type: 'home_assistant_client', - topic: `home_assistant_client:${type}`, - payload: type, - data: data - }); + if ( + !this.nodeConfig.event_type || + this.nodeConfig.event_type === 'home_assistant_client' + ) { + this.send({ + event_type: 'home_assistant_client', + topic: `home_assistant_client:${type}`, + payload: type, + data: data + }); - if (type === 'states_loaded' || type === 'services_loaded') { - this.setStatusSuccess(type); + if (type === 'states_loaded' || type === 'services_loaded') { + this.setStatusSuccess(type); + } } }