mirror of
https://github.com/home-assistant/core
synced 2024-07-21 02:25:24 +00:00
Add diagnostics for tedee (#106662)
* add diagnostics * don't redact lock name * Update test_diagnostics.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
b27e830997
commit
97a5f0b2af
28
homeassistant/components/tedee/diagnostics.py
Normal file
28
homeassistant/components/tedee/diagnostics.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
"""Diagnostics support for tedee."""
|
||||
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
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import TedeeApiCoordinator
|
||||
|
||||
TO_REDACT = {
|
||||
"lock_id",
|
||||
}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: ConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator: TedeeApiCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
# dict has sensitive info as key, redact manually
|
||||
data = {
|
||||
index: lock.to_dict()
|
||||
for index, (_, lock) in enumerate(coordinator.tedee_client.locks_dict.items())
|
||||
}
|
||||
return async_redact_data(data, TO_REDACT)
|
29
tests/components/tedee/snapshots/test_diagnostics.ambr
Normal file
29
tests/components/tedee/snapshots/test_diagnostics.ambr
Normal file
|
@ -0,0 +1,29 @@
|
|||
# serializer version: 1
|
||||
# name: test_diagnostics
|
||||
dict({
|
||||
'0': dict({
|
||||
'battery_level': 70,
|
||||
'duration_pullspring': 2,
|
||||
'is_charging': False,
|
||||
'is_connected': True,
|
||||
'is_enabled_pullspring': 1,
|
||||
'lock_id': '**REDACTED**',
|
||||
'lock_name': 'Lock-1A2B',
|
||||
'lock_type': 2,
|
||||
'state': 2,
|
||||
'state_change_result': 0,
|
||||
}),
|
||||
'1': dict({
|
||||
'battery_level': 70,
|
||||
'duration_pullspring': 0,
|
||||
'is_charging': False,
|
||||
'is_connected': True,
|
||||
'is_enabled_pullspring': 0,
|
||||
'lock_id': '**REDACTED**',
|
||||
'lock_name': 'Lock-2C3D',
|
||||
'lock_type': 4,
|
||||
'state': 2,
|
||||
'state_change_result': 0,
|
||||
}),
|
||||
})
|
||||
# ---
|
21
tests/components/tedee/test_diagnostics.py
Normal file
21
tests/components/tedee/test_diagnostics.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
"""Tests for the diagnostics data provided by the Tedee integration."""
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
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
|
||||
|
||||
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
init_integration: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test diagnostics."""
|
||||
assert (
|
||||
await get_diagnostics_for_config_entry(hass, hass_client, init_integration)
|
||||
== snapshot
|
||||
)
|
Loading…
Reference in a new issue