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 Powerfox integration (home-assistant#132226)
* Add diagnostics to Powerfox integration * Update quality scale list
- Loading branch information
1 parent
96d7f2e
commit 650a500
Showing
4 changed files
with
115 additions
and
1 deletion.
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,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 | ||
], | ||
} |
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
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,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, | ||
}), | ||
}), | ||
]), | ||
}) | ||
# --- |
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 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 |