Add OUI to tplink diagnostics (#97646)
* Add OUI to tplink diagnostics The main reason discovery does not work for new devices is we are missing the OUI. Since we redact the whole mac address in the diagnostics, this makes it difficult to fix. We now include the OUI in the diagnostics * fix: use cached mac * fix: testspull/97752/head
parent
d1f8309423
commit
0cc80a9d29
|
@ -6,6 +6,7 @@ from typing import Any
|
|||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import format_mac
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import TPLinkDataUpdateCoordinator
|
||||
|
@ -36,6 +37,8 @@ async def async_get_config_entry_diagnostics(
|
|||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator: TPLinkDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
oui = format_mac(coordinator.device.mac)[:8].upper()
|
||||
return async_redact_data(
|
||||
{"device_last_response": coordinator.device.internal_state}, TO_REDACT
|
||||
{"device_last_response": coordinator.device.internal_state, "oui": oui},
|
||||
TO_REDACT,
|
||||
)
|
||||
|
|
|
@ -14,17 +14,19 @@ from tests.typing import ClientSessionGenerator
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("mocked_dev", "fixture_file", "sysinfo_vars"),
|
||||
("mocked_dev", "fixture_file", "sysinfo_vars", "expected_oui"),
|
||||
[
|
||||
(
|
||||
_mocked_bulb(),
|
||||
"tplink-diagnostics-data-bulb-kl130.json",
|
||||
["mic_mac", "deviceId", "oemId", "hwId", "alias"],
|
||||
"AA:BB:CC",
|
||||
),
|
||||
(
|
||||
_mocked_plug(),
|
||||
"tplink-diagnostics-data-plug-hs110.json",
|
||||
["mac", "deviceId", "oemId", "hwId", "alias", "longitude_i", "latitude_i"],
|
||||
"AA:BB:CC",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
@ -34,6 +36,7 @@ async def test_diagnostics(
|
|||
mocked_dev: SmartDevice,
|
||||
fixture_file: str,
|
||||
sysinfo_vars: list[str],
|
||||
expected_oui: str | None,
|
||||
):
|
||||
"""Test diagnostics for config entry."""
|
||||
diagnostics_data = json.loads(load_fixture(fixture_file, "tplink"))
|
||||
|
@ -58,3 +61,5 @@ async def test_diagnostics(
|
|||
sysinfo = last_response["system"]["get_sysinfo"]
|
||||
for var in sysinfo_vars:
|
||||
assert sysinfo[var] == "**REDACTED**"
|
||||
|
||||
assert result["oui"] == expected_oui
|
||||
|
|
Loading…
Reference in New Issue