Skip to content

Conversation

@CoMPaTech
Copy link
Owner

@CoMPaTech CoMPaTech commented Aug 2, 2025

Note: temporarily adjust minimal coverage (TODO)

Improvements:

  • New function for discovery for consumption by HA
  • Adjusted exceptions to all start with AirOS
  • Adjusted all other Airos occasions to AirOS
  • Adjusted dataclass to use all-caps for Enums
  • Add base amount of testing for new/changed functionality

Summary by CodeRabbit

  • New Features

    • Added a method to control provisioning mode for AirOS devices.
    • Introduced a high-level asynchronous device discovery function for AirOS devices.
  • Refactor

    • Standardized class, exception, and log naming from "Airos" to "AirOS" across the codebase.
    • Renamed enum members in WirelessMode for improved clarity.
  • Bug Fixes

    • Updated tests and fixtures to use new naming conventions and to cover new discovery functionality.
  • Chores

    • Lowered the code coverage threshold in CI from 85% to 80%.
    • Updated project version to 0.2.2.

@coderabbitai
Copy link

coderabbitai bot commented Aug 2, 2025

Walkthrough

This update standardizes exception and class names across the codebase to use the "AirOS" prefix, introduces a new provisioning mode API and asynchronous device discovery function, updates enum member names for clarity, adds new tests and fixtures for discovery, and slightly lowers the test coverage threshold. The project version is incremented.

Changes

Cohort / File(s) Change Summary
Exception Renaming
airos/exceptions.py, airos/airos8.py, airos/discovery.py, tests/test_stations.py, tests/test_discovery.py
All exception classes and related references are renamed to use the "AirOS" prefix (e.g., ConnectionSetupErrorAirOSConnectionSetupError). All usages, imports, and log messages reflect this naming convention for consistency throughout the codebase.
Discovery Protocol & API Enhancements
airos/discovery.py, tests/test_discovery.py, tests/conftest.py
The discovery protocol class is renamed (AirosDiscoveryProtocolAirOSDiscoveryProtocol). A new asynchronous function async_discover_devices is added for device discovery. Tests are updated and expanded to cover new discovery API scenarios, including error and cancellation cases. A new pytest fixture is introduced to mock UDP datagram endpoints for testing.
Provisioning Mode API
airos/airos8.py
A new asynchronous method provmode is added to the AirOS class to control provisioning mode via the /api/provmode endpoint. Minor variable renaming and log message updates are made for clarity in the stakick method.
Enum Naming Consistency
airos/data.py
Enum member names in WirelessMode are updated from AccessPoint_PointToPoint/Station_PointToPoint to PTP_ACCESSPOINT/PTP_STATION for improved clarity and consistency, with no change to their string values.
Project Metadata and Coverage
pyproject.toml, .github/workflows/verify.yml
The project version is bumped from 0.2.1 to 0.2.2. The coverage threshold in the GitHub Actions workflow is lowered from 85% to 80%.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AirOS
    participant API_Server

    User->>AirOS: provmode(active: bool)
    AirOS->>API_Server: POST /api/provmode {"action": "start"/"stop"}
    API_Server-->>AirOS: HTTP 200/Failure
    AirOS-->>User: True/False or raise AirOSDeviceConnectionError
Loading
sequenceDiagram
    participant User
    participant async_discover_devices
    participant EventLoop
    participant AirOSDiscoveryProtocol

    User->>async_discover_devices: call with timeout
    async_discover_devices->>EventLoop: create_datagram_endpoint(AirOSDiscoveryProtocol)
    EventLoop-->>async_discover_devices: (transport, protocol)
    AirOSDiscoveryProtocol-->>async_discover_devices: discovered device(s)
    async_discover_devices-->>User: {mac: device_info, ...}
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~18 minutes

Possibly related PRs

  • CoMPaTech/python-airos#13: Introduced AirOS-prefixed exception classes and began updating their usage, directly related to the exception renaming in this PR.
  • CoMPaTech/python-airos#19: Modified the stakick method in airos8.py, which is also affected in this PR by variable renaming and log message updates.

Suggested labels

enhancement

Poem

A rabbit hops through fields of code,
AirOS names now clearly showed.
Discovery’s easier, errors precise,
Provisioning mode? Just call it—nice!
With tests that mock and enums neat,
This version hop is quite a feat!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch testing

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
.github/workflows/verify.yml (1)

154-154: Ensure the coverage threshold reduction is tracked and reverted.

The coverage threshold was lowered from 85% to 80%, which aligns with the PR objectives mentioning this as a temporary adjustment. Consider adding a TODO comment in the workflow file itself to ensure this reduction is reverted once the new functionality is fully tested.

  coverage combine coverage*/.coverage*
+ # TODO: Revert coverage threshold back to 85% once new discovery functionality is fully tested
  coverage report --fail-under=80
airos/discovery.py (1)

85-86: Consider adding context to the raised exception.

When re-raising AirOSDiscoveryError in connection_lost, consider including the original exception or a descriptive message for better debugging.

-            raise AirOSDiscoveryError from None
+            raise AirOSDiscoveryError("Connection lost due to error") from exc
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0e13428 and 5ac7749.

