diff --git a/alerts.py b/alerts.py --- a/alerts.py +++ b/alerts.py @@ -6,8 +6,9 @@ import logging class AlertManager: - def __init__(self, config): + def __init__(self, database, config): self.logger = logging.getLogger('hydrobot') + self.database = database self.from_addr = config.get("alerts", "from_address") self.to_addr = config.get("alerts", "to_address") self.mail_server = config.get("alerts", "mail_server") @@ -59,7 +60,7 @@ class AlertManager: server.login(self.username, self.password) server.send_message(msg) server.quit() - self.logger.debug("Sent email alert: " + message) + self.logger.info("Sent email alert: " + message) except: self.logger.error("Sending email alert failed!") @@ -96,19 +97,24 @@ class OutputFeedbackAlert(Alert): def evalutate(self): #get output status - output_status = 1 + output_status = self.manager.database.read_value(self.output_module, self.output_type, int(self.output_number)) + print("Output status: " + str(output_status)) #get input status - input_status = 0 - if output_status == 1: - if input_status < self.on_threshold: - #alert! - print("Alert! " + self.name + " did not turn on!") - self.manager.send_alert("Alert! " + self.name + " did not turn on!") - if output_status == 0: - if input_status > self.off_threshold: - #alert! - print("Alert! " + self.name + " did not turn off!") - self.manager.send_alert("Alert! " + self.name + " did not turn off!") + input_status = self.manager.database.read_value(self.input_module, self.input_type, int(self.input_number)) + print("Input status: " + str(input_status)) + + if input_status != None: + + if output_status == 1: + if input_status < self.on_threshold: + #alert! + #print("Alert! " + self.name + " did not turn on!") + self.manager.send_alert("Alert! " + self.name + " did not turn on!") + if output_status == 0: + if input_status > self.off_threshold: + #alert! + #print("Alert! " + self.name + " did not turn off!") + self.manager.send_alert("Alert! " + self.name + " did not turn off!") class MeasurementAlert(Alert): @@ -124,14 +130,17 @@ class MeasurementAlert(Alert): self.hysteresis = hysteresis def evalutate(self): - #get input status - input_status = 0 - if input_status > self.high_threshold: - #alert! - print("Alert! " + self.name + " is too high!") - self.manager.send_alert("Alert! " + self.name + " is too high!") - if input_status < self.low_threshold: - #alert! - print("Alert! " + self.name + " is too low!") - self.manager.send_alert("Alert! " + self.name + " is too low!") + #get measurement + measurement = self.manager.database.read_value(self.input_module, self.input_type, int(self.input_number)) + print("Measurement: " + str(measurement)) + + if measurement != None: + if measurement > self.high_threshold: + #alert! + #print("Alert! " + self.name + " is too high!") + self.manager.send_alert("Alert! " + self.name + " is too high!") + if measurement < self.low_threshold: + #alert! + #print("Alert! " + self.name + " is too low!") + self.manager.send_alert("Alert! " + self.name + " is too low!")