Skip to content

Commit 89bb6f3

Browse files
Fix mypy error: cast icon return value to str
1 parent ccc6160 commit 89bb6f3

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

custom_components/rooms/config_flow.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
CONF_CLIMATE_ENTITY,
1414
CONF_ENERGY_ENTITY,
1515
CONF_HUMIDITY_ENTITY,
16+
CONF_ICON,
1617
CONF_MOTION_ENTITY,
1718
CONF_POWER_ENTITY,
1819
CONF_ROOM_NAME,
1920
CONF_TEMP_ENTITY,
2021
CONF_WINDOW_ENTITY,
22+
DEFAULT_ICON,
2123
DOMAIN,
2224
)
2325

@@ -55,6 +57,7 @@ async def async_step_user(self, user_input: Optional[Dict[str, Any]] = None) ->
5557
data_schema=vol.Schema(
5658
{
5759
vol.Required(CONF_ROOM_NAME): str,
60+
vol.Optional(CONF_ICON, default=DEFAULT_ICON): str,
5861
vol.Optional(CONF_POWER_ENTITY): selector.EntitySelector(
5962
selector.EntitySelectorConfig(domain="sensor")
6063
),

custom_components/rooms/const.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
CONF_WINDOW_ENTITY = "window_entity"
1111
CONF_CLIMATE_ENTITY = "climate_entity"
1212
CONF_ACTIVE_THRESHOLD = "active_threshold"
13+
CONF_ICON = "icon"
1314

1415
# Default values
1516
DEFAULT_ACTIVE_THRESHOLD = 50.0
17+
DEFAULT_ICON = "mdi:texture-box"
1618

1719
# State values
1820
STATE_ACTIVE = "active"

custom_components/rooms/sensor.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@
3838
CONF_CLIMATE_ENTITY,
3939
CONF_ENERGY_ENTITY,
4040
CONF_HUMIDITY_ENTITY,
41+
CONF_ICON,
4142
CONF_MOTION_ENTITY,
4243
CONF_POWER_ENTITY,
4344
CONF_ROOM_NAME,
4445
CONF_TEMP_ENTITY,
4546
CONF_WINDOW_ENTITY,
4647
DEFAULT_ACTIVE_THRESHOLD,
48+
DEFAULT_ICON,
4749
DOMAIN,
48-
ICON_HOME,
4950
ICON_MOTION,
5051
ICON_WINDOW_OPEN,
5152
STATE_ACTIVE,
@@ -243,7 +244,8 @@ def icon(self) -> str:
243244
if motion_state and motion_state.state == STATE_ON:
244245
return ICON_MOTION
245246

246-
return ICON_HOME
247+
# Return configured icon or default
248+
return str(data.get(CONF_ICON, DEFAULT_ICON))
247249

248250
@property
249251
def extra_state_attributes(self) -> Dict[str, Any]:

custom_components/rooms/tests/test_sensor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def test_room_summary_sensor_initialization(mock_coordinator, mock_config_entry,
6161
sensor.hass = mock_hass
6262

6363
assert sensor.name == "Test Room"
64-
assert sensor.unique_id == "test_entry_id_summary"
64+
assert sensor.unique_id == "room_test_entry_id_summary"
6565
assert sensor.should_poll is False
6666

6767

@@ -211,7 +211,7 @@ def mock_get(entity_id):
211211

212212
mock_hass.states.get = mock_get
213213

214-
assert sensor.icon == "mdi:home"
214+
assert sensor.icon == "mdi:texture-box"
215215

216216
# Test motion icon
217217
motion_state.state = STATE_ON

0 commit comments

Comments
 (0)