alert = RaspberryPiGPIOAlert() # get gpio pin settings alert.gpioPin = int(item.find("gpio").attrib["gpioPin"]) if int(item.find("gpio").attrib["gpioPinStateNormal"]) == 1: alert.gpioPinStateNormal = GPIO.HIGH else: alert.gpioPinStateNormal = GPIO.LOW if int(item.find("gpio").attrib["gpioPinStateTriggered"]) == 1: alert.gpioPinStateTriggered = GPIO.HIGH else: alert.gpioPinStateTriggered = GPIO.LOW # these options are needed by the server to # differentiate between the registered alerts alert.id = int(item.find("general").attrib["id"]) alert.description = str(item.find("general").attrib["description"]) alert.alertLevels = list() for alertLevelXml in item.iterfind("alertLevel"): alert.alertLevels.append(int(alertLevelXml.text)) # check if description is empty if len(alert.description) == 0: raise ValueError("Description of alert %d is empty." % alert.id) # check if the id of the alert is unique for registeredAlert in globalData.alerts: if registeredAlert.id == alert.id: raise ValueError("Id of alert %d"
recv_off_activated = str( item.find("gpio").find( "off").attrib["activated"]).upper() == "TRUE" alert.recv_off_activated = recv_off_activated gpio_reset_activated = str( item.find("gpio").find( "reset").attrib["activated"]).upper() == "TRUE" alert.gpio_reset_activated = gpio_reset_activated if gpio_reset_activated: alert.gpio_reset_state_time = int( item.find("gpio").find("reset").attrib["time"]) # these options are needed by the server to # differentiate between the registered alerts alert.id = int(item.find("general").attrib["id"]) alert.description = str(item.find("general").attrib["description"]) if alert.gpio_reset_activated and alert.gpio_reset_state_time <= 0: raise ValueError( "time for reset of Alert %d has to be greater to 0." % alert.id) if recv_triggered_activated and alert.recv_triggered_state != 0 and alert.recv_triggered_state != 1: raise ValueError( "state for 'triggered' sensor alert of Alert %d has to be 0 or 1." % alert.id) if recv_normal_activated and alert.recv_normal_state != 0 and alert.recv_normal_state != 1: raise ValueError( "state for 'normal' sensor alert of Alert %d has to be 0 or 1."
# parse smtp options if activated smtpActivated = config.getboolean("smtp", "smtpActivated") if smtpActivated is True: smtpServer = config.get("smtp", "server") smtpPort = config.getint("smtp", "serverPort") smtpFromAddr = config.get("smtp", "fromAddr") smtpToAddr = config.get("smtp", "toAddr") # parse all alerts for section in config.sections(): if section.find("alert") != -1: alert = RaspberryPiGPIOAlert() # these options are needed for the by the server to # differentiate between the registered alerts alert.id = config.getint(section, "id") alert.description = config.get(section, "description") alert.alertLevels = map(int, config.get(section, "alertLevels").split(",")) # get gpio pin settings alert.gpioPin = config.getint(section, "gpioPin") if config.getint(section, "gpioPinStateNormal") == 1: alert.gpioPinStateNormal = GPIO.HIGH else: alert.gpioPinStateNormal = GPIO.LOW if config.getint(section, "gpioPinStateTriggered") == 1: alert.gpioPinStateTriggered = GPIO.HIGH else: alert.gpioPinStateTriggered = GPIO.LOW