windkh / node-red-contrib-shelly

Shelly control nodes for node red.
MIT License
34 stars 21 forks source link

GEN 2 | Callback Mode | If Shelly is password protected install script fails #132

Closed teixemf closed 1 year ago

teixemf commented 1 year ago

If a Shelly is password protected, while activating the Callback Mode, installing the script fails while calling "/rpc/Script.GetStatus" The debugger returns the message: "Uploading script failed Unauthorized /rpc/Script.GetStatus"

https://github.com/windkh/node-red-contrib-shelly/blob/ad512d0ed326d6d73b0b6d7f1a7c341fd1af685b/shelly/99-shelly.js#L1880

If uninstalling the script, it also fails calling the same route "/rpc/Script.GetStatus" The node lights up red with the message: Uninstalling script failed image

I believe the root cause of the issue is related to the function shellyRequestAsync() and the way it deals with a GET with the credentials variable set and the params variable different then NULL I believe it because the function that gets the Scripts List calls a GET with credentials set but with the params variable set to NULL

https://github.com/windkh/node-red-contrib-shelly/blob/1ddedcbe9a004881532adb49839b8fec6065007a/shelly/99-shelly.js#L1836

and doesn't return error.

Meanwhile, while uninstalling the script, the GET call to /rpc/Script.Delete also returns error.

https://github.com/windkh/node-red-contrib-shelly/blob/1ddedcbe9a004881532adb49839b8fec6065007a/shelly/99-shelly.js#L1933

During the my tests I also found the POST call to /rpc/Script.Delete in the uninstall script function, has the parameters "params" and "data" missplaced.

windkh commented 1 year ago

Thanks for reporting, will check it out if I am back.

About the params and data: recently the api was changed when updating from fw 0.x to 1.x In former versions params were expected and from 1.x on POST calls required the values in the body. I already complained at the shelly support.

teixemf commented 1 year ago

await shellyRequestAsync('GET', '/rpc/Script.Delete', params, null, credentials); returns fine if your Shelly has is not password protect. but it returns error if you have the password set.

await shellyRequestAsync('GET', '/rpc/Script.List', null, null, credentials); always returns fine whether you have a password set or not.

That's why I believe it appears to be an issue with shellyRequestAsync() when using GET + params != null + shelly with password enabled. While I couldn't understand why these combination makes shellyRequestAsync() I wrote a workaround for the issue using POST to call Script.GetStatus nas Script.Delete

@windkh I can make a pull request you want.

windkh commented 1 year ago

The shelly support said that the developers will update the documentation... I am a bit confused what they did.

Yes please make a pull request so that I can see what you tested so far. I will also do some tests as soon as I find some time ...