forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add diagnostics to Nice G.O. (home-assistant#124194)
- Loading branch information
Showing
3 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")) |