Skip to content

Commit 352563b

Browse files
authored
fix: halt keepalive when websocket stopped (#418)
1 parent 459bd73 commit 352563b

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

openevsehttp/__main__.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ def _start_listening(self):
242242

243243
if not self._ws_listening:
244244
_LOGGER.debug("Setting up websocket ping...")
245-
self._loop.create_task(self.repeat(300, self.websocket.keepalive))
246245
self._loop.create_task(self.websocket.listen())
246+
self._loop.create_task(self.repeat(300, self.websocket.keepalive))
247247
pending = asyncio.all_tasks()
248248
self._ws_listening = True
249249
try:
@@ -296,11 +296,6 @@ async def ws_disconnect(self) -> None:
296296
self._ws_listening = False
297297
assert self.websocket
298298
await self.websocket.close()
299-
if self._loop:
300-
try:
301-
self._loop.cancel()
302-
except AttributeError:
303-
pass
304299

305300
def is_coroutine_function(self, callback):
306301
"""Check if a callback is a coroutine function."""
@@ -320,7 +315,7 @@ async def repeat(self, interval, func, *args, **kwargs):
320315
321316
*args and **kwargs are passed as the arguments to func.
322317
"""
323-
while True:
318+
while self.ws_state != "stopped":
324319
await asyncio.sleep(interval)
325320
await func(*args, **kwargs)
326321

setup.py

+1-1
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.76"
9+
VERSION = "0.1.77"
1010

1111
setup(
1212
name="python_openevse_http",

0 commit comments

Comments
 (0)