mirror of
https://github.com/home-assistant/core.git
synced 2026-07-12 17:18:04 +01:00
Add diagnostics support for stiebel_eltron integration (#175905)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
"""Diagnostics support for STIEBEL ELTRON."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.const import CONF_HOST
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import StiebelEltronConfigEntry
|
||||
|
||||
TO_REDACT = {CONF_HOST}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: StiebelEltronConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
return {
|
||||
"entry_data": async_redact_data(entry.data, TO_REDACT),
|
||||
"model": coordinator.device_info["model"],
|
||||
"modbus": {
|
||||
"is_connected": coordinator.api_client.is_connected,
|
||||
},
|
||||
"data": {
|
||||
"current_temp": coordinator.api_client.get_current_temp(),
|
||||
"target_temp": coordinator.api_client.get_target_temp(),
|
||||
"current_humidity": coordinator.api_client.get_current_humidity(),
|
||||
"operating_mode": coordinator.api_client.get_operation().name,
|
||||
"heating_status": coordinator.api_client.get_heating_status(),
|
||||
"cooling_status": coordinator.api_client.get_cooling_status(),
|
||||
"filter_alarm": coordinator.api_client.get_filter_alarm_status(),
|
||||
},
|
||||
}
|
||||
@@ -47,7 +47,7 @@ rules:
|
||||
|
||||
# Gold
|
||||
devices: done
|
||||
diagnostics: todo
|
||||
diagnostics: done
|
||||
discovery-update-info: todo
|
||||
discovery: todo
|
||||
docs-data-update: todo
|
||||
|
||||
@@ -44,9 +44,14 @@ def mock_lwz_api() -> Generator[MagicMock]:
|
||||
api_client.get_current_temp = MagicMock(return_value=21.0)
|
||||
api_client.get_current_humidity = MagicMock(return_value=45.0)
|
||||
api_client.get_operation = MagicMock(return_value=OperatingMode.AUTOMATIC)
|
||||
api_client.get_heating_status = MagicMock(return_value=True)
|
||||
api_client.get_cooling_status = MagicMock(return_value=False)
|
||||
api_client.get_filter_alarm_status = MagicMock(return_value=False)
|
||||
|
||||
api_client.connect = AsyncMock()
|
||||
def _connect() -> None:
|
||||
api_client.is_connected = True
|
||||
|
||||
api_client.connect = AsyncMock(side_effect=_connect)
|
||||
api_client.close = AsyncMock()
|
||||
api_client.async_update = AsyncMock()
|
||||
api_client.set_operation = AsyncMock()
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
# serializer version: 1
|
||||
# name: test_diagnostics
|
||||
dict({
|
||||
'data': dict({
|
||||
'cooling_status': False,
|
||||
'current_humidity': 45.0,
|
||||
'current_temp': 21.0,
|
||||
'filter_alarm': False,
|
||||
'heating_status': True,
|
||||
'operating_mode': 'AUTOMATIC',
|
||||
'target_temp': 22.5,
|
||||
}),
|
||||
'entry_data': dict({
|
||||
'host': '**REDACTED**',
|
||||
'port': 502,
|
||||
}),
|
||||
'modbus': dict({
|
||||
'is_connected': True,
|
||||
}),
|
||||
'model': 'LWZ',
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,26 @@
|
||||
"""Tests for STIEBEL ELTRON diagnostics."""
|
||||
|
||||
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
|
||||
|
||||
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert (
|
||||
await get_diagnostics_for_config_entry(hass, hass_client, mock_config_entry)
|
||||
== snapshot
|
||||
)
|
||||
Reference in New Issue
Block a user