mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 04:08:19 -04:00
Adapt mikrotik device tracker to base class changes (#189202)
This commit is contained in:
@@ -8,6 +8,7 @@ from homeassistant.components.device_tracker import (
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
|
||||
from homeassistant.helpers.entity import EntityDescription
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.util import dt as dt_util
|
||||
@@ -79,6 +80,9 @@ class MikrotikDataUpdateCoordinatorTracker(MikrotikBaseEntity, ScannerEntity):
|
||||
super().__init__(coordinator, EntityDescription(key=device.mac))
|
||||
self.device = device
|
||||
self._attr_unique_id = device.mac
|
||||
self._attr_device_info = DeviceInfo(
|
||||
connections={(CONNECTION_NETWORK_MAC, device.mac)}, name=device.name
|
||||
)
|
||||
|
||||
@property
|
||||
@override
|
||||
|
||||
@@ -10,7 +10,7 @@ from pytest_homeassistant.common import async_fire_time_changed, patch
|
||||
from homeassistant.components import device_tracker, mikrotik
|
||||
from homeassistant.const import STATE_UNAVAILABLE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from . import setup_mikrotik_entry
|
||||
@@ -101,6 +101,43 @@ async def test_device_trackers(hass: HomeAssistant) -> None:
|
||||
assert device_2.state == "not_home"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("dhcp_data", "entity_id", "expected_device_name"),
|
||||
[
|
||||
pytest.param(
|
||||
[DEVICE_1_DHCP], "device_tracker.device_1", "Device_1", id="hostname"
|
||||
),
|
||||
# A wireless client without a DHCP lease has no hostname
|
||||
pytest.param(
|
||||
[],
|
||||
"device_tracker.00_00_00_00_00_01",
|
||||
"00:00:00:00:00:01",
|
||||
id="no_hostname",
|
||||
),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_tracker_device(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
dhcp_data: list[dict[str, Any]],
|
||||
entity_id: str,
|
||||
expected_device_name: str,
|
||||
) -> None:
|
||||
"""Test the tracker device is named by the hostname, else the MAC address."""
|
||||
await setup_mikrotik_entry(
|
||||
hass, dhcp_data=dhcp_data, wireless_data=[DEVICE_1_WIRELESS]
|
||||
)
|
||||
|
||||
registry_entry = entity_registry.async_get(entity_id)
|
||||
assert registry_entry is not None
|
||||
device = device_registry.async_get(registry_entry.device_id)
|
||||
assert device is not None
|
||||
assert device.name == expected_device_name
|
||||
assert device.connections == {(dr.CONNECTION_NETWORK_MAC, "00:00:00:00:00:01")}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_force_dhcp(hass: HomeAssistant) -> None:
|
||||
"""Test updating hub that supports wireless with forced dhcp method."""
|
||||
|
||||
Reference in New Issue
Block a user