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

Add support for DIRMODE #23

Merged
merged 4 commits into from
Nov 6, 2024
Merged

Add support for DIRMODE #23

merged 4 commits into from
Nov 6, 2024

Conversation

mvdwetering
Copy link
Owner

@mvdwetering mvdwetering commented Nov 6, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a "Pure Direct mode" section in the documentation, detailing control methods and examples for YNCA protocol devices.
    • Introduced a new enumeration, DirMode, to enhance command handling related to device operational modes.
  • Bug Fixes

    • Expanded documentation sections for improved clarity on functionality and known issues with various receivers.
  • Tests

    • Enhanced test coverage for DirMode functionality, ensuring proper handling of device commands and states.
  • Chores

    • Improved organization and clarity of the ZoneBase class and related methods for better maintainability.

Copy link

coderabbitai bot commented Nov 6, 2024

Walkthrough

The pull request introduces significant updates to the documentation and codebase related to the YNCA protocol. Key changes include the addition of a "Pure Direct mode" section in the documentation, enhancements to existing sections for clarity, and the introduction of a new DirMode enumeration. The code updates include new tests for the DirMode functionality, modifications to the ZoneBase class, and an expansion of command handling capabilities in the server. These changes collectively improve the understanding and functionality of the YNCA protocol.

Changes

File Change Summary
docs/PRACTICALITIES.md Added "Pure Direct mode" section; expanded existing sections on volume control, scene activation, and more.
tests/test_enums.py Introduced DirMode enumeration; updated tests to cover invalid values for DirMode.
tests/test_zone.py Added tests for DirMode in ZoneBase; verified command handling for DirMode.ON and DirMode.OFF.
ynca/init.py Added DirMode to imports and updated __all__ list.
ynca/enums.py Created DirMode enumeration with ON, OFF, and UNKNOWN handling.
ynca/server.py Added "DIRMODE" entry to multiresponse_functions_table under "BASIC" key.
ynca/subunits/zone.py Enhanced ZoneBase with dirmode, volume adjustment methods, and synchronization attributes.

Possibly related PRs

  • Add ZoneB support #20: The changes in docs/PRACTICALITIES.md regarding Zone A/B receivers directly relate to the main PR's updates on the same document, enhancing the understanding of operational characteristics and control mechanisms.
  • Explicitly request pure dir mode #21: The modifications to the Zone A/B receivers section in docs/PRACTICALITIES.md also connect with the main PR, as both involve clarifications and details about the behavior of devices using the YNCA protocol, particularly in relation to the Pure Direct mode.

🐇 In the realm of YNCA's grace,
New modes take their rightful place.
With DirMode shining bright,
Commands now dance in delight.
Pure Direct and zones align,
In harmony, they intertwine! 🌟


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

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: 3

🧹 Outside diff range and nitpick comments (6)
ynca/subunits/zone.py (1)

Line range hint 48-70: LGTM! Well-structured helper functions.

Good refactoring to reduce code duplication across volume control methods. The functions are well-documented and handle step sizes appropriately.

Consider adding a note about what happens when an unsupported step size is provided:

 def do_vol_up(self, step_size: float, function: str):
     """
     Increase the volume with given stepsize.
-    Supported stepsizes are: 0.5, 1, 2 and 5
+    Supported stepsizes are: 0.5, 1, 2 and 5.
+    For 0.5, uses "Up" command. For others, uses "Up X dB" format.
     """
docs/PRACTICALITIES.md (3)

174-177: Add language identifier to code block.

Specify the language for the code block to improve syntax highlighting.

-```
+```yaml
 @MAIN:PUREDIRMODE=?  e.g. RX-A810
 @MAIN:DIRMODE=?  e.g. RX-V473

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Markdownlint</summary>

174-174: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</details>

</details>

---

`171-172`: **Improve sentence readability.**

Add a comma for better readability.

```diff
-Both ways seem to support `On` and `Off`. Unclear why there are 2 ways or to which models it applies.
+Both ways seem to support `On` and `Off`. Unclear why there are 2 ways, or to which models it applies.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~172-~172: Possible missing comma found.
Context: ...On and Off. Unclear why there are 2 ways or to which models it applies. ``` @ma...

(AI_HYDRA_LEO_MISSING_COMMA)


181-181: Format bare URL as a proper link.

Convert the bare URL to a proper markdown link.

