-
-
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
feat: segregate connect/auth/refresh/enable device duties #233
feat: segregate connect/auth/refresh/enable device duties #233
Conversation
WalkthroughThe recent changes enhance the connection and authentication processes in the device management code, improving reliability and logging. A new method for refreshing authentication capabilities was introduced, and existing methods were adjusted to streamline operations and improve traceability. In testing, the transition to a synchronous approach simplifies test structure, enhancing clarity and maintainability. Overall, these updates contribute to a more robust and user-friendly device experience. Changes
Poem
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 as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #233 +/- ##
==========================================
- Coverage 36.62% 34.05% -2.57%
==========================================
Files 81 81
Lines 7138 7142 +4
==========================================
- Hits 2614 2432 -182
- Misses 4524 4710 +186 ☔ 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: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- midealocal/device.py (4 hunks)
- tests/device_test.py (3 hunks)
Additional comments not posted (8)
tests/device_test.py (4)
30-30
: Class restructuring: Removed inheritance fromIsolatedAsyncioTestCase
.The class no longer inherits from
IsolatedAsyncioTestCase
, indicating a shift to synchronous testing.
Line range hint
34-49
:
LGTM! Ensure consistency in device initialization.The
_setup_device
fixture correctly initializes theMideaDevice
instance with appropriate parameters.
61-75
: Improved test readability and maintainability withpytest.mark.parametrize
.The use of
pytest.mark.parametrize
streamlines the testing of various scenarios for theconnect
method, enhancing readability and maintainability.
81-82
: LGTM! Ensure proper handling of generic exceptions.The
test_connect_generic_exception
method correctly tests theconnect
method with a generic exception.midealocal/device.py (4)
143-143
: Initialization: Set_available
toFalse
.The
_available
attribute is now initialized toFalse
, indicating the device is unavailable upon instantiation.
193-199
: New method:_authenticate_refresh_enable
.The
_authenticate_refresh_enable
method streamlines the connection process, including authentication and status refresh. Ensure that it correctly integrates these processes.
201-236
: Enhanced connection reliability with retry mechanism.The
connect
method now includes a retry mechanism, allowing up to three attempts to establish a socket connection. This enhances the robustness of the connection logic.
466-469
: Improved logging inenable_device
method.The
enable_device
method now logs when the device is enabled or disabled, providing better visibility into the device's state changes.
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.
I saw just a possible issue.
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: 3
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- midealocal/device.py (4 hunks)
Additional comments not posted (3)
midealocal/device.py (3)
143-143
: Initialization of_available
attribute.The
_available
attribute is now initialized toFalse
, ensuring the device is marked as unavailable upon initialization. This change is straightforward and improves clarity.
246-246
: Added debug log message inauthenticate
.The debug log message for the authentication handshake enhances traceability and debugging.
469-469
: Added log message inenable_device
.The log message indicating when the device is enabled or disabled improves visibility into the device's state changes.
<!--pre-commit.ci start--> updates: - astral-sh/ruff-pre-commit@v0.5.2...v0.5.4 - commitizen-tools/commitizen@v3.27.0...v3.28.0 <!--pre-commit.ci end--> Co-authored-by: Lucas Mindêllo de Andrade <[email protected]>
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Summary by CodeRabbit - **New Features** - Introduced a new framework for parsing message bodies, allowing for flexible and type-safe handling of various data types. - Added specific parsers for boolean, integer, and enumeration types to the message parsing logic. - Enhanced the `MessageBody` class with a method to parse multiple attributes automatically. - **Tests** - Added a comprehensive suite of unit tests for the message parsing features, ensuring functionality and error handling across various parser classes. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Simone Chemelli <[email protected]>
ca1d0ea
to
119879d
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- midealocal/device.py (5 hunks)
- midealocal/exceptions.py (1 hunks)
Additional comments not posted (5)
midealocal/exceptions.py (1)
14-16
: LGTM!The addition of the
CannotConnect
exception class enhances error handling by providing a specific error type for connection failures.midealocal/device.py (4)
193-198
: LGTM!The addition of the
_authenticate_refresh_capabilities
method consolidates related operations, improving code organization and maintainability.
199-234
: LGTM!The modifications to the
connect
method, including the retry mechanism and enhanced logging, improve the robustness and traceability of the connection logic.
513-520
: LGTM!The updates to the
run
method streamline the connection and authentication process, improving reliability and maintainability.
464-467
: LGTM!The added logging in the
enable_device
method provides better visibility into the device's state changes.
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.
LGTM
…)" This reverts commit 681bd79.
🤖 I have created a release *beep* *boop* --- ## [2.4.0](v2.3.0...v2.4.0) (2024-07-24) ### Features * **cli:** set attribute from device ([#241](#241)) ([6f0a109](6f0a109)) * segregate connect/auth/refresh/enable device duties ([#233](#233)) ([681bd79](681bd79)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced the ability to set device attributes directly from the command-line interface. - **Improvements** - Enhanced modularity of device management functionalities for better maintainability and clarity, addressing user feedback from issue #233. - **Version Update** - Updated the project version to 2.4.0, indicating the inclusion of new features and improvements. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
) | ||
self._socket.connect((self._ip_address, self._port)) | ||
_LOGGER.debug("[%s] Connected", self._device_id) | ||
connected = True |
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.
Add break
after connected?
Summary by CodeRabbit
New Features
Bug Fixes
Tests