@@ -45,11 +45,11 @@ def state(self):
4545 return self ._state
4646
4747 @state .setter
48- def state (self , value ):
48+ async def state (self , value ):
4949 """Set the state."""
5050 self ._state = value
5151 _LOGGER .debug ("Websocket %s" , value )
52- self .callback (SIGNAL_CONNECTION_STATE , value , self ._error_reason )
52+ await self .callback (SIGNAL_CONNECTION_STATE , value , self ._error_reason )
5353 self ._error_reason = None
5454
5555 @staticmethod
@@ -59,7 +59,7 @@ def _get_uri(server):
5959
6060 async def running (self ):
6161 """Open a persistent websocket connection and act on events."""
62- self .state = STATE_STARTING
62+ await OpenEVSEWebsocket .state . fset ( self , STATE_STARTING )
6363 auth = None
6464
6565 if self ._user and self ._password :
@@ -81,7 +81,7 @@ async def running(self):
8181 if message .type == aiohttp .WSMsgType .TEXT :
8282 msg = message .json ()
8383 msgtype = "data"
84- self .callback (msgtype , msg , None )
84+ await self .callback (msgtype , msg , None )
8585
8686 elif message .type == aiohttp .WSMsgType .CLOSED :
8787 _LOGGER .warning ("Websocket connection closed" )
@@ -98,7 +98,7 @@ async def running(self):
9898 else :
9999 _LOGGER .error ("Unexpected response received: %s" , error )
100100 self ._error_reason = ERROR_UNKNOWN
101- self .state = STATE_STOPPED
101+ await OpenEVSEWebsocket .state . fset ( self , STATE_STOPPED )
102102 except (aiohttp .ClientConnectionError , asyncio .TimeoutError ) as error :
103103 if self .failed_attempts >= MAX_FAILED_ATTEMPTS :
104104 self ._error_reason = ERROR_TOO_MANY_RETRIES
@@ -111,7 +111,7 @@ async def running(self):
111111 retry_delay ,
112112 error ,
113113 )
114- self .state = STATE_DISCONNECTED
114+ await OpenEVSEWebsocket .state . fset ( self , STATE_DISCONNECTED )
115115 await asyncio .sleep (retry_delay )
116116 except Exception as error : # pylint: disable=broad-except
117117 if self .state != STATE_STOPPED :
@@ -129,6 +129,6 @@ async def listen(self):
129129 while self .state != STATE_STOPPED :
130130 await self .running ()
131131
132- def close (self ):
132+ async def close (self ):
133133 """Close the listening websocket."""
134- self .state = STATE_STOPPED
134+ await OpenEVSEWebsocket .state . fset ( self , STATE_STOPPED )
0 commit comments