mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Add and remove Snapcast client/group callbacks properly (#77624)
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
parent
d1ecd74a1a
commit
8afcde4ea9
@ -125,10 +125,17 @@ class SnapcastGroupDevice(MediaPlayerEntity):
|
|||||||
|
|
||||||
def __init__(self, group, uid_part):
|
def __init__(self, group, uid_part):
|
||||||
"""Initialize the Snapcast group device."""
|
"""Initialize the Snapcast group device."""
|
||||||
group.set_callback(self.schedule_update_ha_state)
|
|
||||||
self._group = group
|
self._group = group
|
||||||
self._uid = f"{GROUP_PREFIX}{uid_part}_{self._group.identifier}"
|
self._uid = f"{GROUP_PREFIX}{uid_part}_{self._group.identifier}"
|
||||||
|
|
||||||
|
async def async_added_to_hass(self) -> None:
|
||||||
|
"""Subscribe to group events."""
|
||||||
|
self._group.set_callback(self.schedule_update_ha_state)
|
||||||
|
|
||||||
|
async def async_will_remove_from_hass(self) -> None:
|
||||||
|
"""Disconnect group object when removed."""
|
||||||
|
self._group.set_callback(None)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state of the player."""
|
"""Return the state of the player."""
|
||||||
@ -213,10 +220,17 @@ class SnapcastClientDevice(MediaPlayerEntity):
|
|||||||
|
|
||||||
def __init__(self, client, uid_part):
|
def __init__(self, client, uid_part):
|
||||||
"""Initialize the Snapcast client device."""
|
"""Initialize the Snapcast client device."""
|
||||||
client.set_callback(self.schedule_update_ha_state)
|
|
||||||
self._client = client
|
self._client = client
|
||||||
self._uid = f"{CLIENT_PREFIX}{uid_part}_{self._client.identifier}"
|
self._uid = f"{CLIENT_PREFIX}{uid_part}_{self._client.identifier}"
|
||||||
|
|
||||||
|
async def async_added_to_hass(self) -> None:
|
||||||
|
"""Subscribe to client events."""
|
||||||
|
self._client.set_callback(self.schedule_update_ha_state)
|
||||||
|
|
||||||
|
async def async_will_remove_from_hass(self) -> None:
|
||||||
|
"""Disconnect client object when removed."""
|
||||||
|
self._client.set_callback(None)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user