Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions custom_components/hilo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
),
Expand Down
16 changes: 16 additions & 0 deletions custom_components/hilo/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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())