Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion airos/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def datagram_received(self, data: bytes, addr: tuple[str, int]) -> None:
parsed_data: dict[str, Any] | None = self.parse_airos_packet(data, host_ip)
if parsed_data:
# Schedule the user-provided callback, don't await to keep listener responsive
asyncio.create_task(self.callback(parsed_data)) # noqa: RUF006
self.callback(parsed_data)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Critical: Async callback not properly invoked.

The callback is documented as asynchronous (line 36) but is now called directly without awaiting, causing the coroutine to never execute. The pipeline failure confirms this with "RuntimeWarning: coroutine was never awaited."

Choose one of these solutions:

Option 1: Restore async task scheduling (recommended)

-                self.callback(parsed_data)
+                asyncio.create_task(self.callback(parsed_data))

Option 2: Await the callback (blocks the listener)

-                self.callback(parsed_data)
+                await self.callback(parsed_data)

Option 3: Make callback synchronous (breaking change)

-    def __init__(self, callback: Callable[[dict[str, Any]], None]) -> None:
+    def __init__(self, callback: Callable[[dict[str, Any]], None]) -> None:
         """Initialize AirosDiscoveryProtocol.

         Args:
-            callback: An asynchronous function to call when a device is discovered.
+            callback: A synchronous function to call when a device is discovered.
                       It should accept a dictionary containing device information.

The first option maintains the original responsive behavior while properly handling async callbacks.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
self.callback(parsed_data)
- self.callback(parsed_data)
+ asyncio.create_task(self.callback(parsed_data))
🧰 Tools
🪛 GitHub Actions: Latest commit

[warning] 62-62: RuntimeWarning: coroutine 'AsyncMockMixin._execute_mock_call' was never awaited. This warning indicates a coroutine was not awaited properly.

🤖 Prompt for AI Agents
In airos/discovery.py at line 62, the async callback is called directly without
awaiting, causing the coroutine to never execute. To fix this, restore the async
task scheduling by using an appropriate method like asyncio.create_task to
schedule the callback instead of calling it directly. This ensures the callback
runs asynchronously without blocking the listener.

except (AirosEndpointError, AirosListenerError) as err:
# These are expected types of malformed packets. Log the specific error
# and then re-raise as AirosDiscoveryError.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "airos"
version = "0.2.0"
version = "0.2.1"
license = "MIT"
description = "Ubiquity airOS module(s) for Python 3."
readme = "README.md"
Expand Down
Loading