mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 19:57:07 +00:00
Small cleanups to expand_entity_ids (#96585)
This commit is contained in:
parent
7d4016d7bf
commit
fca40be5df
@ -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,28 +181,19 @@ def expand_entity_ids(hass: HomeAssistant, entity_ids: Iterable[Any]) -> list[st
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
entity_id = entity_id.lower()
|
entity_id = entity_id.lower()
|
||||||
|
# If entity_id points at a group, expand it
|
||||||
try:
|
if entity_id.startswith(ENTITY_PREFIX):
|
||||||
# If entity_id points at a group, expand it
|
child_entities = get_entity_ids(hass, entity_id)
|
||||||
domain, _ = ha.split_entity_id(entity_id)
|
if entity_id in child_entities:
|
||||||
|
child_entities = list(child_entities)
|
||||||
if domain == DOMAIN:
|
child_entities.remove(entity_id)
|
||||||
child_entities = get_entity_ids(hass, entity_id)
|
found_ids.extend(
|
||||||
if entity_id in child_entities:
|
ent_id
|
||||||
child_entities = list(child_entities)
|
for ent_id in expand_entity_ids(hass, child_entities)
|
||||||
child_entities.remove(entity_id)
|
if ent_id not in found_ids
|
||||||
found_ids.extend(
|
)
|
||||||
ent_id
|
elif entity_id not in found_ids:
|
||||||
for ent_id in expand_entity_ids(hass, child_entities)
|
found_ids.append(entity_id)
|
||||||
if ent_id not in found_ids
|
|
||||||
)
|
|
||||||
|
|
||||||
elif entity_id not in found_ids:
|
|
||||||
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
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user