22
33from typing import Any , cast
44
5+ from aiohttp import CookieJar
56from homeassistant .core import HomeAssistant
7+ from homeassistant .helpers .aiohttp_client import async_create_clientsession
68from homeassistant .helpers .config_entry_oauth2_flow import LocalOAuth2Implementation
79from pyhilo .const import AUTH_AUTHORIZE , AUTH_CLIENT_ID , AUTH_TOKEN , DOMAIN
810from pyhilo .oauth2helper import OAuth2Helper
@@ -25,6 +27,9 @@ def __init__(
2527 AUTH_TOKEN ,
2628 )
2729
30+ self .session = async_create_clientsession (
31+ self .hass , cookie_jar = CookieJar (quote_cookie = False )
32+ )
2833 self .oauth_helper = OAuth2Helper ()
2934
3035 # ... Override AbstractOAuth2Implementation details
@@ -48,3 +53,14 @@ async def async_resolve_external_data(self, external_data: Any) -> dict:
4853 )
4954 ),
5055 )
56+
57+ async def _token_request (self , data : dict ) -> dict :
58+ """Make a token request."""
59+ data ["client_id" ] = self .client_id
60+
61+ if self .client_secret :
62+ data ["client_secret" ] = self .client_secret
63+
64+ resp = await self .session .post (self .token_url , data = data )
65+ resp .raise_for_status ()
66+ return cast (dict , await resp .json ())
0 commit comments