mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-10-15 10:31:57 +00:00
fix: bare except (#1159)
Bare `except:` catches SystemExit and KeyboardInterrupt, which can: - Mask Ctrl+C handling during long optimization runs - Hide critical system signals - Make debugging harder Replacement by `except Exception:` preserves the same error handling while respecting system-level exceptions. Co-authored-by: Milo @KeloYuan Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
This commit is contained in:
co-authored by
Milo @KeloYuan
parent
6933b33542
commit
8bf798daeb
@@ -974,7 +974,7 @@ class GeneticOptimization(OptimizationBase):
|
||||
if self.optimize_ev and parameters.eauto and self.simulation.ev:
|
||||
try:
|
||||
penalty = self.config.optimization.genetic.penalties["ev_soc_miss"]
|
||||
except:
|
||||
except Exception:
|
||||
# Use default
|
||||
penalty = 10
|
||||
logger.error(
|
||||
@@ -1005,7 +1005,7 @@ class GeneticOptimization(OptimizationBase):
|
||||
individuals = self.config.optimization.genetic.individuals
|
||||
if individuals is None:
|
||||
raise
|
||||
except:
|
||||
except Exception:
|
||||
individuals = 300
|
||||
logger.error("Individuals not configured. Using {}.", individuals)
|
||||
|
||||
@@ -1076,7 +1076,7 @@ class GeneticOptimization(OptimizationBase):
|
||||
if generations is None:
|
||||
try:
|
||||
generations = self.config.optimization.genetic.generations
|
||||
except:
|
||||
except Exception:
|
||||
generations = 400
|
||||
logger.error("Generations not configured. Using {}.", generations)
|
||||
|
||||
|
||||
@@ -282,9 +282,9 @@ class GeneticOptimizationParameters(
|
||||
fill_method="linear",
|
||||
)
|
||||
pvforecast_ac_power = (array * power_to_energy_per_interval_factor).to_list()
|
||||
except:
|
||||
except Exception as e:
|
||||
logger.info(
|
||||
"No PV forecast data available - defaulting to demo data. Parameter preparation attempt {}.",
|
||||
"No PV forecast data available - defaulting to demo data. Parameter preparation attempt {}: {e}",
|
||||
attempt,
|
||||
)
|
||||
cls.config.merge_settings_from_dict(
|
||||
@@ -336,9 +336,9 @@ class GeneticOptimizationParameters(
|
||||
fill_method="ffill",
|
||||
)
|
||||
elecprice_marketprice_wh = array.to_list()
|
||||
except:
|
||||
except Exception as e:
|
||||
logger.info(
|
||||
"No Electricity Marketprice forecast data available - defaulting to demo data. Parameter preparation attempt {}.",
|
||||
"No Electricity Marketprice forecast data available - defaulting to demo data. Parameter preparation attempt {}: {e}",
|
||||
attempt,
|
||||
)
|
||||
cls.config.elecprice.provider = "ElecPriceAkkudoktor"
|
||||
@@ -353,9 +353,9 @@ class GeneticOptimizationParameters(
|
||||
fill_method="ffill",
|
||||
)
|
||||
loadforecast_power_w = array.to_list()
|
||||
except:
|
||||
except Exception as e:
|
||||
logger.info(
|
||||
"No Load forecast data available - defaulting to demo data. Parameter preparation attempt {}.",
|
||||
"No Load forecast data available - defaulting to demo data. Parameter preparation attempt {}: {e}",
|
||||
attempt,
|
||||
)
|
||||
cls.config.merge_settings_from_dict(
|
||||
@@ -379,9 +379,9 @@ class GeneticOptimizationParameters(
|
||||
fill_method="ffill",
|
||||
)
|
||||
feed_in_tariff_wh = array.to_list()
|
||||
except:
|
||||
except Exception as e:
|
||||
logger.info(
|
||||
"No feed in tariff forecast data available - defaulting to demo data. Parameter preparation attempt {}.",
|
||||
"No feed in tariff forecast data available - defaulting to demo data. Parameter preparation attempt {}: {e}",
|
||||
attempt,
|
||||
)
|
||||
cls.config.merge_settings_from_dict(
|
||||
@@ -407,9 +407,9 @@ class GeneticOptimizationParameters(
|
||||
fill_method="ffill",
|
||||
)
|
||||
weather_temp_air = array.to_list()
|
||||
except:
|
||||
except Exception as e:
|
||||
logger.info(
|
||||
"No weather forecast data available - defaulting to demo data. Parameter preparation attempt {}.",
|
||||
"No weather forecast data available - defaulting to demo data. Parameter preparation attempt {}: {e}",
|
||||
attempt,
|
||||
)
|
||||
cls.config.weather.provider = "BrightSky"
|
||||
@@ -442,9 +442,9 @@ class GeneticOptimizationParameters(
|
||||
max_soc_percentage=battery_config.max_soc_percentage,
|
||||
charge_rates=battery_config.charge_rates,
|
||||
)
|
||||
except:
|
||||
except Exception as e:
|
||||
logger.info(
|
||||
"No battery device data available - defaulting to demo data. Parameter preparation attempt {}.",
|
||||
"No battery device data available - defaulting to demo data. Parameter preparation attempt {}: {e}",
|
||||
attempt,
|
||||
)
|
||||
cls.config.devices.batteries = [{"device_id": "battery1", "capacity_wh": 8000}]
|
||||
@@ -472,7 +472,7 @@ class GeneticOptimizationParameters(
|
||||
initial_soc_factor = 0.0
|
||||
# genetic parameter is 0..100 as int
|
||||
initial_soc_percentage = int(initial_soc_factor * 100)
|
||||
except:
|
||||
except Exception:
|
||||
initial_soc_percentage = None
|
||||
if initial_soc_percentage is None:
|
||||
logger.info(
|
||||
@@ -514,9 +514,9 @@ class GeneticOptimizationParameters(
|
||||
min_soc_percentage=electric_vehicle_config.min_soc_percentage,
|
||||
max_soc_percentage=electric_vehicle_config.max_soc_percentage,
|
||||
)
|
||||
except:
|
||||
except Exception as e:
|
||||
logger.info(
|
||||
"No electric_vehicle device data available - defaulting to demo data. Parameter preparation attempt {}.",
|
||||
"No electric_vehicle device data available - defaulting to demo data. Parameter preparation attempt {}: {e}",
|
||||
attempt,
|
||||
)
|
||||
cls.config.devices.max_electric_vehicles = 1
|
||||
@@ -544,7 +544,7 @@ class GeneticOptimizationParameters(
|
||||
initial_soc_factor = 0.0
|
||||
# genetic parameter is 0..100 as int
|
||||
initial_soc_percentage = int(initial_soc_factor * 100)
|
||||
except:
|
||||
except Exception:
|
||||
initial_soc_percentage = None
|
||||
if initial_soc_percentage is None:
|
||||
logger.info(
|
||||
@@ -580,9 +580,9 @@ class GeneticOptimizationParameters(
|
||||
dc_to_ac_efficiency=inverter_config.dc_to_ac_efficiency,
|
||||
max_ac_charge_power_w=inverter_config.max_ac_charge_power_w,
|
||||
)
|
||||
except:
|
||||
except Exception as e:
|
||||
logger.info(
|
||||
"No inverter device data available - defaulting to demo data. Parameter preparation attempt {}.",
|
||||
"No inverter device data available - defaulting to demo data. Parameter preparation attempt {}: {e}",
|
||||
attempt,
|
||||
)
|
||||
cls.config.devices.inverters = [
|
||||
@@ -635,9 +635,9 @@ class GeneticOptimizationParameters(
|
||||
duration_h=home_appliance_config.duration_h,
|
||||
time_windows=home_appliance_config.time_windows,
|
||||
)
|
||||
except:
|
||||
except Exception as e:
|
||||
logger.info(
|
||||
"No home appliance device data available - defaulting to demo data. Parameter preparation attempt {}.",
|
||||
"No home appliance device data available - defaulting to demo data. Parameter preparation attempt {}: {e}",
|
||||
attempt,
|
||||
)
|
||||
cls.config.devices.home_appliances = [
|
||||
@@ -668,9 +668,9 @@ class GeneticOptimizationParameters(
|
||||
dishwasher=home_appliance_params,
|
||||
start_solution=start_solution,
|
||||
)
|
||||
except:
|
||||
except Exception as e:
|
||||
logger.info(
|
||||
"Can not prepare optimization parameters - will retry. Parameter preparation attempt {}.",
|
||||
"Can not prepare optimization parameters - will retry. Parameter preparation attempt {}: {e}",
|
||||
attempt,
|
||||
)
|
||||
oparams = None
|
||||
|
||||
@@ -100,7 +100,7 @@ class OptimizationCommonSettings(SettingsBaseModel):
|
||||
"""The keys of the solution."""
|
||||
try:
|
||||
ems_eos = get_ems()
|
||||
except:
|
||||
except Exception:
|
||||
# ems might not be initialized
|
||||
return []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user