Added consumo_historico and python-dotenv for reading username and password from env vars#54
Conversation
hectorespert
left a comment
There was a problem hiding this comment.
Thanks for you collaboration.
I would rather not make the library depend on dotenv. If loading environment variables is necessary, it should be handled by the application that uses the library.
There was a problem hiding this comment.
Pull request overview
This PR extends the i-DE clients to support reading credentials from environment variables (including .env via python-dotenv) and adds new “billed consumption” retrieval methods, along with updates to tests and documentation.
Changes:
- Add
.env/environment-variable based authentication for both sync (Iber) and async (AsyncIber) clients. - Add new billed-consumption endpoints (
consumption_facturado/total_consumption_facturado) for sync and async clients. - Update unit tests and README examples; add
python-dotenvto dependencies.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 18 comments.
Show a summary per file
| File | Description |
|---|---|
oligo/requests/iber.py |
Adds dotenv/env-var login path and new billed-consumption methods; includes several refactors/formatting updates. |
oligo/asyncio/asynciber.py |
Adds dotenv/env-var login path and new billed-consumption methods for the async client. |
tests/test_iber.py |
Reworks HTTP mocking and adds coverage for new billed-consumption methods and env-var auth behavior. |
README.md |
Documents env-var / .env authentication and new billed-consumption examples (sync/async). |
setup.py |
Adds python-dotenv to install_requires and applies formatting updates. |
requirements.txt |
Adds python-dotenv dependency. |
oligo/exception.py |
Extends LoginException to accept a custom message; minor string formatting updates. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…env vars - Remove python-dotenv dependency; env-var loading is the app's responsibility. - login() reads I_DE_USER / I_DE_PASSWORD; explicit args take precedence; the sync client no longer instantiates a shared Session at import time and the async client validates credentials before creating aiohttp.ClientSession. - Rename consumption_facturado / total_consumption_facturado to billed_consumption / total_billed_consumption for consistency with the rest of the English API; keep the old names as deprecated aliases. - Update README and tests accordingly; add a test that pins the explicit-args-over-env-vars precedence.
|
Thanks for the comments. I've applied changes to address them:
Environment variables:
Billed consumption API:
Other fixes:
Tests: 13/13 passing. @hectorespert, please let me know if this works for you, and @copilot, a re-review would be appreciated. |
| def tearDown(self): | ||
| for key, value in self._env_backup.items(): | ||
| os.environ[key] = value |
| if session is None: | ||
| session = Session() | ||
| self.__session = session | ||
| user = user or os.getenv("I_DE_USER") | ||
| password = password or os.getenv("I_DE_PASSWORD") |
| install_requires=["deprecated"], | ||
| extras_require={"requests": ["requests"], "asyncio": ["aiohttp"]}, |
| user = user or os.getenv("I_DE_USER") | ||
| password = password or os.getenv("I_DE_PASSWORD") |
| data = await self._consumption_raw(start, end) | ||
| return float(data["acumulado"]) | ||
|
|
||
| async def _consumption_facturado_raw(self, start: datetime, end: datetime) -> list: |
| print(consumo[:10]) | ||
| ``` | ||
|
|
||
| #### Obtener el consumo horario facturado durante un periodo (ASync) |
Added a new endpoint for consumo_historico
Username and password can be read as an alternative of function parameters from I-DE-USER and I-DE-PASSWORD environmental variables using python-dotenv
Several fixes in tests