refactor: modularize library structure and support session reuse#202
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR refactors the openeihttp package by extracting the Rates client class from ChangesRates Client Module Refactoring
🎯 4 (Complex) | ⏱️ ~75 minutes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@openeihttp/cache.py`:
- Around line 29-31: The check-then-create for the cache directory in the method
using self._directory with aiofiles.ospath.exists and aiofiles.os.makedirs is
racy; replace it with an idempotent creation by attempting to create the
directory and swallowing FileExistsError (or OSError with errno.EEXIST) so
concurrent callers won’t error, i.e., remove the separate exists() branch and
wrap the makedirs call in a try/except that logs success/failure but ignores
EEXIST; reference self._directory and the current usage of aiofiles.os.makedirs
in openeihttp/cache.py when applying the change.
- Line 59: The cache size check currently rejects files equal to the configured
minimum because it uses a strict greater-than; update the condition from "size >
MIN_CACHE_SIZE" to "size >= MIN_CACHE_SIZE" so files that meet the minimum are
accepted—modify the return expression in the cache validation/check function
where the local variable size is compared to the MIN_CACHE_SIZE constant.
In `@openeihttp/client.py`:
- Around line 106-110: The current validation in lookup_plans allows a partial
coordinate (one of self._lat or self._lon being None); change the check so it
requires either a non-empty self._address OR both self._lat and self._lon to be
not None (i.e., validate that both coordinates exist together), and if that
requirement is not met log an error and raise InvalidCall from lookup_plans;
reference the lookup_plans method and the self._lat / self._lon fields when
updating the condition and error path so incomplete coordinates cannot proceed
to the API call.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 4a6198af-b862-4afd-8b11-9e516d99106a
📒 Files selected for processing (6)
openeihttp/__init__.pyopeneihttp/cache.pyopeneihttp/client.pyopeneihttp/const.pyopeneihttp/exceptions.pytests/test_init.py
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
This PR refactors the
python-openeilibrary structure to modularize the codebase, supportaiohttp.ClientSessionreuse, and replace blocking cache I/O calls.Changes Summary
Ratesclient class to client.py.__all__.aiohttp.ClientSessioninstance.latandlon) toNoneinstead of9000.os.path.existsfor asyncaiofiles.ospath.existsto avoid event-loop blockage (crucial for Home Assistant integration).test_session_reuse) and coordinate defaults (test_default_none_coordinates).All environments and checks (mypy, ruff, tests across python 3.9-3.14) are fully passing via
tox.Summary by CodeRabbit
New Features
Improvements
Tests