diff --git a/custom_components/spook/ectoplasms/lovelace/repairs/unknown_entity_references.py b/custom_components/spook/ectoplasms/lovelace/repairs/unknown_entity_references.py index 300b24ea..48f32eb0 100644 --- a/custom_components/spook/ectoplasms/lovelace/repairs/unknown_entity_references.py +++ b/custom_components/spook/ectoplasms/lovelace/repairs/unknown_entity_references.py @@ -90,24 +90,36 @@ async def async_inspect(self) -> None: ) @callback - def __async_extract_entities(self, config: dict[str, Any]) -> set[str]: # noqa: C901 + def __async_extract_entities(self, config: dict[str, Any]) -> set[str]: """Extract entities from a dashboard config.""" entities = set() if isinstance(config, dict) and (views := config.get("views")): for view in views: - if badges := view.get("badges"): - for badge in badges: - entities.update(self.__async_extract_entities_from_badge(badge)) - if cards := view.get("cards"): - for card in cards: - entities.update(self.__async_extract_entities_from_card(card)) - if sections := view.get("sections"): - for section in sections: - if cards := section.get("cards"): - for card in cards: - entities.update( - self.__async_extract_entities_from_card(card) - ) + entities.update(self.__async_extract_entities_from_view(view)) + return entities + + @callback + def __async_extract_entities_from_view(self, config: dict[Any]) -> set[str]: + """Extract entities from a view config.""" + entities = set() + if badges := config.get("badges"): + for badge in badges: + entities.update(self.__async_extract_entities_from_badge(badge)) + if cards := config.get("cards"): + for card in cards: + entities.update(self.__async_extract_entities_from_card(card)) + if sections := config.get("sections"): + for section in sections: + entities.update(self.__async_extract_entities_from_section(section)) + return entities + + @callback + def __async_extract_entities_from_section(self, config: dict[Any]) -> set[str]: + """Extract entities from a section config.""" + entities = set() + if cards := config.get("cards"): + for card in cards: + entities.update(self.__async_extract_entities_from_card(card)) return entities @callback