Skip to content

Commit

Permalink
fix(events-all): only send home_assistant_client events when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
zachowj committed Apr 6, 2019
1 parent fd9d4a1 commit 67857b5
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions nodes/events-all/events-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
}
}

Expand Down

0 comments on commit 67857b5

Please sign in to comment.