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
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.
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
def async_create_task(

View File

@ -67,7 +67,10 @@ def discover(
hass_config: ConfigType,
) -> None:
"""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
@ -127,8 +130,9 @@ def load_platform(
hass_config: ConfigType,
) -> None:
"""Load a component and platform dynamically."""
hass.add_job(
async_load_platform(hass, component, platform, discovered, hass_config)
hass.create_task(
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
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
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.
"""
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:
"""Set up a full entity component.