-This was brought up in https://github.com/mvdwetering/yamaha_ynca/discussions/340
+This was brought up in [discussion #340](https://github.com/mvdwetering/yamaha_ynca/discussions/340)
🧰 Tools
🪛 Markdownlint

181-181: null
Bare URL used

(MD034, no-bare-urls)

ynca/enums.py (1)

80-91: Consider standardizing all ON/OFF enums

While reviewing the DirMode implementation, I noticed that several other ON/OFF enums in this file are inconsistent in their inheritance patterns. Some inherit from str, Enum while others only inherit from Enum. Consider standardizing all simple ON/OFF enums to follow the same pattern.

Affected enums:

  • Party
  • PartyMute
  • PureDirMode
  • SpeakerA
  • SpeakerB
  • Straight

Would you like me to create a GitHub issue to track this standardization task?

tests/test_zone.py (1)

481-493: LGTM: Test function follows established patterns.

The test_dirmode function follows the same pattern as other similar tests (e.g., test_puredirmode), properly testing both writing to the device and handling updates from the device.

However, consider adding tests for handling unknown values to maintain consistency with other enum tests like test_twochdecoder.

 def test_dirmode(connection, initialized_zone: ZoneBase):
     # Writing to device
     initialized_zone.dirmode = DirMode.ON
     connection.put.assert_called_with(SUBUNIT, "DIRMODE", "On")
     initialized_zone.dirmode = DirMode.OFF
     connection.put.assert_called_with(SUBUNIT, "DIRMODE", "Off")
 
     # Updates from device
     connection.send_protocol_message(SUBUNIT, "DIRMODE", "On")
     assert initialized_zone.dirmode == DirMode.ON
     connection.send_protocol_message(SUBUNIT, "DIRMODE", "Off")
     assert initialized_zone.dirmode == DirMode.OFF
+
+    # Unknown value
+    connection.send_protocol_message(SUBUNIT, "DIRMODE", "UnknownValue")
+    assert initialized_zone.dirmode == DirMode.UNKNOWN
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b6a2a23 and 197c8fc.

📒 Files selected for processing (7)
  • docs/PRACTICALITIES.md (1 hunks)
  • tests/test_enums.py (2 hunks)
  • tests/test_zone.py (5 hunks)
  • ynca/__init__.py (2 hunks)
  • ynca/enums.py (1 hunks)
  • ynca/server.py (1 hunks)
  • ynca/subunits/zone.py (10 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/PRACTICALITIES.md

[uncategorized] ~172-~172: Possible missing comma found.
Context: ...On and Off. Unclear why there are 2 ways or to which models it applies. ``` @ma...

(AI_HYDRA_LEO_MISSING_COMMA)

🪛 Markdownlint
docs/PRACTICALITIES.md

181-181: null
Bare URL used

(MD034, no-bare-urls)


174-174: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🔇 Additional comments (12)
ynca/__init__.py (2)

19-19: LGTM! Import statement follows the module's conventions.

The DirMode enum is correctly imported and maintains alphabetical ordering within the import group.


64-64: LGTM! Public API exposure is properly configured.

The DirMode enum is correctly exposed in the module's public API through __all__ list, maintaining alphabetical ordering.

tests/test_enums.py (2)

10-10: LGTM! Import statement is well-placed.

The DirMode enum import follows the alphabetical ordering convention and matches the existing import pattern.


47-47: LGTM! Test case follows best practices.

The test case for DirMode.UNKNOWN handling is consistent with the existing test pattern and properly validates the graceful handling of invalid values.

ynca/subunits/zone.py (4)

9-11: LGTM! Clean import organization.

The import changes are well-structured and properly organized, with clear separation between enum and function imports.

Also applies to: 30-37


77-77: LGTM! Well-integrated dirmode attribute.

The dirmode attribute is properly implemented using EnumFunctionMixin and follows the class's pattern of BASIC initialization.


146-148: LGTM! Good model-specific documentation.

The comment clearly documents that puredirmode behavior differs on the RX-V1067 model, which is valuable information for maintainers.


206-207: LGTM! Clear model-specific documentation.

The comments effectively document the difference in BASIC mode support between RX-V583 and RX-V573 models for speaker A/B functionality.

docs/PRACTICALITIES.md (1)

169-181: LGTM! Documentation structure is consistent.

The new Pure Direct mode section follows the established documentation pattern, providing clear examples and practical information about the feature's implementation variations.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~172-~172: Possible missing comma found.
Context: ...On and Off. Unclear why there are 2 ways or to which models it applies. ``` @ma...

(AI_HYDRA_LEO_MISSING_COMMA)

🪛 Markdownlint

181-181: null
Bare URL used

(MD034, no-bare-urls)


174-174: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

ynca/server.py (1)

122-122: LGTM! Verify DIRMODE command handling.

The addition of "DIRMODE" to the multiresponse_functions_table is correct and follows the existing pattern. This enables the server to handle DIRMODE commands consistently with other BASIC functions.

Let's verify the DIRMODE implementation across the codebase:

✅ Verification successful

Let's check the actual implementation in the test file and look for any potential issues.


Let's check the actual zone implementation since we couldn't find zone.py directly.


DIRMODE implementation is properly integrated and verified

The implementation is complete and correct:

  • DirMode enum is properly defined in ynca/enums.py with ON/OFF values
  • Zone implementation in ynca/subunits/zone.py correctly includes dirmode property with BASIC initialization
  • Test coverage in tests/test_zone.py verifies both device updates and command handling
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify DIRMODE implementation and test coverage

# Test 1: Check for DIRMODE command handling in tests
echo "Checking test coverage for DIRMODE..."
rg -l "DIRMODE" "tests/"

# Test 2: Check for DIRMODE usage in main code
echo "Checking DIRMODE usage in main code..."
rg -l "DIRMODE" "ynca/" --glob "!server.py"

# Test 3: Check for any DIRMODE-related enums
echo "Checking for DIRMODE-related enums..."
ast-grep --pattern 'class $_ {
  $$$
  DIRMODE
  $$$
}'

Length of output: 398


Script:

#!/bin/bash
# Check the DIRMODE test implementation
echo "Checking DIRMODE test implementation..."
rg "DIRMODE" tests/test_zone.py -B 2 -A 2

# Check if there are any DIRMODE-related functions or properties in zone.py
echo "Checking zone.py for DIRMODE implementation..."
rg "DIRMODE" ynca/zone.py -B 2 -A 2

Length of output: 1722


Script:

#!/bin/bash
# Find the zone implementation file
echo "Finding zone implementation file..."
fd zone

# Check for DirMode enum definition
echo "Checking for DirMode enum..."
ast-grep --pattern 'class DirMode {
  $$$
}'

