Add entity ids to grouped hue light (#113053)
This commit is contained in:
parent
7ba1e4446c
commit
bad5eaf329
2 changed files with 34 additions and 5 deletions
|
@ -26,6 +26,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
import homeassistant.helpers.entity_registry as er
|
||||
|
||||
from ..bridge import HueBridge
|
||||
from ..const import DOMAIN
|
||||
|
@ -136,15 +137,18 @@ class GroupedHueLight(HueBaseEntity, LightEntity):
|
|||
scenes = {
|
||||
x.metadata.name for x in self.api.scenes if x.group.rid == self.group.id
|
||||
}
|
||||
lights = {
|
||||
self.controller.get_device(x.id).metadata.name
|
||||
for x in self.controller.get_lights(self.resource.id)
|
||||
}
|
||||
light_resource_ids = tuple(
|
||||
x.id for x in self.controller.get_lights(self.resource.id)
|
||||
)
|
||||
light_names, light_entities = self._get_names_and_entity_ids_for_resource_ids(
|
||||
light_resource_ids
|
||||
)
|
||||
return {
|
||||
"is_hue_group": True,
|
||||
"hue_scenes": scenes,
|
||||
"hue_type": self.group.type.value,
|
||||
"lights": lights,
|
||||
"lights": light_names,
|
||||
"entity_id": light_entities,
|
||||
"dynamics": self._dynamic_mode_active,
|
||||
}
|
||||
|
||||
|
@ -278,3 +282,19 @@ class GroupedHueLight(HueBaseEntity, LightEntity):
|
|||
self._attr_color_mode = ColorMode.BRIGHTNESS
|
||||
else:
|
||||
self._attr_color_mode = ColorMode.ONOFF
|
||||
|
||||
@callback
|
||||
def _get_names_and_entity_ids_for_resource_ids(
|
||||
self, resource_ids: tuple[str]
|
||||
) -> tuple[set[str], set[str]]:
|
||||
"""Return the names and entity ids for the given Hue (light) resource IDs."""
|
||||
ent_reg = er.async_get(self.hass)
|
||||
light_names: set[str] = set()
|
||||
light_entities: set[str] = set()
|
||||
for resource_id in resource_ids:
|
||||
light_names.add(self.controller.get_device(resource_id).metadata.name)
|
||||
if entity_id := ent_reg.async_get_entity_id(
|
||||
self.platform.domain, DOMAIN, resource_id
|
||||
):
|
||||
light_entities.add(entity_id)
|
||||
return light_names, light_entities
|
||||
|
|
|
@ -412,6 +412,11 @@ async def test_grouped_lights(
|
|||
"Hue light with color and color temperature gradient",
|
||||
"Hue light with color and color temperature 2",
|
||||
}
|
||||
assert test_entity.attributes["entity_id"] == {
|
||||
"light.hue_light_with_color_and_color_temperature_gradient",
|
||||
"light.hue_light_with_color_and_color_temperature_2",
|
||||
"light.hue_light_with_color_and_color_temperature_1",
|
||||
}
|
||||
|
||||
# test light created for hue room
|
||||
test_entity = hass.states.get("light.test_room")
|
||||
|
@ -431,6 +436,10 @@ async def test_grouped_lights(
|
|||
"Hue on/off light",
|
||||
"Hue light with color temperature only",
|
||||
}
|
||||
assert test_entity.attributes["entity_id"] == {
|
||||
"light.hue_light_with_color_temperature_only",
|
||||
"light.hue_on_off_light",
|
||||
}
|
||||
|
||||
# Test calling the turn on service on a grouped light
|
||||
test_light_id = "light.test_zone"
|
||||
|
|
Loading…
Add table
Reference in a new issue