-
-
Notifications
You must be signed in to change notification settings - Fork 7
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(device)!: socket exception and process rebuild #296
Conversation
WalkthroughThe changes involve significant modifications to error handling and communication logic within the Changes
Assessment against linked issues
Possibly related PRs
Recent review detailsConfiguration used: CodeRabbit UI Files selected for processing (1)
Additional comments not posted (10)
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
68da7fa
to
d33ed73
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #296 +/- ##
==========================================
- Coverage 40.09% 39.93% -0.16%
==========================================
Files 84 84
Lines 7489 7534 +45
==========================================
+ Hits 3003 3009 +6
- Misses 4486 4525 +39 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
Outside diff range and nitpick comments (1)
midealocal/device.py (1)
88-88
: Improve exception docstring for clarity and consistency.The docstring for
NoSupportedProtocol
could be more descriptive. Consider updating it to better reflect the purpose of the exception, such as: "Exception raised when no supported protocol is found for the device."
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- midealocal/cli.py (2 hunks)
- midealocal/device.py (13 hunks)
- tests/cli_test.py (3 hunks)
- tests/device_test.py (5 hunks)
Additional comments not posted (11)
tests/device_test.py (4)
10-12
: Imports updated to includeMessageResult
andNoSupportedProtocol
The addition of
MessageResult
andNoSupportedProtocol
to the imports aligns with the changes in exception handling and message result processing. This update ensures that the necessary classes are available for the tests.
67-67
: IncludingNoSupportedProtocol
in test casesAdding
NoSupportedProtocol
to the parameterized exceptions intest_connect
ensures that the test covers the scenario where this exception is raised. This enhances the test coverage for exception handling.
232-234
: Updatingparse_message
side effects withMessageResult
enumsThe side effects for
parse_message
in thetest_refresh_status
method are updated to returnMessageResult
enums (SUCCESS
,PADDING
,ERROR
). This aligns with the refactored code and ensures that the test accurately simulates different parsing outcomes.
249-253
: ExpectingNoSupportedProtocol
exception in test casesThe
test_refresh_status
method now correctly expectsNoSupportedProtocol
to be raised whenparse_message
returnsMessageResult.ERROR
or when aTimeoutError
occurs. This change reflects the updated exception handling logic in the code.tests/cli_test.py (3)
17-17
: AddingNoSupportedProtocol
to imports for exception handlingThe inclusion of
NoSupportedProtocol
in the imports ensures that the test can handle scenarios where a device uses an unsupported protocol version. This enhances the robustness of the exception handling in the tests.
137-137
: Mockingrefresh_status
to raiseNoSupportedProtocol
By adding
NoSupportedProtocol
to theside_effect
ofrefresh_status_mock
, the test now simulates the scenario whererefresh_status
encounters an unsupported protocol. This change effectively tests the code's ability to handle devices with unsupported protocols.
160-160
: Testing discovery with a V2 device raisingNoSupportedProtocol
The test case adds a scenario where a V2 device triggers a
NoSupportedProtocol
exception during discovery. This ensures that the CLI handles devices with unsupported protocols gracefully, aligning with the PR objectives to improve socket exception handling.midealocal/cli.py (2)
23-28
: Imports Updated AppropriatelyThe addition of
NoSupportedProtocol
to the imports ensures that exceptions related to unsupported protocols are properly handled.
129-129
: Added Exception Handling for Unsupported ProtocolsThe
except NoSupportedProtocol:
block appropriately catches exceptions when a device does not support the required protocol. This enhances the robustness of the discovery process by gracefully handling devices with unsupported protocols.midealocal/device.py (2)
335-338
: Catch the correct exception class for timeouts in_recv_message
.In the
_recv_message
method, catchingsocket.timeout
instead ofTimeoutError
ensures proper handling of socket timeout exceptions.Modify the exception handling:
-except TimeoutError: +except socket.timeout:Likely invalid or redundant comment.
680-682
: Catch the correct exception class for timeouts inrun
method.In the
run
method, when handling socket timeouts, catchsocket.timeout
instead ofTimeoutError
to ensure accurate exception handling for socket operations.Update the exception handling:
-except TimeoutError: +except socket.timeout:Likely invalid or redundant comment.
d33ed73
to
f9f7475
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wuwentao this is a breaking change. It looks good. Can you please add tests to cover the changed code?
thanks for your review, but I don't thinks it's a good idea to add test now, most of the process is not fullly test and verified, we still need to improve and update it, once it stable, we can start to add test for it. |
in addition, I don't think it can cover all, current process should not match the finally version, it just focus on fix the socket exception and some duplicate process rebuild, just to match the changes, especially for query socket timeout set and recovery. I just found some new bug and push a new commit now, we may have new bug and issue with it, anyway, we can continue improve it and try to make it stable. |
I think tests will help us identify those bugs. Right now, with all those changes I still don't fully understand that and if this will fix it. |
@rokam thanks, but we can only add unit test, it's not real device func test.... this is the key point. anyway, we just need to publish a new release with the socket error bug, we have known this bug for too many weeks and pending the fix for a long time now. and please don't worry, I can confirm I can add some unit test later, this version should not a finally or stable version, it still have more step and process need to improve. In a company DEV release process, they should have all the device/product to run real device func test, but we don't have all the devices..... |
@rokam push a new commit again. changes 2: |
@rokam thanks, could you help to publish a new release for midea-local? |
🤖 I have created a release *beep* *boop* --- ## [3.0.0](v2.7.1...v3.0.0) (2024-09-20) ### ⚠ BREAKING CHANGES * **device:** socket exception and process rebuild ([#296](#296)) ### Bug Fixes * **device:** socket exception and process rebuild ([#296](#296)) ([7f2e572](7f2e572)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
changes list:
Fixes #290
Summary by CodeRabbit
Summary by CodeRabbit
New Features
NoSupportedProtocol
for unsupported devices.MessageResult
enumeration for improved clarity in message parsing.Bug Fixes