mirror of
https://github.com/home-assistant/core.git
synced 2026-09-26 09:23:17 -04:00
Use async_create_background_task for the songpal notification listener (#178000)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user