hjespers / node-red-contrib-nest

Node-Red module for Nest thermostats and smoke detectors
20 stars 15 forks source link

Streaming mode returns stringified data rather than JSON #6

Open hjespers opened 7 years ago

hjespers commented 7 years ago

streaming mode does not parse the data into JSON like the none-streaming mode. Need to fix this datapath to match non-streaming

rtenklooster commented 7 years ago

Hi, thanks for this great plugin. I'm facing the same problem with the stringified data in streaming mode. Node-red isn't able to turn the string into a valid json object, so i'm not able to use the data generated. Would be nice to see a fix for this bug.

Planning on a node-red nest -> mqtt publisher to make my nest thermostat platform independent.

Besides that; disabling streaming (setting false) still generates the null messages for me. So it appears to be an ignored setting.

hjespers commented 7 years ago

If I put a node-red json node inline right after the output of my nest node and it converts the stringified data back into JSON for me. I know it's nopt ideal and that streaming and non-streaming modes should produce consistent output formats but at least for now you should be able to use both.

hjespers commented 7 years ago

I see the problem. You can convert back to JSON but the data is now in msg.payload.data instead of msg.payload so you also need change all your downstream logic (or insert another node that copies into contents of msg.payload.data into msg.payload).

rtenklooster commented 7 years ago

Thanks, i gave it a try, appears to be working indeed thanks a lot :)

hjespers commented 7 years ago

Sorry that's it so cumbersome and difficult to switch between non-streaming and streaming. That is what this issue is a reminder for me to fix. Also, don't expect that streaming ever stops unless you kill and restart node-red. Once a streaming subscription is made it is not ever destroyed, even if you switch back to non-streaming in the nest node.

PaulWieland commented 6 years ago

Is there a reason to use streaming mode at all rather than an inject node on an interval?

hjespers commented 6 years ago

An inject node on an interval will poll for data every interval even if it has not changed. Streaming mode will only send data when there is a change in one of the fields so it's lower latency and less unnecessary polling. Use whichever mode you feel fits your use case, that's why they are both there.