Add test for mikrotik device tracker with numerical device name (#72808)

Add mikrotik test for numerical device name
This commit is contained in:
Erik Montnemery 2022-06-01 09:39:56 +02:00 committed by GitHub
parent 4902af2f4e
commit 9ac0c5907f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 30 deletions

View file

@ -45,6 +45,14 @@ DEVICE_2_DHCP = {
"host-name": "Device_2",
"comment": "PC",
}
DEVICE_3_DHCP_NUMERIC_NAME = {
".id": "*1C",
"address": "0.0.0.3",
"mac-address": "00:00:00:00:00:03",
"active-address": "0.0.0.3",
"host-name": 123,
"comment": "Mobile",
}
DEVICE_1_WIRELESS = {
".id": "*264",
"interface": "wlan1",
@ -81,38 +89,16 @@ DEVICE_1_WIRELESS = {
}
DEVICE_2_WIRELESS = {
**DEVICE_1_WIRELESS,
".id": "*265",
"interface": "wlan1",
"mac-address": "00:00:00:00:00:02",
"ap": False,
"wds": False,
"bridge": False,
"rx-rate": "72.2Mbps-20MHz/1S/SGI",
"tx-rate": "72.2Mbps-20MHz/1S/SGI",
"packets": "59542,17464",
"bytes": "17536671,2966351",
"frames": "59542,17472",
"frame-bytes": "17655785,2862445",
"hw-frames": "78935,38395",
"hw-frame-bytes": "25636019,4063445",
"tx-frames-timed-out": 0,
"uptime": "5h49m36s",
"last-activity": "170ms",
"signal-strength": "-62@1Mbps",
"signal-to-noise": 52,
"signal-strength-ch0": -63,
"signal-strength-ch1": -69,
"strength-at-rates": "-62@1Mbps 16s330ms,-64@6Mbps 13s560ms,-65@HT20-3 52m6s30ms,-66@HT20-4 52m4s350ms,-66@HT20-5 51m58s580ms,-65@HT20-6 51m24s780ms,-65@HT20-7 5s680ms",
"tx-ccq": 93,
"p-throughput": 54928,
"last-ip": "0.0.0.2",
"802.1x-port-enabled": True,
"authentication-type": "wpa2-psk",
"encryption": "aes-ccm",
"group-encryption": "aes-ccm",
"management-protection": False,
"wmm-enabled": True,
"tx-rate-set": "OFDM:6-54 BW:1x SGI:1x HT:0-7",
}
DEVICE_3_WIRELESS = {
**DEVICE_1_WIRELESS,
".id": "*266",
"mac-address": "00:00:00:00:00:03",
"last-ip": "0.0.0.3",
}
DHCP_DATA = [DEVICE_1_DHCP, DEVICE_2_DHCP]

View file

@ -9,7 +9,15 @@ from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
from . import DEVICE_2_WIRELESS, DHCP_DATA, MOCK_DATA, MOCK_OPTIONS, WIRELESS_DATA
from . import (
DEVICE_2_WIRELESS,
DEVICE_3_DHCP_NUMERIC_NAME,
DEVICE_3_WIRELESS,
DHCP_DATA,
MOCK_DATA,
MOCK_OPTIONS,
WIRELESS_DATA,
)
from .test_hub import setup_mikrotik_entry
from tests.common import MockConfigEntry, patch
@ -27,6 +35,7 @@ def mock_device_registry_devices(hass):
(
"00:00:00:00:00:01",
"00:00:00:00:00:02",
"00:00:00:00:00:03",
)
):
dev_reg.async_get_or_create(
@ -115,6 +124,24 @@ async def test_device_trackers(hass, mock_device_registry_devices):
assert device_2.state == "not_home"
async def test_device_trackers_numerical_name(hass, mock_device_registry_devices):
"""Test device_trackers created by mikrotik with numerical device name."""
await setup_mikrotik_entry(
hass, dhcp_data=[DEVICE_3_DHCP_NUMERIC_NAME], wireless_data=[DEVICE_3_WIRELESS]
)
device_3 = hass.states.get("device_tracker.123")
assert device_3 is not None
assert device_3.state == "home"
assert device_3.attributes["friendly_name"] == "123"
assert device_3.attributes["ip"] == "0.0.0.3"
assert "ip_address" not in device_3.attributes
assert device_3.attributes["mac"] == "00:00:00:00:00:03"
assert device_3.attributes["host_name"] == 123
assert "mac_address" not in device_3.attributes
async def test_restoring_devices(hass):
"""Test restoring existing device_tracker entities if not detected on startup."""
config_entry = MockConfigEntry(