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

Save references to telnet callback tasks #277

Merged
merged 1 commit into from
Feb 3, 2024
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
6 changes: 5 additions & 1 deletion denonavr/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
Hashable,
List,
Optional,
Set,
Tuple,
cast,
)
Expand Down Expand Up @@ -435,6 +436,7 @@ class DenonAVRTelnetApi:
default=attr.Factory(dict),
init=False,
)
_callback_tasks: Set[asyncio.Task] = attr.ib(attr.Factory(set))

async def async_connect(self) -> None:
"""Connect to the receiver asynchronously."""
Expand Down Expand Up @@ -624,7 +626,9 @@ def _process_event(self, message: str) -> None:
if event not in TELNET_EVENTS:
return

asyncio.create_task(self._async_run_callbacks(event, zone, parameter))
task = asyncio.create_task(self._async_run_callbacks(event, zone, parameter))
self._callback_tasks.add(task)
task.add_done_callback(self._callback_tasks.discard)

async def _async_run_callbacks(self, event: str, zone: str, parameter: str) -> None:
"""Handle triggering the registered callbacks for the event."""
Expand Down
Loading