@thingwala/node-red-contrib-geyserwala-connect 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Change Log - Geyserwala Connect - Node-RED Plugin
2
2
 
3
+ ## [0.0.8] - 2025-02-23
4
+
5
+ Fix multiple API Connector handling
6
+
3
7
  ## [0.0.7] - 2024-01-08
4
8
 
5
9
  Improved error handling
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thingwala/node-red-contrib-geyserwala-connect",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "Node-RED nodes for the Geyserwala Connect",
5
5
  "author": "Thingwala",
6
6
  "license": "MIT",
@@ -8,13 +8,14 @@ class GeyserwalaConnectorMqtt {
8
8
  this.nodes = []
9
9
  this.subscriptions = {}
10
10
 
11
- if (this.broker && !this.broker.client) {
12
- this.broker.connect(() => {
13
- this.setupBrokerEvents()
14
- })
15
- } else {
16
- this.setupBrokerEvents();
17
- }
11
+ this.broker._clientAwaiter.push(
12
+ (client) => {
13
+ client.on('connect', () => {
14
+ this.updateSubscriptions()
15
+ this.setupBrokerEvents()
16
+ });
17
+ }
18
+ );
18
19
  }
19
20
  setupBrokerEvents() {
20
21
  if (!this.broker || !this.broker.client) {
@@ -66,7 +67,6 @@ class GeyserwalaConnectorMqtt {
66
67
 
67
68
  this.broker.client.on("error", (error) => {
68
69
  this.status({ fill: "red", shape: "ring", text: "error" });
69
- this.RED.log.error(`{Geyserwala Connect} MQTT error: ${error}`);
70
70
  });
71
71
  }
72
72
  subTopic(key) {
@@ -87,17 +87,18 @@ class GeyserwalaConnectorMqtt {
87
87
  }
88
88
  hookNode(node) {
89
89
  this.nodes.push(node)
90
- this.updateSubscriptions()
90
+ this.broker.register(node)
91
91
  }
92
92
  unhookAllNodes() {
93
93
  for (const node in this.nodes) {
94
- node.status({ fill: "grey", shape: "ring", text: "disconnected" });
95
- this.nodes = []
96
- for(const topic in this.subscriptions) {
97
- this.unsubscribe(topic)
98
- }
99
- this.subscriptions = {}
94
+ this.broker.deregister(node, ()=>{})
95
+ this.status({ fill: "grey", shape: "ring", text: "disconnected" });
100
96
  }
97
+ for(const topic in this.subscriptions) {
98
+ this.unsubscribeTopic(topic)
99
+ }
100
+ this.subscriptions = {}
101
+ this.nodes = []
101
102
  }
102
103
  updateSubscriptions() {
103
104
  this.subscriptions = {}
@@ -1,4 +1,3 @@
1
-
2
1
  module.exports = function (RED) {
3
2
  class GeyserwalaConnectApi {
4
3
  constructor (config) {
@@ -7,8 +6,24 @@ module.exports = function (RED) {
7
6
  if (config.api == "MQTT") {
8
7
  const GeyserwalaConnectorMqtt = require('./geyserwala-api-mqtt');
9
8
 
9
+ let mqttBroker = RED.nodes.getNode(config.mqttBroker)
10
+
11
+ if (mqttBroker._clientAwaiter === undefined) {
12
+ mqttBroker._clientAwaiter = []
13
+ let _client;
14
+ Object.defineProperty(mqttBroker, 'client', {
15
+ get: function () { return _client; },
16
+ set: function (val) {
17
+ _client = val;
18
+ mqttBroker._clientAwaiter.forEach(awaiter => {
19
+ awaiter(val)
20
+ });
21
+ }
22
+ });
23
+ }
24
+
10
25
  this.api = new GeyserwalaConnectorMqtt(RED,
11
- RED.nodes.getNode(config.mqttBroker),
26
+ mqttBroker,
12
27
  config.mqttPubQos,
13
28
  config.mqttRetain,
14
29
  config.mqttTopicTemplate,
@@ -12,6 +12,8 @@ module.exports = function (RED) {
12
12
  "String": String,
13
13
  }[config.valueType]
14
14
 
15
+ this.status({fill:"grey", shape:"ring", text:"initialising ..."});
16
+
15
17
  var geyserwalaApi = RED.nodes.getNode(config.geyserwalaApi)
16
18
  if (!geyserwalaApi) {
17
19
  setTimeout(()=>{