Skip to content

Commit c2d50d1

Browse files
fix: keep entity_id room_ prefix via suggested_object_id; display name remains clean
1 parent 911abbd commit c2d50d1

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.0.3] - 2025-09-09
11+
12+
### Fixed
13+
- Ensure entity_id keeps `room_` prefix using `suggested_object_id` while keeping the display name clean (just the room name). Existing entities may need a manual rename or re-add to pick up the new object_id.
14+
1015
## [0.0.2] - 2025-09-09
1116

1217
### Changed

custom_components/rooms/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
"iot_class": "local_push",
1111
"issue_tracker": "https://github.com/DefinitelyADev/room-entity/issues",
1212
"requirements": [],
13-
"version": "0.0.1"
13+
"version": "0.0.3"
1414
}

custom_components/rooms/sensor.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,10 @@ def __init__(self, coordinator: RoomSensorCoordinator, config_entry: ConfigEntry
143143
"""Initialize the sensor."""
144144
self.coordinator = coordinator
145145
self.config_entry = config_entry
146-
self._attr_name = f"room_{config_entry.data[CONF_ROOM_NAME]}"
146+
# Display name (friendly): just the room name
147+
self._attr_name = str(config_entry.data.get(CONF_ROOM_NAME, ""))
147148
self._attr_unique_id = f"room_{config_entry.entry_id}_summary"
148149
self._attr_should_poll = False
149-
# Ensure entity_id keeps the "room_" prefix while display name stays clean
150-
room_name_val = str(config_entry.data.get(CONF_ROOM_NAME, "")).strip()
151-
if room_name_val:
152-
# Home Assistant will slugify this and create: sensor.room_<room_name>
153-
self._attr_suggested_object_id = f"room_{room_name_val}"
154150

155151
# Register with coordinator
156152
coordinator.register_summary_sensor(self)
@@ -169,6 +165,15 @@ def name(self) -> str:
169165
room_name = self.config_entry.data.get(CONF_ROOM_NAME, "")
170166
return str(room_name) if room_name else ""
171167

168+
@property
169+
def suggested_object_id(self) -> Optional[str]:
170+
"""Suggest object_id so entity_id gets a room_ prefix.
171+
172+
Home Assistant will slugify this into the final object_id.
173+
"""
174+
room_name = str(self.config_entry.data.get(CONF_ROOM_NAME, "")).strip()
175+
return f"room_{room_name}" if room_name else None
176+
172177
def _get_numeric_state(self, entity_id: str, default_value: float = 0.0) -> Optional[float]:
173178
"""Get numeric state from entity, with fallback to default."""
174179
if not entity_id:

0 commit comments

Comments
 (0)