rlindner / node-red-contrib-sma-webconnect

Node-RED node to query the web interface of SMA inverters
MIT License
13 stars 9 forks source link

Change the scope of the `message` var to local #34

Closed rlindner closed 1 year ago

rlindner commented 1 year ago

I did some investigation regarding https://github.com/rlindner/node-red-contrib-sma-webconnect/issues/22 and think I found the issue. What caught my interest is that all reporters on the issue were using at least two instances of this node in their flow and I thought there must be a problem with shared state.

The message var was defined "globally" in the scope of the exported function. And it appears that this function may only be called once from the runtime and then reused for all nodes. So I've just moved the message into the getValues function now, as there's no need for it to be defined outside of it.

rlindner commented 1 year ago

@HoLo85 Could you do a quick sanity check here?

HoLo85 commented 1 year ago

Hi, sry for the late response, I haven't logged in for a while.

Your fix looks good, since the message is only used in getValues() it did not make sense to define it globally, sry for that. A further improvement would be to declare message as let inside the method. Also I think deviceConfigs could be declared as const because its only set once on init. My plan was to be able to reload the configs, but I think for now it does not make sense.

As I currently don't always have access to my solar installation I can not test your update, but I will try it the next time I can access my setup.