From 0048da232e46b986cc47b540b6229fc77cc0485e Mon Sep 17 00:00:00 2001 From: "firstof9@gmail.com" Date: Fri, 3 Jan 2025 14:35:02 -0700 Subject: [PATCH 1/3] fix: fix asyncio task scheduling for websocket ping --- openevsehttp/__main__.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/openevsehttp/__main__.py b/openevsehttp/__main__.py index ffe8901..21b490c 100644 --- a/openevsehttp/__main__.py +++ b/openevsehttp/__main__.py @@ -26,6 +26,7 @@ TTF, TYPE, VALUE, + VERSION, VOLTAGE, ) from .exceptions import ( @@ -239,8 +240,9 @@ def _start_listening(self): _LOGGER.debug("Using new event loop...") 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: @@ -311,10 +313,9 @@ async def repeat(self, interval, func, *args, **kwargs): *args and **kwargs are passed as the arguments to func. """ while True: - await asyncio.gather( - func(*args, **kwargs), - asyncio.sleep(interval), - ) + await asyncio.sleep(interval) + await func(*args, **kwargs) + async def get_schedule(self) -> Union[Dict[str, str], Dict[str, Any]]: """Return the current schedule.""" From 88c4c6b84b6ce6d5c611e52d2732a84aaff4c6d0 Mon Sep 17 00:00:00 2001 From: "firstof9@gmail.com" Date: Fri, 3 Jan 2025 14:37:48 -0700 Subject: [PATCH 2/3] formatting --- openevsehttp/__main__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openevsehttp/__main__.py b/openevsehttp/__main__.py index 21b490c..5c1f948 100644 --- a/openevsehttp/__main__.py +++ b/openevsehttp/__main__.py @@ -316,7 +316,6 @@ async def repeat(self, interval, func, *args, **kwargs): await asyncio.sleep(interval) await func(*args, **kwargs) - async def get_schedule(self) -> Union[Dict[str, str], Dict[str, Any]]: """Return the current schedule.""" url = f"{self.url}schedule" From 5c7dc1c10a2d0578e5e9f1e10dbac89ff31722ef Mon Sep 17 00:00:00 2001 From: "firstof9@gmail.com" Date: Fri, 3 Jan 2025 14:38:47 -0700 Subject: [PATCH 3/3] linting --- openevsehttp/__main__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openevsehttp/__main__.py b/openevsehttp/__main__.py index 5c1f948..6fdc135 100644 --- a/openevsehttp/__main__.py +++ b/openevsehttp/__main__.py @@ -26,7 +26,6 @@ TTF, TYPE, VALUE, - VERSION, VOLTAGE, ) from .exceptions import (