From 6ac7c0f893ddc78c7b0dcc9d5dd9b9d84e9600f7 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Wed, 23 Oct 2024 16:22:08 +0200 Subject: [PATCH] Fix devolo_home_network devices not reporting a MAC address (#129021) --- .../components/devolo_home_network/entity.py | 6 +++- tests/components/devolo_home_network/mock.py | 2 +- .../snapshots/test_init.ambr | 34 ++++++++++++++++++- .../devolo_home_network/test_init.py | 5 ++- 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/devolo_home_network/entity.py b/homeassistant/components/devolo_home_network/entity.py index d381f48ca058a..f29f528c77fc1 100644 --- a/homeassistant/components/devolo_home_network/entity.py +++ b/homeassistant/components/devolo_home_network/entity.py @@ -9,6 +9,7 @@ ) from devolo_plc_api.plcnet_api import DataRate, LogicalNetwork +from homeassistant.const import ATTR_CONNECTIONS from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo from homeassistant.helpers.entity import Entity from homeassistant.helpers.update_coordinator import ( @@ -45,7 +46,6 @@ def __init__( self._attr_device_info = DeviceInfo( configuration_url=f"http://{self.device.ip}", - connections={(CONNECTION_NETWORK_MAC, self.device.mac)}, identifiers={(DOMAIN, str(self.device.serial_number))}, manufacturer="devolo", model=self.device.product, @@ -53,6 +53,10 @@ def __init__( serial_number=self.device.serial_number, sw_version=self.device.firmware_version, ) + if self.device.mac: + self._attr_device_info[ATTR_CONNECTIONS] = { + (CONNECTION_NETWORK_MAC, self.device.mac) + } self._attr_translation_key = self.entity_description.key self._attr_unique_id = ( f"{self.device.serial_number}_{self.entity_description.key}" diff --git a/tests/components/devolo_home_network/mock.py b/tests/components/devolo_home_network/mock.py index fc7786669b72a..82bf3e5ad762d 100644 --- a/tests/components/devolo_home_network/mock.py +++ b/tests/components/devolo_home_network/mock.py @@ -50,7 +50,7 @@ async def async_connect( self, session_instance: httpx.AsyncClient | None = None ) -> None: """Give a mocked device the needed properties.""" - self.mac = DISCOVERY_INFO.properties["PlcMacAddress"] + self.mac = DISCOVERY_INFO.properties["PlcMacAddress"] if self.plcnet else None self.mt_number = DISCOVERY_INFO.properties["MT"] self.product = DISCOVERY_INFO.properties["Product"] self.serial_number = DISCOVERY_INFO.properties["SN"] diff --git a/tests/components/devolo_home_network/snapshots/test_init.ambr b/tests/components/devolo_home_network/snapshots/test_init.ambr index 619a8ce11217a..297c9a2518314 100644 --- a/tests/components/devolo_home_network/snapshots/test_init.ambr +++ b/tests/components/devolo_home_network/snapshots/test_init.ambr @@ -1,5 +1,5 @@ # serializer version: 1 -# name: test_setup_entry +# name: test_setup_entry[mock_device] DeviceRegistryEntrySnapshot({ 'area_id': None, 'config_entries': , @@ -35,3 +35,35 @@ 'via_device_id': None, }) # --- +# name: test_setup_entry[mock_repeater_device] + DeviceRegistryEntrySnapshot({ + 'area_id': None, + 'config_entries': , + 'configuration_url': 'http://192.0.2.1', + 'connections': set({ + }), + 'disabled_by': None, + 'entry_type': None, + 'hw_version': None, + 'id': , + 'identifiers': set({ + tuple( + 'devolo_home_network', + '1234567890', + ), + }), + 'is_new': False, + 'labels': set({ + }), + 'manufacturer': 'devolo', + 'model': 'dLAN pro 1200+ WiFi ac', + 'model_id': '2730', + 'name': 'Mock Title', + 'name_by_user': None, + 'primary_config_entry': , + 'serial_number': '1234567890', + 'suggested_area': None, + 'sw_version': '5.6.1', + 'via_device_id': None, + }) +# --- diff --git a/tests/components/devolo_home_network/test_init.py b/tests/components/devolo_home_network/test_init.py index 1b8903c568e87..71823eabe828f 100644 --- a/tests/components/devolo_home_network/test_init.py +++ b/tests/components/devolo_home_network/test_init.py @@ -27,13 +27,16 @@ from tests.common import MockConfigEntry +@pytest.mark.parametrize("device", ["mock_device", "mock_repeater_device"]) async def test_setup_entry( hass: HomeAssistant, - mock_device: MockDevice, + device: str, device_registry: dr.DeviceRegistry, snapshot: SnapshotAssertion, + request: pytest.FixtureRequest, ) -> None: """Test setup entry.""" + mock_device: MockDevice = request.getfixturevalue(device) entry = configure_integration(hass) assert await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done()