From 82fab375eaa4181ce4c6fbc725d6e719379eba97 Mon Sep 17 00:00:00 2001 From: jbruce Date: Mon, 16 May 2022 09:01:59 -0400 Subject: [PATCH] fix keyerror in logging --- lib/oven.py | 59 +++++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/lib/oven.py b/lib/oven.py index fb0dd18..28d09c5 100644 --- a/lib/oven.py +++ b/lib/oven.py @@ -374,19 +374,22 @@ class SimulatedOven(Oven): time_left = self.totaltime - self.runtime - log.info("temp=%.2f, target=%.2f, error=%.2f, pid=%.2f, p=%.2f, i=%.2f, d=%.2f, heat_on=%.2f, heat_off=%.2f, run_time=%d, total_time=%d, time_left=%d" % - (self.pid.pidstats['ispoint'], - self.pid.pidstats['setpoint'], - self.pid.pidstats['err'], - self.pid.pidstats['pid'], - self.pid.pidstats['p'], - self.pid.pidstats['i'], - self.pid.pidstats['d'], - heat_on, - heat_off, - self.runtime, - self.totaltime, - time_left)) + try: + log.info("temp=%.2f, target=%.2f, error=%.2f, pid=%.2f, p=%.2f, i=%.2f, d=%.2f, heat_on=%.2f, heat_off=%.2f, run_time=%d, total_time=%d, time_left=%d" % + (self.pid.pidstats['ispoint'], + self.pid.pidstats['setpoint'], + self.pid.pidstats['err'], + self.pid.pidstats['pid'], + self.pid.pidstats['p'], + self.pid.pidstats['i'], + self.pid.pidstats['d'], + heat_on, + heat_off, + self.runtime, + self.totaltime, + time_left)) + except KeyError: + pass # we don't actually spend time heating & cooling during # a simulation, so sleep. @@ -427,20 +430,22 @@ class RealOven(Oven): if heat_off: self.output.cool(heat_off) time_left = self.totaltime - self.runtime - - log.info("temp=%.2f, target=%.2f, error=%.2f, pid=%.2f, p=%.2f, i=%.2f, d=%.2f, heat_on=%.2f, heat_off=%.2f, run_time=%d, total_time=%d, time_left=%d" % - (self.pid.pidstats['ispoint'], - self.pid.pidstats['setpoint'], - self.pid.pidstats['err'], - self.pid.pidstats['pid'], - self.pid.pidstats['p'], - self.pid.pidstats['i'], - self.pid.pidstats['d'], - heat_on, - heat_off, - self.runtime, - self.totaltime, - time_left)) + try: + log.info("temp=%.2f, target=%.2f, error=%.2f, pid=%.2f, p=%.2f, i=%.2f, d=%.2f, heat_on=%.2f, heat_off=%.2f, run_time=%d, total_time=%d, time_left=%d" % + (self.pid.pidstats['ispoint'], + self.pid.pidstats['setpoint'], + self.pid.pidstats['err'], + self.pid.pidstats['pid'], + self.pid.pidstats['p'], + self.pid.pidstats['i'], + self.pid.pidstats['d'], + heat_on, + heat_off, + self.runtime, + self.totaltime, + time_left)) + except KeyError: + pass class Profile(): def __init__(self, json_data):