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

feat: add AiPort support #330

Merged
merged 11 commits into from
Dec 18, 2024
Merged

feat: add AiPort support #330

merged 11 commits into from
Dec 18, 2024

Conversation

RaHehl
Copy link
Collaborator

@RaHehl RaHehl commented Dec 16, 2024

Description of change

Pull-Request Checklist

  • Code is up-to-date with the main branch
  • This pull request follows the contributing guidelines.
  • This pull request links relevant issues as Fixes #0000
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change
  • The new commits follow conventions outlined in the conventional commit spec, such as "fix(api): prevent racing of requests".
  • If pre-commit.ci is failing, try pre-commit run -a for further information.
  • If CI / test is failing, try poetry run pytest for further information.

Summary by CodeRabbit

  • New Features

    • Introduced support for a new device type, AiPort, enhancing device management capabilities.
    • Added methods to retrieve AiPort devices and their details.
    • Expanded sample data generation to include AiPort data.
    • Updated JSON structures to reflect AiPort properties and relationships with cameras.
    • Integrated AiPort management into the command-line interface.
    • Added new test coverage for AiPort functionality within the API client.
  • Bug Fixes

    • Improved object comparison logic to accommodate the new AiPort type.
  • Documentation

    • Updated sample JSON files to include new attributes related to AiPort.

Copy link
Contributor

coderabbitai bot commented Dec 16, 2024

Walkthrough

This pull request introduces support for a new device type called AiPort across multiple files in the uiprotect package. The changes involve updating the API client, data models, type definitions, and test utilities to accommodate the new device. Key modifications include adding methods to retrieve AiPort devices, extending the Bootstrap class with an aiports attribute, updating model conversion mappings, and creating a new AiPort class that inherits from the Camera class.

Changes

File Change Summary
src/uiprotect/api.py - Added get_aiports() and get_aiport() methods
- Updated import to include AiPort
src/uiprotect/data/__init__.py - Imported AiPort
- Added AiPort to __all__
src/uiprotect/data/bootstrap.py - Added aiports attribute to Bootstrap class
src/uiprotect/data/convert.py - Updated MODEL_TO_CLASS to include ModelType.AIPORT
src/uiprotect/data/devices.py - Added new AiPort class inheriting from Camera
- Implemented paired_cameras property
src/uiprotect/data/types.py - Added AIPORT enum value to ModelType
src/uiprotect/test_util/__init__.py - Added generate_aiport_data() method
- Updated generate_device_data() to include aiport data
tests/conftest.py - Added new constants and methods for handling AiPort in tests
tests/sample_data/sample_bootstrap.json - Added aiports section with device details
tests/sample_data/sample_camera.json - Added isPairedWithAiPort property
src/uiprotect/cli/__init__.py - Integrated aiports CLI commands
src/uiprotect/cli/aiports.py - Created CLI for managing AiPort devices
tests/sample_data/sample_aiport.json - Added JSON configuration for the "AI Port" device
tests/test_api.py - Added tests for AiPort functionality

Possibly related PRs

  • feat: add keyring and ulp-user #299: This PR modifies the ProtectApiClient class in src/uiprotect/api.py, which is also the file modified in the main PR. It introduces new functionality related to handling keyrings and ULP users, which may share some underlying logic with the new methods for handling AiPort devices.
  • feat: refactor keyrings and ulpusers to add internal indices #313: This PR also focuses on changes in the ProtectApiClient class in src/uiprotect/api.py, specifically altering how keyrings and users are processed. The modifications to the data handling in this file could relate to the overall structure and functionality being enhanced in the main PR for the AiPort device management.

Suggested reviewers

  • bdraco

Poem

🐰 Hop, hop, a new device arrives!
AiPort dancing through our code's hives
Cameras paired, connections bright
A rabbit's tech takes playful flight! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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 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

codecov bot commented Dec 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
src/uiprotect/api.py 56.53% <100.00%> (+0.34%) ⬆️
src/uiprotect/data/__init__.py 100.00% <ø> (ø)
src/uiprotect/data/bootstrap.py 68.84% <100.00%> (+0.09%) ⬆️
src/uiprotect/data/convert.py 88.88% <ø> (ø)
src/uiprotect/data/devices.py 86.27% <100.00%> (+0.29%) ⬆️
src/uiprotect/data/types.py 99.79% <100.00%> (+<0.01%) ⬆️

