Skip to content

Commit ccc6160

Browse files
fix: resolve mypy type error in name property
Fix mypy error by ensuring the name property returns a proper string type. Use .get() method with fallback and explicit string conversion to satisfy type checker requirements.
1 parent 7b93bc1 commit ccc6160

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

custom_components/rooms/sensor.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def __init__(self, coordinator: RoomSensorCoordinator, config_entry: ConfigEntry
142142
"""Initialize the sensor."""
143143
self.coordinator = coordinator
144144
self.config_entry = config_entry
145-
self._attr_name = f"{config_entry.data[CONF_ROOM_NAME]}"
145+
self._attr_name = f"room_{config_entry.data[CONF_ROOM_NAME]}"
146146
self._attr_unique_id = f"room_{config_entry.entry_id}_summary"
147147
self._attr_should_poll = False
148148

@@ -157,6 +157,12 @@ def __init__(self, coordinator: RoomSensorCoordinator, config_entry: ConfigEntry
157157
model="Room Sensor",
158158
)
159159

160+
@property
161+
def name(self) -> str:
162+
"""Return the name of the sensor (display name without room_ prefix)."""
163+
room_name = self.config_entry.data.get(CONF_ROOM_NAME, "")
164+
return str(room_name) if room_name else ""
165+
160166
def _get_numeric_state(self, entity_id: str, default_value: float = 0.0) -> Optional[float]:
161167
"""Get numeric state from entity, with fallback to default."""
162168
if not entity_id:

0 commit comments

Comments
 (0)