From 3c515761e85d1822035e1a01d37019435f6f2dfa Mon Sep 17 00:00:00 2001 From: James Kirikland Garner Date: Mon, 26 Dec 2022 20:32:51 -0800 Subject: [PATCH] skip sink on API start with start time set --- config.py | 2 +- kiln-controller.py | 7 ++++++- lib/oven.py | 10 ++++++---- lib/ovenWatcher.py | 1 + 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/config.py b/config.py index 79ce694..8d2a424 100644 --- a/config.py +++ b/config.py @@ -8,7 +8,7 @@ import busio # General options ### Logging -log_level = logging.INFO +log_level = logging.DEBUG log_format = '%(asctime)s %(levelname)s %(name)s: %(message)s' ### Server diff --git a/kiln-controller.py b/kiln-controller.py index 17fc3f9..9b23c1a 100755 --- a/kiln-controller.py +++ b/kiln-controller.py @@ -73,6 +73,11 @@ def handle_api(): if 'startat' in bottle.request.json: startat = bottle.request.json['startat'] + #Shut off seek if start time has been set + allow_seek = True + if startat > 0: + allow_seek = False + # get the wanted profile/kiln schedule profile = find_profile(wanted) if profile is None: @@ -81,7 +86,7 @@ def handle_api(): # FIXME juggling of json should happen in the Profile class profile_json = json.dumps(profile) profile = Profile(profile_json) - oven.run_profile(profile,startat=startat) + oven.run_profile(profile, startat=startat, allow_seek=allow_seek) ovenWatcher.record(profile) if bottle.request.json['cmd'] == 'stop': diff --git a/lib/oven.py b/lib/oven.py index 48fe985..9eafd06 100644 --- a/lib/oven.py +++ b/lib/oven.py @@ -334,14 +334,15 @@ class Oven(threading.Thread): target_temp = profile.get_target_temperature(0) if temp > target_temp + 5: startat = profile.find_next_time_from_temperature(temp) - log.info("seek_start is in effect") + log.info("seek_start is in effect, starting at: {} s, {} deg".format(round(startat), round(temp))) else: startat = 0 return startat - def run_profile(self, profile, startat=0, auto_start=False): + def run_profile(self, profile, startat=0, allow_seek=True): + log.debug('run_profile run on thread' + threading.current_thread().name) runtime = startat * 60 - if not auto_start: + if allow_seek: if self.state == 'IDLE': if config.seek_start: temp = self.board.temp_sensor.temperature() # Defined in a subclass @@ -485,7 +486,7 @@ class Oven(threading.Thread): with open(profile_path) as infile: profile_json = json.dumps(json.load(infile)) profile = Profile(profile_json) - self.run_profile(profile,startat=startat, auto_start=True) + self.run_profile(profile, startat=startat, allow_seek=False) # We don't want a seek on an auto restart. self.cost = d["cost"] time.sleep(1) self.ovenwatcher.record(profile) @@ -496,6 +497,7 @@ class Oven(threading.Thread): def run(self): while True: + log.debug('Oven running on ' + threading.current_thread().name) if self.state == "IDLE": if self.should_i_automatic_restart() == True: self.automatic_restart() diff --git a/lib/ovenWatcher.py b/lib/ovenWatcher.py index 3e47e4f..3a420e5 100644 --- a/lib/ovenWatcher.py +++ b/lib/ovenWatcher.py @@ -79,6 +79,7 @@ class OvenWatcher(threading.Thread): def notify_all(self,message): message_json = json.dumps(message) log.debug("sending to %d clients: %s"%(len(self.observers),message_json)) + for wsock in self.observers: if wsock: try: