Skip to content

Commit

Permalink
Tweat heart beat loop
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsayre committed Jan 26, 2025
1 parent 8ccb03f commit 4060b0c
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions pyheos/connection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Define the connection module."""

import asyncio
from contextlib import suppress
import logging
from collections.abc import Awaitable, Callable, Coroutine
from datetime import datetime, timedelta
Expand Down Expand Up @@ -301,13 +302,10 @@ async def _heart_beat_handler(self) -> None:
while self._state == ConnectionState.CONNECTED:
last_acitvity_delta = datetime.now() - self._last_activity
if last_acitvity_delta >= self._heart_beat_interval_delta:
try:
with suppress(CommandError):
await self.command(HeosCommand(COMMAND_HEART_BEAT))
except (CommandError, asyncio.TimeoutError):
# Exit the task, as the connection will be reset/closed.
return
# Sleep until next interval
await asyncio.sleep(float(self._heart_beat_interval / 2))
await asyncio.sleep(self._heart_beat_interval)

async def _attempt_reconnect(self) -> None:
"""Attempt to reconnect after disconnection from error."""
Expand Down

0 comments on commit 4060b0c

Please sign in to comment.