From ccf9fbc60c71add734ee97ca46ae7ea39fa0a36e Mon Sep 17 00:00:00 2001 From: Jason Date: Sat, 30 Mar 2019 19:17:32 -0700 Subject: [PATCH] feat(events-all): Will includes HA client events Events all node will now receive HA client events: connecting, connected, disconnected, and error under event_type home_assistant_client Closes #75 --- nodes/events-all/events-all.html | 146 ++++++++++++++++++------------- nodes/events-all/events-all.js | 31 +++++++ 2 files changed, 116 insertions(+), 61 deletions(-) diff --git a/nodes/events-all/events-all.html b/nodes/events-all/events-all.html index f7519bf385..115afbb949 100644 --- a/nodes/events-all/events-all.html +++ b/nodes/events-all/events-all.html @@ -1,74 +1,98 @@ + }; + if (!NODE.server) { + utils.setDefaultServerSelection(); + } + } + }); + \ No newline at end of file +

Client Events

+

Possible Event Types

+ + Structure +
+
event_type string
+
home_assistant_client
+ +
topic string
+
home_assistant_client:{event_type}
+ +
payload string
+
connecting | connected | disconnected | error
+ +
data string
+
Will contain the error message if event type is type error
+
+ diff --git a/nodes/events-all/events-all.js b/nodes/events-all/events-all.js index e3f1c3ab6b..2242c93131 100644 --- a/nodes/events-all/events-all.js +++ b/nodes/events-all/events-all.js @@ -24,6 +24,37 @@ module.exports = function(RED) { }); this.setStatusSuccess(evt.event_type); } + + clientEvent(type, data) { + this.send({ + event_type: 'home_assistant_client', + topic: `home_assistant_client:${type}`, + payload: type, + data: data + }); + } + + onHaEventsClose() { + super.onHaEventsClose(); + this.clientEvent('disconnected'); + } + + onHaEventsOpen() { + super.onHaEventsOpen(); + this.clientEvent('connected'); + } + + onHaEventsConnecting() { + super.onHaEventsConnecting(); + this.clientEvent('connecting'); + } + + onHaEventsError(err) { + super.onHaEventsError(err); + if (err) { + this.clientEvent('error', err.message); + } + } } RED.nodes.registerType('server-events', ServerEventsNode);