mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Use standard device tracker attributes for "ip" and "mac" in Mikrotik (#45255)
* Mikrotik now uses the device_tracker standard attributes for "ip" and "mac" The "mac_address" and "ip_address" attributes have been removed. * Update homeassistant/components/mikrotik/device_tracker.py
This commit is contained in:
parent
41e7d960ee
commit
28a611f3da
@ -16,6 +16,10 @@ from .const import DOMAIN
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
# These are normalized to ATTR_IP and ATTR_MAC to conform
|
||||||
|
# to device_tracker
|
||||||
|
FILTER_ATTRS = ("ip_address", "mac_address")
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
"""Set up device tracker for Mikrotik component."""
|
"""Set up device tracker for Mikrotik component."""
|
||||||
@ -122,7 +126,7 @@ class MikrotikHubTracker(ScannerEntity):
|
|||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Return the device state attributes."""
|
"""Return the device state attributes."""
|
||||||
if self.is_connected:
|
if self.is_connected:
|
||||||
return self.device.attrs
|
return {k: v for k, v in self.device.attrs.items() if k not in FILTER_ATTRS}
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -49,8 +49,10 @@ async def test_device_trackers(hass, legacy_patchable_time):
|
|||||||
assert device_1 is not None
|
assert device_1 is not None
|
||||||
assert device_1.state == "home"
|
assert device_1.state == "home"
|
||||||
assert device_1.attributes["ip"] == "0.0.0.1"
|
assert device_1.attributes["ip"] == "0.0.0.1"
|
||||||
|
assert "ip_address" not in device_1.attributes
|
||||||
assert device_1.attributes["mac"] == "00:00:00:00:00:01"
|
assert device_1.attributes["mac"] == "00:00:00:00:00:01"
|
||||||
assert device_1.attributes["host_name"] == "Device_1"
|
assert device_1.attributes["host_name"] == "Device_1"
|
||||||
|
assert "mac_address" not in device_1.attributes
|
||||||
device_2 = hass.states.get("device_tracker.device_2")
|
device_2 = hass.states.get("device_tracker.device_2")
|
||||||
assert device_2 is None
|
assert device_2 is None
|
||||||
|
|
||||||
@ -65,7 +67,9 @@ async def test_device_trackers(hass, legacy_patchable_time):
|
|||||||
assert device_2 is not None
|
assert device_2 is not None
|
||||||
assert device_2.state == "home"
|
assert device_2.state == "home"
|
||||||
assert device_2.attributes["ip"] == "0.0.0.2"
|
assert device_2.attributes["ip"] == "0.0.0.2"
|
||||||
|
assert "ip_address" not in device_2.attributes
|
||||||
assert device_2.attributes["mac"] == "00:00:00:00:00:02"
|
assert device_2.attributes["mac"] == "00:00:00:00:00:02"
|
||||||
|
assert "mac_address" not in device_2.attributes
|
||||||
assert device_2.attributes["host_name"] == "Device_2"
|
assert device_2.attributes["host_name"] == "Device_2"
|
||||||
|
|
||||||
# test state remains home if last_seen consider_home_interval
|
# test state remains home if last_seen consider_home_interval
|
||||||
|
Loading…
x
Reference in New Issue
Block a user