Skip to content

Commit 14f6af4

Browse files
authored
Merge pull request #685 from thibaulf/main
Disable session cookie quoting to work with aiohttp v3.12.12
2 parents 80210d4 + 3546068 commit 14f6af4

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

custom_components/hilo/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import traceback
99
from typing import TYPE_CHECKING, List, Optional
1010

11+
from aiohttp import CookieJar
1112
from homeassistant.components.select import (
1213
ATTR_OPTION,
1314
DOMAIN as SELECT_DOMAIN,
@@ -26,11 +27,11 @@
2627
from homeassistant.core import Context, Event, HomeAssistant, callback
2728
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
2829
from homeassistant.helpers import (
29-
aiohttp_client,
3030
config_entry_oauth2_flow,
3131
device_registry as dr,
3232
entity_registry as er,
3333
)
34+
from homeassistant.helpers.aiohttp_client import async_create_clientsession
3435
from homeassistant.helpers.dispatcher import async_dispatcher_send
3536
from homeassistant.helpers.event import async_call_later
3637
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
@@ -140,7 +141,9 @@ async def async_setup_entry( # noqa: C901
140141

141142
try:
142143
api = await API.async_create(
143-
session=aiohttp_client.async_get_clientsession(hass),
144+
session=async_create_clientsession(
145+
hass, cookie_jar=CookieJar(quote_cookie=False)
146+
),
144147
oauth_session=config_entry_oauth2_flow.OAuth2Session(
145148
hass, entry, implementation
146149
),

custom_components/hilo/oauth2.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
from typing import Any, cast
44

5+
from aiohttp import CookieJar
56
from homeassistant.core import HomeAssistant
7+
from homeassistant.helpers.aiohttp_client import async_create_clientsession
68
from homeassistant.helpers.config_entry_oauth2_flow import LocalOAuth2Implementation
79
from pyhilo.const import AUTH_AUTHORIZE, AUTH_CLIENT_ID, AUTH_TOKEN, DOMAIN
810
from 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

Comments
 (0)