Skip to content

Commit

Permalink
Avoid creating tasks to update universal media player (#116350)
Browse files Browse the repository at this point in the history
* Avoid creating tasks to update universal media player

Nothing was being awaited in async_update. This entity has polling
disabled and there was no reason to implement manual updates since
the state is always coming from other entities

* manual update
  • Loading branch information
bdraco committed Apr 28, 2024
1 parent e215270 commit b8ddf51
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions homeassistant/components/universal/media_player.py
Expand Up @@ -162,7 +162,7 @@ def __init__(
):
"""Initialize the Universal media device."""
self.hass = hass
self._name = config.get(CONF_NAME)
self._attr_name = config.get(CONF_NAME)
self._children = config.get(CONF_CHILDREN)
self._active_child_template = config.get(CONF_ACTIVE_CHILD_TEMPLATE)
self._active_child_template_result = None
Expand All @@ -189,7 +189,8 @@ def _async_on_dependency_update(
) -> None:
"""Update ha state when dependencies update."""
self.async_set_context(event.context)
self.async_schedule_update_ha_state(True)
self._async_update()
self.async_write_ha_state()

@callback
def _async_on_template_update(
Expand All @@ -213,7 +214,8 @@ def _async_on_template_update(
if event:
self.async_set_context(event.context)

self.async_schedule_update_ha_state(True)
self._async_update()
self.async_write_ha_state()

track_templates: list[TrackTemplate] = []
if self._state_template:
Expand Down Expand Up @@ -306,11 +308,6 @@ def master_state(self):

return None

@property
def name(self):
"""Return the name of universal player."""
return self._name

@property
def assumed_state(self) -> bool:
"""Return True if unable to access real state of the entity."""
Expand Down Expand Up @@ -659,7 +656,8 @@ async def async_browse_media(
return await entity.async_browse_media(media_content_type, media_content_id)
raise NotImplementedError

async def async_update(self) -> None:
@callback
def _async_update(self) -> None:
"""Update state in HA."""
if self._active_child_template_result:
self._child_state = self.hass.states.get(self._active_child_template_result)
Expand All @@ -676,3 +674,7 @@ async def async_update(self) -> None:
self._child_state = child_state
else:
self._child_state = child_state

async def async_update(self) -> None:
"""Manual update from API."""
self._async_update()

0 comments on commit b8ddf51

Please sign in to comment.