Skip to content

Added consumo_historico and python-dotenv for reading username and password from env vars#54

Merged
hectorespert merged 3 commits into
hectorespert:masterfrom
Oneirag:master
Jun 19, 2026
Merged

Added consumo_historico and python-dotenv for reading username and password from env vars#54
hectorespert merged 3 commits into
hectorespert:masterfrom
Oneirag:master

Conversation

@Oneirag

@Oneirag Oneirag commented May 26, 2026

Copy link
Copy Markdown

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

@hectorespert hectorespert left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-dotenv to 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.

Comment thread oligo/requests/iber.py Outdated
Comment thread oligo/requests/iber.py Outdated
Comment thread oligo/requests/iber.py Outdated
Comment thread oligo/requests/iber.py Outdated
Comment thread setup.py Outdated
Comment thread README.md
Comment thread oligo/requests/iber.py Outdated
Comment thread oligo/asyncio/asynciber.py Outdated
Comment thread tests/test_iber.py Outdated
Comment thread oligo/asyncio/asynciber.py Outdated
…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.
@Oneirag

Oneirag commented Jun 3, 2026

Copy link
Copy Markdown
Author

Thanks for the comments. I've applied changes to address them:
On the python-dotenv dependency (@hectorespert's request):

  • Removed python-dotenv from setup.py and requirements.txt. Loading .env files is the responsibility of the application using the library.
  • Removed the load_dotenv() call at import time from oligo/requests/iber.py and oligo/asyncio/asynciber.py. Importing the library no longer implies filesystem access.

Environment variables:

  • Renamed to I_DE_USER and I_DE_PASSWORD (exportable directly in bash/zsh via export I_DE_USER=...). No hyphenated aliases to keep things unambiguous.
  • Updated tests, README, and LoginException messages to match the new names.
  • Precedence is now what the docstring says: explicit arguments win over env vars (consistent with commit 08dd840). Added a dedicated test to lock that in.

Billed consumption API:

  • Renamed to billed_consumption and total_billed_consumption on both the sync and async clients, aligned with the rest of the English API.
  • The previous names (consumption_facturado, total_consumption_facturado) are kept as @deprecated wrappers that delegate to the new methods, so existing consumers don't break.

Other fixes:

  • The sync login() no longer instantiates Session() in its default argument (a fresh Session is created inside the function when needed).
  • The async client now validates credentials before creating aiohttp.ClientSession(), avoiding resource leaks.
  • Async login type hints corrected to Optional[str].

Tests: 13/13 passing. @hectorespert, please let me know if this works for you, and @copilot, a re-review would be appreciated.

@hectorespert hectorespert merged commit 3c4c793 into hectorespert:master Jun 19, 2026
4 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.

Comment thread tests/test_iber.py
Comment on lines +21 to +23
def tearDown(self):
for key, value in self._env_backup.items():
os.environ[key] = value
Comment thread oligo/requests/iber.py
Comment on lines +78 to +82
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")
Comment thread setup.py
Comment on lines +25 to +26
install_requires=["deprecated"],
extras_require={"requests": ["requests"], "asyncio": ["aiohttp"]},
Comment on lines +79 to +80
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:
Comment thread README.md
print(consumo[:10])
```

#### Obtener el consumo horario facturado durante un periodo (ASync)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants