mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Add diagnostics to Waze Travel Time (#193937)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
81cc787145
commit
ddb4b3814f
@@ -0,0 +1,40 @@
|
||||
"""Diagnostics support for Waze Travel Time."""
|
||||
|
||||
from dataclasses import asdict
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import (
|
||||
CONF_BASE_COORDINATES,
|
||||
CONF_DESTINATION,
|
||||
CONF_EXCL_FILTER,
|
||||
CONF_INCL_FILTER,
|
||||
CONF_ORIGIN,
|
||||
)
|
||||
from .coordinator import WazeTravelTimeConfigEntry
|
||||
|
||||
# The name and the street filters often point to home or work.
|
||||
TO_REDACT = {
|
||||
CONF_BASE_COORDINATES,
|
||||
CONF_DESTINATION,
|
||||
CONF_EXCL_FILTER,
|
||||
CONF_INCL_FILTER,
|
||||
CONF_NAME,
|
||||
CONF_ORIGIN,
|
||||
}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: WazeTravelTimeConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator = entry.runtime_data
|
||||
return {
|
||||
"data": async_redact_data(entry.data, TO_REDACT),
|
||||
"options": async_redact_data(entry.options, TO_REDACT),
|
||||
"last_update_success": coordinator.last_update_success,
|
||||
"coordinator_data": async_redact_data(asdict(coordinator.data), TO_REDACT),
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
# serializer version: 1
|
||||
# name: test_diagnostics[name_filters_and_base_coordinates]
|
||||
dict({
|
||||
'coordinator_data': dict({
|
||||
'destination': '**REDACTED**',
|
||||
'distance': 300,
|
||||
'duration': 150,
|
||||
'origin': '**REDACTED**',
|
||||
'route': 'E1337 - Teststreet',
|
||||
}),
|
||||
'data': dict({
|
||||
'destination': '**REDACTED**',
|
||||
'name': '**REDACTED**',
|
||||
'origin': '**REDACTED**',
|
||||
'region': 'US',
|
||||
}),
|
||||
'last_update_success': True,
|
||||
'options': dict({
|
||||
'avoid_ferries': False,
|
||||
'avoid_subscription_roads': False,
|
||||
'avoid_toll_roads': False,
|
||||
'base_coordinates': '**REDACTED**',
|
||||
'excl_filter': '**REDACTED**',
|
||||
'incl_filter': '**REDACTED**',
|
||||
'realtime': True,
|
||||
'time_delta': dict({
|
||||
'minutes': 0,
|
||||
}),
|
||||
'units': 'metric',
|
||||
'vehicle_type': 'car',
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,43 @@
|
||||
"""Test Waze Travel Time diagnostics."""
|
||||
|
||||
import pytest
|
||||
from pytest_homeassistant.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from pytest_homeassistant.typing import ClientSessionGenerator
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.waze_travel_time.const import (
|
||||
CONF_BASE_COORDINATES,
|
||||
CONF_EXCL_FILTER,
|
||||
CONF_INCL_FILTER,
|
||||
DEFAULT_OPTIONS,
|
||||
)
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import MOCK_CONFIG
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("data", "options"),
|
||||
[
|
||||
pytest.param(
|
||||
{**MOCK_CONFIG, CONF_NAME: "Home to work"},
|
||||
{
|
||||
**DEFAULT_OPTIONS,
|
||||
CONF_INCL_FILTER: ["IncludeThis"],
|
||||
CONF_EXCL_FILTER: ["ExcludeThis"],
|
||||
CONF_BASE_COORDINATES: {CONF_LATITUDE: 52.52, CONF_LONGITUDE: 13.4},
|
||||
},
|
||||
id="name_filters_and_base_coordinates",
|
||||
)
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("mock_update", "mock_config")
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
entry = hass.config_entries.async_get_entry("test")
|
||||
assert await get_diagnostics_for_config_entry(hass, hass_client, entry) == snapshot
|
||||
Reference in New Issue
Block a user