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

Chime ringtones #346

Merged
merged 4 commits into from
Jan 3, 2025
Merged

Chime ringtones #346

merged 4 commits into from
Jan 3, 2025

Conversation

RaHehl
Copy link
Collaborator

@RaHehl RaHehl commented Jan 3, 2025

Description of change

Resolves #342

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

    • Added support for playing specific ringtones and tracks on chimes.
    • Introduced new ringtone management capabilities.
    • Enhanced speaker playback with additional configuration options.
  • Bug Fixes

    • Improved error handling for chime playback.
  • Tests

    • Added comprehensive test coverage for new speaker playback functionality.

Copy link
Contributor

coderabbitai bot commented Jan 3, 2025

Walkthrough

The pull request introduces support for ringtones in the UI Protect system. A new Ringtone class is added to represent ringtone objects, with attributes like ID, name, and size. The play_speaker method in the API client is enhanced to allow specifying ringtone IDs and track numbers when playing sounds on a chime. Corresponding updates are made to the type system, data conversion, and bootstrap mechanisms to integrate this new functionality seamlessly.

Changes

File Changes
src/uiprotect/api.py Updated play_speaker method signature to include ringtone_id and track_no parameters
src/uiprotect/data/bootstrap.py Added ringtones attribute to Bootstrap class
src/uiprotect/data/convert.py Added Ringtone to model conversion mapping
src/uiprotect/data/devices.py New Ringtone class with attributes like id, name, size, is_default, nvr_mac, model_key
src/uiprotect/data/types.py Added RINGTONE enum value to ModelType
tests/sample_data/sample_bootstrap.json Added sample ringtone data
tests/test_api.py Added test methods for play_speaker with various parameter combinations

Sequence Diagram

sequenceDiagram
    participant User
    participant ProtectApiClient
    participant ChimeDevice
    User->>ProtectApiClient: play_speaker(device_id, ringtone_id, volume)
    ProtectApiClient->>ChimeDevice: Send play request
    ChimeDevice-->>ProtectApiClient: Confirm playback
    ProtectApiClient-->>User: Playback completed
Loading

Poem

🐰 A Chime's New Melody

Ringtones dance, a digital song
With tracks and volumes, nothing wrong
A rabbit's code, both swift and bright
Brings music to the system's might
Hop, hop, hooray for sound's delight! 🎵


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 232d4c8 and 679200d.

📒 Files selected for processing (2)
  • src/uiprotect/data/devices.py (1 hunks)
  • tests/test_api.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/test_api.py
  • src/uiprotect/data/devices.py

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 Jan 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
src/uiprotect/api.py 56.82% <100.00%> (+0.28%) ⬆️
src/uiprotect/data/bootstrap.py 68.93% <100.00%> (+0.09%) ⬆️
src/uiprotect/data/devices.py 86.32% <100.00%> (+0.05%) ⬆️
src/uiprotect/data/types.py 99.80% <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: 1

🧹 Nitpick comments (4)
src/uiprotect/api.py (1)

1809-1810: Include docstring updates for newly introduced parameters.
The play_speaker method signature now includes ringtone_id and track_no, but the method docstring doesn’t mention these new parameters. Document them for clarity and completeness.

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

3392-3398: Implement unit tests for the new Ringtone class.
Great addition of the Ringtone model. Ensure you add tests for data serialization/deserialization, especially if size or model_key are used for downstream logic or filtering.

tests/sample_data/sample_bootstrap.json (2)

7279-7296: Review ringtone configuration structure.

The ringtones section is well-structured with essential fields (id, name, size, isDefault, nvrMac). However, consider enhancing it with additional metadata.

Consider adding:

  • Audio format metadata (e.g., format, bitrate, duration)
  • Size limits validation
  • Compatibility flags for different chime models
 {
     "id": "66a14fa502d44203e40003eb",
     "name": "Default",
     "size": 208,
     "isDefault": true,
     "nvrMac": "4B8290F6D7A3",
-    "modelKey": "ringtone"
+    "modelKey": "ringtone",
+    "format": "mp3",
+    "bitrate": 128,
+    "duration": 2,
+    "compatibleModels": ["UP Chime"]
 }

7289-7291: Fix typo in custom ringtone name.

The custom ringtone name "custometest" appears to have a typo.

Apply this diff to fix the typo:

-            "name": "custometest",
+            "name": "customtest",
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f015a3a and 232d4c8.

📒 Files selected for processing (7)
  • src/uiprotect/api.py (1 hunks)
  • src/uiprotect/data/bootstrap.py (2 hunks)
  • src/uiprotect/data/convert.py (2 hunks)
  • src/uiprotect/data/devices.py (1 hunks)
  • src/uiprotect/data/types.py (1 hunks)
  • tests/sample_data/sample_bootstrap.json (1 hunks)
  • tests/test_api.py (1 hunks)
🔇 Additional comments (11)
src/uiprotect/data/convert.py (2)

17-17: Great addition of Ringtone import.
No issues found. The import statement is clean and follows the existing pattern.


48-48: Mapping Ringtone to ModelType.RINGTONE looks correct.
This inclusion will enable JSON parsing for the new ringtone model.

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

131-131: Enum entry for RINGTONE.
Adding the new enumeration value is consistent. Ensure that external consumers or switch-case logic correctly handle this expanded set of model types.

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

33-33: New import for Ringtone recognized.
This is consistent with the companion changes in convert.py and devices.py.


187-187: New ringtones list in Bootstrap.
Defining a dedicated list for ringtones is a straightforward way to integrate the new model. Consider verifying that your bootstrap loading code properly populates this list in practice.

tests/test_api.py (5)

972-988: Test: test_play_speaker
This test checks the default parameters scenario for the new play_speaker method. It appears thorough and correctly invokes the API with no JSON payload. Nicely done.


989-1008: Test: test_play_speaker_with_volume
Good job verifying that a specified volume is passed in the JSON payload. This ensures volume override is handled.


1009-1029: Test: test_play_speaker_with_ringtone_id
Great addition checking that the ringtoneId parameter is included in the request payload.


1030-1039: Test: test_play_speaker_invalid_chime_id
Verifies exception handling for invalid chime IDs. Good negative test coverage.


1040-1067: Test: test_play_speaker_with_all_parameters
Excellent coverage by specifying all parameters: volume, repeat times, ringtone ID, and track number. This ensures the method can handle multiple simultaneous parameters.

src/uiprotect/api.py (1)

1814-1814: 🛠️ Refactor suggestion

Consider handling fallback logic for track number.
Currently, if ringtone_id is provided, the code removes "trackNo". This is fine if the system intends for these to be mutually exclusive. However, if the user might specify both (ringtone_id for a certain ringtone but also a specific track?), add a guard or a clarifying comment to confirm that only one of the two is truly valid at a time.

Also applies to: 1822-1826

tests/sample_data/sample_bootstrap.json Show resolved Hide resolved
@RaHehl RaHehl merged commit d0c93b5 into uilibs:main Jan 3, 2025
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.

Play specific sound on chime
2 participants