Skip to content

Commit d32e335

Browse files
Add icon selection to room config flow
- Add IconSelector to config flow with dropdown of all HA icons - Set default icon to mdi:texture-box - Update translations for icon field - Update stubs with IconSelector and IconSelectorConfig
1 parent 4c4ee63 commit d32e335

File tree

4 files changed

+40
-7
lines changed

4 files changed

+40
-7
lines changed

custom_components/rooms/config_flow.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ async def async_step_user(self, user_input: Optional[Dict[str, Any]] = None) ->
4747
await self.async_set_unique_id(user_input[CONF_ROOM_NAME])
4848
self._abort_if_unique_id_configured()
4949

50+
# Ensure icon has a default value if not provided
51+
if CONF_ICON not in user_input or user_input[CONF_ICON] is None:
52+
user_input[CONF_ICON] = DEFAULT_ICON
53+
5054
return self.async_create_entry(
5155
title=user_input[CONF_ROOM_NAME],
5256
data=user_input,
@@ -57,8 +61,8 @@ async def async_step_user(self, user_input: Optional[Dict[str, Any]] = None) ->
5761
data_schema=vol.Schema(
5862
{
5963
vol.Required(CONF_ROOM_NAME): str,
60-
vol.Optional(CONF_ICON, default=DEFAULT_ICON): getattr(selector, "IconSelector")(
61-
getattr(selector, "IconSelectorConfig")()
64+
vol.Optional(CONF_ICON): selector.IconSelector(
65+
selector.IconSelectorConfig(placeholder="mdi:texture-box")
6266
),
6367
vol.Optional(CONF_POWER_ENTITY): selector.EntitySelector(
6468
selector.EntitySelectorConfig(domain="sensor")

custom_components/rooms/strings.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"motion_entity": "Motion Sensor (optional)",
1414
"window_entity": "Window Sensor (optional)",
1515
"climate_entity": "Climate Entity (optional)",
16-
"active_threshold": "Active Power Threshold (W)"
16+
"active_threshold": "Active Power Threshold (W)",
17+
"icon": "Icon (optional)"
1718
}
1819
}
1920
},
@@ -39,7 +40,8 @@
3940
"motion_entity": "Motion Sensor (optional)",
4041
"window_entity": "Window Sensor (optional)",
4142
"climate_entity": "Climate Entity (optional)",
42-
"active_threshold": "Active Power Threshold (W)"
43+
"active_threshold": "Active Power Threshold (W)",
44+
"icon": "Icon (optional)"
4345
}
4446
}
4547
}

custom_components/rooms/translations/en.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"motion_entity": "Motion Sensor (optional)",
1414
"window_entity": "Window Sensor (optional)",
1515
"climate_entity": "Climate Entity (optional)",
16-
"active_threshold": "Active Power Threshold (W)"
16+
"active_threshold": "Active Power Threshold (W)",
17+
"icon": "Icon (optional)"
1718
}
1819
}
1920
},
@@ -39,7 +40,8 @@
3940
"motion_entity": "Motion Sensor (optional)",
4041
"window_entity": "Window Sensor (optional)",
4142
"climate_entity": "Climate Entity (optional)",
42-
"active_threshold": "Active Power Threshold (W)"
43+
"active_threshold": "Active Power Threshold (W)",
44+
"icon": "Icon (optional)"
4345
}
4446
}
4547
}

stubs/homeassistant/helpers/selector.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Selector:
88

99
def __init__(
1010
self,
11-
config: Union[Dict[str, Any], "EntitySelectorConfig", "TextSelectorConfig"],
11+
config: Union[Dict[str, Any], "EntitySelectorConfig", "TextSelectorConfig", "IconSelectorConfig"],
1212
) -> None:
1313
"""Initialize selector."""
1414
...
@@ -41,6 +41,18 @@ def __init__(
4141
...
4242

4343

44+
class IconSelectorConfig:
45+
"""Configuration for icon selector."""
46+
47+
def __init__(
48+
self,
49+
*,
50+
placeholder: Optional[str] = None,
51+
) -> None:
52+
"""Initialize icon selector config."""
53+
...
54+
55+
4456
class EntitySelector(Selector):
4557
"""Entity selector."""
4658

@@ -68,3 +80,16 @@ def __init__(
6880
) -> None:
6981
"""Initialize text selector."""
7082
...
83+
84+
85+
class IconSelector(Selector):
86+
"""Icon selector."""
87+
88+
def __init__(
89+
self,
90+
config: Optional[Union[Dict[str, Any], IconSelectorConfig]] = None,
91+
*,
92+
placeholder: Optional[str] = None,
93+
) -> None:
94+
"""Initialize icon selector."""
95+
...

0 commit comments

Comments
 (0)