mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Add diagnostics to Powerfox integration (#132226)
* Add diagnostics to Powerfox integration * Update quality scale list
This commit is contained in:
parent
58d06ebc39
commit
ab1f03f392
58
homeassistant/components/powerfox/diagnostics.py
Normal file
58
homeassistant/components/powerfox/diagnostics.py
Normal file
@ -0,0 +1,58 @@
|
||||
"""Support for Powerfox diagnostics."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from powerfox import PowerMeter, WaterMeter
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import PowerfoxConfigEntry, PowerfoxDataUpdateCoordinator
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: PowerfoxConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for Powerfox config entry."""
|
||||
powerfox_data: list[PowerfoxDataUpdateCoordinator] = entry.runtime_data
|
||||
|
||||
return {
|
||||
"devices": [
|
||||
{
|
||||
**(
|
||||
{
|
||||
"power_meter": {
|
||||
"outdated": coordinator.data.outdated,
|
||||
"timestamp": datetime.strftime(
|
||||
coordinator.data.timestamp, "%Y-%m-%d %H:%M:%S"
|
||||
),
|
||||
"power": coordinator.data.power,
|
||||
"energy_usage": coordinator.data.energy_usage,
|
||||
"energy_return": coordinator.data.energy_return,
|
||||
"energy_usage_high_tariff": coordinator.data.energy_usage_high_tariff,
|
||||
"energy_usage_low_tariff": coordinator.data.energy_usage_low_tariff,
|
||||
}
|
||||
}
|
||||
if isinstance(coordinator.data, PowerMeter)
|
||||
else {}
|
||||
),
|
||||
**(
|
||||
{
|
||||
"water_meter": {
|
||||
"outdated": coordinator.data.outdated,
|
||||
"timestamp": datetime.strftime(
|
||||
coordinator.data.timestamp, "%Y-%m-%d %H:%M:%S"
|
||||
),
|
||||
"cold_water": coordinator.data.cold_water,
|
||||
"warm_water": coordinator.data.warm_water,
|
||||
}
|
||||
}
|
||||
if isinstance(coordinator.data, WaterMeter)
|
||||
else {}
|
||||
),
|
||||
}
|
||||
for coordinator in powerfox_data
|
||||
],
|
||||
}
|
@ -51,7 +51,7 @@ rules:
|
||||
|
||||
# Gold
|
||||
devices: done
|
||||
diagnostics: todo
|
||||
diagnostics: done
|
||||
discovery-update-info:
|
||||
status: exempt
|
||||
comment: |
|
||||
|
26
tests/components/powerfox/snapshots/test_diagnostics.ambr
Normal file
26
tests/components/powerfox/snapshots/test_diagnostics.ambr
Normal file
@ -0,0 +1,26 @@
|
||||
# serializer version: 1
|
||||
# name: test_entry_diagnostics
|
||||
dict({
|
||||
'devices': list([
|
||||
dict({
|
||||
'power_meter': dict({
|
||||
'energy_return': 111.111,
|
||||
'energy_usage': 1111.111,
|
||||
'energy_usage_high_tariff': 111.111,
|
||||
'energy_usage_low_tariff': 111.111,
|
||||
'outdated': False,
|
||||
'power': 111,
|
||||
'timestamp': '2024-11-26 10:48:51',
|
||||
}),
|
||||
}),
|
||||
dict({
|
||||
'water_meter': dict({
|
||||
'cold_water': 1111.111,
|
||||
'outdated': False,
|
||||
'timestamp': '2024-11-26 10:48:51',
|
||||
'warm_water': 0.0,
|
||||
}),
|
||||
}),
|
||||
]),
|
||||
})
|
||||
# ---
|
30
tests/components/powerfox/test_diagnostics.py
Normal file
30
tests/components/powerfox/test_diagnostics.py
Normal file
@ -0,0 +1,30 @@
|
||||
"""Test for PowerFox 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_powerfox_client: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test the PowerFox 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