@@ -87,8 +87,6 @@ async def _create_session() -> aiohttp.ClientSession:
8787 self .websession = websession
8888
8989 self ._auth = aiohttp .BasicAuth (username , password = password )
90- # Work-around for Stretchv2-aiohttp-deflate-error, can be removed for aiohttp v3.7
91- self ._headers = {"Accept-Encoding" : "gzip" }
9290
9391 self ._timeout = timeout
9492 self ._endpoint = f"http://{ host } :{ str (port )} "
@@ -226,25 +224,21 @@ async def request(
226224 resp = None
227225 url = f"{ self ._endpoint } { command } "
228226
229- if headers is None :
230- headers = {"Content-type" : "text/xml" }
231-
232227 try :
233228 with async_timeout .timeout (self ._timeout ):
234229 if method == "get" :
235- # Work-around, see above, can be removed for aiohttp v3.7:
230+ # Work-around for Stretchv2, should not hurt the other smiles
231+ headers = {"Accept-Encoding" : "gzip" }
236232 resp = await self .websession .get (
237- url , auth = self ._auth , headers = self . _headers
233+ url , auth = self ._auth , headers = headers
238234 )
239235 if method == "put" :
236+ headers = {"Content-type" : "text/xml" }
240237 resp = await self .websession .put (
241238 url , data = data , headers = headers , auth = self ._auth
242239 )
243240 if method == "delete" :
244241 resp = await self .websession .delete (url , auth = self ._auth )
245- if resp .status == 401 :
246- raise InvalidAuthentication
247-
248242 except asyncio .TimeoutError :
249243 if retry < 1 :
250244 _LOGGER .error ("Timed out sending command to Plugwise: %s" , command )
@@ -258,6 +252,9 @@ async def request(
258252 if method == "put" and resp .status == 200 :
259253 return
260254
255+ if resp .status == 401 :
256+ raise InvalidAuthentication
257+
261258 result = await resp .text ()
262259 if not result or "<error>" in result :
263260 _LOGGER .error ("Smile response empty or error in %s" , result )
0 commit comments