44from enum import Enum
55import logging
66import struct
7- import traceback
87from typing import Any , Callable , TypeVar
98from asyncio import Event , wait_for , sleep
109from PIL import Image
@@ -31,9 +30,12 @@ async def wrapper(self, *args, **kwargs):
3130 try :
3231 return await func (self , * args , ** kwargs )
3332 except (BleakServiceMissing , BleakCharacteristicMissing ):
34- if self .client .is_connected :
35- await self .client .clear_cache ()
36- await self .client .disconnect ()
33+ try :
34+ if self .client .is_connected :
35+ await self .client .clear_cache ()
36+ await self .client .disconnect ()
37+ except Exception :
38+ pass
3739 raise
3840 return wrapper # type: ignore
3941
@@ -59,11 +61,13 @@ async def update_image(
5961 gicisky = GiciskyClient (client , sorted_uuids , device )
6062 await gicisky .start_notify ()
6163 success = await gicisky .write_image (image , threshold , red_threshold )
62- await gicisky .stop_notify ()
64+ try :
65+ await gicisky .stop_notify ()
66+ except Exception as e :
67+ _LOGGER .warning (f"{ ble_device .address } Already stop notify: { e } " )
6368 return success
6469 except Exception as e :
65- _LOGGER .error (f"Fail update: { e } " )
66- _LOGGER .error (traceback .print_exc ())
70+ _LOGGER .error (f"Update failed: { e } " )
6771 return False
6872 finally :
6973 if client :
@@ -200,7 +204,7 @@ async def write_image(self, image: Image, threshold: int, red_threshold: int) ->
200204 raise Exception (f"Status Error: { status } " )
201205 return True
202206 except Exception as e :
203- _LOGGER .error ("Fail write: %s" , e )
207+ _LOGGER .error (f"Write failed: { e } " )
204208 return False
205209 finally :
206210 _LOGGER .debug ("Finish" )
0 commit comments