Add names to common helper tasks (#90803)

This commit is contained in:
J. Nick Koston 2023-04-04 20:41:15 -10:00 committed by GitHub
parent 21a873f0af
commit 5eb0c35a97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 7 deletions

View File

@ -505,12 +505,14 @@ class HomeAssistant:
return task return task
def create_task(self, target: Coroutine[Any, Any, Any]) -> None: def create_task(
self, target: Coroutine[Any, Any, Any], name: str | None = None
) -> None:
"""Add task to the executor pool. """Add task to the executor pool.
target: target to call. target: target to call.
""" """
self.loop.call_soon_threadsafe(self.async_create_task, target) self.loop.call_soon_threadsafe(self.async_create_task, target, name)
@callback @callback
def async_create_task( def async_create_task(

View File

@ -67,7 +67,10 @@ def discover(
hass_config: ConfigType, hass_config: ConfigType,
) -> None: ) -> None:
"""Fire discovery event. Can ensure a component is loaded.""" """Fire discovery event. Can ensure a component is loaded."""
hass.add_job(async_discover(hass, service, discovered, component, hass_config)) hass.create_task(
async_discover(hass, service, discovered, component, hass_config),
f"discover {service} {component} {discovered}",
)
@bind_hass @bind_hass
@ -127,8 +130,9 @@ def load_platform(
hass_config: ConfigType, hass_config: ConfigType,
) -> None: ) -> None:
"""Load a component and platform dynamically.""" """Load a component and platform dynamically."""
hass.add_job( hass.create_task(
async_load_platform(hass, component, platform, discovered, hass_config) async_load_platform(hass, component, platform, discovered, hass_config),
f"discovery load_platform {component} {platform}",
) )

View File

@ -698,7 +698,10 @@ class Entity(ABC):
If state is changed more than once before the ha state change task has If state is changed more than once before the ha state change task has
been executed, the intermediate state transitions will be missed. been executed, the intermediate state transitions will be missed.
""" """
self.hass.add_job(self.async_update_ha_state(force_refresh)) self.hass.create_task(
self.async_update_ha_state(force_refresh),
f"Entity {self.entity_id} schedule update ha state",
)
@callback @callback
def async_schedule_update_ha_state(self, force_refresh: bool = False) -> None: def async_schedule_update_ha_state(self, force_refresh: bool = False) -> None:

View File

@ -114,7 +114,9 @@ class EntityComponent(Generic[_EntityT]):
This doesn't block the executor to protect from deadlocks. This doesn't block the executor to protect from deadlocks.
""" """
self.hass.add_job(self.async_setup(config)) self.hass.create_task(
self.async_setup(config), f"EntityComponent setup {self.domain}"
)
async def async_setup(self, config: ConfigType) -> None: async def async_setup(self, config: ConfigType) -> None:
"""Set up a full entity component. """Set up a full entity component.