-
Notifications
You must be signed in to change notification settings - Fork 639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix HA sensor discovery with MQTT #1957
Conversation
As already mentioned in gitter, we should probably just re-use some key as the root instead of using the global one. Note that directly removing keys is probably a bad idea memory-wise. For example: But, if the object is re-created under the same key: |
And I already had basic draft of structs for switch & sensors, which I now have here rebased on the recent dev: |
I got to review your branch and I do agree with the above comment. Nice to move out of JsonBuffer but the increased complexity makes it hard to sell. Your implementation shows that need to recompute I could change my patch to meet half way. We have a shared What do you think? I'd be happy to implement that if you give your green light. |
Maybe. I can think on my changes for some time, but we can still apply the specific fix using separate roots for 1.13.6. Instead of directly using pre-defined root object as storage, haSendMagnitudes/haSendSwitches can either create an another temporary object in the config.jsonBuffer (since we send everything at once, just before loop) or use subkey. The main reason why I also want that change with generic map is to also use it in yaml generation as-is. And also name ha_config_t -> ha_ctx_t (since this is the thing I made it do) |
ok, that makes sense and I understand your intent regarding the yaml generation. I agree that giving a super simple yaml instructions are the way to help new-comers to integrate Espurna with HA. |
- stack-like discovery struct to store pending mqtt topic and message - use separate json objects for sensor and switch data (different solution for the xoseperez#1957)
Closing via #1969 |
Before this patch, the config object (and its JSON) was reused across the
sendSwitch
andsendMagnitude
. This led to a situation that advertising for the sensors includes some old keys (state_command, payload_on, ...) to be sent. Which leads to HA ignoring the sensor advertisement withThis patch is intended to clean that. Since no data has be shared between
sendSwitch
andsendMagnitude
except the common info, each function now uses it own config object (at the price of 2 inits when advertising in mqtt).Impact: RAM and CPU.
Rational of this patch: I could have removed the Json keys that we didn't need, but I found this kind of manipulation rather dirty and unwelcoming for new developers that will have to understand the logic.