mysensors / NodeManager

Plugin for a rapid development of battery-powered sensors
130 stars 82 forks source link

[Question about a PR] HomeAssistant controller compatibilty #532

Open nekromant opened 3 years ago

nekromant commented 3 years ago

Hello and thanks for the awesome project. I've been hacking NodeManager to run nicely with HomeAssistant, but ran into a few problems that required altering the some of the core API and concepts of the NodeManager. So far I've fixed SensorDimmer and SensorNeopixel to play nicely with hass. Before opening a pull request I wanted to ask if these changes are okay, and what branch I should file them against. Here's the stuff I've put together so far:

To implement this I added a

Child* Sensor::getChild(uint8_t child_id, uint8_t ctype);

method to Sensor.cpp and made some changes so that it is called in a few parts of NodeManager to make use of the new variant of call. This allowed a sensor to have children with same IDs.

Other minor fixes:

Well, that's all.

castorinop commented 3 years ago

@nekromant Can you submit a PR ?

nekromant commented 3 years ago

@castorinop Against development or master branch? Let me know. Will rebase and submit ASAP.

castorinop commented 3 years ago

@nekromant i have same issues with home assistant.

nekromant commented 3 years ago

@castorinop I've put up my fork over to github here: https://github.com/nekromant/NodeManager

Please note, it's all still work in progress: I haven't finalized SensorDimmer that needs async handling of fading (or it will crash the node), haven't yet ported my SensorChild and my Node UpLink quality checker and would really love to hear back from NodeManager maintainers if they're interested in accepting these changes.

castorinop commented 3 years ago

@nekromant thanks! should be use simpleTimer for async events

castorinop commented 3 years ago

also a queue implementation https://gist.github.com/castorinop/90f1909376bf1adca896ac425e168f2a

nekromant commented 3 years ago

also a queue implementation https://gist.github.com/castorinop/90f1909376bf1adca896ac425e168f2a

I don't think it's worth queuing packets, since the nodes have VERY little ram. Timers for Dimmer are on my TODO, but I haven't finished it yet.

user2684 commented 3 years ago

@nekromant thanks for bring this up. I was aware HA requires a specific behaviour in order to work correctly and this could be a good excuse to make NodeManager fully compatible with it, finally. I remember last time I get into the code for something similar to this, having the same child_id responding with multiple types was kind of a challenge and breaking other things here and there but let's dig into it more seriously now.

The only constraint I'd like to put in place for whoever is willing to contribute on this, is to ensure the original behaviour of NodeManager is not changed so to avoid messing up with existing users but instead make everything optional wherever possible. If this would bring an impact on the code size, we can make it as a feature which can be enabled/disabled like other already available in NodeManager.

But first we need something working, I agree. A PR against the development branch is the way to go. Thanks!

nekromant commented 3 years ago

@user2684 Thanks a lot for the answer, I'll submit the first PR against the core in a few days. I don't have too much time, so I'll send in code in small batches. The nasty stuff about current HomeAssistant implementation is that actual sensors' code in NM need changes, but I'll think how to implement it as compatible as possible.

Submitted in #533 (core)

WIP (core)

Planned

nekromant commented 3 years ago

Here goes the first one. I have updated the TODO and will edit later the comment once more stuff is ready.