python-snapcast
python-snapcast copied to clipboard
Change of Group in Combination of the use of this Module in Home Assistant
In the Home Assistant Snapcast integration seems something not to work in the right way in the combination with this module, my knowledge at this point is to limited to find the problem myself:
https://github.com/home-assistant/core/issues/63928
Maybe someone is here who can can look into this?
I can confirm that issue #63928 is still not fixed in Home Assistant 2022.4.1. The issue is closed but should be reopened!
I think what is happening is this:
When group membership is changed, control.server.synchronize
gets called, and this clobbers all existing groups, clients and streams in the process of rediscovering them (code here).
In doing so, it loses the callbacks that the home assistant snapcast component registers with the clients and groups, which makes home assistant no longer able to observe the state changes in these entities. This happens even if you change the group membership from inside home assistant (which, IMO, is the entire reason that I am using the snapcast component in the first place).
Two ways of fixing this that I can think of:
- Don't clobber existing objects, just update them as needed.
- Allow a global callback method for groups, clients and streams to be defined during
control.server
invocation, which is inherited by all discovered objects (this is a two edged sword, since it will allow newly discovered objects to have the callback immediately invoked, but this might lead to undefined behavior in the callback code if it doesn't have logic to handle new objects in it).
@happyleavesaoc Is this behavior that you have seen before?
The problem described by @eschwim is fixed with #47 in 2.3.0. However, the home-assistant integration still uses 2.1.3 and does not react on any server update/connect/disconnect events. I will send in a PR in the next days and link it here.
HA will switch to 2.3.0 in 2022.11, this will fix the initial issue. To fix the remaining issues I made a new PR https://github.com/home-assistant/core/pull/80846 If you want to get this merged more quickly, please like and review. @happyleavesaoc: I think you can close here.