Skip to content

Commit

Permalink
Add diagnostics to Autarco integration (home-assistant#121732)
Browse files Browse the repository at this point in the history
  • Loading branch information
klaasnicolaas authored Jul 11, 2024
1 parent 22c8935 commit bb81cfa
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
33 changes: 33 additions & 0 deletions homeassistant/components/autarco/diagnostics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Support for the Autarco diagnostics."""

from __future__ import annotations

from typing import Any

from homeassistant.core import HomeAssistant

from . import AutarcoConfigEntry, AutarcoDataUpdateCoordinator


async def async_get_config_entry_diagnostics(
hass: HomeAssistant, config_entry: AutarcoConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
autarco_data: list[AutarcoDataUpdateCoordinator] = config_entry.runtime_data

return {
"sites_data": [
{
"id": coordinator.site.site_id,
"name": coordinator.site.system_name,
"health": coordinator.site.health,
"solar": {
"power_production": coordinator.data.solar.power_production,
"energy_production_today": coordinator.data.solar.energy_production_today,
"energy_production_month": coordinator.data.solar.energy_production_month,
"energy_production_total": coordinator.data.solar.energy_production_total,
},
}
for coordinator in autarco_data
],
}
18 changes: 18 additions & 0 deletions tests/components/autarco/snapshots/test_diagnostics.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# serializer version: 1
# name: test_entry_diagnostics
dict({
'sites_data': list([
dict({
'health': 'OK',
'id': 1,
'name': 'test-system',
'solar': dict({
'energy_production_month': 58,
'energy_production_today': 4,
'energy_production_total': 10379,
'power_production': 200,
}),
}),
]),
})
# ---
30 changes: 30 additions & 0 deletions tests/components/autarco/test_diagnostics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Test Autarco diagnostics."""

from unittest.mock import AsyncMock

from syrupy 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


async def test_entry_diagnostics(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
mock_autarco_client: AsyncMock,
mock_config_entry: MockConfigEntry,
snapshot: SnapshotAssertion,
) -> None:
"""Test config entry diagnostics."""
await setup_integration(hass, mock_config_entry)

result = await get_diagnostics_for_config_entry(
hass, hass_client, mock_config_entry
)

assert result == snapshot

0 comments on commit bb81cfa

Please sign in to comment.