1 """Diagnostics support for EnergyZero."""
3 from __future__
import annotations
5 from datetime
import timedelta
11 from .
import EnergyZeroDataUpdateCoordinator
12 from .const
import DOMAIN
13 from .coordinator
import EnergyZeroData
17 """Get the gas price for a given hour.
20 data: The data object.
21 hours: The number of hours to add to the current time.
24 The gas market price value.
27 if not data.gas_today:
29 return data.gas_today.price_at_time(
30 data.gas_today.utcnow() +
timedelta(hours=hours)
35 hass: HomeAssistant, entry: ConfigEntry
37 """Return diagnostics for a config entry."""
38 coordinator: EnergyZeroDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
45 "current_hour_price": coordinator.data.energy_today.current_price,
46 "next_hour_price": coordinator.data.energy_today.price_at_time(
47 coordinator.data.energy_today.utcnow() +
timedelta(hours=1)
49 "average_price": coordinator.data.energy_today.average_price,
50 "max_price": coordinator.data.energy_today.extreme_prices[1],
51 "min_price": coordinator.data.energy_today.extreme_prices[0],
52 "highest_price_time": coordinator.data.energy_today.highest_price_time,
53 "lowest_price_time": coordinator.data.energy_today.lowest_price_time,
54 "percentage_of_max": coordinator.data.energy_today.pct_of_max_price,
55 "hours_priced_equal_or_lower": coordinator.data.energy_today.hours_priced_equal_or_lower,
dict[str, Any] async_get_config_entry_diagnostics(HomeAssistant hass, ConfigEntry entry)
float|None get_gas_price(EnergyZeroData data, int hours)