... and 1 file with indirect coverage changes

@RaHehl RaHehl marked this pull request as draft December 16, 2024 19:52
Copy link
Contributor

@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 (1)
src/uiprotect/api.py (1)

1397-1404: Fix typo in docstring

There's a typo in the docstring: self.bootstrap.aiport[device_id] should be self.bootstrap.aiports[device_id].

-        The websocket is connected and running, you likely just want to use `self.bootstrap.aiport[device_id]`
+        The websocket is connected and running, you likely just want to use `self.bootstrap.aiports[device_id]`
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2264ea4 and a700e9a.

📒 Files selected for processing (10)
  • src/uiprotect/api.py (3 hunks)
  • src/uiprotect/data/__init__.py (2 hunks)
  • src/uiprotect/data/bootstrap.py (2 hunks)
  • src/uiprotect/data/convert.py (2 hunks)
  • src/uiprotect/data/devices.py (2 hunks)
  • src/uiprotect/data/types.py (2 hunks)
  • src/uiprotect/test_util/__init__.py (3 hunks)
  • tests/conftest.py (1 hunks)
  • tests/sample_data/sample_bootstrap.json (12 hunks)
  • tests/sample_data/sample_camera.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • tests/sample_data/sample_camera.json
👮 Files not reviewed due to content moderation or server errors (2)
  • src/uiprotect/data/devices.py
  • tests/sample_data/sample_bootstrap.json
🔇 Additional comments (14)
tests/conftest.py (1)

784-784: Adding AiPort to object comparison in tests

Including ModelType.AIPORT.value in the condition ensures that AiPort devices are correctly handled in the compare_objs function alongside cameras.

src/uiprotect/data/convert.py (2)

11-11: Importing AiPort for model conversion

Adding AiPort to the import statement allows it to be used in the model conversion mappings.


44-44: Mapping ModelType.AIPORT to AiPort class

Including ModelType.AIPORT: AiPort in the MODEL_TO_CLASS mapping integrates the AiPort model into the conversion system, enabling proper instantiation from data dictionaries.

src/uiprotect/data/__init__.py (2)

13-13: Importing AiPort into the data module

Adding AiPort to the list of imports ensures it is accessible within the data package.


89-89: Exposing AiPort in the public API

Including AiPort in the __all__ list makes it part of the module's public interface, allowing users to import it directly.

src/uiprotect/data/types.py (2)

127-127: Adding AiPort to ModelType enum

Defining AIPORT = "aiport" in the ModelType enum ensures the new device type is recognized throughout the codebase.


177-177: Including AiPort in bootstrap model types

Adding ModelType.AIPORT to the _bootstrap_model_types method includes AiPort devices in the bootstrap process, ensuring they are properly initialized during startup.

src/uiprotect/test_util/__init__.py (3)

134-134: LGTM: Device count tracking is consistent

The addition of "aiport" count follows the established pattern for tracking device counts in the bootstrap data.


287-287: LGTM: Device data generation is properly integrated

The addition of aiport data generation maintains consistency with other device types and preserves the alphabetical ordering.


474-488: LGTM: AiPort data generation implementation is well-structured

The implementation follows the established pattern for device data generation, including:

  • Proper error handling for when no aiport is found
  • Appropriate logging
  • Consistent API endpoint usage
src/uiprotect/data/bootstrap.py (2)

26-26: LGTM: Import statement follows conventions

The addition of AiPort to the imports maintains consistency with the existing import style and alphabetical ordering.


185-185: LGTM: Bootstrap class attribute is properly defined

The aiports attribute is correctly typed and follows the established pattern for device storage in the Bootstrap class.

src/uiprotect/api.py (2)

60-60: LGTM: Import statement is consistent

The addition of AiPort to the imports follows the established pattern.


1271-1278: LGTM: get_aiports method is well-implemented

The implementation follows the established pattern for device retrieval methods and includes appropriate type safety through casting.

@RaHehl RaHehl marked this pull request as ready for review December 17, 2024 22:32
Copy link
Contributor

@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: 4

🧹 Nitpick comments (1)
src/uiprotect/cli/aiports.py (1)

44-44: Enhance error message for invalid device ID

The error message could be more descriptive to help users understand the issue.

