From c181fb6de0ff403056d05e720ca60f220dde09f5 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Mon, 9 Jan 2023 16:37:03 +0100 Subject: [PATCH] Bump aiohue library to 4.6.1 (#85504) * Bump aiohue to 4.6.0 * fix device name for lights * fix name for groups too * ignore smart scenes * bump to 4.6.1 instead * fix test fixture * update tests * fix scene test --- homeassistant/components/hue/manifest.json | 2 +- homeassistant/components/hue/scene.py | 4 +- homeassistant/components/hue/v2/entity.py | 8 ++-- homeassistant/components/hue/v2/group.py | 5 ++- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/hue/const.py | 2 +- .../components/hue/fixtures/v2_resources.json | 38 ++++++------------- tests/components/hue/test_light_v2.py | 4 +- 9 files changed, 27 insertions(+), 40 deletions(-) diff --git a/homeassistant/components/hue/manifest.json b/homeassistant/components/hue/manifest.json index d726f773b9b..0c460d1dd36 100644 --- a/homeassistant/components/hue/manifest.json +++ b/homeassistant/components/hue/manifest.json @@ -3,7 +3,7 @@ "name": "Philips Hue", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/hue", - "requirements": ["aiohue==4.5.0"], + "requirements": ["aiohue==4.6.1"], "ssdp": [ { "manufacturer": "Royal Philips Electronics", diff --git a/homeassistant/components/hue/scene.py b/homeassistant/components/hue/scene.py index 5b0c17ebbf4..b93d8f76fed 100644 --- a/homeassistant/components/hue/scene.py +++ b/homeassistant/components/hue/scene.py @@ -47,10 +47,10 @@ async def async_setup_entry( @callback def async_add_entity(event_type: EventType, resource: HueScene) -> None: """Add entity from Hue resource.""" - async_add_entities([HueSceneEntity(bridge, api.scenes, resource)]) + async_add_entities([HueSceneEntity(bridge, api.scenes.scene, resource)]) # add all current items in controller - for item in api.scenes: + for item in api.scenes.scene: async_add_entity(EventType.RESOURCE_ADDED, item) # register listener for new items only diff --git a/homeassistant/components/hue/v2/entity.py b/homeassistant/components/hue/v2/entity.py index 7335bf71058..ac901d63758 100644 --- a/homeassistant/components/hue/v2/entity.py +++ b/homeassistant/components/hue/v2/entity.py @@ -71,11 +71,11 @@ class HueBaseEntity(Entity): # creating a pretty name for device-less entities (e.g. groups/scenes) # should be handled in the platform instead return self.resource.type.value - # if resource is a light, use the name from metadata - if self.resource.type == ResourceTypes.LIGHT: - return self.resource.name - # for sensors etc, use devicename + pretty name of type dev_name = self.device.metadata.name + # if resource is a light, use the device name itself + if self.resource.type == ResourceTypes.LIGHT: + return dev_name + # for sensors etc, use devicename + pretty name of type type_title = RESOURCE_TYPE_NAMES.get( self.resource.type, self.resource.type.value.replace("_", " ").title() ) diff --git a/homeassistant/components/hue/v2/group.py b/homeassistant/components/hue/v2/group.py index cbf974325e0..dd22c98f63e 100644 --- a/homeassistant/components/hue/v2/group.py +++ b/homeassistant/components/hue/v2/group.py @@ -120,7 +120,10 @@ class GroupedHueLight(HueBaseEntity, LightEntity): scenes = { x.metadata.name for x in self.api.scenes if x.group.rid == self.group.id } - lights = {x.metadata.name for x in self.controller.get_lights(self.resource.id)} + lights = { + self.controller.get_device(x.id).metadata.name + for x in self.controller.get_lights(self.resource.id) + } return { "is_hue_group": True, "hue_scenes": scenes, diff --git a/requirements_all.txt b/requirements_all.txt index a3bda2f1349..9179340776d 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -184,7 +184,7 @@ aiohomekit==2.4.3 aiohttp_cors==0.7.0 # homeassistant.components.hue -aiohue==4.5.0 +aiohue==4.6.1 # homeassistant.components.imap aioimaplib==1.0.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 13112dfecc2..8fc9e3ee26d 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -168,7 +168,7 @@ aiohomekit==2.4.3 aiohttp_cors==0.7.0 # homeassistant.components.hue -aiohue==4.5.0 +aiohue==4.6.1 # homeassistant.components.imap aioimaplib==1.0.1 diff --git a/tests/components/hue/const.py b/tests/components/hue/const.py index 03b2f1947cf..01b9c7f84b8 100644 --- a/tests/components/hue/const.py +++ b/tests/components/hue/const.py @@ -32,7 +32,6 @@ FAKE_LIGHT = { }, "id": "fake_light_id_1", "id_v1": "/lights/1", - "metadata": {"archetype": "unknown", "name": "Hue fake light"}, "mode": "normal", "on": {"on": False}, "owner": {"rid": "fake_device_id_1", "rtype": "device"}, @@ -93,5 +92,6 @@ FAKE_SCENE = { }, "palette": {"color": [], "color_temperature": [], "dimming": []}, "speed": 0.5, + "auto_dynamic": False, "type": "scene", } diff --git a/tests/components/hue/fixtures/v2_resources.json b/tests/components/hue/fixtures/v2_resources.json index be9509f9652..51eff8451b8 100644 --- a/tests/components/hue/fixtures/v2_resources.json +++ b/tests/components/hue/fixtures/v2_resources.json @@ -168,6 +168,7 @@ "dimming": [] }, "speed": 0.6269841194152832, + "auto_dynamic": false, "type": "scene" }, { @@ -220,6 +221,7 @@ "dimming": [] }, "speed": 0.5, + "auto_dynamic": false, "type": "scene" }, { @@ -624,14 +626,12 @@ }, "effects": { "status_values": ["no_effect", "candle", "fire"], - "status": "no_effect" + "status": "no_effect", + "effect_values": ["no_effect", "candle", "fire"], + "effect": "no_effect" }, "id": "02cba059-9c2c-4d45-97e4-4f79b1bfbaa1", "id_v1": "/lights/29", - "metadata": { - "archetype": "floor_shade", - "name": "Hue light with color and color temperature 1" - }, "mode": "normal", "on": { "on": true @@ -666,18 +666,18 @@ }, "effects": { "status_values": ["no_effect", "candle"], - "status": "no_effect" + "status": "no_effect", + "effect_values": ["no_effect", "candle", "fire"], + "effect": "no_effect" }, "timed_effects": { "status_values": ["no_effect", "sunrise"], - "status": "no_effect" + "status": "no_effect", + "effect_values": ["no_effect", "sunrise"], + "effect": "no_effect" }, "id": "3a6710fa-4474-4eba-b533-5e6e72968feb", "id_v1": "/lights/4", - "metadata": { - "archetype": "ceiling_round", - "name": "Hue light with color temperature only" - }, "mode": "normal", "on": { "on": false @@ -733,10 +733,6 @@ }, "id": "b3fe71ef-d0ef-48de-9355-d9e604377df0", "id_v1": "/lights/16", - "metadata": { - "archetype": "hue_lightstrip", - "name": "Hue light with color and color temperature 2" - }, "mode": "normal", "on": { "on": true @@ -759,10 +755,6 @@ }, "id": "7697ac8a-25aa-4576-bb40-0036c0db15b9", "id_v1": "/lights/23", - "metadata": { - "archetype": "classic_bulb", - "name": "Hue on/off light" - }, "mode": "normal", "on": { "on": false @@ -810,10 +802,6 @@ }, "id": "74a45fee-1b3d-4553-b5ab-040da8a10cfd", "id_v1": "/lights/11", - "metadata": { - "archetype": "hue_bloom", - "name": "Hue light with color only" - }, "mode": "normal", "on": { "on": true @@ -914,10 +902,6 @@ }, "id": "8015b17f-8336-415b-966a-b364bd082397", "id_v1": "/lights/24", - "metadata": { - "archetype": "hue_lightstrip_tv", - "name": "Hue light with color and color temperature gradient" - }, "mode": "normal", "on": { "on": true diff --git a/tests/components/hue/test_light_v2.py b/tests/components/hue/test_light_v2.py index bba28e03477..0427c9f7c4d 100644 --- a/tests/components/hue/test_light_v2.py +++ b/tests/components/hue/test_light_v2.py @@ -277,7 +277,7 @@ async def test_light_added(hass, mock_bridge_v2): await setup_platform(hass, mock_bridge_v2, "light") - test_entity_id = "light.hue_fake_light" + test_entity_id = "light.hue_mocked_device" # verify entity does not exist before we start assert hass.states.get(test_entity_id) is None @@ -290,7 +290,7 @@ async def test_light_added(hass, mock_bridge_v2): test_entity = hass.states.get(test_entity_id) assert test_entity is not None assert test_entity.state == "off" - assert test_entity.attributes["friendly_name"] == FAKE_LIGHT["metadata"]["name"] + assert test_entity.attributes["friendly_name"] == FAKE_DEVICE["metadata"]["name"] async def test_light_availability(hass, mock_bridge_v2, v2_resources_test_data):