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
pull/45303/head
J. Nick Koston 2021-01-16 23:18:07 -10:00 committed by GitHub
parent 41e7d960ee
commit 28a611f3da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -16,6 +16,10 @@ from .const import DOMAIN
_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):
"""Set up device tracker for Mikrotik component."""
@ -122,7 +126,7 @@ class MikrotikHubTracker(ScannerEntity):
def device_state_attributes(self):
"""Return the device state attributes."""
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
@property

View File

@ -49,8 +49,10 @@ async def test_device_trackers(hass, legacy_patchable_time):
assert device_1 is not None
assert device_1.state == "home"
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["host_name"] == "Device_1"
assert "mac_address" not in device_1.attributes
device_2 = hass.states.get("device_tracker.device_2")
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.state == "home"
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 "mac_address" not in device_2.attributes
assert device_2.attributes["host_name"] == "Device_2"
# test state remains home if last_seen consider_home_interval