📒 Files selected for processing (9)
  • .github/workflows/verify.yml (1 hunks)
  • airos/airos8.py (10 hunks)
  • airos/data.py (1 hunks)
  • airos/discovery.py (9 hunks)
  • airos/exceptions.py (1 hunks)
  • pyproject.toml (1 hunks)
  • tests/conftest.py (2 hunks)
  • tests/test_discovery.py (9 hunks)
  • tests/test_stations.py (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (5)
airos/data.py (1)
airos/airos8data.py (5)
  • WirelessMode (18-23)
  • Wireless (265-301)
  • check_for_warnings (394-425)
  • Station (227-261)
  • AirOSData (367-431)
tests/conftest.py (2)
airos/airos8.py (1)
  • AirOS (25-345)
airos/discovery.py (1)
  • AirOSDiscoveryProtocol (18-275)
tests/test_stations.py (3)
airos/exceptions.py (4)
  • AirOSConnectionSetupError (8-9)
  • AirOSDataMissingError (16-17)
  • AirOSConnectionAuthenticationError (12-13)
  • AirOSDeviceConnectionError (24-25)
airos/airos8.py (2)
  • status (227-268)
  • login (76-193)
tests/conftest.py (1)
  • airos_device (20-25)
airos/airos8.py (3)
airos/exceptions.py (5)
  • AirOSConnectionAuthenticationError (12-13)
  • AirOSConnectionSetupError (8-9)
  • AirOSDataMissingError (16-17)
  • AirOSDeviceConnectionError (24-25)
  • AirOSKeyDataMissingError (20-21)
tests/conftest.py (1)
  • base_url (14-16)
airos/airos8data.py (3)
  • AirOSData (367-431)
  • check_for_warnings (394-425)
  • ProvisioningMode (337-340)
airos/discovery.py (2)
airos/exceptions.py (3)
  • AirOSDiscoveryError (28-29)
  • AirOSEndpointError (36-37)
  • AirOSListenerError (32-33)
airos/airos8data.py (2)
  • AirOSData (367-431)
  • check_for_warnings (394-425)
🔇 Additional comments (11)
airos/data.py (1)

45-46: PTP enum renaming is consistent and complete

– Searched for AccessPoint_PointToPoint and Station_PointToPoint: no occurrences found
– Verified PTP_ACCESSPOINT and PTP_STATION only exist in airos/data.py

All references have been updated; this change is ready to merge.

pyproject.toml (1)

7-7: LGTM! Appropriate version increment.

The patch version bump from 0.2.1 to 0.2.2 is appropriate for the improvements, refactoring, and new discovery functionality introduced in this PR.

tests/test_stations.py (1)

108-108: LGTM! Exception names updated consistently.

The exception names have been updated to use the new "AirOS" prefixed naming convention, which aligns with the standardization effort across the codebase. The test logic remains intact while properly catching the renamed exception types.

Also applies to: 127-127, 138-138, 146-146

tests/conftest.py (2)

3-4: LGTM! Appropriate imports for new discovery functionality.

The new imports support the discovery testing functionality with proper asyncio and mocking capabilities.

Also applies to: 7-7


28-50: LGTM! Well-designed test fixture for discovery functionality.

The mock_datagram_endpoint fixture is well-implemented for testing the new UDP discovery functionality:

  • Properly mocks asyncio.DatagramTransport and AirOSDiscoveryProtocol with appropriate specs
  • Uses context managers for clean patch management
  • Pre-defines mock objects to avoid scope issues
  • Returns both transport and protocol instances for comprehensive testing

The fixture follows testing best practices and will enable reliable testing of the discovery protocol.

airos/exceptions.py (1)

8-29: Consistent naming convention applied successfully.

The renaming of all exception classes to include the "AirOS" prefix improves consistency across the codebase. The inheritance hierarchy is properly maintained with all exceptions deriving from the base AirOSException class.

airos/discovery.py (1)

278-325: Well-implemented asynchronous discovery function.

The new async_discover_devices function provides a clean, high-level interface for device discovery with proper error handling and resource cleanup. The use of a closure to capture discovered devices is appropriate, and the transport is correctly closed in the finally block.

airos/airos8.py (2)

15-19: Exception renaming applied consistently throughout the module.

All exception references have been properly updated to use the "AirOS" prefix, maintaining the same error handling behavior while improving naming consistency across the codebase.

Also applies to: 107-345


308-345: New provisioning mode method follows established patterns.

The provmode method is well-implemented, following the same structure and error handling patterns as other methods in the class. The boolean parameter provides a clear interface for enabling/disabling provisioning mode.

tests/test_discovery.py (2)

8-211: Test updates maintain coverage while reflecting naming changes.

All existing tests have been properly updated to use the new "AirOS" prefixed class and exception names. The test logic and coverage remain unchanged, ensuring backward compatibility of the test suite.


217-306: Comprehensive test coverage for the new async discovery function.

The new tests thoroughly cover all aspects of async_discover_devices:

  • Success scenarios with device discovery
  • Empty results when no devices are found
  • Error handling for network issues (OSError)
  • Proper cleanup during cancellation

The tests follow async best practices and ensure proper resource cleanup in all scenarios.

@CoMPaTech CoMPaTech merged commit 8cefa49 into main Aug 2, 2025
9 checks passed
@CoMPaTech CoMPaTech deleted the testing branch August 2, 2025 09:49
This was referenced Aug 2, 2025
@coderabbitai coderabbitai bot mentioned this pull request Oct 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant