Skip to content

Commit

Permalink
fix: fix asyncio task scheduling for websocket ping (#402)
Browse files Browse the repository at this point in the history
* fix: fix asyncio task scheduling for websocket ping

* formatting

* linting
  • Loading branch information
firstof9 authored Jan 3, 2025
1 parent 2853f57 commit 7bb4b80
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions openevsehttp/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,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:
Expand Down Expand Up @@ -311,10 +312,8 @@ 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."""
Expand Down

0 comments on commit 7bb4b80

Please sign in to comment.