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 feature flags for nfc and fingerprint #276

Merged

Conversation

RaHehl
Copy link
Collaborator

@RaHehl RaHehl commented Nov 17, 2024

Description of change

add missing featureflags for nfc and fingerprint

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 new camera feature flags: support for NFC and fingerprint sensor capabilities.
    • Expanded user management with additional user entries and permissions.
    • Enhanced device configurations with new sensors, doorlocks, and chimes.
  • Bug Fixes

    • Improved test validations for NFC and fingerprint sensor feature flags in relevant tests.
  • Documentation

    • Updated configuration files to reflect new features and settings for devices.

Copy link
Contributor

coderabbitai bot commented Nov 17, 2024

Walkthrough

This pull request introduces several enhancements to the CameraFeatureFlags class in src/uiprotect/data/devices.py by adding two new optional boolean attributes: support_nfc and has_fingerprint_sensor. Additionally, it updates the testing framework in tests/conftest.py to accommodate new API features and enhance mock functionalities. The sample_bootstrap.json and sample_camera.json files have been modified to include new feature flags and user configurations. Lastly, the test suite in tests/test_api_ws.py has been updated to validate the new feature flags during relevant events.

Changes

File Path Change Summary
src/uiprotect/data/devices.py Added attributes support_nfc and has_fingerprint_sensor to CameraFeatureFlags. Updated class docstring.
tests/conftest.py Expanded mock_api_request functions for new endpoints. Added new dictionaries: NEW_FIELDS, NEW_CAMERA_FEATURE_FLAGS, NEW_ISP_SETTINGS. Updated compare_objs for new field checks.
tests/sample_data/sample_bootstrap.json Added feature flags hasFingerprintSensor and supportNfc. Expanded users, sensors, and doorlocks sections with new entries.
tests/sample_data/sample_camera.json Added properties hasFingerprintSensor and supportNfc to featureFlags.
tests/test_api_ws.py Added assertions for NFC and fingerprint feature flags in relevant tests.

Possibly related PRs

Suggested reviewers

  • bdraco

🐰 Hopping through the code, we add new flair,
With flags for fingerprint and NFC to share.
In tests we ensure, all features align,
For cameras that capture, and functions that shine!
Let's cheer for the changes, a leap and a bound,
In the world of devices, our joy knows no ground! 🎉


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 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.

@RaHehl RaHehl marked this pull request as ready for review November 18, 2024 08:33
Copy link

codecov bot commented Nov 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
src/uiprotect/data/devices.py 85.40% <100.00%> (+0.01%) ⬆️

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

🧹 Outside diff range and nitpick comments (6)
tests/conftest.py (1)

747-749: Align indentation of new feature flags with existing entries

The indentation of "supportNfc" and "hasFingerprintSensor" is inconsistent with the other entries in NEW_CAMERA_FEATURE_FLAGS. For consistency and readability, please adjust the indentation.

Apply this diff to fix the indentation:

 # 4.73.71+
-        "supportNfc",
-        "hasFingerprintSensor",
+    "supportNfc",
+    "hasFingerprintSensor",
tests/sample_data/sample_camera.json (2)

471-471: Maintain consistent naming convention for feature flags

While the addition of NFC and fingerprint sensor flags is appropriate, the naming convention should be consistent with other hardware capability flags in the configuration.

Consider updating the NFC flag to follow the "has" prefix convention:

         "hasFingerprintSensor": true,
         "mountPositions": [],
         "smartDetectTypes": [
             "person",
             "vehicle"
         ],
-        "supportNfc": true,
+        "hasNfc": true,
         "motionAlgorithms": [

Also applies to: 477-477


471-477: Consider grouping related feature flags

For better maintainability and readability, consider grouping related hardware capability flags together (e.g., authentication-related features like NFC, fingerprint sensor, and biometrics).

Consider moving these flags next to other hardware-related flags like hasBluetooth or hasLcdScreen to maintain a logical grouping.

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

862-864: LGTM! Consider adding docstrings for the new feature flags.

The new feature flags follow the established naming conventions and type patterns. Consider adding docstrings to describe their purpose and usage.

    # 4.73.71+
-   support_nfc: bool | None = None
-   has_fingerprint_sensor: bool | None = None
+   # Whether the camera supports NFC card scanning capabilities
+   support_nfc: bool | None = None
+   # Whether the camera has a fingerprint sensor for biometric authentication
+   has_fingerprint_sensor: bool | None = None

862-864: Consider adding helper properties for the new feature flags.

For consistency with other feature flags in the codebase, consider adding helper properties to the Camera class to check these capabilities.

Add these properties to the Camera class:

@property
def is_nfc_supported(self) -> bool:
    """Whether the camera supports NFC card scanning."""
    return self.feature_flags.support_nfc is True

@property
def has_fingerprint(self) -> bool:
    """Whether the camera has a fingerprint sensor."""
    return self.feature_flags.has_fingerprint_sensor is True
tests/sample_data/sample_bootstrap.json (1)

Line range hint 1-2024: Consider adding documentation for new feature flags.

The new feature flags have been added but there's no documentation explaining their purpose or expected behavior. Consider adding comments or documentation to describe:

  • When these features are enabled/disabled
  • How they interact with other settings
  • Any dependencies or requirements
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c1c5d48 and cc8becd.

📒 Files selected for processing (5)
  • src/uiprotect/data/devices.py (1 hunks)
  • tests/conftest.py (1 hunks)
  • tests/sample_data/sample_bootstrap.json (1 hunks)
  • tests/sample_data/sample_camera.json (1 hunks)
  • tests/test_api_ws.py (2 hunks)
🔇 Additional comments (4)
tests/test_api_ws.py (2)

342-342: LGTM! Good feature validation.

The assertion correctly validates that the camera has NFC support before testing NFC card scanning events.


416-416: LGTM! Good feature validation.

The assertion correctly validates that the camera has fingerprint sensor support before testing fingerprint identification events.

tests/sample_data/sample_bootstrap.json (2)

2003-2003: LGTM: Feature flags properly added to G4 Doorbell Pro device.

The new feature flags hasFingerprintSensor and supportNfc are correctly added to the G4 Doorbell Pro device configuration, which is the appropriate device type for these capabilities.

Also applies to: 2009-2009


2003-2009: Verify feature flags are enabled only for supported devices.

The feature flags are currently only added to the G4 Doorbell Pro device. Let's verify this is intentional and no other device types should have these capabilities.

@bdraco bdraco merged commit e208d9e into uilibs:main Nov 18, 2024
13 of 14 checks passed
@bdraco
Copy link
Member

bdraco commented Nov 18, 2024

Thanks @RaHehl

@bdraco
Copy link
Member

bdraco commented Nov 18, 2024

6.6.0 cooking

@RaHehl
Copy link
Collaborator Author

RaHehl commented Nov 18, 2024

Thanks @bdraco, created a pr in HA home-assistant/core#130872

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