From 42fd5b5ecf5dd6ea3b31490d38a66fa12d61e95a Mon Sep 17 00:00:00 2001 From: Thibaut Etienne Date: Sat, 12 Dec 2020 00:53:09 +0100 Subject: [PATCH] Use HA helper to manage http session --- custom_components/veolia/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/custom_components/veolia/__init__.py b/custom_components/veolia/__init__.py index 16cec40..e334cf7 100644 --- a/custom_components/veolia/__init__.py +++ b/custom_components/veolia/__init__.py @@ -11,8 +11,10 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.core import Config, HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady +from homeassistant.helpers import aiohttp_client from homeassistant.helpers.typing import HomeAssistantType -from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed +from homeassistant.helpers.update_coordinator import DataUpdateCoordinator + from pyolia.client import VeoliaClient from .const import ( @@ -44,7 +46,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): username = entry.data.get(CONF_USERNAME) password = entry.data.get(CONF_PASSWORD) - hass.data[DOMAIN][API] = VeoliaClient(username, password) + session = aiohttp_client.async_create_clientsession(hass) + hass.data[DOMAIN][API] = VeoliaClient(username, password, session) async def _get_consumption(): """Return the water consumption for each day of the current month."""