mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Add diagnostics support to PVOutput (#64625)
This commit is contained in:
parent
71106074a7
commit
b4c5bcf44d
21
homeassistant/components/pvoutput/diagnostics.py
Normal file
21
homeassistant/components/pvoutput/diagnostics.py
Normal file
@ -0,0 +1,21 @@
|
||||
"""Diagnostics support for PVOutput."""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import PVOutputDataUpdateCoordinator
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: ConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator: PVOutputDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
# Round-trip via JSON to trigger serialization
|
||||
data: dict[str, Any] = json.loads(coordinator.data.json())
|
||||
return data
|
28
tests/components/pvoutput/test_diagnostics.py
Normal file
28
tests/components/pvoutput/test_diagnostics.py
Normal file
@ -0,0 +1,28 @@
|
||||
"""Tests for the diagnostics data provided by the PVOutput integration."""
|
||||
from aiohttp import ClientSession
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
|
||||
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSession,
|
||||
init_integration: MockConfigEntry,
|
||||
):
|
||||
"""Test diagnostics."""
|
||||
assert await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, init_integration
|
||||
) == {
|
||||
"energy_consumption": 1000,
|
||||
"energy_generation": 500,
|
||||
"normalized_output": 0.5,
|
||||
"power_consumption": 2500,
|
||||
"power_generation": 1500,
|
||||
"reported_date": "2021-12-29",
|
||||
"reported_time": "22:37:00",
|
||||
"temperature": 20.2,
|
||||
"voltage": 220.5,
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user