refactor: allow setting stats internally

this should better reflect user requested temp while waiting for temp

as a negative other frontends will not reflect the same value during the wait, nor will ks if it's restarted
This commit is contained in:
Alfredo Monclus
2024-12-07 10:34:54 -03:00
parent 23248af10c
commit 36c413f148
3 changed files with 12 additions and 0 deletions

View File

@@ -305,6 +305,15 @@ class Printer:
else:
return self.data.get(stat, {})
def set_stat(self, stat, data):
if self.data is None:
logging.error("Data is not initialized")
return
if stat not in self.data:
logging.error(f"Stat '{stat}' not found in data")
return
self.data[stat].update(data)
def get_fan_speed(self, fan="fan"):
speed = 0
if fan not in self.config or fan not in self.data:

View File

@@ -193,6 +193,7 @@ class Panel(MenuPanel):
else:
logging.info(f"Unknown heater: {self.active_heater}")
self._screen.show_popup_message(_("Unknown Heater") + " " + self.active_heater)
self._printer.set_stat(name, {"target": temp})
def verify_max_temp(self, temp):
temp = int(temp)

View File

@@ -170,6 +170,7 @@ class Panel(ScreenPanel):
else:
logging.info(f"Unknown heater: {heater}")
self._screen.show_popup_message(_("Unknown Heater") + " " + heater)
self._printer.set_stat(heater, {"target": target})
logging.info(f"Setting {heater} to {target}")
def update_graph_visibility(self, force_hide=False):
@@ -479,6 +480,7 @@ class Panel(ScreenPanel):
self._screen.show_popup_message(
_("Unknown Heater") + " " + self.active_heater
)
self._printer.set_stat(name, {"target": temp})
def verify_max_temp(self, temp):
temp = int(temp)