Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix asyncio task scheduling for websocket ping #402

Merged
merged 3 commits into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
_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 @@
*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)

Check warning on line 316 in openevsehttp/__main__.py

View check run for this annotation

Codecov / codecov/patch

openevsehttp/__main__.py#L316

Added line #L316 was not covered by tests

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