Skip to content

electricity pricing: if last price key is before next calculated query time set last price key as query time - #3458

Merged
LKuemmel merged 5 commits into
openWB:masterfrom
LKuemmel:fix_electricity_pricing_next_query_time
Jun 3, 2026
Merged

LKuemmel merged 5 commits into
openWB:masterfrom
LKuemmel:fix_electricity_pricing_next_query_time

Conversation

@LKuemmel

@LKuemmel LKuemmel commented Jun 3, 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

This PR adjusts the electricity pricing refresh scheduling so that when the currently stored price list ends before the next planned update window, the next query is moved forward to align with the last available price timestamp (rather than waiting until the next configured tariff update hour).

Changes:

  • Refactors next-query-time calculation to accept the latest available price timestamp and potentially schedule earlier updates.
  • Updates the component updater flow to pass the latest price timestamp into the scheduling logic.
  • Adds unit tests to validate the next-query-time calculation behavior.

Reviewed changes

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

File Description
packages/modules/common/configurable_tariff.py Updates next query scheduling logic to consider latest price timestamp.
packages/modules/common/configurable_tariff_test.py Adds tests for the new next query time behavior and updates private-method test calls.

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

Comment on lines +84 to +89
if latest_price_timestamp < next_query_time:
# Falls die Preise nicht bis zum nächsten geplanten Abruf gültig sind,
# den Abruf auf die Gültigkeitsdauer der Preise setzen
log.debug(f"Die Preise sind nur bis {latest_price_timestamp} gültig, "
f"setze nächsten Abruf auf dieses Datum.")
next_query_time = latest_price_timestamp
Comment on lines +96 to +100
last_known_timestamp = datetime.fromtimestamp(int(max(self.get.prices.keys()) if self.get.prices else 0))
tariff_state = self._component_updater()
if last_known_timestamp < datetime.fromtimestamp(int(max(tariff_state.prices.keys()))):
self.__calculate_next_query_time()
latest_price_timestamp = datetime.fromtimestamp(
int(max(tariff_state.prices.keys()) if tariff_state.prices else 0))
if last_known_timestamp < latest_price_timestamp:

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment on lines +88 to +89
if next_query_time <= now:
next_query_time += timedelta(hours=1)
next_query_time = now + timedelta(hours=1)
@LKuemmel
LKuemmel requested a review from Copilot June 3, 2026 07:44
@LKuemmel
LKuemmel marked this pull request as draft June 3, 2026 07:45

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

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

Comment on lines +165 to +172
latest_price_timestamp = datetime(2022, 5, 16, 12, 30, 0)

# execution
tariff._calculate_next_query_time(latest_price_timestamp) # pyright: ignore[reportPrivateUsage]

# evaluation
expected_timestamp = int(latest_price_timestamp.timestamp())
assert tariff.get.next_query_time == expected_timestamp
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@LKuemmel
LKuemmel marked this pull request as ready for review June 3, 2026 07:50
@LKuemmel
LKuemmel merged commit 26c1dbf into openWB:master Jun 3, 2026
1 check passed
@LKuemmel
LKuemmel deleted the fix_electricity_pricing_next_query_time branch June 8, 2026 08:59
ndrsnhs pushed a commit to ndrsnhs/core that referenced this pull request Aug 24, 2026
…y time set last price key as query time (openWB#3458)

* electricity pricing_: if last price key is before next calculated query time set last price key as query time

* fix

* review

* review

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <[email protected]>

---------

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
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.

2 participants