@@ -20,7 +20,7 @@ def __init__(
2020 loop : asyncio .AbstractEventLoop = None ,
2121 websession : aiohttp .ClientSession = None
2222 ) -> None :
23- self .login_data = {'email' : email , 'password' : password_to_hash (password )}
23+ self .login_data = {'email' : email , 'password' : self . password_to_hash (password )}
2424 self .loop = loop or asyncio .get_event_loop ()
2525 # set request handler params
2626 RequestHandler .websession = websession or aiohttp .ClientSession (loop = loop )
@@ -29,7 +29,7 @@ def __init__(
2929 self .spheres : Optional [Spheres ] = None
3030
3131 def __del__ (self ):
32- self .cleanup ()
32+ self .reset ()
3333
3434 async def initialize (self ) -> None :
3535 """Async initialize the cloud data"""
@@ -68,10 +68,11 @@ async def sync(self) -> None:
6868 # get the data from the sphere attributes
6969 for sphere in self .spheres :
7070 await asyncio .gather (
71+ sphere .update_sphere_presence (),
7172 sphere .crownstones .update (),
7273 sphere .crownstones .update_state (),
7374 sphere .locations .update (),
74- sphere .locations .update_presence (),
75+ sphere .locations .update_location_presence (),
7576 sphere .users .update ()
7677 )
7778 _LOGGER .warning ("Cloud data successfully initialized" )
@@ -88,15 +89,27 @@ def get_crownstone_by_id(self, crownstone_id) -> Crownstone:
8889 for sphere in self .spheres :
8990 return sphere .crownstones [crownstone_id ]
9091
91- def cleanup (self ) -> None :
92+ @staticmethod
93+ def reset () -> None :
94+ """Cleanup the request handler instance data"""
95+ RequestHandler .access_token = None
96+ RequestHandler .websession = None
97+ RequestHandler .login_data = None
98+
99+ @staticmethod
100+ async def close_session () -> None :
92101 """Close the websession after we are done"""
93- self . loop . create_task ( RequestHandler .websession .close () )
102+ await RequestHandler .websession .close ()
94103 _LOGGER .warning ("Session closed." )
95104
105+ def close_session_sync (self ) -> None :
106+ """Sync version of close session"""
107+ self .loop .run_until_complete (self .close_session ())
96108
97- def password_to_hash (password ):
98- """Generate a sha1 password from string"""
99- if password is None :
100- return None
101- pw_hash = hashlib .sha1 (password .encode ('utf-8' ))
102- return pw_hash .hexdigest ()
109+ @staticmethod
110+ def password_to_hash (password ):
111+ """Generate a sha1 password from string"""
112+ if password is None :
113+ return None
114+ pw_hash = hashlib .sha1 (password .encode ('utf-8' ))
115+ return pw_hash .hexdigest ()
0 commit comments