Compare commits

...
3 Commits
Author SHA1 Message Date
anima a484e2fe15 fix missing ) on debug messages 2026-11-13 02:39:51 +01:00
anima 4cb9cfa8fa optmise notifications 2026-11-13 02:37:14 +01:00
anima ca498db3bc streamline default 2026-11-13 02:14:34 +01:00
+21 -12
View File
@@ -41,12 +41,12 @@ class ThermalCapWrapper:
clock = get_component("clock")
default_threshold = 0.98
def __init__(self, cap: ThermalCap | str, threshold: float = 0.99, outposts: list[OutpostComponent] | OutpostComponent | OutpostRef | str | None = None):
def __init__(self, cap: ThermalCap | str, threshold: float = 0.98, outposts: list[OutpostComponent] | OutpostComponent | OutpostRef | str | None = None):
"""init wrapper for `ThermalCap`
Args:
cap (`ThermalCap`): thermal cap component. usally self.
threshold (`float`, optional): percent level what thermal cap hold this pressure level. (0-1). default 0.99.
threshold (`float`, optional): percent level what thermal cap hold this pressure level. (0-1). default 0.98.
outpost (`OutpostComposnent` | `OutpostRef` | `str` | `None`, optional): outpost for steam out. None = nearest. default None.
"""
self.cap = cap
@@ -125,7 +125,7 @@ class ThermalCapWrapper:
@property
def cap(self) -> ThermalCap:
if isinstance(self.__cap, ThermalCap): return self.__cap
raise TypeError(f"{self.__cap=} ({type(self.__cap)=} is not a ThermalCap)")
raise TypeError(f"{self.__cap=} ({type(self.__cap)=}) is not a ThermalCap)")
@cap.setter
def cap(self, value: ThermalCap | str):
@@ -177,6 +177,7 @@ class SteamTurbineWrapper:
"""wrapper class wor `SteamTurbine`"""
default_threshold = 25
notify_threshold = 10
notify_timeout = 100
def __init__(self, turbine: SteamTurbine, threshold: int = 25, storages: list[GasTank] = None):
"""init wrapper for `SteamTurbine`
@@ -191,6 +192,7 @@ class SteamTurbineWrapper:
self.storages = storages
self.pcontrol = get_component("power_control")
self.steam_in = turbine.steam_in
self.__notify_timeout = 0
def run(self):
"""run loop for `SteamTurbine`"""
@@ -201,11 +203,19 @@ class SteamTurbineWrapper:
def check_health(self):
"""check own function and notify if not in expected parameters"""
if self.steam_in.level() < self.notify_threshold:
notify(f"{self.turbine.id}: steam level under {self.notify_threshold}", "warn", 30)
if self.__notify_timeout:
self.__notify_timeout -= 1
return
if self.turbine.is_stalled() or self.steam_in.level() == 0:
notify(f"{self.turbine.id}: stopped working or has low efficency ({self.turbine.efficiency()*100}%)", "error", 30)
sleep(30)
return
if self.turbine.power_output() == 108 and get_component("power_control").grid(self.turbine.id).net < self.notify_threshold * -1:
notify(f"{self.turbine.id}: insufficient energy supply", "error", 30)
return
if self.steam_in.level() < self.notify_threshold:
notify(f"{self.turbine.id}: steam level under {self.notify_threshold}", "warn", 30)
return
self.notify_timeout = 100
def fill_steam(self):
"""fills steam if own steam under threshold"""
@@ -248,19 +258,18 @@ class SteamTurbineWrapper:
`list[GasTank]`
"""
gastanks = [ get_component(s.id) for s in get_component(self.turbine.outpost.id).buildings("gas_tank") ]
if prefiled:
return [ s for s in gastanks if s.fluid() == "steam" ]
if prefiled: return [ s for s in gastanks if s.fluid() == "steam" ]
else: return gastanks
@property
def turbine(self) -> SteamTurbine:
if isinstance(self.__turbine, SteamTurbine): return self.__turbine
raise TypeError(f"{self.__turbine=} ({type(self.__turbine)=} is not a SteamTurbine)")
raise TypeError(f"{self.__turbine=} ({type(self.__turbine)=}) is not a SteamTurbine)")
@turbine.setter
def turbine(self, value: SteamTurbine | str):
if isinstance(value, str): value = get_component(value)
if not isinstance(value, SteamTurbine): raise TypeError(f"{self.__turbine=} ({type(self.__turbine)=} is not a SteamTurbine)")
if not isinstance(value, SteamTurbine): raise TypeError(f"{self.__turbine=} ({type(self.__turbine)=}) is not a SteamTurbine)")
self.__turbine = value
@property
@@ -276,7 +285,7 @@ class SteamTurbineWrapper:
@threshold.setter
def threshold(self, value: int):
if not isinstance(value, int) or not 0 < value < 100:
warn(f"set threshold: {value=} ({type(value)=} is not a int, use {self.default_threshold=}")
warn(f"set threshold: {value=} ({type(value)=}) is not a int, use {self.default_threshold=}")
self.__threshold = self.default_threshold
return
self.__threshold = value
@@ -298,5 +307,5 @@ class SteamTurbineWrapper:
if isinstance(value, list):
self.__storages = [ s for s in value if isinstance(s, GasTank) ]
return
warn(f"set storages: given {value=} ({type(value)=} has incorrect type, use default.")
warn(f"set storages: given {value=} ({type(value)=}) has incorrect type, use default.")
self.__storages = self.get_local_storages()