Add Naturstrom#3695
Draft
AlexanderHa98 wants to merge 4 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new “Naturstrom” flexible electricity tariff provider module to the electricity pricing subsystem, including configuration models and runtime fetching/refresh logic.
Changes:
- Introduces Naturstrom tariff fetching, including OAuth refresh-token handling and publishing refreshed tokens back into config.
- Adds Naturstrom provider configuration dataclasses (token + account identification + update schedule).
- Registers the provider package via an (empty) module initializer.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| packages/modules/electricity_pricing/flexible_tariffs/naturstrom/tariff.py | Implements token validation/refresh and price retrieval/parsing for Naturstrom. |
| packages/modules/electricity_pricing/flexible_tariffs/naturstrom/config.py | Adds dataclass-based configuration for Naturstrom (token, account, update_hours). |
| packages/modules/electricity_pricing/flexible_tariffs/naturstrom/init.py | Initializes the Naturstrom provider package. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def _get_raw_prices(config: NaturstromTariff): | ||
| headers = { | ||
| 'Accept': 'application/json', | ||
| 'Authorization': f"{config.configuration.token.token_type} {config.configuration.token.access_token}" |
| 'stop': end_of_today.isoformat(), | ||
| } | ||
| return req.get_http_session().get( | ||
| f"https://naturstrom-staging.powerquartier.de/api/public/accounts/{config.configuration.account_id}/rate", |
| } | ||
| try: | ||
| token_data = req.get_http_session().post( | ||
| 'https://naturstrom-staging.powerquartier.de/api/public-auth/oauth2/token', |
| Pub().pub("openWB/set/optional/ep/flexible_tariff/provider", asdict(config)) | ||
| log.debug("Token erfolgreich erneuert.") | ||
| except HTTPError as e: | ||
| raise Exception(f"Token-Erneuerung fehlgeschlagen: {e}.") |
| raise Exception(f"Token-Erneuerung fehlgeschlagen: {e}.") | ||
|
|
||
|
|
||
| def fetch(config: NaturstromTariff) -> None: |
Comment on lines
+102
to
+106
| prices: Dict[int, float] = {} | ||
| for data in raw_prices["data"]: | ||
| formatted_price = data["price"] / 100000 # ct/kWh -> €/Wh | ||
| timestamp = datetime.datetime.strptime(data["start_time"], "%Y-%m-%dT%H:%M:%S.%fZ").timestamp() | ||
| prices.update({str(int(timestamp)): formatted_price}) |
| account_id: Optional[str] = None | ||
| account_name: Optional[str] = None | ||
|
|
||
| # Rabot publishes once daily at 00:00 for the following day |
LKuemmel
requested changes
Jul 22, 2026
| account_id: Optional[str] = None | ||
| account_name: Optional[str] = None | ||
|
|
||
| # Rabot publishes once daily at 00:00 for the following day |
Contributor
There was a problem hiding this comment.
Gilt das auch für Naturstrom?
| from dataclass_utils import asdict | ||
| from helpermodules import timecheck | ||
| from helpermodules.pub import Pub | ||
| from requests.exceptions import HTTPError |
Contributor
There was a problem hiding this comment.
Imports aus Bibliotheken bitte zu den anderen an den Dateianfang.
LKuemmel
approved these changes
Jul 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://github.com/openWB/internal-projects/issues/326#issuecomment-4875812689
openWB/openwb-ui-settings#1022