Skip to content

Separate Room Devices#52

Open
pink88 wants to merge 3 commits intotonyroberts:mainfrom
pink88:SeparateRooms
Open

Separate Room Devices#52
pink88 wants to merge 3 commits intotonyroberts:mainfrom
pink88:SeparateRooms

Conversation

@pink88
Copy link
Contributor

@pink88 pink88 commented Dec 2, 2025

I'm not sure if this is something you'd want, but I made a change such that instead of a single hub device with all entities beneath it there are now individual devices for each room, with the relevant entities beneath them. It reuses all the entity ids, so its a pretty seamless switch. The hub device remains in place for things like Hot Water and the heartbeat. I also added an options flow in the config to switch between the two modes on-the-fly called "Separate Rooms". If you switch from separate rooms to no rooms, it should auto clean up any orphaned devices.

I also added a preset_mode of NONE which has resolved the issue I was getting when manually changing the temperatures.

I've not encountered any issues with it in my testing.

Split each room into Devices beneath the Hub, instead of entities.
@tonyroberts
Copy link
Owner

Thanks for the PR @pink88, glad to see you figured out the preset problem (although still strange that I wasn't seeing the same issue).

Could you split this into two PRs? It would be easier for me to review and approve since the two changes seem unrelated. Thanks!

@tonyroberts
Copy link
Owner

tonyroberts commented Dec 5, 2025

Thanks for splitting @pink88. If you rebase and re-push I can review the remaining changes.

[EDIT] Forget that, I was able to do it - no need to do anything

@tonyroberts tonyroberts self-requested a review December 5, 2025 18:03
Copy link
Owner

@tonyroberts tonyroberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for the PR @pink88, appreciate it!

I hope you don't mind but I've added some comments for your consideration.

"separate_room_devices": "Separate Room Devices"
},
"data_description": {
"separate_room_devices": "When enabled, each room becomes a separate device. When disabled, all entities are grouped under the hub device (legacy mode). WARNING: Switching from enabled to disabled may leave orphaned room devices that need to be manually removed from Settings > Devices & Services > Devices."
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"separate_room_devices": "When enabled, each room becomes a separate device. When disabled, all entities are grouped under the hub device (legacy mode). WARNING: Switching from enabled to disabled may leave orphaned room devices that need to be manually removed from Settings > Devices & Services > Devices."
"separate_room_devices": "When enabled, separate devices are created for each room. By default, all entities are grouped under a single device."

Reworded and removed warning since it seems that the cleanup should now be done automatically.

"separate_room_devices": "Separate Room Devices"
},
"data_description": {
"separate_room_devices": "When enabled, each room becomes a separate device. When disabled, all entities are grouped under the hub device (legacy mode). WARNING: Switching from enabled to disabled may leave orphaned room devices that need to be manually removed from Settings > Devices & Services > Devices."
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"separate_room_devices": "When enabled, each room becomes a separate device. When disabled, all entities are grouped under the hub device (legacy mode). WARNING: Switching from enabled to disabled may leave orphaned room devices that need to be manually removed from Settings > Devices & Services > Devices."
"separate_room_devices": "When enabled, separate devices are created for each room. By default, all entities are grouped under a single device."

Reworded and removed warning since it seems that the cleanup should now be done automatically.


async def _cleanup_room_devices(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
"""Remove room devices when switching to legacy mode."""
from homeassistant.helpers import device_registry as dr
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this import be moved to the top of the module?

# Check if this is a room device (not the main hub)
for identifier in device.identifiers:
if identifier[0] == DOMAIN and "_room_" in str(identifier[1]):
_LOGGER.info(f"Removing orphaned room device: {device.name} ({identifier[1]})")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be using the debug log level

break

if removed_count > 0:
_LOGGER.info(f"Removed {removed_count} orphaned room device(s) when switching to legacy mode")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one too

name: str,
coordinator: WundasmartDataUpdateCoordinator,
description: WundaSensorDescription,
room_id: str = None,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be required since the room_id is now always supplied

self._attr_device_info = coordinator.device_info

# Determine device info based on whether this sensor belongs to a room
if room_id is not None:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified since we will always have a room id and the logic for which device info to get is already in coordinator.get_room_device_info. Duplicating the logic here makes the code marginally harder to maintain.

coordinator,
desc)
desc,
room_id=wunda_id)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the wunda_id is the same as the room id for the type ROOM, but for consistency/clarity, it might be worth using get_room_id_from_device here too. The marginal overhead of that function call is worth it for clarity, IMHO

self._wunda_id = wunda_id
self._attr_name = device["name"]
self._attr_device_info = coordinator.get_room_device_info(wunda_id, device)
# Use simple name for separate devices, full name for legacy mode
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

full name is used in the default mode, so doesn't follow to call that legacy mode here. Maybe "Use simple name for separate devices, or full name otherwise"?

self._attr_name = device["name"]
self._attr_device_info = coordinator.get_room_device_info(wunda_id, device)
# Use simple name for separate devices, full name for legacy mode
if coordinator._separate_room_devices:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor point but this could be a single line, if it's not too long. Happy with leaving it this way if it looks better to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants