Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/control/optional.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def _reset_state(self, module: Union[FlexibleTariff, GridFee]):
module.get.fault_str = NO_ERROR
Pub().pub(f"openWB/set/optional/ep/{module.name}/get/fault_state", 0)
Pub().pub(f"openWB/set/optional/ep/{module.name}/get/fault_str", NO_ERROR)
Pub().pub(f"openWB/set/optional/ep/{module.name}/get/prices", {})
Pub().pub(f"openWB/set/optional/ep/{module.name}/get/next_query_time", None)
Pub().pub(f"openWB/set/optional/ep/{module.name}/get/prices", {})
Pub().pub(f"openWB/set/optional/ep/{module.name}/get/next_query_time", None)
Pub().pub("openWB/set/optional/ep/get/prices", {})

def monitoring_start(self):
Expand Down Expand Up @@ -242,8 +242,6 @@ def ep_get_loading_hours(self, duration: float, remaining_time: float) -> List[i
return []

def _is_et_price_update_required_for_module(self, module: Union[FlexibleTariff, GridFee]) -> bool:
if module is None:
return False
if module.get.next_query_time is None:
return True
now = timecheck.create_timestamp()
Expand All @@ -261,8 +259,10 @@ def et_price_update_required(self) -> bool:
return False
if len(self.data.electricity_pricing.get.prices) == 0:
return True
return (self._is_et_price_update_required_for_module(self.data.electricity_pricing.flexible_tariff) or
self._is_et_price_update_required_for_module(self.data.electricity_pricing.grid_fee))
return ((self._flexible_tariff_module is not None and
self._is_et_price_update_required_for_module(self.data.electricity_pricing.flexible_tariff)) or
(self._grid_fee_module is not None and
self._is_et_price_update_required_for_module(self.data.electricity_pricing.grid_fee)))

def ocpp_transfer_meter_values(self):
try:
Expand Down
2 changes: 1 addition & 1 deletion packages/control/optional_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def test_et_price_update_required(monkeypatch, flexible_tariff, grid_fee, curren
# setup
opt = Optional()
opt._flexible_tariff_module = Mock()
opt._grid_fee_module = Mock()
opt._grid_fee_module = None
opt.data.electricity_pricing.get.prices = flexible_tariff["prices"]
opt.data.electricity_pricing.flexible_tariff.get.prices = flexible_tariff["prices"]
opt.data.electricity_pricing.flexible_tariff.get.next_query_time = flexible_tariff["next_query_time"]
Expand Down
13 changes: 9 additions & 4 deletions packages/modules/common/store/_tariff.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def __reduce_prices(prices: Dict[str, float]) -> Dict[int, float]:
return {int(float(k)): v for k, v in prices.items() if int(float(k)) >= first_timestamp}

def __get_default_grid_fee_price(prices: Dict[str, float]) -> float:
if (hasattr(data.data.optional_data.grid_fee_module.config, "default_price") and
if (data.data.optional_data.grid_fee_module is not None and
hasattr(data.data.optional_data.grid_fee_module.config, "default_price") and
data.data.optional_data.grid_fee_module.config.default_price is not None):
log.debug("Using default grid fee price from configuration: " +
f"{data.data.optional_data.grid_fee_module.config.default_price}")
Expand All @@ -93,8 +94,9 @@ def __normalize_grid_fee_prices(grid_fee_prices: Dict[int, float], max_timestamp
grid_fee_prices = __reduce_prices(grid_fee_prices)
grid_fee_prices = {int(float(k)): v for k, v in grid_fee_prices.items() if int(float(k)) <= max_timestamp}

if (hasattr(data.data.optional_data.flexible_tariff_module.config, "includes_grid_fee")
and data.data.optional_data.flexible_tariff_module.config.includes_grid_fee is False):
if (data.data.optional_data.flexible_tariff_module is not None and
hasattr(data.data.optional_data.flexible_tariff_module.config, "includes_grid_fee") and
data.data.optional_data.flexible_tariff_module.config.includes_grid_fee is False):
return grid_fee_prices
else:
# Bei flexiblen Tarifen, die das Netzentgelt _nicht_ enthalten,
Expand All @@ -105,7 +107,7 @@ def __normalize_grid_fee_prices(grid_fee_prices: Dict[int, float], max_timestamp
def __sum_of_tariff_and_grid_fee(
flexible_tariff_prices: Dict[int, float],
grid_fee_prices: Dict[int, float]
) -> Dict[int, float]:
) -> Dict[int, float]:
grid_fee_prices = __normalize_grid_fee_prices(grid_fee_prices, max(flexible_tariff_prices.keys()))
timestamps = sorted(list(set(flexible_tariff_prices.keys()) | set(grid_fee_prices.keys())))
return {ts: (__get_value_at_or_before(flexible_tariff_prices, ts) +
Expand All @@ -120,6 +122,9 @@ def __sum_of_tariff_and_grid_fee(
in electricity_pricing.grid_fee.get.prices.items()}

flexible_tariff_prices = __reduce_prices(flexible_tariff_prices)
if len(flexible_tariff_prices) == 0 and len(grid_fee_prices) == 0:
return {}

if len(grid_fee_prices) == 0 and len(flexible_tariff_prices) > 0:
return flexible_tariff_prices

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import logging
import random
import requests
import time
from typing import Dict
from datetime import datetime, timedelta
from helpermodules import timecheck
Expand All @@ -11,8 +8,6 @@
from modules.electricity_pricing.flexible_tariffs.energycharts.config import EnergyChartsTariffConfiguration
from modules.electricity_pricing.flexible_tariffs.energycharts.config import EnergyChartsTariff

MAX_RETRIES = 10
MAX_DELAY = 10
log = logging.getLogger(__name__)


Expand All @@ -39,19 +34,9 @@ def parse_response(config: EnergyChartsTariffConfiguration, raw_prices: dict) ->

def fetch_prices(config: EnergyChartsTariffConfiguration) -> Dict[str, float]:
url = create_request_url(config)
for attempt in range(MAX_RETRIES):
attempt += 1 # one-based indexing
try:
response = req.get_http_session().get(url, timeout=(10, 20))
response.raise_for_status()
return parse_response(config, response.json())
except requests.exceptions.Timeout as e:
if MAX_RETRIES > attempt:
delay = (attempt) * random.uniform(attempt, MAX_DELAY)
log.warning(f"Timeout beim Abrufen der Preise (Versuch {attempt}/{MAX_RETRIES}) : {str(e)}"
f", neuer Versuch in {delay:.1f} Sekunden...")
time.sleep(delay)
raise Exception("Timeout beim Abrufen der Preise nach {MAX_RETRIES} Versuchen")
response = req.get_http_session().get(url, timeout=(10, 20))
response.raise_for_status()
return parse_response(config, response.json())


def create_electricity_tariff(config: EnergyChartsTariff):
Comment on lines +38 to 42

Copilot AI Mar 30, 2026

Copy link

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.
Expand Down
Loading