Skip to content

Commit aaa4d28

Browse files
authored
feat: return better messages from websocket handler (#405)
* feat: return better messages from websocket handler * formatting
1 parent 3fa2153 commit aaa4d28

File tree

4 files changed

+90
-10
lines changed

4 files changed

+90
-10
lines changed

openevsehttp/__main__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,13 @@ def ws_start(self) -> None:
231231

232232
def _start_listening(self):
233233
"""Start the websocket listener."""
234-
try:
235-
_LOGGER.debug("Attempting to find running loop...")
236-
self._loop = asyncio.get_running_loop()
237-
except RuntimeError:
238-
self._loop = asyncio.get_event_loop()
239-
_LOGGER.debug("Using new event loop...")
234+
if not self._loop:
235+
try:
236+
_LOGGER.debug("Attempting to find running loop...")
237+
self._loop = asyncio.get_running_loop()
238+
except RuntimeError:
239+
self._loop = asyncio.get_event_loop()
240+
_LOGGER.debug("Using new event loop...")
240241

241242
if not self._ws_listening:
242243
_LOGGER.debug("Setting up websocket ping...")
@@ -260,6 +261,7 @@ async def _update_status(self, msgtype, data, error):
260261
"Websocket to %s disconnected, retrying",
261262
self.websocket.uri,
262263
)
264+
_LOGGER.debug("Disconnect message: %s", error)
263265
self._ws_listening = False
264266
self.ws_start()
265267
# Stopped websockets without errors are expected during shutdown
@@ -291,9 +293,9 @@ async def _update_status(self, msgtype, data, error):
291293

292294
async def ws_disconnect(self) -> None:
293295
"""Disconnect the websocket listener."""
296+
self._ws_listening = False
294297
assert self.websocket
295298
await self.websocket.close()
296-
self._ws_listening = False
297299

298300
def is_coroutine_function(self, callback):
299301
"""Check if a callback is a coroutine function."""

openevsehttp/websocket.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ async def running(self):
107107
self._error_reason = ERROR_AUTH_FAILURE
108108
else:
109109
_LOGGER.error("Unexpected response received: %s", error)
110-
self._error_reason = ERROR_UNKNOWN
110+
self._error_reason = error
111111
await OpenEVSEWebsocket.state.fset(self, STATE_STOPPED)
112112
except (aiohttp.ClientConnectionError, asyncio.TimeoutError) as error:
113113
if self.failed_attempts >= MAX_FAILED_ATTEMPTS:
@@ -126,7 +126,7 @@ async def running(self):
126126
except Exception as error: # pylint: disable=broad-except
127127
if self.state != STATE_STOPPED:
128128
_LOGGER.exception("Unexpected exception occurred: %s", error)
129-
self._error_reason = ERROR_UNKNOWN
129+
self._error_reason = error
130130
await OpenEVSEWebsocket.state.fset(self, STATE_STOPPED)
131131
else:
132132
if self.state != STATE_STOPPED:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
PROJECT_DIR = Path(__file__).parent.resolve()
88
README_FILE = PROJECT_DIR / "README.md"
9-
VERSION = "0.1.69"
9+
VERSION = "0.1.70"
1010

1111
setup(
1212
name="python_openevse_http",

0 commit comments

Comments
 (0)