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

aiocoap: Adjust to subtle API change #536

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 6 additions & 4 deletions pytradfri/api/aiocoap_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def __init__(
self._host = host
self._psk_id = psk_id
self._observations_err_callbacks: list[Callable[[Exception], None]] = []
self._protocol: asyncio.Task[Context] | None = None
self._protocol: Context | None = None
self._protocol_creation_lock = asyncio.Lock()
self._reset_lock = asyncio.Lock()
self._shutdown = False

Expand All @@ -100,9 +101,10 @@ def psk(self) -> str | None:

async def _get_protocol(self) -> Context:
"""Get the protocol for the request."""
if self._protocol is None:
self._protocol = asyncio.create_task(Context.create_client_context())
return await self._protocol
async with self._protocol_creation_lock:
if self._protocol is None:
self._protocol = await Context.create_client_context()
return self._protocol

async def _reset_protocol(self, exc: BaseException | None = None) -> None:
"""Reset the protocol if an error occurs."""
Expand Down