Skip to content

Commit

Permalink
Handle CancelledError in bluesound integration (#124873)
Browse files Browse the repository at this point in the history
Catch CancledError in async_will_remove_from_hass
  • Loading branch information
LouisChrist authored Aug 30, 2024
1 parent 6781a76 commit f394dfb
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions homeassistant/components/bluesound/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ async def force_update_sync_status(self) -> bool:

return True

async def _start_poll_command(self):
async def _poll_loop(self):
"""Loop which polls the status of the player."""
while True:
try:
Expand All @@ -335,7 +335,7 @@ async def async_added_to_hass(self) -> None:
await super().async_added_to_hass()

self._polling_task = self.hass.async_create_background_task(
self._start_poll_command(),
self._poll_loop(),
name=f"bluesound.polling_{self.host}:{self.port}",
)

Expand All @@ -345,7 +345,9 @@ async def async_will_remove_from_hass(self) -> None:

assert self._polling_task is not None
if self._polling_task.cancel():
await self._polling_task
# the sleeps in _poll_loop will raise CancelledError
with suppress(CancelledError):
await self._polling_task

self.hass.data[DATA_BLUESOUND].remove(self)

Expand Down

0 comments on commit f394dfb

Please sign in to comment.