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
23 changes: 15 additions & 8 deletions packages/control/optional.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,19 @@ def ep_is_charging_allowed_price_threshold(self, max_price: float) -> bool:
return False

def __get_first_entry(self) -> tuple[str, float]:
prices = self.data.electricity_pricing.get.prices
if prices is None or len(prices) == 0:
raise Exception("Keine Preisdaten für strompreisbasiertes Laden vorhanden.")
else:
timestamp, first = next(iter(prices.items()))
return timestamp, first

def remove_outdated_prices(self):
if self.data.electricity_pricing.configured:
prices = self.data.electricity_pricing.get.prices
if prices is None or len(prices) == 0:
raise Exception("Keine Preisdaten für strompreisbasiertes Laden vorhanden.")
log.debug("Keine Preisdaten für strompreisbasiertes Laden vorhanden.")
else:
timestamp, first = next(iter(prices.items()))
price_timeslot_seconds = self.__calculate_price_timeslot_length(prices)
now = timecheck.create_timestamp()
prices = {
Expand All @@ -156,18 +163,18 @@ def __get_first_entry(self) -> tuple[str, float]:
if float(price[0]) > now - (price_timeslot_seconds - 1)
}
self.data.electricity_pricing.get.prices = prices
timestamp, first = next(iter(prices.items()))
return timestamp, first
else:
raise Exception("Kein Anbieter für strompreisbasiertes Laden konfiguriert.")
Pub().pub("openWB/set/optional/ep/get/prices", prices)

def __get_current_timeslot_start(self) -> int:
timestamp = self.__get_first_entry()[0]
return float(timestamp)

def ep_get_current_price(self) -> float:
first = self.__get_first_entry()[1]
return first
if self.data.electricity_pricing.configured:
first = self.__get_first_entry()[1]
return first
else:
raise Exception("Kein Anbieter für strompreisbasiertes Laden konfiguriert.")

def __calculate_price_timeslot_length(self, prices: dict) -> int:
first_timestamps = list(prices.keys())[:2]
Expand Down
1 change: 0 additions & 1 deletion packages/helpermodules/measurement_logging/write_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ def create_entry(log_type: LogType, sh_log_data: LegacySmartHomeLogData, previou
try:
grid_price = data.data.optional_data.ep_get_current_price()
except Exception:
log.exception("Fehler im Werte-Logging-Modul für aktuellen Netzpreis, nutze hinterlegten Netzpreis")
grid_price = prices.grid
prices_dict = {"grid": grid_price,
"pv": prices.pv,
Expand Down
4 changes: 1 addition & 3 deletions packages/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def handler5MinAlgorithm(self):
data.data.optional_data.ocpp_transfer_meter_values()
data.data.counter_all_data.validate_hierarchy()
loadvars_.ep_get_prices()
data.data.optional_data.remove_outdated_prices()
except Exception:
log.exception("Fehler im Main-Modul")

Expand Down Expand Up @@ -252,9 +253,6 @@ def handler_hour(self):
""" Handler, der jede Stunde aufgerufen wird und die Aufgaben ausführt, die nur jede Stunde ausgeführt werden müssen.
"""
try:
with ChangedValuesContext(loadvars_.event_module_update_completed):
for cp in data.data.cp_data.values():
calculate_charged_energy_by_source(cp)
logger.clear_in_memory_log_handler(None)
except Exception:
log.exception("Fehler im Main-Modul")
Expand Down
9 changes: 6 additions & 3 deletions packages/modules/common/configurable_tariff.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,15 @@ def _remove_outdated_prices(self, tariff_state: TariffState, timeslot_length_sec
self.fault_state.error("no prices to show")
else:
now = timecheck.create_timestamp()
removed = False
for timestamp in list(tariff_state.prices.keys()):
if int(timestamp) < now - (timeslot_length_seconds - 1): # keep current time slot
tariff_state.prices.pop(timestamp)
log.debug(
'Die Preisliste startet nicht mit der aktuellen Stunde. '
f'Eintrag {timestamp} wurden entfernt. rest: {tariff_state.prices}')
removed = True
if removed:
log.debug(
'Die Preisliste startet nicht mit der aktuellen Stunde. '
f'Abgelaufene Eintraäge wurden entfernt: {tariff_state.prices}')
return tariff_state


Expand Down