Skip to content
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: update mqtt subscriptions when topic was changed #1156

Merged

Conversation

AndreasBoehm
Copy link
Member

Update mqtt subscription and update homeassistant config when topic was changed.

Fixes #1045

@schlimmchen
Copy link
Member

Looks good, but it's a little too much to review on the phone. Is a review necessary? I tend to trust that this is good.

Are all OnBattery extensions covered with this?

@AndreasBoehm
Copy link
Member Author

I went through all classes but because of all the back and forth i would not trust myself that i covered all OnBattery extensions with this.

Let's wait and get it fully reviewed.

@schlimmchen
Copy link
Member

As far as I can tell, you covered all relevant subscriptions. However, I am not happy about duplicating each subscription string to implement the unsubscribing for two reasons: (1) occupies flash storage and (2) when adding new topics the module subscribes to, there is a high chance that the unsubscribe function is not taken care of as well.

What do you think about this idea: In the respective lambdas that call MqttSetting.subscribe() we know the full topic to subscribe to. After subscribing, we add the topic string to a container (I guess a vector). The unsubscribe() function iterates all these topics and calls unsubscribe for them. I know this uses more RAM, which is the only thing that makes me unsure that this is the right approach.

How about a frozen::map? That would live in flash, would be compact (no strings are defined two times), and we could iterate it to subscribe and to unsubscribe?

I just added a respective change. What do you think?

@AndreasBoehm
Copy link
Member Author

I really like the idea, makes sense to do it that way 👍

@schlimmchen schlimmchen merged commit 65407db into hoylabs:development Aug 20, 2024
8 checks passed
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new discussion or issue for related concerns.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MQTT subscriptions not updated when base topic changes
2 participants