Skip to content
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

Add extra sensors by adding support to the extended ESIOS API with API Token #85601

Closed

Conversation

azogue
Copy link
Member

@azogue azogue commented Jan 10, 2023

Proposed change

Add support to the extended ESIOS API, adding 3 more price sensors when using an ESIOS API Token

  • Integration without a token works like before, with no breaking changes for current users, and the same old PVPC sensor.
  • API token can be enabled for a new integration setup, and also from the options flow.
  • 'reauth' flow implemented to change or disable bad tokens
  • Better integration with DataUpdateCoordinator and SensorEntityDescription
  • Final removal of deprecated YAML config (SOURCE_IMPORT)

Detailed changes

  • 📦️ Bump aiopvpc version to v4.0.0
    Release notes: https://github.com/azogue/aiopvpc/releases/tag/v4.0.0
    Changelog: https://github.com/azogue/aiopvpc/blob/master/CHANGELOG.md
    Diff/compare against current version: azogue/aiopvpc@v3.0.0...v4.0.0
  • ♻️ Evolve DataUpdateCoordinator for multiple sensors with EsiosApiData
    • Access API with optional token defined in config entry
    • Handle BadApiTokenAuthError to raise ConfigEntryAuthFailed
    • Expect config-flow options to change power attrs and API token, but not the PVPC tariff
    • Remove deprecated CONFIG_SCHEMA
  • ✨ Add 3 price sensors more when API token is enabledEvolve ElecPriceSensor to work with multiple sensors,
    relying on coordinator.data to store the downloaded info for all sensors
    New sensors added:
    • Injection price: price of excess energy from self-consumption
    • OMIE price: electricity price in the 'open' market
    • MAG price: Temporal tax cost for gas compensation
  • ✨ Evolve config-flow with extra step and reauth
    • Add 'api_token' and (bool)'use_api_token' to config entry data to handle both ways of setup.
    • Add info about how to get the token in the config-flow step, with a direct link to generate the request email
  • 🌐 Add generated EN translation
  • 🍱 tests: Update tests fixtures with new sensor data
  • ✅ tests: Adapt test suite for new sensors and add test for reauth flow
  • 🔥 Remove already deprecated YAML configuration

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

* Access API with optional token defined in config entry
* Handle `BadApiTokenAuthError` to raise `ConfigEntryAuthFailed`
* Expect config-flow options to change power attrs and API token,
  but not the PVPC tariff
* Remove deprecated `CONFIG_SCHEMA`
Evolve `ElecPriceSensor` to work with multiple sensors,
relying on `coordinator.data` to store the downloaded info for all sensors

New sensors added:
- Injection price: price of excess energy from self-consumption
- OMIE price: electricity price in the 'open' market
- MAG price: Temporal tax cost for gas compensation
* Add 'api_token' and (bool)'use_api_token' to config entry data
  to handle both ways of setup.
* Fill the token in a second step if the boolean is cheched
* Add verify method to check valid API token in config-flow before entry creation
* Add reauth + reauth_confirm steps to trigger re-config if the token fails anytime
* Enable option to define (or disable) the API token for current installs
* Add info about how to get the token in the config-flow step,
  with a direct link to generate the request email
Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

This PR contains a whole lot of things that don't have to be in a single PR.

It contains dependency bumps, refactoring, new features...

Please split the PR out into multiple smaller PRs so we can get there in tinier but quicker steps.

Thanks 👍

../Frenck

@frenck frenck changed the title ✨ Add extra sensors by adding support to the extended ESIOS API with API Token Add extra sensors by adding support to the extended ESIOS API with API Token Jan 10, 2023
@azogue
Copy link
Member Author

azogue commented Jan 10, 2023

It contains dependency bumps, refactoring, new features...

Sorry @frenck 🙈, wasn't my initial intention to make it so big 😰. Most of it are new fixtures, but you're totally right, there is too much here 😢

Ok, I'll try to split it, but not sure how, for the most part. How about?

  • The dependency bump is what triggers the change with the DataEntityCoordinator and the SensorEntities. That could be one MR, without config-flow changes (so, no token, no new features, only maintenance)
  • Another with the 'feature', including all config-flow changes + 3 new sensors, + the tests fixtures and most test changes. That'll be the big one
  • The last change I did was removing the old YAML config (was already deprecated a long time ago). I did it because of the 100% coverage requirement (2 LOC missing because of it 😂). Do you want me to make a third one with it, or include it in the 1st one, or leave it untouched?

@azogue
Copy link
Member Author

azogue commented Jan 10, 2023

Closed, to be split in parts:

@azogue azogue closed this Jan 10, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jan 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Changes api.esios.ree.es (Spain electricity hourly pricing (PVPC))
2 participants