SondreNjaastad / node-red-contrib-bluelinky

19 stars 8 forks source link

Bluelinky nodes seem to create new message objects, discarding metadata #89

Closed olithissen closed 5 months ago

olithissen commented 5 months ago

First of all: Thank you for bridging Bluelinky to Node-RED!

Problem

Bluelinky nodes seem to create new messages on output instead of extending the original input data.

I just noticed this when I tried to forward output to PostgreSQL: My input-message provides an msg.topic property with the name of the used endpoint (like DriveHistory). The output message of DriveHistory only contains the payload object and a new _msgid. So I have no way to pass additional information through the node.

Possible fix

A fix might be quite easy: Not sending an anonymous object in node.send() but by manipulating and sending the original msg instead. (This would need to be done for all nodes and goes for the error responses as well)

        // before
        // ...
        node.send({
          payload: result,
        });
        // ...

        // after
        // ...
        msg.payload = result;
        node.send(msg);
        // ...

Let me know what you think!

All the best! Oli

Hacksore commented 5 months ago

Seems reasonable @olithissen, care to make a PR and I'll take a look?

olithissen commented 5 months ago

NodeJS is not my day to day ecosystem but I'll see what I can do 👍

olithissen commented 5 months ago

As mentioned above, this is not my day to day ecosystem and I failed at step one.

I went the straight forward way, installed Node-RED locally and installed the cloned repo via npm install ~/dev/node-red-contrib-bluelinky. All the nodes are available but after configuring and deploying in Node-RED I just get a BlueLinky is not a constructor error. This is even before I do any code changes.

Decades of Java did not prepare me for this. Any hints?

Hacksore commented 5 months ago

Hmm I thought it was fixed in https://github.com/SondreNjaastad/node-red-contrib-bluelinky/pull/87

Can you make sure you have the latest node red addon installed?

image
olithissen commented 5 months ago

I think I'm missing something: Installing via Node-RED palette works as well as npm install node-red-contrib-bluelinky from within my Node-RED directory. However doing the same with the locally cloned repo npm install ~/dev/node-red-contrib-bluelinky installs only node-red-contrib-bluelinky but none of the ~135 required dependencies.

The process for testing it seemed wrong: I installed the packaged npm dependency, changed the code in there and copied the changes back to my cloned repo. This seems totally off.

It looks like Node-RED expects the dependencies in .node-red/node_modules/ and not in .node-red/node-red-contrib-bluelinky/node_modules/

Hacksore commented 5 months ago

@olithissen my knowledge of node-red is limited so if you figure it out please do share more.