mirror of
https://github.com/home-assistant/core.git
synced 2026-04-02 00:20:30 +01:00
Add freshr diagnostics (#166912)
This commit is contained in:
34
homeassistant/components/freshr/diagnostics.py
Normal file
34
homeassistant/components/freshr/diagnostics.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""Diagnostics support for Fresh-r."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import dataclasses
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.const import CONF_PASSWORD
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .coordinator import FreshrConfigEntry
|
||||
|
||||
TO_REDACT = {CONF_PASSWORD}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: FreshrConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
runtime_data = entry.runtime_data
|
||||
|
||||
return {
|
||||
"entry": async_redact_data(entry.as_dict(), TO_REDACT),
|
||||
"devices": [
|
||||
dataclasses.asdict(device) for device in runtime_data.devices.data.values()
|
||||
],
|
||||
"readings": {
|
||||
device_id: dataclasses.asdict(coordinator.data)
|
||||
if coordinator.data is not None
|
||||
else None
|
||||
for device_id, coordinator in runtime_data.readings.items()
|
||||
},
|
||||
}
|
||||
@@ -41,7 +41,7 @@ rules:
|
||||
|
||||
# Gold
|
||||
devices: done
|
||||
diagnostics: todo
|
||||
diagnostics: done
|
||||
discovery-update-info:
|
||||
status: exempt
|
||||
comment: Integration connects to a cloud service; no local network discovery is possible.
|
||||
|
||||
53
tests/components/freshr/snapshots/test_diagnostics.ambr
Normal file
53
tests/components/freshr/snapshots/test_diagnostics.ambr
Normal file
@@ -0,0 +1,53 @@
|
||||
# serializer version: 1
|
||||
# name: test_diagnostics
|
||||
dict({
|
||||
'devices': list([
|
||||
dict({
|
||||
'active_from': None,
|
||||
'extras': dict({
|
||||
}),
|
||||
'id': 'SN001',
|
||||
'type': 'unknown',
|
||||
}),
|
||||
]),
|
||||
'entry': dict({
|
||||
'created_at': '2026-01-01T00:00:00+00:00',
|
||||
'data': dict({
|
||||
'password': '**REDACTED**',
|
||||
'username': 'test-user',
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'discovery_keys': dict({
|
||||
}),
|
||||
'domain': 'freshr',
|
||||
'entry_id': '01JKRA6QKPBE00ZZ9BKWDB3CTB',
|
||||
'minor_version': 1,
|
||||
'modified_at': '2026-01-01T00:00:00+00:00',
|
||||
'options': dict({
|
||||
}),
|
||||
'pref_disable_new_entities': False,
|
||||
'pref_disable_polling': False,
|
||||
'source': 'user',
|
||||
'subentries': list([
|
||||
]),
|
||||
'title': 'Mock Title',
|
||||
'unique_id': 'test-user',
|
||||
'version': 1,
|
||||
}),
|
||||
'readings': dict({
|
||||
'SN001': dict({
|
||||
'co2': 850,
|
||||
'dp': 10.2,
|
||||
'extras': dict({
|
||||
}),
|
||||
'flow': 0.12,
|
||||
'hum': 45,
|
||||
't1': 21.5,
|
||||
't2': 5.3,
|
||||
't3': None,
|
||||
't4': None,
|
||||
'temp': None,
|
||||
}),
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
25
tests/components/freshr/test_diagnostics.py
Normal file
25
tests/components/freshr/test_diagnostics.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""Test the Fresh-r diagnostics."""
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion 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
|
||||
|
||||
|
||||
@pytest.mark.freeze_time("2026-01-01T00:00:00+00:00")
|
||||
@pytest.mark.usefixtures("init_integration")
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
snapshot: SnapshotAssertion,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test diagnostics."""
|
||||
assert (
|
||||
await get_diagnostics_for_config_entry(hass, hass_client, mock_config_entry)
|
||||
== snapshot
|
||||
)
|
||||
Reference in New Issue
Block a user