Add diagnostics to Nice G.O. (#124194)
This commit is contained in:
parent
d9c98316fd
commit
013b91394e
3 changed files with 60 additions and 1 deletions
30
homeassistant/components/nice_go/diagnostics.py
Normal file
30
homeassistant/components/nice_go/diagnostics.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
"""Diagnostics support for Nice G.O.."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from dataclasses import asdict
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from homeassistant.components.diagnostics import async_redact_data
|
||||||
|
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from . import NiceGOConfigEntry
|
||||||
|
from .const import CONF_REFRESH_TOKEN
|
||||||
|
|
||||||
|
TO_REDACT = {CONF_PASSWORD, CONF_EMAIL, CONF_REFRESH_TOKEN, "title", "unique_id"}
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_config_entry_diagnostics(
|
||||||
|
hass: HomeAssistant, entry: NiceGOConfigEntry
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Return diagnostics for a config entry."""
|
||||||
|
coordinator = entry.runtime_data
|
||||||
|
|
||||||
|
return {
|
||||||
|
"entry": async_redact_data(entry.as_dict(), TO_REDACT),
|
||||||
|
"coordinator_data": {
|
||||||
|
device_id: asdict(device_data)
|
||||||
|
for device_id, device_data in coordinator.data.items()
|
||||||
|
},
|
||||||
|
}
|
|
@ -36,7 +36,7 @@
|
||||||
'pref_disable_polling': False,
|
'pref_disable_polling': False,
|
||||||
'source': 'user',
|
'source': 'user',
|
||||||
'title': '**REDACTED**',
|
'title': '**REDACTED**',
|
||||||
'unique_id': None,
|
'unique_id': '**REDACTED**',
|
||||||
'version': 1,
|
'version': 1,
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
29
tests/components/nice_go/test_diagnostics.py
Normal file
29
tests/components/nice_go/test_diagnostics.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
"""Test diagnostics of Nice G.O.."""
|
||||||
|
|
||||||
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
|
from syrupy import SnapshotAssertion
|
||||||
|
from syrupy.filters import props
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from . import setup_integration
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
|
|
||||||
|
async def test_entry_diagnostics(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
hass_client: ClientSessionGenerator,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
mock_nice_go: AsyncMock,
|
||||||
|
mock_config_entry: MockConfigEntry,
|
||||||
|
) -> None:
|
||||||
|
"""Test config entry diagnostics."""
|
||||||
|
await setup_integration(hass, mock_config_entry, [])
|
||||||
|
result = await get_diagnostics_for_config_entry(
|
||||||
|
hass, hass_client, mock_config_entry
|
||||||
|
)
|
||||||
|
assert result == snapshot(exclude=props("created_at", "modified_at"))
|
Loading…
Add table
Reference in a new issue