Skip to content

Commit

Permalink
fix: halt keepalive when websocket stopped (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
firstof9 authored Feb 11, 2025
1 parent 459bd73 commit 352563b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
9 changes: 2 additions & 7 deletions openevsehttp/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ def _start_listening(self):

if not self._ws_listening:
_LOGGER.debug("Setting up websocket ping...")
self._loop.create_task(self.repeat(300, self.websocket.keepalive))
self._loop.create_task(self.websocket.listen())
self._loop.create_task(self.repeat(300, self.websocket.keepalive))
pending = asyncio.all_tasks()
self._ws_listening = True
try:
Expand Down Expand Up @@ -296,11 +296,6 @@ async def ws_disconnect(self) -> None:
self._ws_listening = False
assert self.websocket
await self.websocket.close()
if self._loop:
try:
self._loop.cancel()
except AttributeError:
pass

def is_coroutine_function(self, callback):
"""Check if a callback is a coroutine function."""
Expand All @@ -320,7 +315,7 @@ async def repeat(self, interval, func, *args, **kwargs):
*args and **kwargs are passed as the arguments to func.
"""
while True:
while self.ws_state != "stopped":
await asyncio.sleep(interval)
await func(*args, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

PROJECT_DIR = Path(__file__).parent.resolve()
README_FILE = PROJECT_DIR / "README.md"
VERSION = "0.1.76"
VERSION = "0.1.77"

setup(
name="python_openevse_http",
Expand Down

0 comments on commit 352563b

Please sign in to comment.