221 files
This commit is contained in:
@@ -7,11 +7,11 @@ from homeassistant.const import (
|
||||
EVENT_COMPONENT_LOADED,
|
||||
)
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.entity_platform import DATA_ENTITY_PLATFORM, EntityPlatform
|
||||
|
||||
from ....const import LOGGER
|
||||
from ....entity_filtering import async_filter_known_entity_ids, async_get_all_entity_ids
|
||||
from ....entity_suggestions import async_describe_unknown_entities
|
||||
from ....helper_sources import async_group_members
|
||||
from ....repairs import AbstractSpookRepair
|
||||
|
||||
|
||||
@@ -35,55 +35,35 @@ class SpookRepair(AbstractSpookRepair):
|
||||
|
||||
known_entity_ids = async_get_all_entity_ids(self.hass)
|
||||
|
||||
platforms: list[EntityPlatform] | None
|
||||
if not (platforms := self.hass.data[DATA_ENTITY_PLATFORM].get(self.domain)):
|
||||
return # Nothing to do.
|
||||
for entity, members in async_group_members(self.hass):
|
||||
self.possible_issue_ids.add(entity.entity_id)
|
||||
|
||||
# Taken as a snapshot: describing what is missing can hand the event
|
||||
# loop a turn, and a change to the live collection during it ends the
|
||||
# inspection in a `RuntimeError`. #1558.
|
||||
for platform in list(platforms):
|
||||
# We don't want to check the old style group platform
|
||||
for entity in list(platform.entities.values()):
|
||||
self.possible_issue_ids.add(entity.entity_id)
|
||||
members = []
|
||||
if platform.domain == group.DOMAIN:
|
||||
members = entity.tracking
|
||||
elif hasattr(entity, "_entity_ids"):
|
||||
# pylint: disable-next=protected-access
|
||||
members = entity._entity_ids # noqa: SLF001
|
||||
elif hasattr(entity, "_entities"):
|
||||
# pylint: disable-next=protected-access
|
||||
members = entity._entities # noqa: SLF001
|
||||
|
||||
if unknown_entities := async_filter_known_entity_ids(
|
||||
self.hass, entity_ids=members, known_entity_ids=known_entity_ids
|
||||
):
|
||||
described = await async_describe_unknown_entities(
|
||||
self.hass, sorted(unknown_entities)
|
||||
)
|
||||
self.async_create_issue(
|
||||
issue_id=entity.entity_id,
|
||||
references=unknown_entities,
|
||||
is_fixable=True,
|
||||
data={
|
||||
"group_entity_id": entity.entity_id,
|
||||
# What the fix checks again before dropping any.
|
||||
"group_unknown_entity_ids": ",".join(
|
||||
sorted(unknown_entities)
|
||||
),
|
||||
"group": entity.name,
|
||||
"entities": described,
|
||||
},
|
||||
translation_placeholders={
|
||||
"entities": described,
|
||||
"group": entity.name,
|
||||
"entity_id": entity.entity_id,
|
||||
},
|
||||
)
|
||||
LOGGER.debug(
|
||||
"Spook found unknown member entities in %s "
|
||||
"and created an issue for it; Entities: %s",
|
||||
entity.entity_id,
|
||||
", ".join(unknown_entities),
|
||||
)
|
||||
if unknown_entities := async_filter_known_entity_ids(
|
||||
self.hass, entity_ids=members, known_entity_ids=known_entity_ids
|
||||
):
|
||||
described = await async_describe_unknown_entities(
|
||||
self.hass, sorted(unknown_entities)
|
||||
)
|
||||
self.async_create_issue(
|
||||
issue_id=entity.entity_id,
|
||||
references=unknown_entities,
|
||||
is_fixable=True,
|
||||
data={
|
||||
"group_entity_id": entity.entity_id,
|
||||
# What the fix checks again before dropping any.
|
||||
"group_unknown_entity_ids": ",".join(sorted(unknown_entities)),
|
||||
"group": entity.name,
|
||||
"entities": described,
|
||||
},
|
||||
translation_placeholders={
|
||||
"entities": described,
|
||||
"group": entity.name,
|
||||
"entity_id": entity.entity_id,
|
||||
},
|
||||
)
|
||||
LOGGER.debug(
|
||||
"Spook found unknown member entities in %s "
|
||||
"and created an issue for it; Entities: %s",
|
||||
entity.entity_id,
|
||||
", ".join(unknown_entities),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user