forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add diagnostics to Autarco integration (home-assistant#121732)
- Loading branch information
1 parent
22c8935
commit bb81cfa
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}), | ||
}), | ||
]), | ||
}) | ||
# --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |