Add try/catch for client's "read temp" logic

this can isolate an error for a certain probe, so that other probes can go
ahead and take their readings during each client run.  that way only the bad
one is marked as "error" status by the server
This commit is contained in:
Lance Edgar 2018-10-23 17:39:18 -05:00
parent b644818eef
commit 8220082359

View file

@ -137,22 +137,28 @@ class TempmonClient(Daemon):
Take a single reading and add to Rattail database. Take a single reading and add to Rattail database.
""" """
reading = tempmon.Reading() reading = tempmon.Reading()
reading.degrees_f = self.read_temp(probe)
# a reading of 185.0 °F indicates some sort of power issue. when this try:
# happens we log an error (which sends basic email) but do not record reading.degrees_f = self.read_temp(probe)
# the temperature. that way the server doesn't see the 185.0 reading
# and send out a "false alarm" about the temperature being too high.
# https://www.controlbyweb.com/support/faq/temp-sensor-reading-error.html
if reading.degrees_f == 185.0:
log.error("got reading of 185.0 from probe: %s", probe.description)
else: # we have a good reading except:
reading.client = probe.client log.exception("Failed to read temperature (but will keep trying) for probe: %s", probe)
reading.probe = probe
reading.taken = datetime.datetime.utcnow() else:
session.add(reading) # a reading of 185.0 °F indicates some sort of power issue. when this
return reading # happens we log an error (which sends basic email) but do not record
# the temperature. that way the server doesn't see the 185.0 reading
# and send out a "false alarm" about the temperature being too high.
# https://www.controlbyweb.com/support/faq/temp-sensor-reading-error.html
if reading.degrees_f == 185.0:
log.error("got reading of 185.0 from probe: %s", probe.description)
else: # we have a good reading
reading.client = probe.client
reading.probe = probe
reading.taken = datetime.datetime.utcnow()
session.add(reading)
return reading
def read_temp(self, probe): def read_temp(self, probe):
""" """