Skip to content

Commit

Permalink
Split into multiple methods
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya authored and frenck committed Aug 6, 2024
1 parent 45321af commit 078f555
Showing 1 changed file with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 078f555

Please sign in to comment.