@@ -115,30 +115,31 @@ async def _request(
115115 use_headers = headers
116116
117117 try :
118- if method == "delete" :
119- resp = await self ._websession .delete (url , auth = self ._auth )
120- if method == "get" :
121- # Work-around for Stretchv2, should not hurt the other smiles
122- use_headers = {"Accept-Encoding" : "gzip" }
123- resp = await self ._websession .get (
124- url , headers = use_headers , auth = self ._auth
125- )
126- if method == "post" :
127- use_headers = {"Content-type" : "text/xml" }
128- resp = await self ._websession .post (
129- url ,
130- headers = use_headers ,
131- data = data ,
132- auth = self ._auth ,
133- )
134- if method == "put" :
135- use_headers = {"Content-type" : "text/xml" }
136- resp = await self ._websession .put (
137- url ,
138- headers = use_headers ,
139- data = data ,
140- auth = self ._auth ,
141- )
118+ match method :
119+ case "delete" :
120+ resp = await self ._websession .delete (url , auth = self ._auth )
121+ case "get" :
122+ # Work-around for Stretchv2, should not hurt the other smiles
123+ use_headers = {"Accept-Encoding" : "gzip" }
124+ resp = await self ._websession .get (
125+ url , headers = use_headers , auth = self ._auth
126+ )
127+ case "post" :
128+ use_headers = {"Content-type" : "text/xml" }
129+ resp = await self ._websession .post (
130+ url ,
131+ headers = use_headers ,
132+ data = data ,
133+ auth = self ._auth ,
134+ )
135+ case "put" :
136+ use_headers = {"Content-type" : "text/xml" }
137+ resp = await self ._websession .put (
138+ url ,
139+ headers = use_headers ,
140+ data = data ,
141+ auth = self ._auth ,
142+ )
142143 except (
143144 ClientError
144145 ) as exc : # ClientError is an ancestor class of ServerTimeoutError
@@ -167,23 +168,22 @@ async def _request(
167168
168169 async def _request_validate (self , resp : ClientResponse , method : str ) -> etree :
169170 """Helper-function for _request(): validate the returned data."""
170- # Command accepted gives empty body with status 202
171- if resp .status == 202 :
172- return
173-
174- # Cornercase for server not responding with 202
175- if method in ("post" , "put" ) and resp .status == 200 :
176- return
177-
178- if resp .status == 401 :
179- msg = "Invalid Plugwise login, please retry with the correct credentials."
180- LOGGER .error ("%s" , msg )
181- raise InvalidAuthentication
182-
183- if resp .status == 405 :
184- msg = "405 Method not allowed."
185- LOGGER .error ("%s" , msg )
186- raise ConnectionFailedError
171+ match resp .status :
172+ case 200 :
173+ # Cornercases for server not responding with 202
174+ if method in ("post" , "put" ):
175+ return
176+ case 202 :
177+ # Command accepted gives empty body with status 202
178+ return
179+ case 401 :
180+ msg = "Invalid Plugwise login, please retry with the correct credentials."
181+ LOGGER .error ("%s" , msg )
182+ raise InvalidAuthentication
183+ case 405 :
184+ msg = "405 Method not allowed."
185+ LOGGER .error ("%s" , msg )
186+ raise ConnectionFailedError
187187
188188 if not (result := await resp .text ()) or (
189189 "<error>" in result and "Not started" not in result
0 commit comments