From 579e44fa2ad5dfd8675ba63c94ae672f5c18fb9e Mon Sep 17 00:00:00 2001 From: windkh Date: Thu, 19 Sep 2024 07:57:21 +0200 Subject: [PATCH] fixed #178 --- CHANGELOG.md | 3 +++ package.json | 2 +- shelly/99-shelly.js | 43 ++++++++++++++++++++++++++----------------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f348d96..0316500 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog All notable changes to this project will be documented in this file. +## [11.1.0] - 2024-09-19 +### fixed callback - [#178](https://github.com/windkh/node-red-contrib-shelly/issues/178) + ## [11.0.0] - 2024-09-16 ### updated dependencies - [#176](https://github.com/windkh/node-red-contrib-shelly/issues/176) diff --git a/package.json b/package.json index 902800d..17683d5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-contrib-shelly", - "version": "11.0.1", + "version": "11.1.0", "description": "Shelly nodes.", "node-red": { "version": ">=3.0.0", diff --git a/shelly/99-shelly.js b/shelly/99-shelly.js index 2835537..47671bf 100644 --- a/shelly/99-shelly.js +++ b/shelly/99-shelly.js @@ -498,7 +498,6 @@ module.exports = function (RED) { requiredNodeType = 'shelly gen-type is not supported'; } - if (requiredNodeType === node.type) { let found = false; for (let i = 0; i < types.length; i++) { @@ -1853,13 +1852,15 @@ module.exports = function (RED) { RED.nodes.createNode(this, config); let node = this; - this.port = config.port; + this.port = parseInt(config.port); this.hostname = config.hostname; this.hostip = config.hostip; - this.server = fastify(); - + this.server = fastify({ + logger: false // set to true when debugging. + }); + if (node.port > 0 && node.port <= 65535){ - node.server.listen({port : node.port}, (err, address) => { + node.server.listen({port : node.port, host: '::'}, (err, address) => { if (!err){ console.info("Shelly gen1 server is listening on port " + node.port); } @@ -2472,6 +2473,7 @@ module.exports = function (RED) { case 'Dimmer': case 'RGBW': result = initializer2CallbackAsync; + // result = initializer2BluCallbackAsync; // TODO: break; case 'BluGateway': result = initializer2BluCallbackAsync; @@ -2537,10 +2539,15 @@ module.exports = function (RED) { let statusValue = status[key]; if (statusValue !== undefined) { // we only copy the key that contain a : like input:0... + let newKey; if (key.indexOf(":") !== -1){ - let newKey = replace(key, ":", ""); + newKey = replace(key, ":", ""); result[newKey] = statusValue; } + else { + newKey = key; + } + result[newKey] = statusValue; } }); @@ -2636,21 +2643,14 @@ module.exports = function (RED) { RED.nodes.createNode(this, config); let node = this; - this.port = config.port; + this.port = parseInt(config.port); this.hostname = config.hostname; this.hostip = config.hostip; - this.server = fastify(); + this.server = fastify({ + logger: false // set to true when debugging. + }); if (node.port > 0 && node.port <= 65535){ - node.server.listen({port : node.port}, (err, address) => { - if (!err){ - console.info("Shelly gen2 server is listening on port " + node.port); - } - else{ - node.error("Shelly gen2 server failed to listen on port " + node.port); - } - }) - node.server.put("/callback", (request, reply) => { let data = { sender : request.body.sender, @@ -2671,6 +2671,15 @@ module.exports = function (RED) { reply.code(200); reply.send(); }); + + node.server.listen({port : node.port, host: '::'}, (err, address) => { + if (!err){ + console.info("Shelly gen2 server is listening on port " + node.port); + } + else{ + node.error("Shelly gen2 server failed to listen on port " + node.port); + } + }) } else { node.error("Shelly gen1 server failed to start: port number is not betwee 0 and 65535: " + node.port);