Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix devolo_home_network devices not reporting a MAC address #129021

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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