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 Google Assistant SDK diagnostics (home-assistant#118513)
- Loading branch information
Showing
4 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
homeassistant/components/google_assistant_sdk/diagnostics.py
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,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, | ||
) |
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
17 changes: 17 additions & 0 deletions
17
tests/components/google_assistant_sdk/snapshots/test_diagnostics.ambr
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,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', | ||
}), | ||
}) | ||
# --- |
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,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 | ||
) |