diff --git a/alerts.py b/alerts.py --- a/alerts.py +++ b/alerts.py @@ -12,6 +12,34 @@ class AlertManager: self.mail_server = config.get("alerts", "mail_server") self.username = config.get("alerts", "username") self.password = config.get("alerts", "password") + + self.alerts = [] + load_alerts(config) + + def load_alerts(self, config): + + for section in self.config.sections(): + if "alert" in section: + type = self.config.get(section, "type") + if type == "output_feedback": + name = self.config.get(section, "name") + output_module = self.config.get(section, "output_module") + output = self.config.get(section, "output") + input_module = self.config.get(section, "input_module") + input = self.config.get(section, "input") + on_threshold = self.config.get(section, "on_threshold") + off_threshold = self.config.get(section, "off_threshold") + deadband = self.config.get(section, "deadband") + self.alerts.append(OutputFeedbackAlert(name, output_module, output, input_module, input, on_threshold, off_threshold, deadband)) + elif type == "measurement": + name = self.config.get(section, "name") + input_module = self.config.get(section, "input_module") + input = self.config.get(section, "input") + high_threshold = self.config.get(section, "high_threshold") + low_threshold = self.config.get(section, "low_threshold") + deadband = self.config.get(section, "deadband") + self.alerts.append(MeasurementAlert(name, input_module, input, high_threshold, low_threshold, deadband)) + def send_alert(self, message): @@ -26,3 +54,33 @@ class AlertManager: server.login(self.username, self.password) server.send_message(msg) server.quit() + + def evaluate_alerts(self): + for alert in self.alerts: + alert.evalutate() + +class Alert(metaclass=ABCMeta): + + def __init__(self, name): + self.name = name + + @abstractmethod + def evalutate(self): + pass + +class OutputFeedbackAlert(Alert): + + def __init__(self, name, output_module, output, input_module, input, on_threshold, off_threshold, deadband): + super(Alert, self).__init__(name) + + def evalutate(self): + print(self.name) + +class MeasurementAlert(Alert): + + def __init__(self, name, input_module, input, high_threshold, low_threshold, deadband): + super(Alert, self).__init__(name) + + def evalutate(self): + print(self.name) + diff --git a/hydrobot_example.conf b/hydrobot_example.conf --- a/hydrobot_example.conf +++ b/hydrobot_example.conf @@ -24,3 +24,72 @@ trigger: interval #weeks, days, hours, minutes, seconds on_duration: [0, 0, 0, 0, 20] off_duration: [0, 0, 0, 0, 10] + +[alert1] +name: "Pump" +type: output_feedback +output_module: RelayDrive1 +output: output_1 +input_module: RelayDrive1 +input: input_1 +on_threshold: 50 +off_threshold: 1 +deadband: 5 + +[alert2] +name: "Light" +type: output_feedback +output_module: RelayDrive1 +output: output_1 +input_module: AirSense1 +input: ambient_light +on_threshold: 5000 +off_threshold: 500 +deadband: 10 + +[alert3] +name: "Lamp Dim" +type: output_feedback +output_module: RelayDrive1 +output: output_1 +input_module: AirSense1 +input: ambient_light +on_threshold: 10000 +off_threshold: None +deadband: 10 + +[alert4] +name: "Air Temperature" +type: measurement +input_module: AirSense1 +input: air_temp +high_threshold: 35 +low_threshold: 15 +deadband: 10 + +[alert5] +name: "Air Humidity" +type: measurement +input_module: AirSense1 +input: air_humid +high_threshold: 80 +low_threshold: 30 +deadband: 10 + +[alert6] +name: "Water Level" +type: measurement +input_module: WaterSense1 +input: water_level +high_threshold: None +low_threshold: 50 +deadband: 10 + +[alert7] +name: "Water Temperature" +type: measurement +input_module: WaterSense1 +input: water_temp +high_threshold: 30 +low_threshold: 20 +deadband: 10 \ No newline at end of file