mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 00:37:13 +00:00
Add diagnostics to Autarco integration (#121732)
This commit is contained in:
parent
22c89356c0
commit
bb81cfa57a
33
homeassistant/components/autarco/diagnostics.py
Normal file
33
homeassistant/components/autarco/diagnostics.py
Normal file
@ -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
tests/components/autarco/snapshots/test_diagnostics.ambr
Normal file
18
tests/components/autarco/snapshots/test_diagnostics.ambr
Normal file
@ -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
tests/components/autarco/test_diagnostics.py
Normal file
30
tests/components/autarco/test_diagnostics.py
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user