Skip to content

Commit

Permalink
Add Google Assistant SDK diagnostics (home-assistant#118513)
Browse files Browse the repository at this point in the history
  • Loading branch information
tronikos authored May 31, 2024
1 parent eae04bf commit 2b7685b
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
24 changes: 24 additions & 0 deletions homeassistant/components/google_assistant_sdk/diagnostics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Diagnostics support for Google Assistant SDK."""

from __future__ import annotations

from typing import Any

from homeassistant.components.diagnostics import async_redact_data
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant

TO_REDACT = {"access_token", "refresh_token"}


async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: ConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
return async_redact_data(
{
"data": entry.data,
"options": entry.options,
},
TO_REDACT,
)
1 change: 0 additions & 1 deletion script/hassfest/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ class QualityScale(IntEnum):
"dlna_dms",
"gdacs",
"geonetnz_quakes",
"google_assistant_sdk",
"hyperion",
# Modbus is excluded because it doesn't have to have a config flow
# according to ADR-0010, since it's a protocol integration. This
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# serializer version: 1
# name: test_diagnostics
dict({
'data': dict({
'auth_implementation': 'google_assistant_sdk',
'token': dict({
'access_token': '**REDACTED**',
'expires_at': 1717074000.0,
'refresh_token': '**REDACTED**',
'scope': 'https://www.googleapis.com/auth/assistant-sdk-prototype',
}),
}),
'options': dict({
'language_code': 'en-US',
}),
})
# ---
38 changes: 38 additions & 0 deletions tests/components/google_assistant_sdk/test_diagnostics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Tests for the diagnostics data provided by the Google Assistant SDK integration."""

from freezegun import freeze_time
import pytest
from syrupy.assertion import SnapshotAssertion

from homeassistant.components.google_assistant_sdk.const import CONF_LANGUAGE_CODE
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


@pytest.fixture(autouse=True)
def freeze_the_time():
"""Freeze the time."""
with freeze_time("2024-05-30 12:00:00", tz_offset=0):
yield


async def test_diagnostics(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
config_entry: MockConfigEntry,
snapshot: SnapshotAssertion,
) -> None:
"""Test diagnostics."""
config_entry.add_to_hass(hass)
hass.config_entries.async_update_entry(
config_entry,
options={CONF_LANGUAGE_CODE: "en-US"},
)
await hass.config_entries.async_setup(config_entry.entry_id)
assert (
await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
== snapshot
)

0 comments on commit 2b7685b

Please sign in to comment.