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

fix: ed device power/lock return message set and body_type 0x15 parse #284

Merged
merged 1 commit into from
Sep 9, 2024

Conversation

wuwentao
Copy link
Member

@wuwentao wuwentao commented Aug 29, 2024

fix #283
origin from wuwentao/midea_ac_lan#299

Summary by CodeRabbit

  • New Features

    • Introduced a new body type, X15, to enhance message categorization.
    • Expanded response handling to accommodate a new message type, improving flexibility in message processing.
  • Improvements

    • Updated initialization parameters for message handling classes to enhance readability and maintainability.
    • Established a comprehensive suite of unit tests for ED message handling, ensuring robust functionality and correctness.

Copy link
Contributor

coderabbitai bot commented Aug 29, 2024

Walkthrough

The changes involve modifications to the MessageED and MessageEDResponse classes, enhancing the initialization parameters and control flow logic. A new enumeration value, X15, is added to the BodyType class. Additionally, a comprehensive suite of unit tests is introduced to validate the functionalities of the message handling system, ensuring robust processing of various message types.

Changes

Files Change Summary
midealocal/devices/ed/message.py Updated MessageED to use BodyType.X15 instead of 0x15. Expanded MessageEDResponse to include MessageType.set and BodyType.X15 in conditionals.
midealocal/message.py Added X15 to BodyType enumeration as a new member.
tests/devices/ed/message_ed_test.py Introduced a comprehensive suite of unit tests for MessageED, MessageEDResponse, and various message body classes, validating their functionalities.
tests/devices/ed/__init__.py Introduced a module for testing Midea local ED functionality.
tests/devices/ed/device_ed_test.py Added unit tests for MideaEDDevice, validating its functionalities and message processing.

Assessment against linked issues

