Add _attr_has_entity_name to devolo Home Network device tracker platform (#146978)

* Add _attr_has_entity_name to devolo Home Network device tracker platform

* Set name

* Fix tests
This commit is contained in:
Guido Schmitz 2025-06-17 20:49:52 +02:00 committed by GitHub
parent 8e82e3aa3a
commit fc6844b3c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 10 deletions

View File

@ -87,6 +87,7 @@ class DevoloScannerEntity( # pylint: disable=hass-enforce-class-module
):
"""Representation of a devolo device tracker."""
_attr_has_entity_name = True
_attr_translation_key = "device_tracker"
def __init__(
@ -99,6 +100,7 @@ class DevoloScannerEntity( # pylint: disable=hass-enforce-class-module
super().__init__(coordinator)
self._device = device
self._attr_mac_address = mac
self._attr_name = mac
@property
def extra_state_attributes(self) -> dict[str, str]:

View File

@ -3,12 +3,13 @@
StateSnapshot({
'attributes': ReadOnlyDict({
'band': '5 GHz',
'friendly_name': 'AA:BB:CC:DD:EE:FF',
'mac': 'AA:BB:CC:DD:EE:FF',
'source_type': <SourceType.ROUTER: 'router'>,
'wifi': 'Main',
}),
'context': <ANY>,
'entity_id': 'device_tracker.devolo_home_network_1234567890_aa_bb_cc_dd_ee_ff',
'entity_id': 'device_tracker.aa_bb_cc_dd_ee_ff',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,

View File

@ -17,13 +17,12 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from . import configure_integration
from .const import CONNECTED_STATIONS, DISCOVERY_INFO, NO_CONNECTED_STATIONS
from .const import CONNECTED_STATIONS, NO_CONNECTED_STATIONS
from .mock import MockDevice
from tests.common import async_fire_time_changed
STATION = CONNECTED_STATIONS[0]
SERIAL = DISCOVERY_INFO.properties["SN"]
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
@ -35,9 +34,7 @@ async def test_device_tracker(
snapshot: SnapshotAssertion,
) -> None:
"""Test device tracker states."""
state_key = (
f"{PLATFORM}.{DOMAIN}_{SERIAL}_{STATION.mac_address.lower().replace(':', '_')}"
)
state_key = f"{PLATFORM}.{STATION.mac_address.lower().replace(':', '_')}"
entry = configure_integration(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
@ -77,14 +74,12 @@ async def test_restoring_clients(
entity_registry: er.EntityRegistry,
) -> None:
"""Test restoring existing device_tracker entities."""
state_key = (
f"{PLATFORM}.{DOMAIN}_{SERIAL}_{STATION.mac_address.lower().replace(':', '_')}"
)
state_key = f"{PLATFORM}.{STATION.mac_address.lower().replace(':', '_')}"
entry = configure_integration(hass)
entity_registry.async_get_or_create(
PLATFORM,
DOMAIN,
f"{SERIAL}_{STATION.mac_address}",
f"{STATION.mac_address}",
config_entry=entry,
)