mirror of
https://github.com/home-assistant/core.git
synced 2026-04-03 00:46:46 +01:00
Add diagnostics support for Powerfox Local integration (#163985)
This commit is contained in:
24
homeassistant/components/powerfox_local/diagnostics.py
Normal file
24
homeassistant/components/powerfox_local/diagnostics.py
Normal file
@@ -0,0 +1,24 @@
|
||||
"""Support for Powerfox Local diagnostics."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .coordinator import PowerfoxLocalConfigEntry
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: PowerfoxLocalConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for Powerfox Local config entry."""
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
return {
|
||||
"power": coordinator.data.power,
|
||||
"energy_usage": coordinator.data.energy_usage,
|
||||
"energy_usage_high_tariff": coordinator.data.energy_usage_high_tariff,
|
||||
"energy_usage_low_tariff": coordinator.data.energy_usage_low_tariff,
|
||||
"energy_return": coordinator.data.energy_return,
|
||||
}
|
||||
@@ -48,7 +48,7 @@ rules:
|
||||
|
||||
# Gold
|
||||
devices: done
|
||||
diagnostics: todo
|
||||
diagnostics: done
|
||||
discovery-update-info: done
|
||||
discovery: done
|
||||
docs-data-update: done
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# serializer version: 1
|
||||
# name: test_entry_diagnostics
|
||||
dict({
|
||||
'energy_return': 111111,
|
||||
'energy_usage': 1111111,
|
||||
'energy_usage_high_tariff': 111111,
|
||||
'energy_usage_low_tariff': 111111,
|
||||
'power': 111,
|
||||
})
|
||||
# ---
|
||||
30
tests/components/powerfox_local/test_diagnostics.py
Normal file
30
tests/components/powerfox_local/test_diagnostics.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""Test for Powerfox Local diagnostics."""
|
||||
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from syrupy.assertion 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_powerfox_local_client: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test the Powerfox Local 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
|
||||
Reference in New Issue
Block a user