Skip to content

Commit

Permalink
fix: pingback did not hold a strong reference to the task (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Jun 14, 2024
1 parent 832865e commit 7b11ce9
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/uiprotect/data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
ProtectObject = TypeVar("ProtectObject", bound="ProtectBaseObject")
RECENT_EVENT_MAX = timedelta(seconds=30)
EVENT_PING_INTERVAL = timedelta(seconds=3)
EVENT_PING_INTERVAL_SECONDS = EVENT_PING_INTERVAL.total_seconds()

_LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -787,10 +789,14 @@ async def _save_device_changes(
raise

if force_emit:
await self.emit_message(updated)
self._emit_message(updated)

async def emit_message(self, updated: dict[str, Any]) -> None:
"""Emites fake WS message for ProtectApiClient to process."""
"""Emits fake WS message for ProtectApiClient to process."""
self._emit_message(updated)

def _emit_message(self, updated: dict[str, Any]) -> None:
"""Emits fake WS message for ProtectApiClient to process."""
if updated == {}:
_LOGGER.debug("Event ping callback started for %s", self.id)

Expand Down Expand Up @@ -877,9 +883,9 @@ def _event_callback_ping(self) -> None:
_LOGGER.debug("Event ping timer started for %s", self.id)
loop = asyncio.get_event_loop()
self._callback_ping = loop.call_later(
EVENT_PING_INTERVAL.total_seconds(),
asyncio.create_task,
self.emit_message({}),
EVENT_PING_INTERVAL_SECONDS,
self._emit_message,
{},
)

async def set_name(self, name: str | None) -> None:
Expand Down

0 comments on commit 7b11ce9

Please sign in to comment.