Objective Addressed Explanation
Support parsing of message type 0x02 and body type 0x15 (##283)
Ensure response handling accommodates new message types (##283)

Poem

🐰 In the meadow where bunnies play,
New messages hop in a bright array.
With types and bodies now so grand,
We dance and twirl, a happy band!
Let's celebrate with joy and cheer,
For every change brings us near! 🌼✨

Tip

New features

Walkthrough comment now includes:

  • Possibly related PRs: A list of potentially related PRs to help you recall past context.
  • Suggested labels: CodeRabbit can now suggest labels by learning from your past PRs. You can also provide custom labeling instructions in the UI or configuration file.

Notes:

  • Please share any feedback in the discussion post on our Discord.
  • Possibly related PRs, automatic label suggestions based on past PRs, learnings, and possibly related issues require data opt-in (enabled by default).

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

@github-actions github-actions bot added the bug Something isn't working label Aug 29, 2024
@codecov-commenter
Copy link

codecov-commenter commented Aug 29, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 40.11%. Comparing base (e0e6370) to head (62322b6).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #284      +/-   ##
==========================================
+ Coverage   37.79%   40.11%   +2.32%     
==========================================
  Files          84       84              
  Lines        7477     7478       +1     
==========================================
+ Hits         2826     3000     +174     
+ Misses       4651     4478     -173     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8610f1e and 3e7f15e.

Files selected for processing (2)
  • midealocal/devices/ed/message.py (2 hunks)
  • midealocal/message.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • midealocal/message.py
Additional comments not posted (2)
midealocal/devices/ed/message.py (2)

88-88: LGTM!

The change from 0x15 to BodyType.X15 improves code readability and maintainability.


247-253: LGTM!

The expanded conditional logic to include MessageType.set and BodyType.X15 enhances the handling of message types and body types, making the message processing more versatile.

Copy link
Contributor

@rokam rokam left a comment

Choose a reason for hiding this comment

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

Can you please add tests

chemelli74
chemelli74 previously approved these changes Aug 29, 2024
@wuwentao
Copy link
Member Author

Can you please add tests

hi rokam,

I don't think it can fix the set action bug and all the set feature still can't works.
it only fix the response. maybe ignore it also can works. as there's still query message exist.

so I don't think I can add test for it now.

in addition, this device is not a standard ED device,like a part of standard ED device and removed most of the core feature in ED device.
still need more info and a physical ED device to confirm current feature can works well.

as I found more difference from current code and the lua scripts.
I'm not sure with the normal ED device, will do more test and change it in future PR.

@wuwentao
Copy link
Member Author

@Necroneco I remember you have changed some translate and can be used for ED device.

what's your device type?

@caibinqing
Copy link
Collaborator

caibinqing commented Sep 1, 2024

@Necroneco I remember you have changed some translate and can be used for ED device.

what's your device type?

Colmo RA08
I have never used the power and child lock in HA.
And I tested the new code here, nothing happened either.

@wuwentao
Copy link
Member Author

wuwentao commented Sep 2, 2024

@Necroneco thanks, I have a DA01, the power and child lock should not work, it still have error from the lua script.
but current response msg can't be parse, so this PR just fix the response msg and not fix the power/lock issue.
I'm not sure with normal product, so not change it.
maybe can have a try with next PR to change it

caibinqing
caibinqing previously approved these changes Sep 2, 2024
@wuwentao wuwentao dismissed stale reviews from caibinqing and chemelli74 via 04e9dcd September 6, 2024 10:35
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

Outside diff range, codebase verification and nitpick comments (1)
tests/devices/ed/message_ed_test.py (1)

39-72: Comprehensive testing of MessageNewSet with a suggestion for improvement.

The tests cover various scenarios for the MessageNewSet class, ensuring that the body property updates correctly with changes to power and lock. This is crucial for verifying the message integrity as it changes state.

Consider adding comments or breaking down the assertions into smaller test functions for better readability and maintainability. Each state change could be a separate test to isolate behaviors.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3e7f15e and 04e9dcd.

Files selected for processing (1)
  • tests/devices/ed/message_ed_test.py (1 hunks)
Additional context used
Ruff
tests/devices/ed/message_ed_test.py

1-1: File tests/devices/ed/message_ed_test.py is part of an implicit namespace package. Add an __init__.py.

(INP001)

Additional comments not posted (9)
tests/devices/ed/message_ed_test.py (9)

19-27: Correct implementation of abstract base class testing.

The test ensures that the MessageEDBase class correctly raises a NotImplementedError for the body property, which is expected behavior for an abstract base class. This is a good practice to ensure that any subclass must implement this property.


29-37: Proper testing of MessageQuery body.

The test verifies that the body property of MessageQuery returns the correct bytearray, matching the expected output. This ensures that the query message is formatted correctly.


74-123: Detailed testing of EDMessageBody01.

The test for EDMessageBody01 is thorough, checking that all relevant attributes are correctly parsed from the bytearray and exposed as properties. This ensures that the message body is interpreted correctly, which is critical for the device's functionality.


125-161: Proper testing of EDMessageBody03.

The test ensures that EDMessageBody03 correctly parses and exposes various attributes from the bytearray. This consistency in testing across different message body types is important for ensuring reliable device communication.


163-182: Consistent testing approach for EDMessageBody05.

Like the previous message body tests, TestEDMessageBody05 correctly verifies that the attributes are parsed and exposed properly from the bytearray. This consistency is key to ensuring that all parts of the message handling are reliable.


184-203: Correct testing pattern followed for EDMessageBody06.

The test for EDMessageBody06 follows the established pattern and correctly checks the parsing of attributes from the bytearray. This ensures that the message body is handled correctly across different scenarios.


205-224: Effective testing of EDMessageBody07.

The test for EDMessageBody07 effectively checks that the class parses the bytearray correctly and exposes the necessary attributes. This is crucial for ensuring that the device's messages are handled correctly.


226-282: Comprehensive testing of EDMessageBodyFF.

The test for EDMessageBodyFF is thorough, covering a complex setup of the bytearray and ensuring that all attributes are parsed correctly. This level of detail is important for ensuring the robustness of the device's message handling.


284-350: Detailed testing of MessageEDResponse.

The test for MessageEDResponse is comprehensive, setting up a detailed bytearray for the header and body and checking a wide range of attributes. This ensures that the response handling is robust and can manage various scenarios effectively.

tests/devices/ed/message_ed_test.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

Commits

Files that changed from the base of the PR and between 04e9dcd and 063e25e.

Files selected for processing (6)
  • .github/workflows/python-build.yml (1 hunks)
  • .github/workflows/python-publish.yml (1 hunks)
  • .pre-commit-config.yaml (1 hunks)
  • tests/devices/ed/init.py (1 hunks)
  • tests/devices/ed/device_ed_test.py (1 hunks)
  • tests/devices/ed/message_ed_test.py (1 hunks)
Files skipped from review due to trivial changes (3)
  • .github/workflows/python-build.yml
  • .pre-commit-config.yaml
  • tests/devices/ed/init.py
Files skipped from review as they are similar to previous changes (1)
  • tests/devices/ed/message_ed_test.py
Additional comments not posted (4)
.github/workflows/python-publish.yml (1)

58-58: Update to GitHub Action version approved.

The update to pypa/gh-action-pypi-publish is approved. However, ensure to verify the new version for compatibility and functionality before deploying to production.

Run the following script to verify the new action version:

tests/devices/ed/device_ed_test.py (3)

16-30: Test setup function is well-implemented.

The _setup_device function correctly initializes the test device with comprehensive attributes, ensuring a robust setup for subsequent tests.


32-44: Initial attributes test is comprehensive.

The test_initial_attributes function effectively verifies the default state of all relevant device attributes, ensuring that the device initializes correctly.


88-101: Query building and attribute setting tests are well-implemented.

The test_build_query and test_set_attribute functions effectively verify the device's functionality in building queries and setting attributes, ensuring that these features work as expected.

tests/devices/ed/device_ed_test.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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 063e25e and 62322b6.

Files selected for processing (5)
  • midealocal/devices/ed/message.py (2 hunks)
  • midealocal/message.py (1 hunks)
  • tests/devices/ed/init.py (1 hunks)
  • tests/devices/ed/device_ed_test.py (1 hunks)
  • tests/devices/ed/message_ed_test.py (1 hunks)
Files skipped from review due to trivial changes (2)
  • tests/devices/ed/init.py
  • tests/devices/ed/message_ed_test.py
Files skipped from review as they are similar to previous changes (1)
  • tests/devices/ed/device_ed_test.py
Additional comments not posted (3)
midealocal/devices/ed/message.py (2)

88-88: Confirm the integration of new body type BodyType.X15.

The addition of BodyType.X15 in the MessageNewSet class is crucial for handling specific device features. Ensure that this change integrates well with the device's functionality and does not disrupt existing message handling.

Verification successful

Integration of BodyType.X15 confirmed, but consider adding tests.

The BodyType.X15 is integrated into the message handling logic in midealocal/devices/ed/message.py, similar to other body types. However, ensure that there are tests covering this new body type to verify its functionality and integration with the device.

  • midealocal/devices/ed/message.py: Integration logic for BodyType.X15.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of `BodyType.X15` with the device.
# Test: Search for the usage of `BodyType.X15` in device integration tests.
rg --type python -A 5 $'BodyType.X15'

Length of output: 67


Script:

#!/bin/bash
# Description: Verify the integration of `BodyType.X15` with the device.
# Test: Search for the usage of `BodyType.X15` in device integration tests.
rg --type py -A 5 $'BodyType.X15'

Length of output: 941


247-253: Review the expanded conditional logic in MessageEDResponse.

The modifications to include more message_type and body_type conditions in the __init__ method are intended to enhance response handling. Confirm that these changes are correctly implemented and test thoroughly to ensure no regressions in message processing.

midealocal/message.py (1)

35-35: Confirm the addition of X15 to BodyType.

The addition of the new enumeration value X15 to the BodyType class is crucial for supporting new device functionalities. Ensure that this change is correctly integrated into the system and does not disrupt existing message handling.

Verification successful

Integration of X15 into BodyType Confirmed

The X15 enumeration value has been successfully integrated into the system. It is used in the midealocal/devices/ed/message.py file as part of the device message handling logic, ensuring support for new device functionalities without disrupting existing processes.

  • midealocal/devices/ed/message.py: X15 is used as a body_type and in conditional checks.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of `X15` in the system.
# Test: Search for the usage of `X15` in device message handling.
rg --type python -A 5 $'X15'

Length of output: 58


Script:

#!/bin/bash
# Description: Verify the integration of `X15` in the system.
# Test: Search for the usage of `X15` in device message handling.
rg -A 5 'X15'

Length of output: 1147

@wuwentao wuwentao requested a review from rokam September 9, 2024 05:16
@wuwentao
Copy link
Member Author

wuwentao commented Sep 9, 2024

Can you please add tests

done, please help to check and review

@rokam rokam merged commit d9d4fac into main Sep 9, 2024
8 checks passed
@rokam rokam deleted the add_ed_response branch September 9, 2024 09:31
@rokam rokam mentioned this pull request Sep 9, 2024
rokam added a commit that referenced this pull request Sep 13, 2024
🤖 I have created a release *beep* *boop*
---


## [2.7.1](v2.7.0...v2.7.1)
(2024-09-12)


### Bug Fixes

* ed device power/lock return message set and body_type 0x15 parse
([#284](#284))
([d9d4fac](d9d4fac))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

colmo DA01 powe/lock action got unidentified protocol
5 participants