Skip to content

Commit

Permalink
Fix devolo_home_network devices not reporting a MAC address (#129021)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shutgun authored and frenck committed Oct 25, 2024
1 parent 096d506 commit 6ac7c0f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
6 changes: 5 additions & 1 deletion homeassistant/components/devolo_home_network/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -45,14 +46,17 @@ 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,
model_id=self.device.mt_number,
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}"
Expand Down
2 changes: 1 addition & 1 deletion tests/components/devolo_home_network/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
34 changes: 33 additions & 1 deletion tests/components/devolo_home_network/snapshots/test_init.ambr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# serializer version: 1
# name: test_setup_entry
# name: test_setup_entry[mock_device]
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
Expand Down Expand Up @@ -35,3 +35,35 @@
'via_device_id': None,
})
# ---
# name: test_setup_entry[mock_repeater_device]
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
'configuration_url': 'http://192.0.2.1',
'connections': set({
}),
'disabled_by': None,
'entry_type': None,
'hw_version': None,
'id': <ANY>,
'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': <ANY>,
'serial_number': '1234567890',
'suggested_area': None,
'sw_version': '5.6.1',
'via_device_id': None,
})
# ---
5 changes: 4 additions & 1 deletion tests/components/devolo_home_network/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 6ac7c0f

Please sign in to comment.