Add FTTH and WAN info to SFR box diagnostics (#89492)
* Add FTTH and WAN info to SFR box diagnostics * Adjust tests * Use snapshotspull/89515/head
parent
74d4a26f97
commit
96bd714364
|
@ -27,8 +27,14 @@ async def async_get_config_entry_diagnostics(
|
|||
},
|
||||
"data": {
|
||||
"dsl": async_redact_data(dataclasses.asdict(data.dsl.data), TO_REDACT),
|
||||
"ftth": async_redact_data(
|
||||
dataclasses.asdict(await data.system.box.ftth_get_info()), TO_REDACT
|
||||
),
|
||||
"system": async_redact_data(
|
||||
dataclasses.asdict(data.system.data), TO_REDACT
|
||||
),
|
||||
"wan": async_redact_data(
|
||||
dataclasses.asdict(await data.system.box.wan_get_info()), TO_REDACT
|
||||
),
|
||||
},
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import json
|
|||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
from sfrbox_api.models import DslInfo, SystemInfo
|
||||
from sfrbox_api.models import DslInfo, FtthInfo, SystemInfo, WanInfo
|
||||
|
||||
from homeassistant.components.sfr_box.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_USER, ConfigEntry
|
||||
|
@ -57,17 +57,6 @@ def get_config_entry_with_auth(hass: HomeAssistant) -> ConfigEntry:
|
|||
return config_entry_with_auth
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def system_get_info() -> Generator[SystemInfo, None, None]:
|
||||
"""Fixture for SFRBox.system_get_info."""
|
||||
system_info = SystemInfo(**json.loads(load_fixture("system_getInfo.json", DOMAIN)))
|
||||
with patch(
|
||||
"homeassistant.components.sfr_box.coordinator.SFRBox.system_get_info",
|
||||
return_value=system_info,
|
||||
):
|
||||
yield system_info
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def dsl_get_info() -> Generator[DslInfo, None, None]:
|
||||
"""Fixture for SFRBox.dsl_get_info."""
|
||||
|
@ -77,3 +66,36 @@ def dsl_get_info() -> Generator[DslInfo, None, None]:
|
|||
return_value=dsl_info,
|
||||
):
|
||||
yield dsl_info
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ftth_get_info() -> Generator[FtthInfo, None, None]:
|
||||
"""Fixture for SFRBox.ftth_get_info."""
|
||||
info = FtthInfo(**json.loads(load_fixture("ftth_getInfo.json", DOMAIN)))
|
||||
with patch(
|
||||
"homeassistant.components.sfr_box.coordinator.SFRBox.ftth_get_info",
|
||||
return_value=info,
|
||||
):
|
||||
yield info
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def system_get_info() -> Generator[SystemInfo, None, None]:
|
||||
"""Fixture for SFRBox.system_get_info."""
|
||||
info = SystemInfo(**json.loads(load_fixture("system_getInfo.json", DOMAIN)))
|
||||
with patch(
|
||||
"homeassistant.components.sfr_box.coordinator.SFRBox.system_get_info",
|
||||
return_value=info,
|
||||
):
|
||||
yield info
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def wan_get_info() -> Generator[WanInfo, None, None]:
|
||||
"""Fixture for SFRBox.wan_get_info."""
|
||||
info = WanInfo(**json.loads(load_fixture("wan_getInfo.json", DOMAIN)))
|
||||
with patch(
|
||||
"homeassistant.components.sfr_box.coordinator.SFRBox.wan_get_info",
|
||||
return_value=info,
|
||||
):
|
||||
yield info
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"status": "down",
|
||||
"wanfibre": "out"
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"status": "up",
|
||||
"uptime": 297464,
|
||||
"ip_addr": "1.2.3.4",
|
||||
"infra": "adsl",
|
||||
"mode": "adsl/routed",
|
||||
"infra6": "",
|
||||
"status6": "down",
|
||||
"uptime6": null,
|
||||
"ipv6_addr": ""
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
# serializer version: 1
|
||||
# name: test_entry_diagnostics
|
||||
dict({
|
||||
'data': dict({
|
||||
'dsl': dict({
|
||||
'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,
|
||||
}),
|
||||
'ftth': dict({
|
||||
'status': 'down',
|
||||
'wanfibre': 'out',
|
||||
}),
|
||||
'system': dict({
|
||||
'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',
|
||||
}),
|
||||
'wan': dict({
|
||||
'infra': 'adsl',
|
||||
'infra6': '',
|
||||
'ip_addr': '1.2.3.4',
|
||||
'ipv6_addr': '',
|
||||
'mode': 'adsl/routed',
|
||||
'status': 'up',
|
||||
'status6': 'down',
|
||||
'uptime': 297464,
|
||||
'uptime6': None,
|
||||
}),
|
||||
}),
|
||||
'entry': dict({
|
||||
'data': dict({
|
||||
'host': '192.168.0.1',
|
||||
}),
|
||||
'title': 'Mock Title',
|
||||
}),
|
||||
})
|
||||
# ---
|
|
@ -3,15 +3,17 @@ from collections.abc import Generator
|
|||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
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
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("system_get_info", "dsl_get_info")
|
||||
pytestmark = pytest.mark.usefixtures(
|
||||
"dsl_get_info", "ftth_get_info", "system_get_info", "wan_get_info"
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
@ -22,49 +24,16 @@ def override_platforms() -> Generator[None, None, None]:
|
|||
|
||||
|
||||
async def test_entry_diagnostics(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry, hass_client: ClientSessionGenerator
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
hass_client: ClientSessionGenerator,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> 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",
|
||||
},
|
||||
},
|
||||
}
|
||||
assert (
|
||||
await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
|
||||
== snapshot
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue