From e74613f8bed330c2ffdab64fa9c9a65a64401478 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Tue, 28 Feb 2023 17:04:10 +0100 Subject: [PATCH] Fix removal of non device-bound resources in Hue (#88897) Fix removal of non device-bound resources (like entertainment areas) --- homeassistant/components/hue/v2/entity.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/hue/v2/entity.py b/homeassistant/components/hue/v2/entity.py index 85b70465854..5878f01889b 100644 --- a/homeassistant/components/hue/v2/entity.py +++ b/homeassistant/components/hue/v2/entity.py @@ -55,7 +55,13 @@ class HueBaseEntity(Entity): self._attr_unique_id = resource.id # device is precreated in main handler # this attaches the entity to the precreated device - if self.device is not None: + if self.device is None: + # attach all device-less entities to the bridge itself + # e.g. config based sensors like entertainment area + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, bridge.api.config.bridge.bridge_id)}, + ) + else: self._attr_device_info = DeviceInfo( identifiers={(DOMAIN, self.device.id)}, ) @@ -137,17 +143,14 @@ class HueBaseEntity(Entity): def _handle_event(self, event_type: EventType, resource: HueResource) -> None: """Handle status event for this resource (or it's parent).""" if event_type == EventType.RESOURCE_DELETED: - # remove any services created for zones/rooms + # handle removal of room and zone 'virtual' devices/services # regular devices are removed automatically by the logic in device.py. if resource.type in (ResourceTypes.ROOM, ResourceTypes.ZONE): dev_reg = async_get_device_registry(self.hass) if device := dev_reg.async_get_device({(DOMAIN, resource.id)}): dev_reg.async_remove_device(device.id) - if resource.type in ( - ResourceTypes.GROUPED_LIGHT, - ResourceTypes.SCENE, - ResourceTypes.SMART_SCENE, - ): + # cleanup entities that are not strictly device-bound and have the bridge as parent + if self.device is None: ent_reg = async_get_entity_registry(self.hass) ent_reg.async_remove(self.entity_id) return