From ffb944810ce6e71146cc294ab2809cebbea25ad1 Mon Sep 17 00:00:00 2001 From: Kyle Gabriel Date: Thu, 10 Oct 2024 12:12:44 -0400 Subject: [PATCH] Fix EC Input error when calibration temperature is None --- mycodo/inputs/atlas_ec.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/mycodo/inputs/atlas_ec.py b/mycodo/inputs/atlas_ec.py index 9a3455f82..aa27bb751 100644 --- a/mycodo/inputs/atlas_ec.py +++ b/mycodo/inputs/atlas_ec.py @@ -261,22 +261,26 @@ def get_measurement(self): _, unit, _ = return_measurement_info( device_measurement, conversion) - if unit != "C": - out_value = convert_from_x_to_y_unit( - unit, "C", last_measurement[1]) + if last_measurement[1] is None: + self.logger.error("Cannot use calibration temperature because it returned None. " + "Fix your temperature measurement and try again.") else: - out_value = last_measurement[1] - - self.logger.debug( - "Latest temperature used to calibrate: {temp}".format( - temp=out_value)) - - ret_value, ret_msg = self.atlas_command.calibrate( - 'temperature', set_amount=out_value) - time.sleep(0.5) - - self.logger.debug("Calibration returned: {val}, {msg}".format( - val=ret_value, msg=ret_msg)) + if unit != "C": + out_value = convert_from_x_to_y_unit( + unit, "C", last_measurement[1]) + else: + out_value = last_measurement[1] + + self.logger.debug( + "Latest temperature used to calibrate: {temp}".format( + temp=out_value)) + + ret_value, ret_msg = self.atlas_command.calibrate( + 'temperature', set_amount=out_value) + time.sleep(0.5) + + self.logger.debug("Calibration returned: {val}, {msg}".format( + val=ret_value, msg=ret_msg)) else: self.logger.error( "Calibration measurement not found within the past "