mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Improve diagnostics code of EnergyZero integration (#133019)
This commit is contained in:
parent
a9d71e0a5f
commit
0006672489
@ -33,25 +33,28 @@ async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: EnergyZeroConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator_data = entry.runtime_data.data
|
||||
energy_today = coordinator_data.energy_today
|
||||
|
||||
return {
|
||||
"entry": {
|
||||
"title": entry.title,
|
||||
},
|
||||
"energy": {
|
||||
"current_hour_price": entry.runtime_data.data.energy_today.current_price,
|
||||
"next_hour_price": entry.runtime_data.data.energy_today.price_at_time(
|
||||
entry.runtime_data.data.energy_today.utcnow() + timedelta(hours=1)
|
||||
"current_hour_price": energy_today.current_price,
|
||||
"next_hour_price": energy_today.price_at_time(
|
||||
energy_today.utcnow() + timedelta(hours=1)
|
||||
),
|
||||
"average_price": entry.runtime_data.data.energy_today.average_price,
|
||||
"max_price": entry.runtime_data.data.energy_today.extreme_prices[1],
|
||||
"min_price": entry.runtime_data.data.energy_today.extreme_prices[0],
|
||||
"highest_price_time": entry.runtime_data.data.energy_today.highest_price_time,
|
||||
"lowest_price_time": entry.runtime_data.data.energy_today.lowest_price_time,
|
||||
"percentage_of_max": entry.runtime_data.data.energy_today.pct_of_max_price,
|
||||
"hours_priced_equal_or_lower": entry.runtime_data.data.energy_today.hours_priced_equal_or_lower,
|
||||
"average_price": energy_today.average_price,
|
||||
"max_price": energy_today.extreme_prices[1],
|
||||
"min_price": energy_today.extreme_prices[0],
|
||||
"highest_price_time": energy_today.highest_price_time,
|
||||
"lowest_price_time": energy_today.lowest_price_time,
|
||||
"percentage_of_max": energy_today.pct_of_max_price,
|
||||
"hours_priced_equal_or_lower": energy_today.hours_priced_equal_or_lower,
|
||||
},
|
||||
"gas": {
|
||||
"current_hour_price": get_gas_price(entry.runtime_data.data, 0),
|
||||
"next_hour_price": get_gas_price(entry.runtime_data.data, 1),
|
||||
"current_hour_price": get_gas_price(coordinator_data, 0),
|
||||
"next_hour_price": get_gas_price(coordinator_data, 1),
|
||||
},
|
||||
}
|
||||
|
@ -5,12 +5,12 @@ from __future__ import annotations
|
||||
from datetime import date, datetime
|
||||
from enum import Enum
|
||||
from functools import partial
|
||||
from typing import Final
|
||||
from typing import TYPE_CHECKING, Final
|
||||
|
||||
from energyzero import Electricity, Gas, VatOption
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import (
|
||||
HomeAssistant,
|
||||
ServiceCall,
|
||||
@ -22,6 +22,9 @@ from homeassistant.exceptions import ServiceValidationError
|
||||
from homeassistant.helpers import selector
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import EnergyZeroConfigEntry
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import EnergyZeroDataUpdateCoordinator
|
||||
|
||||
@ -88,7 +91,7 @@ def __get_coordinator(
|
||||
) -> EnergyZeroDataUpdateCoordinator:
|
||||
"""Get the coordinator from the entry."""
|
||||
entry_id: str = call.data[ATTR_CONFIG_ENTRY]
|
||||
entry: ConfigEntry | None = hass.config_entries.async_get_entry(entry_id)
|
||||
entry: EnergyZeroConfigEntry | None = hass.config_entries.async_get_entry(entry_id)
|
||||
|
||||
if not entry:
|
||||
raise ServiceValidationError(
|
||||
@ -107,8 +110,7 @@ def __get_coordinator(
|
||||
},
|
||||
)
|
||||
|
||||
coordinator: EnergyZeroDataUpdateCoordinator = entry.runtime_data
|
||||
return coordinator
|
||||
return entry.runtime_data
|
||||
|
||||
|
||||
async def __get_prices(
|
||||
|
Loading…
x
Reference in New Issue
Block a user