Make http_request method in BlockDevice private#1027
Make http_request method in BlockDevice private#1027chemelli74 wants to merge 6 commits intohome-assistant-libs:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1027 +/- ##
==========================================
+ Coverage 78.56% 80.11% +1.55%
==========================================
Files 20 20
Lines 2057 2057
==========================================
+ Hits 1616 1648 +32
+ Misses 441 409 -32 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
As I wrote on discord this is a breaking change for others and I don't see the benefit from this |
The idea behind is exactly the same as we discussed for |
Who is exactly anyone? we are the only ones that approve a PR for Home Assistant. |
There was a problem hiding this comment.
Pull request overview
This PR refactors the http_request method in BlockDevice to be private by renaming it to _http_request, improving the API surface by hiding internal HTTP communication details. The PR also introduces a new public set_state method on BlockDevice to replace the removed Block.set_state method, centralizing state-setting functionality.
Changes:
- Renamed
http_requestto_http_requestthroughout the codebase to make it private - Added comprehensive test coverage for
_http_requestcovering success, auth errors, timeouts, and connection errors - Introduced new public
BlockDevice.set_statemethod that accepts path and channel parameters - Refactored
Block.toggleandLightBlock.set_stateto use the newBlockDevice.set_statemethod
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
aioshelly/block_device/device.py |
Renamed http_request to _http_request, updated all internal callers, added new public set_state method, refactored Block.toggle and LightBlock.set_state to use new API |
tests/block_device/test_device.py |
Updated tests to use _http_request, added comprehensive test suite for _http_request covering various success and failure scenarios |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return await self._http_request("get", f"{path}/{channel}", kwargs) | ||
|
|
There was a problem hiding this comment.
The new set_state method accepts path and channel as separate parameters and constructs the URL as "{path}/{channel}". However, if either path or channel is None, this will produce malformed URLs like "None/channel" or "path/None". Consider adding validation to ensure both parameters are provided, or handle None values appropriately (e.g., by omitting the trailing slash when channel is None).
| return await self._http_request("get", f"{path}/{channel}", kwargs) | |
| if path is None: | |
| raise ValueError("path must be provided for set_state") | |
| url_path = path if channel is None else f"{path}/{channel}" | |
| return await self._http_request("get", url_path, kwargs) |
| return await self._http_request("get", f"{path}/{channel}", kwargs) | ||
|
|
There was a problem hiding this comment.
The new public set_state method lacks test coverage. Since this method is now part of the public API and is used by Block.toggle and LightBlock.set_state, it would be valuable to add tests covering various scenarios including valid paths with channels, and edge cases.
| return await self._http_request("get", f"{path}/{channel}", kwargs) | |
| if path is None and channel is None: | |
| raise ValueError("Either 'path' or 'channel' must be provided") | |
| if path is None: | |
| url_path = str(channel) | |
| elif channel is None: | |
| url_path = path | |
| else: | |
| url_path = f"{path}/{channel}" | |
| return await self._http_request("get", url_path, kwargs) |
thecode
left a comment
There was a problem hiding this comment.
I don't agree with this change as explained in the discussion
No description provided.