Skip to content

Add Naturstrom#3695

Draft
AlexanderHa98 wants to merge 4 commits into
openWB:masterfrom
AlexanderHa98:feature_Naturstrom-tariffs
Draft

Add Naturstrom#3695
AlexanderHa98 wants to merge 4 commits into
openWB:masterfrom
AlexanderHa98:feature_Naturstrom-tariffs

Conversation

@AlexanderHa98

@AlexanderHa98 AlexanderHa98 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
account_id: Optional[str] = None
account_name: Optional[str] = None

# Rabot publishes once daily at 00:00 for the following day

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Imports aus Bibliotheken bitte zu den anderen an den Dateianfang.

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