mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 22:07:10 +00:00
Handle CancelledError in bluesound integration (#124873)
Catch CancledError in async_will_remove_from_hass
This commit is contained in:
parent
6781a76de2
commit
f394dfb8d0
@ -309,7 +309,7 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def _start_poll_command(self):
|
async def _poll_loop(self):
|
||||||
"""Loop which polls the status of the player."""
|
"""Loop which polls the status of the player."""
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
@ -335,7 +335,7 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
|
|
||||||
self._polling_task = self.hass.async_create_background_task(
|
self._polling_task = self.hass.async_create_background_task(
|
||||||
self._start_poll_command(),
|
self._poll_loop(),
|
||||||
name=f"bluesound.polling_{self.host}:{self.port}",
|
name=f"bluesound.polling_{self.host}:{self.port}",
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -345,6 +345,8 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||||||
|
|
||||||
assert self._polling_task is not None
|
assert self._polling_task is not None
|
||||||
if self._polling_task.cancel():
|
if self._polling_task.cancel():
|
||||||
|
# the sleeps in _poll_loop will raise CancelledError
|
||||||
|
with suppress(CancelledError):
|
||||||
await self._polling_task
|
await self._polling_task
|
||||||
|
|
||||||
self.hass.data[DATA_BLUESOUND].remove(self)
|
self.hass.data[DATA_BLUESOUND].remove(self)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user