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>
This commit is contained in:
SukramJ 2020-03-29 21:38:59 +02:00 committed by GitHub
parent d45c386149
commit 1cd0e764b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 25 deletions

View File

@ -166,12 +166,19 @@ class HomematicipGenericDevice(Entity):
def name(self) -> str: def name(self) -> str:
"""Return the name of the generic device.""" """Return the name of the generic device."""
name = self._device.label 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}" 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}" name = f"{name} {self.post}"
return name 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 @property
def should_poll(self) -> bool: def should_poll(self) -> bool:
"""No polling needed.""" """No polling needed."""

View File

@ -71,6 +71,14 @@ class HomematicipLight(HomematicipGenericDevice, Light):
"""Initialize the light device.""" """Initialize the light device."""
super().__init__(hap, 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 @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return true if device is on.""" """Return true if device is on."""
@ -193,6 +201,9 @@ class HomematicipNotificationLight(HomematicipGenericDevice, Light):
@property @property
def name(self) -> str: def name(self) -> str:
"""Return the name of the generic device.""" """Return the name of the generic device."""
label = self._get_label_by_channel(self.channel)
if label:
return label
return f"{super().name} Notification" return f"{super().name} Notification"
@property @property

View File

@ -153,6 +153,14 @@ class HomematicipMultiSwitch(HomematicipGenericDevice, SwitchDevice):
self.channel = channel self.channel = channel
super().__init__(hap, device, f"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 @property
def unique_id(self) -> str: def unique_id(self) -> str:
"""Return a unique ID.""" """Return a unique ID."""

View File

@ -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): async def test_hmip_remove_device(hass, default_mock_hap_factory):
"""Test Remove of hmip device.""" """Test Remove of hmip device."""
entity_id = "light.treppe" entity_id = "light.treppe_ch"
entity_name = "Treppe" entity_name = "Treppe CH"
device_model = "HmIP-BSL" device_model = "HmIP-BSL"
mock_hap = await default_mock_hap_factory.async_get_mock_hap( 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( 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): async def test_hmip_add_device(hass, default_mock_hap_factory, hmip_config_entry):
"""Test Remove of hmip device.""" """Test Remove of hmip device."""
entity_id = "light.treppe" entity_id = "light.treppe_ch"
entity_name = "Treppe" entity_name = "Treppe CH"
device_model = "HmIP-BSL" device_model = "HmIP-BSL"
mock_hap = await default_mock_hap_factory.async_get_mock_hap( 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( 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 hass, default_mock_hap_factory
): ):
"""Test make all devices unavaulable when hap is not connected.""" """Test make all devices unavaulable when hap is not connected."""
entity_id = "light.treppe" entity_id = "light.treppe_ch"
entity_name = "Treppe" entity_name = "Treppe CH"
device_model = "HmIP-BSL" device_model = "HmIP-BSL"
mock_hap = await default_mock_hap_factory.async_get_mock_hap( 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( 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): async def test_hap_reconnected(hass, default_mock_hap_factory):
"""Test reconnect hap.""" """Test reconnect hap."""
entity_id = "light.treppe" entity_id = "light.treppe_ch"
entity_name = "Treppe" entity_name = "Treppe CH"
device_model = "HmIP-BSL" device_model = "HmIP-BSL"
mock_hap = await default_mock_hap_factory.async_get_mock_hap( 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( 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): async def test_hap_with_name(hass, mock_connection, hmip_config_entry):
"""Test hap with name.""" """Test hap with name."""
home_name = "TestName" home_name = "TestName"
entity_id = f"light.{home_name.lower()}_treppe" entity_id = f"light.{home_name.lower()}_treppe_ch"
entity_name = f"{home_name} Treppe" entity_name = f"{home_name} Treppe CH"
device_model = "HmIP-BSL" device_model = "HmIP-BSL"
hmip_config_entry.data = {**hmip_config_entry.data, "name": home_name} hmip_config_entry.data = {**hmip_config_entry.data, "name": home_name}

View File

@ -27,11 +27,11 @@ async def test_manually_configured_platform(hass):
async def test_hmip_light(hass, default_mock_hap_factory): async def test_hmip_light(hass, default_mock_hap_factory):
"""Test HomematicipLight.""" """Test HomematicipLight."""
entity_id = "light.treppe" entity_id = "light.treppe_ch"
entity_name = "Treppe" entity_name = "Treppe CH"
device_model = "HmIP-BSL" device_model = "HmIP-BSL"
mock_hap = await default_mock_hap_factory.async_get_mock_hap( 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( 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): async def test_hmip_notification_light(hass, default_mock_hap_factory):
"""Test HomematicipNotificationLight.""" """Test HomematicipNotificationLight."""
entity_id = "light.treppe_top_notification" entity_id = "light.alarm_status"
entity_name = "Treppe Top Notification" entity_name = "Alarm Status"
device_model = "HmIP-BSL" device_model = "HmIP-BSL"
mock_hap = await default_mock_hap_factory.async_get_mock_hap( mock_hap = await default_mock_hap_factory.async_get_mock_hap(
test_devices=["Treppe"] test_devices=["Treppe"]

View File

@ -1591,7 +1591,7 @@
"groupIndex": 1, "groupIndex": 1,
"groups": [], "groups": [],
"index": 1, "index": 1,
"label": "", "label": "Treppe CH",
"on": true, "on": true,
"profileMode": "AUTOMATIC", "profileMode": "AUTOMATIC",
"userDesiredProfileMode": "AUTOMATIC" "userDesiredProfileMode": "AUTOMATIC"
@ -1603,7 +1603,7 @@
"groupIndex": 2, "groupIndex": 2,
"groups": [], "groups": [],
"index": 2, "index": 2,
"label": "", "label": "Alarm Status",
"on": null, "on": null,
"profileMode": "AUTOMATIC", "profileMode": "AUTOMATIC",
"simpleRGBColorState": "RED", "simpleRGBColorState": "RED",
@ -4576,7 +4576,7 @@
"00000000-0000-0000-0000-000000000042" "00000000-0000-0000-0000-000000000042"
], ],
"index": 1, "index": 1,
"label": "", "label": "SW1",
"on": false, "on": false,
"profileMode": "AUTOMATIC", "profileMode": "AUTOMATIC",
"userDesiredProfileMode": "AUTOMATIC" "userDesiredProfileMode": "AUTOMATIC"
@ -4590,7 +4590,7 @@
"00000000-0000-0000-0000-000000000040" "00000000-0000-0000-0000-000000000040"
], ],
"index": 2, "index": 2,
"label": "", "label": "SW2",
"on": false, "on": false,
"profileMode": "AUTOMATIC", "profileMode": "AUTOMATIC",
"userDesiredProfileMode": "AUTOMATIC" "userDesiredProfileMode": "AUTOMATIC"