mirror of
https://github.com/home-assistant/core.git
synced 2026-09-25 17:04:04 -04:00
WeHeat - Diagnostics (#181262)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
dbf135a2ef
commit
bafc126de8
@@ -0,0 +1,30 @@
|
||||
"""Diagnostics support for Weheat."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .coordinator import WeheatConfigEntry
|
||||
|
||||
TO_REDACT = {"heat_pump_id", "uuid", "sn"}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: WeheatConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
return {
|
||||
"heat_pumps": [
|
||||
{
|
||||
"info": async_redact_data(vars(weheatdata.heat_pump_info), TO_REDACT),
|
||||
"logs": async_redact_data(
|
||||
weheatdata.data_coordinator.data.raw_content or {}, TO_REDACT
|
||||
),
|
||||
"energy": async_redact_data(
|
||||
weheatdata.energy_coordinator.data.raw_content or {}, TO_REDACT
|
||||
),
|
||||
}
|
||||
for weheatdata in entry.runtime_data
|
||||
]
|
||||
}
|
||||
@@ -54,7 +54,7 @@ rules:
|
||||
|
||||
# Gold
|
||||
devices: done
|
||||
diagnostics: todo
|
||||
diagnostics: done
|
||||
discovery-update-info:
|
||||
status: exempt
|
||||
comment: |
|
||||
|
||||
@@ -140,6 +140,11 @@ def mock_weheat_heat_pump_instance() -> MagicMock:
|
||||
mock_heat_pump_instance.indoor_unit_dhw_valve_or_pump_state = None
|
||||
mock_heat_pump_instance.indoor_unit_gas_boiler_state = False
|
||||
mock_heat_pump_instance.indoor_unit_electric_heater_state = True
|
||||
mock_heat_pump_instance.raw_content = {
|
||||
"heat_pump_id": TEST_HP_UUID,
|
||||
"t_water_in": 11,
|
||||
"total_ein_heating": 12345,
|
||||
}
|
||||
|
||||
return mock_heat_pump_instance
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
# serializer version: 1
|
||||
# name: test_diagnostics
|
||||
dict({
|
||||
'heat_pumps': list([
|
||||
dict({
|
||||
'energy': dict({
|
||||
'heat_pump_id': '**REDACTED**',
|
||||
't_water_in': 11,
|
||||
'total_ein_heating': 12345,
|
||||
}),
|
||||
'info': dict({
|
||||
'device_name': None,
|
||||
'has_ch_boiler': False,
|
||||
'has_dhw': True,
|
||||
'model': 'Test Model',
|
||||
'sn': '**REDACTED**',
|
||||
'uuid': '**REDACTED**',
|
||||
}),
|
||||
'logs': dict({
|
||||
'heat_pump_id': '**REDACTED**',
|
||||
't_water_in': 11,
|
||||
'total_ein_heating': 12345,
|
||||
}),
|
||||
}),
|
||||
]),
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,50 @@
|
||||
"""Tests for the weheat diagnostics."""
|
||||
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import setup_integration
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_weheat_discover", "mock_weheat_heat_pump")
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test the diagnostics of a config entry."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert (
|
||||
await get_diagnostics_for_config_entry(hass, hass_client, mock_config_entry)
|
||||
== snapshot
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_weheat_discover")
|
||||
async def test_diagnostics_without_data(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_weheat_heat_pump: AsyncMock,
|
||||
) -> None:
|
||||
"""Test the diagnostics of a heat pump that reported nothing yet."""
|
||||
mock_weheat_heat_pump.raw_content = None
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
diagnostics = await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, mock_config_entry
|
||||
)
|
||||
|
||||
assert diagnostics["heat_pumps"][0]["logs"] == {}
|
||||
assert diagnostics["heat_pumps"][0]["energy"] == {}
|
||||
Reference in New Issue
Block a user