# Check for dirmode property implementation
echo "Looking for dirmode property implementation..."
ast-grep --pattern '@property
$$$
dirmode($$$)'

Length of output: 398


Script:

#!/bin/bash
# Check the actual implementation in the correct zone file
echo "Checking zone implementation..."
rg "DIRMODE|DirMode" ynca/subunits/zone.py -B 2 -A 2

# Check for any enum definitions in the file
echo "Checking enums in zone.py..."
ast-grep --pattern 'class $_ (Enum):
  $$$'

Length of output: 8678

tests/test_zone.py (2)

11-11: LGTM: Import added correctly.

The DirMode import is properly added alongside other related enums.


57-57: LGTM: Initialization test updated correctly.

The assertion for dirmode is properly added to verify the initial state in the INITIALIZE_FULL_RESPONSES fixture.

ynca/subunits/zone.py Show resolved Hide resolved
docs/PRACTICALITIES.md Outdated Show resolved Hide resolved
ynca/enums.py Show resolved Hide resolved
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: 1

🧹 Outside diff range and nitpick comments (2)
docs/PRACTICALITIES.md (2)

174-177: Add language identifier to the code block.

The code block should specify a language identifier for better syntax highlighting and to comply with markdown best practices.

-```
+```yaml
 @MAIN:PUREDIRMODE=?  e.g. RX-A810
 @MAIN:DIRMODE=?  e.g. RX-V473

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Markdownlint</summary>

174-174: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</details>

</details>

---

`181-181`: **Format the URL reference properly.**

The bare URL should be formatted as a proper markdown link for better readability and to comply with markdown best practices.

```diff
-This was brought up in https://github.com/mvdwetering/yamaha_ynca/discussions/340
+This was brought up in [discussion #340](https://github.com/mvdwetering/yamaha_ynca/discussions/340)
🧰 Tools
🪛 Markdownlint

181-181: null
Bare URL used

(MD034, no-bare-urls)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 197c8fc and d6e7e9c.

📒 Files selected for processing (1)
  • docs/PRACTICALITIES.md (1 hunks)
🧰 Additional context used
🪛 Markdownlint
docs/PRACTICALITIES.md

181-181: null
Bare URL used

(MD034, no-bare-urls)


174-174: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🔇 Additional comments (1)
docs/PRACTICALITIES.md (1)

179-179: Fix inconsistency in BASIC response behavior documentation.

The statement "Both seem to be part of BASIC" contradicts the earlier note in the BASIC Response section which states that PUREDIRMODE is not part of BASIC response for RX-V1067. Consider revising for clarity.

docs/PRACTICALITIES.md Outdated Show resolved Hide resolved
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: 1

🧹 Outside diff range and nitpick comments (2)
docs/PRACTICALITIES.md (2)

169-183: Enhance the Pure Direct mode documentation with more specific details.

Consider the following improvements to make the documentation more precise and helpful:

  1. Add specific details about which signal processing features are bypassed in Pure Direct mode versus Direct mode.
  2. Update the model applicability statement to be more precise, as per verified logs:
    • DIRMODE: Used by older/lower-end models (RX-V473, RX-V475, RX-V500D, RX-V583)
    • PUREDIRMODE: Used by higher-end/newer models (RX-A series, RX-V685, RX-V2067, TSR-700)
🧰 Tools
🪛 Markdownlint

178-178: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


178-181: Add language specification to the code block.

Add a language identifier to the code block for better syntax highlighting.

-```
+```text
 @MAIN:PUREDIRMODE=?  e.g. RX-A810
 @MAIN:DIRMODE=?  e.g. RX-V473

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Markdownlint</summary>

178-178: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</details>

</details>

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: .coderabbit.yaml**
**Review profile: CHILL**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between d6e7e9c41b83f116fb7a3a9608230f35b7bdcce3 and 441628b2d57f8832fd8b9c4d2da03b2a31bed967.

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `docs/PRACTICALITIES.md` (1 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🪛 Markdownlint</summary>

<details>
<summary>docs/PRACTICALITIES.md</summary>

178-178: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</details>

</details>

</details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

docs/PRACTICALITIES.md Show resolved Hide resolved
@mvdwetering mvdwetering merged commit c03eadf into master Nov 6, 2024
13 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.

1 participant