@@ -195,14 +195,12 @@ def updateStatus(self, updateCapabilities: bool = True, force: bool = False): #
195195 try :
196196 statusResponse : Response = self .weConnect .session .get (url , allow_redirects = False )
197197 except exceptions .ConnectionError as connectionError :
198- self .notifyError (self , WeConnect .ErrorEventType .CONNECTION , 'connection' , 'Could not fetch vehicle status due to connection problem' )
198+ self .weConnect . notifyError (self , WeConnect .ErrorEventType .CONNECTION , 'connection' , 'Could not fetch vehicle status due to connection problem' )
199199 raise RetrievalError from connectionError
200200 except exceptions .ReadTimeout as timeoutError :
201- self .notifyError (self , WeConnect .ErrorEventType .TIMEOUT , 'timeout' , 'Could not fetch vehicle status due to timeout' )
201+ self .weConnect . notifyError (self , WeConnect .ErrorEventType .TIMEOUT , 'timeout' , 'Could not fetch vehicle status due to timeout' )
202202 raise RetrievalError from timeoutError
203203 except exceptions .RetryError as retryError :
204- self .notifyError (self , WeConnect .ErrorEventType .HTTP , str (retryError .response .status_code ),
205- 'Could not fetch vehicle status due to server error' )
206204 raise RetrievalError from retryError
207205 if statusResponse .status_code in (codes ['ok' ], codes ['multiple_status' ]):
208206 data = statusResponse .json ()
@@ -214,23 +212,26 @@ def updateStatus(self, updateCapabilities: bool = True, force: bool = False): #
214212 try :
215213 statusResponse = self .weConnect .session .get (url , allow_redirects = False )
216214 except exceptions .ConnectionError as connectionError :
217- self .notifyError (self , WeConnect .ErrorEventType .CONNECTION , 'connection' , 'Could not fetch vehicle status due to connection problem' )
215+ self .weConnect .notifyError (self , WeConnect .ErrorEventType .CONNECTION , 'connection' ,
216+ 'Could not fetch vehicle status due to connection problem' )
218217 raise RetrievalError from connectionError
219218 except exceptions .ReadTimeout as timeoutError :
220- self .notifyError (self , WeConnect .ErrorEventType .TIMEOUT , 'timeout' , 'Could not fetch vehicle status due to timeout' )
219+ self .weConnect . notifyError (self , WeConnect .ErrorEventType .TIMEOUT , 'timeout' , 'Could not fetch vehicle status due to timeout' )
221220 raise RetrievalError from timeoutError
222221 except exceptions .RetryError as retryError :
223- self .notifyError (self , WeConnect .ErrorEventType .HTTP , str (retryError .response .status_code ),
224- 'Could not fetch vehicle status due to server error' )
225222 raise RetrievalError from retryError
226223 if statusResponse .status_code == codes ['ok' ]:
227224 data = statusResponse .json ()
228225 if self .weConnect .cache is not None :
229226 self .weConnect .cache [url ] = (data , str (datetime .utcnow ()))
230227 else :
228+ self .weConnect .notifyError (self , WeConnect .ErrorEventType .HTTP , str (statusResponse .status_code ),
229+ 'Could not fetch vehicle status due to server error' )
231230 raise RetrievalError ('Could not retrieve vehicle status data even after re-authorization.'
232231 f' Status Code was: { statusResponse .status_code } ' )
233232 else :
233+ self .weConnect .notifyError (self , WeConnect .ErrorEventType .HTTP , str (statusResponse .status_code ),
234+ 'Could not fetch vehicle status due to server error' )
234235 raise RetrievalError (f'Could not retrieve vehicle status data. Status Code was: { statusResponse .status_code } ' )
235236
236237 if self .weConnect .cache is not None :
@@ -330,14 +331,13 @@ def updateStatus(self, updateCapabilities: bool = True, force: bool = False): #
330331 try :
331332 statusResponse = self .weConnect .session .get (url , allow_redirects = False )
332333 except exceptions .ConnectionError as connectionError :
333- self .notifyError (self , WeConnect .ErrorEventType .CONNECTION , 'connection' , 'Could not fetch parking position due to connection problem' )
334+ self .weConnect .notifyError (self , WeConnect .ErrorEventType .CONNECTION , 'connection' ,
335+ 'Could not fetch parking position due to connection problem' )
334336 raise RetrievalError from connectionError
335337 except exceptions .ReadTimeout as timeoutError :
336- self .notifyError (self , WeConnect .ErrorEventType .TIMEOUT , 'timeout' , 'Could not fetch parking position due to timeout' )
338+ self .weConnect . notifyError (self , WeConnect .ErrorEventType .TIMEOUT , 'timeout' , 'Could not fetch parking position due to timeout' )
337339 raise RetrievalError from timeoutError
338340 except exceptions .RetryError as retryError :
339- self .notifyError (self , WeConnect .ErrorEventType .HTTP , str (retryError .response .status_code ),
340- 'Could not fetch parking position due to server error' )
341341 raise RetrievalError from retryError
342342 if statusResponse .status_code == codes ['ok' ]:
343343 data = statusResponse .json ()
@@ -349,20 +349,21 @@ def updateStatus(self, updateCapabilities: bool = True, force: bool = False): #
349349 try :
350350 statusResponse = self .weConnect .session .get (url , allow_redirects = False )
351351 except exceptions .ConnectionError as connectionError :
352- self .notifyError (self , WeConnect .ErrorEventType .CONNECTION , 'connection' , 'Could not fetch parking position due to connection problem' )
352+ self .weConnect .notifyError (self , WeConnect .ErrorEventType .CONNECTION , 'connection' ,
353+ 'Could not fetch parking position due to connection problem' )
353354 raise RetrievalError from connectionError
354355 except exceptions .ReadTimeout as timeoutError :
355- self .notifyError (self , WeConnect .ErrorEventType .TIMEOUT , 'timeout' , 'Could not fetch parking position due to timeout' )
356+ self .weConnect . notifyError (self , WeConnect .ErrorEventType .TIMEOUT , 'timeout' , 'Could not fetch parking position due to timeout' )
356357 raise RetrievalError from timeoutError
357358 except exceptions .RetryError as retryError :
358- self .notifyError (self , WeConnect .ErrorEventType .HTTP , str (retryError .response .status_code ),
359- 'Could not fetch parking position due to server error' )
360359 raise RetrievalError from retryError
361360 if statusResponse .status_code == codes ['ok' ]:
362361 data = statusResponse .json ()
363362 if self .weConnect .cache is not None :
364363 self .weConnect .cache [url ] = (data , str (datetime .utcnow ()))
365364 else :
365+ self .weConnect .notifyError (self , WeConnect .ErrorEventType .HTTP , str (statusResponse .status_code ),
366+ 'Could not fetch parking position due to server error' )
366367 raise RetrievalError ('Could not retrieve parking position even after re-authorization.'
367368 f' Status Code was: { statusResponse .status_code } ' )
368369 elif statusResponse .status_code == codes ['bad_request' ] \
@@ -375,6 +376,8 @@ def updateStatus(self, updateCapabilities: bool = True, force: bool = False): #
375376 except json .JSONDecodeError :
376377 data = None
377378 else :
379+ self .weConnect .notifyError (self , WeConnect .ErrorEventType .HTTP , str (statusResponse .status_code ),
380+ 'Could not fetch parking position due to server error' )
378381 raise RetrievalError (f'Could not retrieve parking position. Status Code was: { statusResponse .status_code } ' )
379382
380383 if data is not None and 'data' in data :
@@ -422,14 +425,13 @@ def updatePictures(self) -> None: # noqa: C901
422425 try :
423426 imageResponse : Response = self .weConnect .session .get (url , allow_redirects = False )
424427 except exceptions .ConnectionError as connectionError :
425- self .notifyError (self , WeConnect .ErrorEventType .CONNECTION , 'connection' , 'Could not fetch vehicle image list due to connection problem' )
428+ self .weConnect .notifyError (self , WeConnect .ErrorEventType .CONNECTION , 'connection' ,
429+ 'Could not fetch vehicle image list due to connection problem' )
426430 raise RetrievalError from connectionError
427431 except exceptions .ReadTimeout as timeoutError :
428- self .notifyError (self , WeConnect .ErrorEventType .TIMEOUT , 'timeout' , 'Could not fetch vehicle image list due to timeout' )
432+ self .weConnect . notifyError (self , WeConnect .ErrorEventType .TIMEOUT , 'timeout' , 'Could not fetch vehicle image list due to timeout' )
429433 raise RetrievalError from timeoutError
430434 except exceptions .RetryError as retryError :
431- self .notifyError (self , WeConnect .ErrorEventType .HTTP , str (retryError .response .status_code ),
432- 'Could not fetch vehicle image list due to server error' )
433435 raise RetrievalError from retryError
434436 if imageResponse .status_code == codes ['ok' ]:
435437 data = imageResponse .json ()
@@ -441,22 +443,25 @@ def updatePictures(self) -> None: # noqa: C901
441443 try :
442444 imageResponse = self .weConnect .session .get (url , allow_redirects = False )
443445 except exceptions .ConnectionError as connectionError :
444- self .notifyError (self , WeConnect .ErrorEventType .CONNECTION , 'connection' , 'Could not fetch vehicle image list due to connection problem' )
446+ self .weConnect .notifyError (self , WeConnect .ErrorEventType .CONNECTION , 'connection' ,
447+ 'Could not fetch vehicle image list due to connection problem' )
445448 raise RetrievalError from connectionError
446449 except exceptions .ReadTimeout as timeoutError :
447- self .notifyError (self , WeConnect .ErrorEventType .TIMEOUT , 'timeout' , 'Could not fetch vehicle image list due to timeout' )
450+ self .weConnect . notifyError (self , WeConnect .ErrorEventType .TIMEOUT , 'timeout' , 'Could not fetch vehicle image list due to timeout' )
448451 raise RetrievalError from timeoutError
449452 except exceptions .RetryError as retryError :
450- self .notifyError (self , WeConnect .ErrorEventType .HTTP , str (retryError .response .status_code ),
451- 'Could not fetch vehicle image list due to server error' )
452453 raise RetrievalError from retryError
453454 if imageResponse .status_code == codes ['ok' ]:
454455 data = imageResponse .json ()
455456 if self .weConnect .cache is not None :
456457 self .weConnect .cache [url ] = (data , str (datetime .utcnow ()))
457458 else :
459+ self .weConnect .notifyError (self , WeConnect .ErrorEventType .HTTP , str (imageResponse .status_code ),
460+ 'Could not fetch vehicle image list due to server error' )
458461 raise RetrievalError ('Could not retrieve vehicle images even after re-authorization.'
459462 f' Status Code was: { imageResponse .status_code } ' )
463+ self .weConnect .notifyError (self , WeConnect .ErrorEventType .HTTP , str (imageResponse .status_code ),
464+ 'Could not fetch vehicle image list due to server error' )
460465 raise RetrievalError (f'Could not retrieve vehicle images. Status Code was: { imageResponse .status_code } ' )
461466 if data is not None and 'data' in data : # pylint: disable=too-many-nested-blocks
462467 for image in data ['data' ]:
@@ -473,14 +478,13 @@ def updatePictures(self) -> None: # noqa: C901
473478 try :
474479 imageDownloadResponse = self .weConnect .session .get (imageurl , stream = True )
475480 except exceptions .ConnectionError as connectionError :
476- self .notifyError (self , WeConnect .ErrorEventType .CONNECTION , 'connection' , 'Could not fetch vehicle image due to connection problem' )
481+ self .weConnect .notifyError (self , WeConnect .ErrorEventType .CONNECTION , 'connection' ,
482+ 'Could not fetch vehicle image due to connection problem' )
477483 raise RetrievalError from connectionError
478484 except exceptions .ReadTimeout as timeoutError :
479- self .notifyError (self , WeConnect .ErrorEventType .TIMEOUT , 'timeout' , 'Could not fetch vehicle image due to timeout' )
485+ self .weConnect . notifyError (self , WeConnect .ErrorEventType .TIMEOUT , 'timeout' , 'Could not fetch vehicle image due to timeout' )
480486 raise RetrievalError from timeoutError
481487 except exceptions .RetryError as retryError :
482- self .notifyError (self , WeConnect .ErrorEventType .HTTP , str (retryError .response .status_code ),
483- 'Could not fetch vehicle image due to server error' )
484488 raise RetrievalError from retryError
485489 if imageDownloadResponse .status_code == codes ['ok' ]:
486490 img = Image .open (imageDownloadResponse .raw )
@@ -495,14 +499,13 @@ def updatePictures(self) -> None: # noqa: C901
495499 try :
496500 imageDownloadResponse = self .weConnect .session .get (imageurl , stream = True )
497501 except exceptions .ConnectionError as connectionError :
498- self .notifyError (self , WeConnect .ErrorEventType .CONNECTION , 'connection' , 'Could not fetch vehicle image due to connection problem' )
502+ self .weConnect .notifyError (self , WeConnect .ErrorEventType .CONNECTION , 'connection' ,
503+ 'Could not fetch vehicle image due to connection problem' )
499504 raise RetrievalError from connectionError
500505 except exceptions .ReadTimeout as timeoutError :
501- self .notifyError (self , WeConnect .ErrorEventType .TIMEOUT , 'timeout' , 'Could not fetch vehicle image due to timeout' )
506+ self .weConnect . notifyError (self , WeConnect .ErrorEventType .TIMEOUT , 'timeout' , 'Could not fetch vehicle image due to timeout' )
502507 raise RetrievalError from timeoutError
503508 except exceptions .RetryError as retryError :
504- self .notifyError (self , WeConnect .ErrorEventType .HTTP , str (retryError .response .status_code ),
505- 'Could not fetch vehicle image due to server error' )
506509 raise RetrievalError from retryError
507510 if imageDownloadResponse .status_code == codes ['ok' ]:
508511 img = Image .open (imageDownloadResponse .raw )
@@ -512,8 +515,12 @@ def updatePictures(self) -> None: # noqa: C901
512515 imgStr = base64 .b64encode (buffered .getvalue ()).decode ("utf-8" )
513516 self .weConnect .cache [imageurl ] = (imgStr , str (datetime .utcnow ()))
514517 else :
518+ self .weConnect .notifyError (self , WeConnect .ErrorEventType .HTTP , str (imageDownloadResponse .status_code ),
519+ 'Could not fetch vehicle image due to server error' )
515520 raise RetrievalError ('Could not retrieve vehicle image even after re-authorization.'
516521 f' Status Code was: { imageDownloadResponse .status_code } ' )
522+ self .weConnect .notifyError (self , WeConnect .ErrorEventType .HTTP , str (imageDownloadResponse .status_code ),
523+ 'Could not fetch vehicle image due to server error' )
517524 raise RetrievalError (f'Could not retrieve vehicle image. Status Code was: { imageDownloadResponse .status_code } ' )
518525 else :
519526 LOG .warning ('Failed downloading picture %s with status code %d will try again in next update' , image ['id' ],
0 commit comments