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 support to P1 Monitor (home-assistant#65060)
* Add diagnostics to P1 Monitor * Add test for diagnostics
- Loading branch information
1 parent
dccc4eb
commit 090a8a9
Showing
2 changed files
with
94 additions
and
0 deletions.
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,35 @@ | ||
"""Diagnostics support for P1 Monitor.""" | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
from homeassistant.components.diagnostics import async_redact_data | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.const import CONF_HOST | ||
from homeassistant.core import HomeAssistant | ||
|
||
from . import P1MonitorDataUpdateCoordinator | ||
from .const import DOMAIN, SERVICE_PHASES, SERVICE_SETTINGS, SERVICE_SMARTMETER | ||
|
||
TO_REDACT = { | ||
CONF_HOST, | ||
} | ||
|
||
|
||
async def async_get_config_entry_diagnostics( | ||
hass: HomeAssistant, entry: ConfigEntry | ||
) -> dict[str, Any]: | ||
"""Return diagnostics for a config entry.""" | ||
coordinator: P1MonitorDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] | ||
|
||
return { | ||
"entry": { | ||
"title": entry.title, | ||
"data": async_redact_data(entry.data, TO_REDACT), | ||
}, | ||
"data": { | ||
"smartmeter": coordinator.data[SERVICE_SMARTMETER].__dict__, | ||
"phases": coordinator.data[SERVICE_PHASES].__dict__, | ||
"settings": coordinator.data[SERVICE_SETTINGS].__dict__, | ||
}, | ||
} |
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,59 @@ | ||
"""Tests for the diagnostics data provided by the P1 Monitor integration.""" | ||
from aiohttp import ClientSession | ||
|
||
from homeassistant.components.diagnostics import REDACTED | ||
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 | ||
) == { | ||
"entry": { | ||
"title": "monitor", | ||
"data": { | ||
"host": REDACTED, | ||
}, | ||
}, | ||
"data": { | ||
"smartmeter": { | ||
"gas_consumption": 2273.447, | ||
"energy_tariff_period": "high", | ||
"power_consumption": 877, | ||
"energy_consumption_high": 2770.133, | ||
"energy_consumption_low": 4988.071, | ||
"power_production": 0, | ||
"energy_production_high": 3971.604, | ||
"energy_production_low": 1432.279, | ||
}, | ||
"phases": { | ||
"voltage_phase_l1": "233.6", | ||
"voltage_phase_l2": "0.0", | ||
"voltage_phase_l3": "233.0", | ||
"current_phase_l1": "1.6", | ||
"current_phase_l2": "4.44", | ||
"current_phase_l3": "3.51", | ||
"power_consumed_phase_l1": 315, | ||
"power_consumed_phase_l2": 0, | ||
"power_consumed_phase_l3": 624, | ||
"power_produced_phase_l1": 0, | ||
"power_produced_phase_l2": 0, | ||
"power_produced_phase_l3": 0, | ||
}, | ||
"settings": { | ||
"gas_consumption_price": "0.64", | ||
"energy_consumption_price_high": "0.20522", | ||
"energy_consumption_price_low": "0.20522", | ||
"energy_production_price_high": "0.20522", | ||
"energy_production_price_low": "0.20522", | ||
}, | ||
}, | ||
} |