mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Add diagnostics for Home Assistant Backup integration (#141407)
add diagnostics platform
This commit is contained in:
parent
e95f2c4282
commit
d954d04d12
27
homeassistant/components/backup/diagnostics.py
Normal file
27
homeassistant/components/backup/diagnostics.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
"""Diagnostics support for Home Assistant Backup integration."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from homeassistant.components.diagnostics import async_redact_data
|
||||||
|
from homeassistant.const import CONF_PASSWORD
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from .coordinator import BackupConfigEntry
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_config_entry_diagnostics(
|
||||||
|
hass: HomeAssistant, entry: BackupConfigEntry
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Return diagnostics for a config entry."""
|
||||||
|
coordinator = entry.runtime_data
|
||||||
|
return {
|
||||||
|
"backup_agents": [
|
||||||
|
{"name": agent.name, "agent_id": agent.agent_id}
|
||||||
|
for agent in coordinator.backup_manager.backup_agents.values()
|
||||||
|
],
|
||||||
|
"backup_config": async_redact_data(
|
||||||
|
coordinator.backup_manager.config.data.to_dict(), [CONF_PASSWORD]
|
||||||
|
),
|
||||||
|
}
|
39
tests/components/backup/snapshots/test_diagnostics.ambr
Normal file
39
tests/components/backup/snapshots/test_diagnostics.ambr
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# serializer version: 1
|
||||||
|
# name: test_diagnostics
|
||||||
|
dict({
|
||||||
|
'backup_agents': list([
|
||||||
|
dict({
|
||||||
|
'agent_id': 'backup.local',
|
||||||
|
'name': 'local',
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
'backup_config': dict({
|
||||||
|
'agents': dict({
|
||||||
|
}),
|
||||||
|
'automatic_backups_configured': False,
|
||||||
|
'create_backup': dict({
|
||||||
|
'agent_ids': list([
|
||||||
|
]),
|
||||||
|
'include_addons': None,
|
||||||
|
'include_all_addons': False,
|
||||||
|
'include_database': True,
|
||||||
|
'include_folders': None,
|
||||||
|
'name': None,
|
||||||
|
'password': None,
|
||||||
|
}),
|
||||||
|
'last_attempted_automatic_backup': None,
|
||||||
|
'last_completed_automatic_backup': None,
|
||||||
|
'retention': dict({
|
||||||
|
'copies': None,
|
||||||
|
'days': None,
|
||||||
|
}),
|
||||||
|
'schedule': dict({
|
||||||
|
'days': list([
|
||||||
|
]),
|
||||||
|
'recurrence': 'never',
|
||||||
|
'state': 'never',
|
||||||
|
'time': None,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
# ---
|
26
tests/components/backup/test_diagnostics.py
Normal file
26
tests/components/backup/test_diagnostics.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
"""Tests the diagnostics for Home Assistant Backup integration."""
|
||||||
|
|
||||||
|
from syrupy import SnapshotAssertion
|
||||||
|
|
||||||
|
from homeassistant.components.backup.const import DOMAIN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from .common import setup_backup_integration
|
||||||
|
|
||||||
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
|
|
||||||
|
async def test_diagnostics(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
hass_client: ClientSessionGenerator,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
) -> None:
|
||||||
|
"""Test diagnostics."""
|
||||||
|
await setup_backup_integration(hass, with_hassio=False)
|
||||||
|
await hass.async_block_till_done(wait_background_tasks=True)
|
||||||
|
|
||||||
|
entry = hass.config_entries.async_entries(DOMAIN)[0]
|
||||||
|
diag_data = await get_diagnostics_for_config_entry(hass, hass_client, entry)
|
||||||
|
|
||||||
|
assert diag_data == snapshot
|
Loading…
x
Reference in New Issue
Block a user