@@ -222,7 +222,7 @@ def _read_config_dtu(self, actual_inverter):
222222 self .pollinginterval = int (get_config_value (config , "ESP8266PollingIntervall" , "DEFAULT" , "" , 10000 ))
223223 self .meter_data = 0
224224 self .httptimeout = get_default_config (config , "HTTPTimeout" , 2.5 )
225- self ._get_error_handling_config (config )
225+ self ._load_error_handling_config (config )
226226
227227 def _read_config_template (self , template_number ):
228228 config = self ._get_config ()
@@ -276,12 +276,12 @@ def _read_config_template(self, template_number):
276276 self .dry_run = is_true (get_default_config (config , "DryRun" , False ))
277277 self .meter_data = 0
278278 self .httptimeout = get_default_config (config , "HTTPTimeout" , 2.5 )
279- self ._get_error_handling_config (config )
279+ self ._load_error_handling_config (config )
280280
281- def _get_error_handling_config (self , config ):
281+ def _load_error_handling_config (self , config ):
282282 '''Loads error handling configuration values from the provided config object.'''
283283
284- self .error_mode = get_default_config (config , "ErrorMode" , "retrycount" ).strip ()
284+ self .error_mode = get_default_config (config , "ErrorMode" , constants . MODE_RETRYCOUNT ).strip ()
285285 self .retry_after_seconds = int (get_default_config (config , "RetryAfterSeconds" , 180 ))
286286 self .min_retries_until_fail = int (get_default_config (config , "MinRetriesUntilFail" , 3 ))
287287 self .error_state_after_seconds = int (get_default_config (config , "ErrorStateAfterSeconds" , 0 ))
@@ -588,7 +588,7 @@ def update(self):
588588 successful = False
589589 now = time .time ()
590590 try :
591- if self .error_mode == "timeout" and self .error_state_after_seconds > 0 :
591+ if self .error_mode == constants . MODE_TIMEOUT and self .error_state_after_seconds > 0 :
592592 # Set zero values only after ErrorStateAfterSeconds has elapsed since last success
593593 if (not self .last_update_successful and (now - self ._last_update ) >= self .error_state_after_seconds ):
594594 self ._handle_reconnect_wait ()
@@ -598,11 +598,23 @@ def update(self):
598598 # In normal operation (no error), always call _refresh_data on every update
599599 if self .last_update_successful :
600600 successful = self ._refresh_and_update ()
601- elif self .error_mode == "retrycount" :
601+ elif self .error_mode == constants . MODE_RETRYCOUNT :
602602 # Classic retry-count-based error handling
603603 if self .failed_update_count >= self .min_retries_until_fail :
604604 self ._handle_reconnect_wait ()
605- if self ._should_refresh_data (now ):
605+ # Determine if we should refresh data based on current state and timing
606+ is_last_update_successful = self .last_update_successful
607+ time_since_last_update = now - self ._last_update
608+ is_retry_interval_elapsed = time_since_last_update >= self .retry_after_seconds
609+ is_below_min_retries = self .failed_update_count < self .min_retries_until_fail
610+
611+ should_refresh_data = (
612+ is_last_update_successful or
613+ is_retry_interval_elapsed or
614+ is_below_min_retries
615+ )
616+
617+ if should_refresh_data :
606618 successful = self ._refresh_and_update ()
607619 except requests .exceptions .RequestException as exception :
608620 logging .warning (f"HTTP Error at _update for inverter "
0 commit comments