From 5eb0c35a977028adfde64e23ff2db454c111d524 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" <nick@koston.org> Date: Tue, 4 Apr 2023 20:41:15 -1000 Subject: [PATCH] Add names to common helper tasks (#90803) --- homeassistant/core.py | 6 ++++-- homeassistant/helpers/discovery.py | 10 +++++++--- homeassistant/helpers/entity.py | 5 ++++- homeassistant/helpers/entity_component.py | 4 +++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/homeassistant/core.py b/homeassistant/core.py index 78ceb620e53..90b44e20693 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -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( diff --git a/homeassistant/helpers/discovery.py b/homeassistant/helpers/discovery.py index b7db5ba69fa..7045966c529 100644 --- a/homeassistant/helpers/discovery.py +++ b/homeassistant/helpers/discovery.py @@ -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}", ) diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index eaac35286d9..fd9c6bb260d 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -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: diff --git a/homeassistant/helpers/entity_component.py b/homeassistant/helpers/entity_component.py index 0c43dddec60..c79726684a2 100644 --- a/homeassistant/helpers/entity_component.py +++ b/homeassistant/helpers/entity_component.py @@ -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. -- GitLab