diff --git a/homeassistant/helpers/entity_component.py b/homeassistant/helpers/entity_component.py index fb627820060..86d5436e287 100644 --- a/homeassistant/helpers/entity_component.py +++ b/homeassistant/helpers/entity_component.py @@ -186,7 +186,7 @@ class EntityComponent(Generic[_EntityT]): This method must be run in the event loop. """ - return await service.async_extract_entities( # type: ignore[return-value] + return await service.async_extract_entities( self.hass, self.entities, service_call, expand_group ) diff --git a/homeassistant/helpers/service.py b/homeassistant/helpers/service.py index cf7fb3b2304..7675686844c 100644 --- a/homeassistant/helpers/service.py +++ b/homeassistant/helpers/service.py @@ -6,7 +6,7 @@ from collections.abc import Awaitable, Callable, Iterable import dataclasses from functools import partial, wraps import logging -from typing import TYPE_CHECKING, Any, TypedDict +from typing import TYPE_CHECKING, Any, TypedDict, TypeVar from typing_extensions import TypeGuard import voluptuous as vol @@ -48,6 +48,8 @@ if TYPE_CHECKING: from .entity import Entity from .entity_platform import EntityPlatform + _EntityT = TypeVar("_EntityT", bound=Entity) + CONF_SERVICE_ENTITY_ID = "entity_id" CONF_SERVICE_DATA_TEMPLATE = "data_template" @@ -276,10 +278,10 @@ def extract_entity_ids( @bind_hass async def async_extract_entities( hass: HomeAssistant, - entities: Iterable[Entity], + entities: Iterable[_EntityT], service_call: ServiceCall, expand_group: bool = True, -) -> list[Entity]: +) -> list[_EntityT]: """Extract a list of entity objects from a service call. Will convert group entity ids to the entity ids it represents.