Skip to content

electricity pricing: fix update required, energycharts#3255

Open
LKuemmel wants to merge 4 commits intoopenWB:masterfrom
LKuemmel:fixes
Open

electricity pricing: fix update required, energycharts#3255
LKuemmel wants to merge 4 commits intoopenWB:masterfrom
LKuemmel:fixes

Conversation

@LKuemmel
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 adjusts electricity pricing handling around EnergyCharts fetching and optional-module update/reset behavior, and hardens grid-fee/tariff price aggregation against missing/empty inputs.

Changes:

  • Simplify EnergyCharts tariff fetching to a single HTTP request/parse path.
  • Add None-safety checks for optional module configs and return {} when both tariff and grid-fee price sets are empty (prevents crashes).
  • Ensure optional electricity-pricing state reset clears published prices/next-query-time consistently and refine “update required” logic.

Reviewed changes

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

File Description
packages/modules/electricity_pricing/flexible_tariffs/energycharts/tariff.py Removes retry/backoff loop and uses a single request+parse flow for EnergyCharts prices.
packages/modules/common/store/_tariff.py Adds None guards when reading optional module configs; prevents failure when both inputs are empty; minor formatting fix.
packages/control/optional.py Makes _reset_state always publish cleared prices/next query time; changes logic determining whether a price update is required.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 262 to 266
return ((self._flexible_tariff_module and
self._is_et_price_update_required_for_module(self.data.electricity_pricing.flexible_tariff)) or
(self._grid_fee_module and
self._is_et_price_update_required_for_module(self.data.electricity_pricing.grid_fee)))

Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

et_price_update_required() currently uses self._flexible_tariff_module and ... / self._grid_fee_module and .... Because these attributes are objects (or None), the expression can return None (e.g., False or None -> None) instead of a bool, and it can also call _is_et_price_update_required_for_module() with module=None if _grid_fee_module is set but self.data.electricity_pricing.grid_fee is None (this is how existing tests model “no grid fee”). Please make this return a strict boolean and handle None modules safely (e.g., use is not None checks and/or reintroduce the module is None guard).

Suggested change
return ((self._flexible_tariff_module and
self._is_et_price_update_required_for_module(self.data.electricity_pricing.flexible_tariff)) or
(self._grid_fee_module and
self._is_et_price_update_required_for_module(self.data.electricity_pricing.grid_fee)))
flexible_required = False
if (
self._flexible_tariff_module is not None
and self.data.electricity_pricing.flexible_tariff is not None
):
flexible_required = self._is_et_price_update_required_for_module(
self.data.electricity_pricing.flexible_tariff
)
grid_required = False
if (
self._grid_fee_module is not None
and self.data.electricity_pricing.grid_fee is not None
):
grid_required = self._is_et_price_update_required_for_module(
self.data.electricity_pricing.grid_fee
)
return flexible_required or grid_required

Copilot uses AI. Check for mistakes.
Comment on lines +40 to 44
response.raise_for_status()
return parse_response(config, response.json())


def create_electricity_tariff(config: EnergyChartsTariff):
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

fetch_prices() no longer uses the retry/backoff logic, but the module still defines MAX_RETRIES/MAX_DELAY and imports random, requests, and time, which are now unused. Please remove the unused constants/imports (or reintroduce the retry logic) to avoid linting/runtime maintenance issues.

Copilot uses AI. Check for mistakes.
@LKuemmel
Copy link
Copy Markdown
Contributor Author

@tpd-opitz Möchtest Du ein Review machen?
Mir ist aufgefallen, dass wenn nur ein Strompreis-Modul konfiguriert ist, jeden Zyklus die Preise abgefragt werden und wenn EnergyCharts nicht erreichbar ist, legt er sehr lange die Regelung lahm.

@tpd-opitz
Copy link
Copy Markdown
Contributor

tpd-opitz commented Mar 30, 2026

@tpd-opitz Möchtest Du ein Review machen?

Vielen Dank für das Vertrauen.

Ich mache das sehr gern, aber ob ich vor Ostern noch Zeit dazu finde kann ich nicht versprechen.

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.

3 participants