Use async_create_background_task for the songpal notification listener (#178000)

This commit is contained in:
Lin Junrong
2026-08-30 18:56:12 +02:00
committed by GitHub
parent 968e26a092
commit 0dab42061c
@@ -161,6 +161,11 @@ class SongpalEntity(MediaPlayerEntity):
"""Activate websocket for listening if wanted."""
_LOGGER.debug("Activating websocket connection")
# Narrowed once here rather than at each call site: the entity is only
# ever added from async_setup_entry, so the platform always has an entry.
entry = self.platform.config_entry
assert entry is not None
async def _volume_changed(volume: VolumeChange):
_LOGGER.debug("Volume changed: %s", volume)
self._volume = volume.volume
@@ -218,7 +223,11 @@ class SongpalEntity(MediaPlayerEntity):
# back from a disconnected state.
await self.async_update_ha_state(force_refresh=True)
self.hass.loop.create_task(self._dev.listen_notifications())
entry.async_create_background_task(
self.hass,
self._dev.listen_notifications(),
"songpal-listen-notifications",
)
_LOGGER.warning(
"[%s(%s)] Connection reestablished", self.name, self._dev.endpoint
)
@@ -234,7 +243,9 @@ class SongpalEntity(MediaPlayerEntity):
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, handle_stop)
self.hass.loop.create_task(self._dev.listen_notifications())
entry.async_create_background_task(
self.hass, self._dev.listen_notifications(), "songpal-listen-notifications"
)
@property
@override