Skip to content

Commit 7bb4b80

Browse files
authored
fix: fix asyncio task scheduling for websocket ping (#402)
* fix: fix asyncio task scheduling for websocket ping * formatting * linting
1 parent 2853f57 commit 7bb4b80

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

openevsehttp/__main__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,9 @@ def _start_listening(self):
239239
_LOGGER.debug("Using new event loop...")
240240

241241
if not self._ws_listening:
242+
_LOGGER.debug("Setting up websocket ping...")
243+
self._loop.create_task(self.repeat(300, self.websocket.keepalive))
242244
self._loop.create_task(self.websocket.listen())
243-
self._loop.create_task(self.repeat(300, self.websocket.keepalive()))
244245
pending = asyncio.all_tasks()
245246
self._ws_listening = True
246247
try:
@@ -311,10 +312,8 @@ async def repeat(self, interval, func, *args, **kwargs):
311312
*args and **kwargs are passed as the arguments to func.
312313
"""
313314
while True:
314-
await asyncio.gather(
315-
func(*args, **kwargs),
316-
asyncio.sleep(interval),
317-
)
315+
await asyncio.sleep(interval)
316+
await func(*args, **kwargs)
318317

319318
async def get_schedule(self) -> Union[Dict[str, str], Dict[str, Any]]:
320319
"""Return the current schedule."""

0 commit comments

Comments
 (0)