Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherit icon from scene #84

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions custom_components/stateful_scenes/StatefulScenes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def get_name_from_entity_id(hass: HomeAssistant, entity_id: str) -> str:
name = er.async_get(entity_id).original_name
return name if name is not None else entity_id

def get_icon_from_entity_id(hass: HomeAssistant, entity_id: str) -> str:
"""Get scene icon from entity_id."""
er = entity_registry.async_get(hass)
icon = er.async_get(entity_id).icon
return icon if icon is not None else None


class Hub:
"""State scene class."""
Expand Down Expand Up @@ -171,7 +177,7 @@ def extract_scene_configuration(self, scene_conf: dict) -> dict:
return {
"name": scene_conf["name"],
"id": scene_conf.get("id", entity_id),
"icon": scene_conf.get("icon", None),
"icon": scene_conf.get("icon", get_icon_from_entity_id(self.hass, entity_id)),
"entity_id": entity_id,
"area": area_id(self.hass, entity_id),
"learn": scene_conf.get("learn", False),
Expand All @@ -183,7 +189,7 @@ def prepare_external_scene(self, entity_id, entities) -> dict:
return {
"name": get_name_from_entity_id(self.hass, entity_id),
"id": get_id_from_entity_id(self.hass, entity_id),
"icon": None,
"icon": get_icon_from_entity_id(self.hass, entity_id),
"entity_id": entity_id,
"area": area_id(self.hass, entity_id),
"learn": True,
Expand Down