mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Add diagnostics platform to SFR Box (#85500)
This commit is contained in:
parent
02357193ad
commit
de2588f6e0
34
homeassistant/components/sfr_box/diagnostics.py
Normal file
34
homeassistant/components/sfr_box/diagnostics.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
"""SFR Box diagnostics platform."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import dataclasses
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from homeassistant.components.diagnostics import async_redact_data
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from .const import DOMAIN
|
||||||
|
from .models import DomainData
|
||||||
|
|
||||||
|
TO_REDACT = {"mac_addr", "serial_number"}
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_config_entry_diagnostics(
|
||||||
|
hass: HomeAssistant, entry: ConfigEntry
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Return diagnostics for a config entry."""
|
||||||
|
data: DomainData = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
|
||||||
|
return {
|
||||||
|
"entry": {
|
||||||
|
"title": entry.title,
|
||||||
|
"data": dict(entry.data),
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"dsl": async_redact_data(dataclasses.asdict(data.dsl.data), TO_REDACT),
|
||||||
|
"system": async_redact_data(
|
||||||
|
dataclasses.asdict(data.system.data), TO_REDACT
|
||||||
|
),
|
||||||
|
},
|
||||||
|
}
|
69
tests/components/sfr_box/test_diagnostics.py
Normal file
69
tests/components/sfr_box/test_diagnostics.py
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
"""Test the SFR Box diagnostics."""
|
||||||
|
from collections.abc import Generator
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.components.diagnostics import REDACTED
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||||
|
|
||||||
|
pytestmark = pytest.mark.usefixtures("system_get_info", "dsl_get_info")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def override_platforms() -> Generator[None, None, None]:
|
||||||
|
"""Override PLATFORMS."""
|
||||||
|
with patch("homeassistant.components.sfr_box.PLATFORMS", []):
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
async def test_entry_diagnostics(
|
||||||
|
hass: HomeAssistant, config_entry: ConfigEntry, hass_client
|
||||||
|
) -> None:
|
||||||
|
"""Test config entry diagnostics."""
|
||||||
|
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
|
||||||
|
"entry": {
|
||||||
|
"data": {"host": "192.168.0.1"},
|
||||||
|
"title": "Mock Title",
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"dsl": {
|
||||||
|
"attenuation_down": 28.5,
|
||||||
|
"attenuation_up": 20.8,
|
||||||
|
"counter": 16,
|
||||||
|
"crc": 0,
|
||||||
|
"line_status": "No Defect",
|
||||||
|
"linemode": "ADSL2+",
|
||||||
|
"noise_down": 5.8,
|
||||||
|
"noise_up": 6.0,
|
||||||
|
"rate_down": 5549,
|
||||||
|
"rate_up": 187,
|
||||||
|
"status": "up",
|
||||||
|
"training": "Showtime",
|
||||||
|
"uptime": 450796,
|
||||||
|
},
|
||||||
|
"system": {
|
||||||
|
"alimvoltage": 12251,
|
||||||
|
"current_datetime": "202212282233",
|
||||||
|
"idur": "RP3P85K",
|
||||||
|
"mac_addr": REDACTED,
|
||||||
|
"net_infra": "adsl",
|
||||||
|
"net_mode": "router",
|
||||||
|
"product_id": "NB6VAC-FXC-r0",
|
||||||
|
"refclient": "",
|
||||||
|
"serial_number": REDACTED,
|
||||||
|
"temperature": 27560,
|
||||||
|
"uptime": 2353575,
|
||||||
|
"version_bootloader": "NB6VAC-BOOTLOADER-R4.0.8",
|
||||||
|
"version_dsldriver": "NB6VAC-XDSL-A2pv6F039p",
|
||||||
|
"version_mainfirmware": "NB6VAC-MAIN-R4.0.44k",
|
||||||
|
"version_rescuefirmware": "NB6VAC-MAIN-R4.0.44k",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user