22"""
33import logging
44from math import ceil
5- import random
65from threading import Thread
76from typing import Dict , List , Optional as TypingOptional , Union
8- from datetime import datetime , timedelta
7+ from datetime import datetime
98
109from control import data
1110from control .ocpp import OcppMixin
12- from control .optional_data import FlexibleTariff , GridFee , OptionalData , PricingGet
11+ from control .optional_data import TARIFF_UPDATE_HOUR , FlexibleTariff , GridFee , OptionalData , PricingGet
1312from helpermodules import hardware_configuration
1413from helpermodules .constants import NO_ERROR
1514from helpermodules .pub import Pub
2019
2120log = logging .getLogger (__name__ )
2221AS_EURO_PER_KWH = 1000.0 # Umrechnung von €/Wh in €/kWh
23- TARIFF_UPDATE_HOUR = 14 # latest expected time for daily tariff update
2422
2523
2624class Optional (OcppMixin ):
@@ -47,9 +45,6 @@ def flexible_tariff_module(self, value: TypingOptional[ConfigurableFlexibleTarif
4745 self .data .electricity_pricing .flexible_tariff .get = PricingGet ()
4846 self ._reset_state (self .data .electricity_pricing .flexible_tariff , "flexible_tariff" )
4947 self ._flexible_tariff_module = value
50- if value :
51- self .data .electricity_pricing .get .next_query_time = None
52- Pub ().pub ("openWB/set/optional/ep/get/next_query_time" , None )
5348 self ._set_ep_configured ()
5449
5550 @property
@@ -63,9 +58,6 @@ def grid_fee_module(self, value: TypingOptional[ConfigurableGridFee]):
6358 self .data .electricity_pricing .grid_fee .get = PricingGet ()
6459 self ._reset_state (self .data .electricity_pricing .grid_fee , "grid_fee" )
6560 self ._grid_fee_module = value
66- if value :
67- self .data .electricity_pricing .get .next_query_time = None
68- Pub ().pub ("openWB/set/optional/ep/get/next_query_time" , None )
6961 self ._set_ep_configured ()
7062
7163 def _set_ep_configured (self ):
@@ -84,6 +76,7 @@ def _reset_state(self, module: Union[FlexibleTariff, GridFee], module_name: str)
8476 Pub ().pub (f"openWB/set/optional/ep/{ module_name } /get/fault_str" , NO_ERROR )
8577 Pub ().pub (f"openWB/set/optional/ep/{ module_name } /get/prices" , {})
8678 Pub ().pub ("openWB/set/optional/ep/get/prices" , {})
79+ Pub ().pub ("openWB/set/optional/ep/get/next_query_time" , None )
8780
8881 def monitoring_start (self ):
8982 if self .monitoring_module is not None :
@@ -256,15 +249,6 @@ def get_last_entry_time_stamp() -> str:
256249 if len (self .data .electricity_pricing .get .prices ) == 0 :
257250 return True
258251 if self .data .electricity_pricing .get .next_query_time is None :
259- next_query_time = datetime .fromtimestamp (float (max (self .data .electricity_pricing .get .prices ))).replace (
260- hour = TARIFF_UPDATE_HOUR , minute = 0 , second = 0
261- ) + timedelta (
262- # aktually ET providers issue next day prices up to half an hour earlier then 14:00
263- # reduce serverload on their site by trying early and randomizing query time
264- minutes = random .randint (1 , 7 ) * - 5
265- )
266- self .data .electricity_pricing .get .next_query_time = next_query_time .timestamp ()
267- Pub ().pub ("openWB/set/optional/ep/get/next_query_time" , self .data .electricity_pricing .get .next_query_time )
268252 return True
269253 if is_tomorrow (get_last_entry_time_stamp ()):
270254 if timecheck .create_timestamp () > self .data .electricity_pricing .get .next_query_time :
0 commit comments