Add diagnostics to solarlog (#125072)
* Add diagnostics to solarlog * Fix wrong comment
This commit is contained in:
parent
633c904852
commit
7c4fd9473c
3 changed files with 123 additions and 0 deletions
27
homeassistant/components/solarlog/diagnostics.py
Normal file
27
homeassistant/components/solarlog/diagnostics.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
"""Provides diagnostics for Solarlog."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
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 SolarlogConfigEntry
|
||||
|
||||
TO_REDACT = [
|
||||
CONF_HOST,
|
||||
]
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, config_entry: SolarlogConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
data = config_entry.runtime_data.data
|
||||
|
||||
return {
|
||||
"config_entry": async_redact_data(config_entry.as_dict(), TO_REDACT),
|
||||
"solarlog_data": data.to_dict(),
|
||||
}
|
64
tests/components/solarlog/snapshots/test_diagnostics.ambr
Normal file
64
tests/components/solarlog/snapshots/test_diagnostics.ambr
Normal file
|
@ -0,0 +1,64 @@
|
|||
# serializer version: 1
|
||||
# name: test_entry_diagnostics
|
||||
dict({
|
||||
'config_entry': dict({
|
||||
'data': dict({
|
||||
'extended_data': True,
|
||||
'host': '**REDACTED**',
|
||||
'name': 'Solarlog test 1 2 3',
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'domain': 'solarlog',
|
||||
'entry_id': 'ce5f5431554d101905d31797e1232da8',
|
||||
'minor_version': 2,
|
||||
'options': dict({
|
||||
}),
|
||||
'pref_disable_new_entities': False,
|
||||
'pref_disable_polling': False,
|
||||
'source': 'user',
|
||||
'title': 'solarlog',
|
||||
'unique_id': None,
|
||||
'version': 1,
|
||||
}),
|
||||
'solarlog_data': dict({
|
||||
'alternator_loss': 2.0,
|
||||
'capacity': 85.5,
|
||||
'consumption_ac': 54.87,
|
||||
'consumption_day': 5.31,
|
||||
'consumption_month': 758.0,
|
||||
'consumption_total': 354687.0,
|
||||
'consumption_year': 4587.0,
|
||||
'consumption_yesterday': 7.34,
|
||||
'efficiency': 98.1,
|
||||
'inverter_data': dict({
|
||||
'0': dict({
|
||||
'consumption_year': 354687,
|
||||
'current_power': 5,
|
||||
'enabled': True,
|
||||
'name': 'Inverter 1',
|
||||
}),
|
||||
'1': dict({
|
||||
'consumption_year': 354,
|
||||
'current_power': 6,
|
||||
'enabled': True,
|
||||
'name': 'Inverter 2',
|
||||
}),
|
||||
}),
|
||||
'last_updated': '2024-08-01T15:20:45+00:00',
|
||||
'power_ac': 100.0,
|
||||
'power_available': 45.13,
|
||||
'power_dc': 102.0,
|
||||
'production_year': None,
|
||||
'self_consumption_year': 545.0,
|
||||
'total_power': 120.0,
|
||||
'usage': 54.8,
|
||||
'voltage_ac': 100.0,
|
||||
'voltage_dc': 100.0,
|
||||
'yield_day': 4.21,
|
||||
'yield_month': 515.0,
|
||||
'yield_total': 56513.0,
|
||||
'yield_year': 1023.0,
|
||||
'yield_yesterday': 5.21,
|
||||
}),
|
||||
})
|
||||
# ---
|
32
tests/components/solarlog/test_diagnostics.py
Normal file
32
tests/components/solarlog/test_diagnostics.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
"""Test Solarlog diagnostics."""
|
||||
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from syrupy import SnapshotAssertion
|
||||
from syrupy.filters import props
|
||||
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import setup_platform
|
||||
|
||||
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_config_entry: MockConfigEntry,
|
||||
mock_solarlog_connector: AsyncMock,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
await setup_platform(hass, mock_config_entry, [Platform.SENSOR])
|
||||
|
||||
result = await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, mock_config_entry
|
||||
)
|
||||
|
||||
assert result == snapshot(exclude=props("created_at", "modified_at"))
|
Loading…
Add table
Add a link
Reference in a new issue