Avoid creating tasks to update universal media player (#116350)
* 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
This commit is contained in:
parent
e215270c05
commit
b8ddf51e28
1 changed files with 11 additions and 9 deletions
|
@ -162,7 +162,7 @@ class UniversalMediaPlayer(MediaPlayerEntity):
|
|||
):
|
||||
"""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
|
||||
|
@ -189,7 +189,8 @@ class UniversalMediaPlayer(MediaPlayerEntity):
|
|||
) -> 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(
|
||||
|
@ -213,7 +214,8 @@ class UniversalMediaPlayer(MediaPlayerEntity):
|
|||
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:
|
||||
|
@ -306,11 +308,6 @@ class UniversalMediaPlayer(MediaPlayerEntity):
|
|||
|
||||
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."""
|
||||
|
@ -659,7 +656,8 @@ class UniversalMediaPlayer(MediaPlayerEntity):
|
|||
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)
|
||||
|
@ -676,3 +674,7 @@ class UniversalMediaPlayer(MediaPlayerEntity):
|
|||
self._child_state = child_state
|
||||
else:
|
||||
self._child_state = child_state
|
||||
|
||||
async def async_update(self) -> None:
|
||||
"""Manual update from API."""
|
||||
self._async_update()
|
||||
|
|
Loading…
Add table
Reference in a new issue