Skip to content

Commit

Permalink
fixed #178
Browse files Browse the repository at this point in the history
  • Loading branch information
windkh committed Sep 19, 2024
1 parent 09b9861 commit 579e44f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
43 changes: 26 additions & 17 deletions shelly/99-shelly.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -2472,6 +2473,7 @@ module.exports = function (RED) {
case 'Dimmer':
case 'RGBW':
result = initializer2CallbackAsync;
// result = initializer2BluCallbackAsync; // TODO:
break;
case 'BluGateway':
result = initializer2BluCallbackAsync;
Expand Down Expand Up @@ -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;
}
});

Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down

0 comments on commit 579e44f

Please sign in to comment.