-            typer.secho("Invalid aiport ID", fg="red")
+            typer.secho(f"Invalid AiPort ID: {device_id}", fg="red")
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a700e9a and ee47bf5.

📒 Files selected for processing (6)
  • src/uiprotect/cli/__init__.py (2 hunks)
  • src/uiprotect/cli/aiports.py (1 hunks)
  • src/uiprotect/data/devices.py (2 hunks)
  • tests/conftest.py (7 hunks)
  • tests/sample_data/sample_aiport.json (1 hunks)
  • tests/test_api.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/conftest.py
🔇 Additional comments (7)
src/uiprotect/cli/aiports.py (2)

17-21: LGTM: AiPortContext class implementation

The class correctly extends base.CliContext and provides appropriate type hints for devices dictionary and device instance.


26-57: LGTM: Main callback implementation

The implementation follows the established pattern for CLI modules:

  • Proper handling of device selection
  • Consistent use of base printing utilities
  • Appropriate error handling and exit codes
src/uiprotect/cli/__init__.py (1)

20-20: LGTM: AiPort CLI integration

The integration of the AiPort CLI module follows the established pattern for sub-application registration.

tests/sample_data/sample_aiport.json (1)

1-757: LGTM: Overall configuration structure

The configuration provides a comprehensive representation of an AiPort device with appropriate settings for:

  • Device capabilities and feature flags
  • Video and audio configuration
  • Smart detection settings
  • Network and connection state
  • Security and privacy settings
tests/test_api.py (3)

908-913: LGTM! Test follows established patterns.

The test case follows the same pattern as other device tests, properly validating the object creation and API response matching.


916-924: LGTM! Error handling test is well implemented.

The test properly validates the error handling for non-adopted devices, following the established pattern.


926-934: LGTM! Test validates ignore_unadopted flag behavior.

The test properly validates the retrieval of non-adopted devices when the ignore flag is disabled, following the established pattern.

src/uiprotect/cli/aiports.py Outdated Show resolved Hide resolved
tests/sample_data/sample_aiport.json Show resolved Hide resolved
tests/sample_data/sample_aiport.json Show resolved Hide resolved
src/uiprotect/data/devices.py Show resolved Hide resolved
Copy link
Contributor

@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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ee47bf5 and 3725574.

📒 Files selected for processing (3)
  • src/uiprotect/cli/aiports.py (1 hunks)
  • tests/conftest.py (8 hunks)
  • tests/test_api.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/uiprotect/cli/aiports.py
🔇 Additional comments (10)
tests/conftest.py (6)

56-56: LGTM: Constant declaration follows existing pattern

The constant TEST_AIPORT_EXISTS is correctly defined following the same pattern as other device existence checks.


93-100: LGTM: Function implementation matches existing patterns

The read_aiport_json_file() function follows the same pattern as other device-specific JSON file readers, including the handling of global recording settings.


162-163: LGTM: Mock API request handler updated correctly

The mock_api_request() function is properly updated to handle AiPort-related requests, maintaining consistency with other device types.

Also applies to: 202-203


474-480: LGTM: Fixture follows established patterns

The aiport_obj fixture follows the same pattern as other device object fixtures, correctly handling the case when test data doesn't exist.


583-589: LGTM: List fixture follows established patterns

The aiports fixture follows the same pattern as other device list fixtures, correctly handling empty lists when test data doesn't exist.


822-822: LGTM: Object comparison updated for new device type

The compare_objs() function is correctly updated to handle AiPort objects with the same field exclusions as cameras.

tests/test_api.py (4)

908-914: LGTM: Basic device retrieval test

The test follows the established pattern for device retrieval tests, correctly using the fixture and comparing the results.


916-924: LGTM: Not adopted error test

The test correctly verifies that attempting to retrieve a non-adopted device raises an NvrError when ignore_unadopted is true.


926-935: LGTM: Not adopted allowed test

The test correctly verifies that non-adopted devices can be retrieved when ignore_unadopted is false.


966-971: LGTM: Device list retrieval test

The test correctly verifies the retrieval of multiple AiPort devices, following the established pattern for device list tests.

tests/conftest.py Show resolved Hide resolved
@RaHehl RaHehl merged commit ba459ff into uilibs:main Dec 18, 2024
9 of 10 checks passed
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.

2 participants