home-assistant-libs / pychromecast

Library for Python 3 to communicate with the Google Chromecast.
MIT License
2.51k stars 380 forks source link

Unregister HomeAssistantController on instance conflict #798

Closed emontnemery closed 6 months ago

emontnemery commented 6 months ago

When developing, it's common to have a production instance and at least one test instance of Home Assistant running at the same time.

Without the changes in this PR, once Home Assistant Cast has been used once, the HomeAssistantController instance is never unregistered by Home Assistant Core. This means the 'HomeAssistantController`s are interfering with each other, even when they are not actively casting.

With the changes in this PR, we detect this and call a callback passed to us by Home Assistant Core, asking to unregister the controller.