Small cleanups to expand_entity_ids (#96585)

This commit is contained in:
J. Nick Koston 2023-07-17 21:41:37 -10:00 committed by GitHub
parent 7d4016d7bf
commit fca40be5df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,7 +10,6 @@ from typing import Any, Protocol, cast
import voluptuous as vol import voluptuous as vol
from homeassistant import core as ha
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
ATTR_ASSUMED_STATE, ATTR_ASSUMED_STATE,
@ -82,6 +81,8 @@ PLATFORMS = [
REG_KEY = f"{DOMAIN}_registry" REG_KEY = f"{DOMAIN}_registry"
ENTITY_PREFIX = f"{DOMAIN}."
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
current_domain: ContextVar[str] = ContextVar("current_domain") current_domain: ContextVar[str] = ContextVar("current_domain")
@ -180,12 +181,8 @@ def expand_entity_ids(hass: HomeAssistant, entity_ids: Iterable[Any]) -> list[st
continue continue
entity_id = entity_id.lower() entity_id = entity_id.lower()
try:
# If entity_id points at a group, expand it # If entity_id points at a group, expand it
domain, _ = ha.split_entity_id(entity_id) if entity_id.startswith(ENTITY_PREFIX):
if domain == DOMAIN:
child_entities = get_entity_ids(hass, entity_id) child_entities = get_entity_ids(hass, entity_id)
if entity_id in child_entities: if entity_id in child_entities:
child_entities = list(child_entities) child_entities = list(child_entities)
@ -195,14 +192,9 @@ def expand_entity_ids(hass: HomeAssistant, entity_ids: Iterable[Any]) -> list[st
for ent_id in expand_entity_ids(hass, child_entities) for ent_id in expand_entity_ids(hass, child_entities)
if ent_id not in found_ids if ent_id not in found_ids
) )
elif entity_id not in found_ids: elif entity_id not in found_ids:
found_ids.append(entity_id) found_ids.append(entity_id)
except AttributeError:
# Raised by split_entity_id if entity_id is not a string
pass
return found_ids return found_ids