77import logging
88import socket
99import uuid
10+ from http .cookies import SimpleCookie
1011from typing import Any , Mapping
1112
1213import aiohttp
@@ -57,7 +58,7 @@ def __init__(
5758 self ._token = None
5859 self ._session = session
5960 self ._close_session = False
60- self ._cookies : dict [ str , str ] = {}
61+ self ._cookies : SimpleCookie | None = None
6162
6263 self ._host = host
6364 self ._base_path = base_path
@@ -80,14 +81,12 @@ async def request(
8081 """Make a request to the Agur API."""
8182
8283 url = URL .build (scheme = "https" , host = self ._host , path = self ._base_path ).join (URL (uri ))
83-
84- LOGGER .debug ("URL: %s" , url )
85- LOGGER .debug ("Headers: %s" , headers )
86- LOGGER .debug ("Cookies: %s" , self ._cookies )
84+ LOGGER .debug ("Request URL: %s" , url )
8785
8886 if headers is None :
8987 headers = {}
9088
89+ headers ["User-Agent" ] = "homeassistant"
9190 headers ["Content-Type" ] = "application/json"
9291
9392 if self ._conversation_id is not None :
@@ -97,15 +96,14 @@ async def request(
9796 headers ["Token" ] = self ._token
9897
9998 if self ._session is None :
100- self ._session = aiohttp .ClientSession ()
101- self ._close_session = True
99+ self ._session = aiohttp .ClientSession (cookie_jar = aiohttp . CookieJar ( unsafe = False , quote_cookie = False ) )
100+ self ._close_session = True
102101
103102 try :
104103 async with async_timeout .timeout (self ._timeout ):
105104 response = await self ._session .request (
106105 method ,
107106 url ,
108- cookies = self ._cookies ,
109107 data = data ,
110108 json = json_data ,
111109 params = params ,
@@ -135,7 +133,7 @@ async def generate_temporary_token(self) -> None:
135133 """Generate a temporary token."""
136134 try :
137135 # Generate a conversation id
138- self ._conversation_id = f"S -WEB-Netscape-{ uuid .uuid4 ()} "
136+ self ._conversation_id = f"JS -WEB-Netscape-{ uuid .uuid4 ()} "
139137
140138 response = await self .request (
141139 uri = GENERATE_TOKEN_PATH ,
@@ -213,6 +211,7 @@ async def __aenter__(self) -> Any:
213211
214212 async def close (self ) -> None :
215213 """Close open client session."""
214+ LOGGER .debug ("Closing session" )
216215 if self ._session and self ._close_session :
217216 await self ._session .close ()
218217
0 commit comments