1 """Support for OVO Energy."""
3 from __future__
import annotations
6 from datetime
import timedelta
10 from ovoenergy
import OVOEnergy
11 from ovoenergy.models
import OVODailyUsage
21 from .const
import CONF_ACCOUNT, DATA_CLIENT, DATA_COORDINATOR, DOMAIN
23 _LOGGER = logging.getLogger(__name__)
25 PLATFORMS = [Platform.SENSOR]
29 """Set up OVO Energy from a config entry."""
35 if (custom_account := entry.data.get(CONF_ACCOUNT))
is not None:
36 client.custom_account_id = custom_account
39 if not await client.authenticate(
40 entry.data[CONF_USERNAME],
41 entry.data[CONF_PASSWORD],
43 raise ConfigEntryAuthFailed
45 await client.bootstrap_accounts()
46 except aiohttp.ClientError
as exception:
47 _LOGGER.warning(exception)
48 raise ConfigEntryNotReady
from exception
50 async
def async_update_data() -> OVODailyUsage:
51 """Fetch data from OVO Energy."""
52 if (custom_account := entry.data.get(CONF_ACCOUNT))
is not None:
53 client.custom_account_id = custom_account
55 async
with asyncio.timeout(10):
57 authenticated = await client.authenticate(
58 entry.data[CONF_USERNAME],
59 entry.data[CONF_PASSWORD],
61 except aiohttp.ClientError
as exception:
65 return await client.get_daily_usage(dt_util.utcnow().strftime(
"%Y-%m"))
67 coordinator = DataUpdateCoordinator[OVODailyUsage](
73 update_method=async_update_data,
78 hass.data.setdefault(DOMAIN, {})
79 hass.data[DOMAIN][entry.entry_id] = {
81 DATA_COORDINATOR: coordinator,
85 await coordinator.async_config_entry_first_refresh()
88 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
94 """Unload OVO Energy config entry."""
96 unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
98 del hass.data[DOMAIN][entry.entry_id]
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)