diff --git a/custom_components/hilo/__init__.py b/custom_components/hilo/__init__.py index 29afca62..554648a4 100644 --- a/custom_components/hilo/__init__.py +++ b/custom_components/hilo/__init__.py @@ -8,6 +8,7 @@ import traceback from typing import TYPE_CHECKING, List, Optional +from aiohttp import CookieJar from homeassistant.components.select import ( ATTR_OPTION, DOMAIN as SELECT_DOMAIN, @@ -26,11 +27,11 @@ from homeassistant.core import Context, Event, HomeAssistant, callback from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.helpers import ( - aiohttp_client, config_entry_oauth2_flow, device_registry as dr, entity_registry as er, ) +from homeassistant.helpers.aiohttp_client import async_create_clientsession from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.event import async_call_later from homeassistant.helpers.update_coordinator import DataUpdateCoordinator @@ -140,7 +141,9 @@ async def async_setup_entry( # noqa: C901 try: api = await API.async_create( - session=aiohttp_client.async_get_clientsession(hass), + session=async_create_clientsession( + hass, cookie_jar=CookieJar(quote_cookie=False) + ), oauth_session=config_entry_oauth2_flow.OAuth2Session( hass, entry, implementation ), diff --git a/custom_components/hilo/oauth2.py b/custom_components/hilo/oauth2.py index d827a3dd..78527185 100644 --- a/custom_components/hilo/oauth2.py +++ b/custom_components/hilo/oauth2.py @@ -2,7 +2,9 @@ from typing import Any, cast +from aiohttp import CookieJar from homeassistant.core import HomeAssistant +from homeassistant.helpers.aiohttp_client import async_create_clientsession from homeassistant.helpers.config_entry_oauth2_flow import LocalOAuth2Implementation from pyhilo.const import AUTH_AUTHORIZE, AUTH_CLIENT_ID, AUTH_TOKEN, DOMAIN from pyhilo.oauth2helper import OAuth2Helper @@ -25,6 +27,9 @@ def __init__( AUTH_TOKEN, ) + self.session = async_create_clientsession( + self.hass, cookie_jar=CookieJar(quote_cookie=False) + ) self.oauth_helper = OAuth2Helper() # ... Override AbstractOAuth2Implementation details @@ -48,3 +53,14 @@ async def async_resolve_external_data(self, external_data: Any) -> dict: ) ), ) + + async def _token_request(self, data: dict) -> dict: + """Make a token request.""" + data["client_id"] = self.client_id + + if self.client_secret: + data["client_secret"] = self.client_secret + + resp = await self.session.post(self.token_url, data=data) + resp.raise_for_status() + return cast(dict, await resp.json())