Add diagnostics platform to pyLoad integration (#120535)
This commit is contained in:
parent
44aad2b821
commit
42d235ce4d
3 changed files with 71 additions and 0 deletions
26
homeassistant/components/pyload/diagnostics.py
Normal file
26
homeassistant/components/pyload/diagnostics.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
"""Diagnostics support for pyLoad."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from homeassistant.components.diagnostics import async_redact_data
|
||||||
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from . import PyLoadConfigEntry
|
||||||
|
from .coordinator import pyLoadData
|
||||||
|
|
||||||
|
TO_REDACT = {CONF_USERNAME, CONF_PASSWORD}
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_config_entry_diagnostics(
|
||||||
|
hass: HomeAssistant, config_entry: PyLoadConfigEntry
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Return diagnostics for a config entry."""
|
||||||
|
pyload_data: pyLoadData = config_entry.runtime_data.data
|
||||||
|
|
||||||
|
return {
|
||||||
|
"config_entry_data": async_redact_data(dict(config_entry.data), TO_REDACT),
|
||||||
|
"pyload_data": pyload_data,
|
||||||
|
}
|
17
tests/components/pyload/snapshots/test_diagnostics.ambr
Normal file
17
tests/components/pyload/snapshots/test_diagnostics.ambr
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
# serializer version: 1
|
||||||
|
# name: test_diagnostics
|
||||||
|
dict({
|
||||||
|
'config_entry_data': dict({
|
||||||
|
'host': 'pyload.local',
|
||||||
|
'password': '**REDACTED**',
|
||||||
|
'port': 8000,
|
||||||
|
'ssl': True,
|
||||||
|
'username': '**REDACTED**',
|
||||||
|
'verify_ssl': False,
|
||||||
|
}),
|
||||||
|
'pyload_data': dict({
|
||||||
|
'__type': "<class 'homeassistant.components.pyload.coordinator.pyLoadData'>",
|
||||||
|
'repr': 'pyLoadData(pause=False, active=1, queue=6, total=37, speed=5405963.0, download=True, reconnect=False, captcha=False, free_space=99999999999)',
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
# ---
|
28
tests/components/pyload/test_diagnostics.py
Normal file
28
tests/components/pyload/test_diagnostics.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
"""Tests for pyLoad diagnostics."""
|
||||||
|
|
||||||
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
|
|
||||||
|
async def test_diagnostics(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
hass_client: ClientSessionGenerator,
|
||||||
|
config_entry: MockConfigEntry,
|
||||||
|
mock_pyloadapi: AsyncMock,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
) -> None:
|
||||||
|
"""Test diagnostics."""
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
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)
|
||||||
|
== snapshot
|
||||||
|
)
|
Loading…
Add table
Add a link
Reference in a new issue