plc_checker.py 1.66 KB

import logging

logger = logging.getLogger(__name__)

class PlcChecker(object):

    def __init__(self, plc_struct):
        self.struct = plc_struct
        self.path_list = None
        #self.plc_global = copy.copy(self.struct["devices"])
        #self.struct
        self.captors = [
            "OutsideTemp",
            "InsideTemp",
            "OutsideHumidity",
            "InsideHumidity",
            "Pressure",
            "RainRate",
            "WindSpeed",
            "WindDir",
            "WindDirCardinal",
            "DewPoint",
        ]
        self.captors_conf = {}

    def scan_sensors(self):
        try:
            logger.debug(self.struct["date"])
        except Exception as e:
            logger.debug("No date")
        for captor_type in self.captors:
            self.captors_conf[captor_type] = {}
            logger.debug(captor_type + ":")
            try:
                self.cross_devices_list(captor_type)
            except Exception as e:
                logger.debug(captor_type + " error")

    def cross_devices_list(self, captor_type):
        """"""
        for device in self.struct["devices"]:
            if device["device_name"] != "GLOBAL" and device["device_type"] == "meteo" and device["valid"] == "yes":
                self.cros_captor_list(device, captor_type)

    def cros_captor_list(self, device, captor_type):
        device_id = device["device_name"] + "/" + device["serial_number"]
        for captor in device["device_values"]:
            if captor["name"] == captor_type:
                self.captors_conf[captor_type][device_id] = captor["value"]
                logger.debug("-- " + device_id + " : " + str(captor["value"]))