From 1cd0e764b6a11d06ea2f640804493fe944986ff7 Mon Sep 17 00:00:00 2001 From: SukramJ Date: Sun, 29 Mar 2020 21:38:59 +0200 Subject: [PATCH] Use new HMIP labels for HomematicIP Cloud multi devices (#32925) * Use new labels for HomematicIP Cloud multi devices * Update homeassistant/components/homematicip_cloud/device.py Co-Authored-By: springstan <46536646+springstan@users.noreply.github.com> * Update name composition Co-authored-by: springstan <46536646+springstan@users.noreply.github.com> --- .../components/homematicip_cloud/device.py | 11 ++++++-- .../components/homematicip_cloud/light.py | 11 ++++++++ .../components/homematicip_cloud/switch.py | 8 ++++++ .../homematicip_cloud/test_device.py | 28 +++++++++---------- .../homematicip_cloud/test_light.py | 10 +++---- tests/fixtures/homematicip_cloud.json | 8 +++--- 6 files changed, 51 insertions(+), 25 deletions(-) diff --git a/homeassistant/components/homematicip_cloud/device.py b/homeassistant/components/homematicip_cloud/device.py index 8e6ca1f75fe..0407a1a0fe2 100644 --- a/homeassistant/components/homematicip_cloud/device.py +++ b/homeassistant/components/homematicip_cloud/device.py @@ -166,12 +166,19 @@ class HomematicipGenericDevice(Entity): def name(self) -> str: """Return the name of the generic device.""" name = self._device.label - if self._home.name is not None and self._home.name != "": + if name and self._home.name: name = f"{self._home.name} {name}" - if self.post is not None and self.post != "": + if name and self.post: name = f"{name} {self.post}" return name + def _get_label_by_channel(self, channel: int) -> str: + """Return the name of the channel.""" + name = self._device.functionalChannels[channel].label + if name and self._home.name: + name = f"{self._home.name} {name}" + return name + @property def should_poll(self) -> bool: """No polling needed.""" diff --git a/homeassistant/components/homematicip_cloud/light.py b/homeassistant/components/homematicip_cloud/light.py index cead186db95..42c18239ac2 100644 --- a/homeassistant/components/homematicip_cloud/light.py +++ b/homeassistant/components/homematicip_cloud/light.py @@ -71,6 +71,14 @@ class HomematicipLight(HomematicipGenericDevice, Light): """Initialize the light device.""" super().__init__(hap, device) + @property + def name(self) -> str: + """Return the name of the multi switch channel.""" + label = self._get_label_by_channel(1) + if label: + return label + return super().name + @property def is_on(self) -> bool: """Return true if device is on.""" @@ -193,6 +201,9 @@ class HomematicipNotificationLight(HomematicipGenericDevice, Light): @property def name(self) -> str: """Return the name of the generic device.""" + label = self._get_label_by_channel(self.channel) + if label: + return label return f"{super().name} Notification" @property diff --git a/homeassistant/components/homematicip_cloud/switch.py b/homeassistant/components/homematicip_cloud/switch.py index 45adf54df2b..79f7b9dfa5c 100644 --- a/homeassistant/components/homematicip_cloud/switch.py +++ b/homeassistant/components/homematicip_cloud/switch.py @@ -153,6 +153,14 @@ class HomematicipMultiSwitch(HomematicipGenericDevice, SwitchDevice): self.channel = channel super().__init__(hap, device, f"Channel{channel}") + @property + def name(self) -> str: + """Return the name of the multi switch channel.""" + label = self._get_label_by_channel(self.channel) + if label: + return label + return super().name + @property def unique_id(self) -> str: """Return a unique ID.""" diff --git a/tests/components/homematicip_cloud/test_device.py b/tests/components/homematicip_cloud/test_device.py index 3cb45182399..71efac3a7c9 100644 --- a/tests/components/homematicip_cloud/test_device.py +++ b/tests/components/homematicip_cloud/test_device.py @@ -26,11 +26,11 @@ async def test_hmip_load_all_supported_devices(hass, default_mock_hap_factory): async def test_hmip_remove_device(hass, default_mock_hap_factory): """Test Remove of hmip device.""" - entity_id = "light.treppe" - entity_name = "Treppe" + entity_id = "light.treppe_ch" + entity_name = "Treppe CH" device_model = "HmIP-BSL" mock_hap = await default_mock_hap_factory.async_get_mock_hap( - test_devices=[entity_name] + test_devices=["Treppe"] ) ha_state, hmip_device = get_and_check_entity_basics( @@ -58,11 +58,11 @@ async def test_hmip_remove_device(hass, default_mock_hap_factory): async def test_hmip_add_device(hass, default_mock_hap_factory, hmip_config_entry): """Test Remove of hmip device.""" - entity_id = "light.treppe" - entity_name = "Treppe" + entity_id = "light.treppe_ch" + entity_name = "Treppe CH" device_model = "HmIP-BSL" mock_hap = await default_mock_hap_factory.async_get_mock_hap( - test_devices=[entity_name] + test_devices=["Treppe"] ) ha_state, hmip_device = get_and_check_entity_basics( @@ -137,11 +137,11 @@ async def test_all_devices_unavailable_when_hap_not_connected( hass, default_mock_hap_factory ): """Test make all devices unavaulable when hap is not connected.""" - entity_id = "light.treppe" - entity_name = "Treppe" + entity_id = "light.treppe_ch" + entity_name = "Treppe CH" device_model = "HmIP-BSL" mock_hap = await default_mock_hap_factory.async_get_mock_hap( - test_devices=[entity_name] + test_devices=["Treppe"] ) ha_state, hmip_device = get_and_check_entity_basics( @@ -161,11 +161,11 @@ async def test_all_devices_unavailable_when_hap_not_connected( async def test_hap_reconnected(hass, default_mock_hap_factory): """Test reconnect hap.""" - entity_id = "light.treppe" - entity_name = "Treppe" + entity_id = "light.treppe_ch" + entity_name = "Treppe CH" device_model = "HmIP-BSL" mock_hap = await default_mock_hap_factory.async_get_mock_hap( - test_devices=[entity_name] + test_devices=["Treppe"] ) ha_state, hmip_device = get_and_check_entity_basics( @@ -192,8 +192,8 @@ async def test_hap_reconnected(hass, default_mock_hap_factory): async def test_hap_with_name(hass, mock_connection, hmip_config_entry): """Test hap with name.""" home_name = "TestName" - entity_id = f"light.{home_name.lower()}_treppe" - entity_name = f"{home_name} Treppe" + entity_id = f"light.{home_name.lower()}_treppe_ch" + entity_name = f"{home_name} Treppe CH" device_model = "HmIP-BSL" hmip_config_entry.data = {**hmip_config_entry.data, "name": home_name} diff --git a/tests/components/homematicip_cloud/test_light.py b/tests/components/homematicip_cloud/test_light.py index 8909e469ee9..8ab62019c3d 100644 --- a/tests/components/homematicip_cloud/test_light.py +++ b/tests/components/homematicip_cloud/test_light.py @@ -27,11 +27,11 @@ async def test_manually_configured_platform(hass): async def test_hmip_light(hass, default_mock_hap_factory): """Test HomematicipLight.""" - entity_id = "light.treppe" - entity_name = "Treppe" + entity_id = "light.treppe_ch" + entity_name = "Treppe CH" device_model = "HmIP-BSL" mock_hap = await default_mock_hap_factory.async_get_mock_hap( - test_devices=[entity_name] + test_devices=["Treppe"] ) ha_state, hmip_device = get_and_check_entity_basics( @@ -66,8 +66,8 @@ async def test_hmip_light(hass, default_mock_hap_factory): async def test_hmip_notification_light(hass, default_mock_hap_factory): """Test HomematicipNotificationLight.""" - entity_id = "light.treppe_top_notification" - entity_name = "Treppe Top Notification" + entity_id = "light.alarm_status" + entity_name = "Alarm Status" device_model = "HmIP-BSL" mock_hap = await default_mock_hap_factory.async_get_mock_hap( test_devices=["Treppe"] diff --git a/tests/fixtures/homematicip_cloud.json b/tests/fixtures/homematicip_cloud.json index a97b1247e2c..e85401aa1ec 100644 --- a/tests/fixtures/homematicip_cloud.json +++ b/tests/fixtures/homematicip_cloud.json @@ -1591,7 +1591,7 @@ "groupIndex": 1, "groups": [], "index": 1, - "label": "", + "label": "Treppe CH", "on": true, "profileMode": "AUTOMATIC", "userDesiredProfileMode": "AUTOMATIC" @@ -1603,7 +1603,7 @@ "groupIndex": 2, "groups": [], "index": 2, - "label": "", + "label": "Alarm Status", "on": null, "profileMode": "AUTOMATIC", "simpleRGBColorState": "RED", @@ -4576,7 +4576,7 @@ "00000000-0000-0000-0000-000000000042" ], "index": 1, - "label": "", + "label": "SW1", "on": false, "profileMode": "AUTOMATIC", "userDesiredProfileMode": "AUTOMATIC" @@ -4590,7 +4590,7 @@ "00000000-0000-0000-0000-000000000040" ], "index": 2, - "label": "", + "label": "SW2", "on": false, "profileMode": "AUTOMATIC", "userDesiredProfileMode": "AUTOMATIC"