Ejemplo n.º 1
0
    def __init__(self):
        # Initialize process framework attributes so we can start using them
        RPiProcessFramework.__init__(self, default_log_level='INFO')

        # We make use of a PiFace, so let's initialize an instance
        RPiPiface.__init__(self)
        if self.get_number_of_boards() == 0:
            self.logger_instance.critical(
                "RPiInputButton - No PiFace boards detected. \
                Unable to process input signals")
            self.run_process = False  # No need to continue
        elif self.get_number_of_boards() == 4:
            self.logger_instance.info(
                "RPiInputButton - Four PiFace boards detected")
        else:
            self.logger_instance.warning(
                "RPiInputButton - Potentially not all PiFace boards detected." +\
                "Address of last detected board = {}".format(self.get_number_of_boards()-1))

        # Initialize the input buttons dictionary
        self.input_buttons = self.create_inputbutton_list(
            self.process_attributes.__repr__())

        # Initialize message sender handles so we can send messages
        self.process_consumers = self.create_message_senders(
            self.process_attributes.__repr__())

        # Initialize the message sender handler
        output_queue_configuration = {
            'exchangeName': 'HOMEDOMOTICA',
            'host': 'localhost'
        }
        self.process_output_queue_handler = RPiMessageSender(
            output_queue_configuration, self.logger_instance)
Ejemplo n.º 2
0
    def __init__(self):
        # Initialize process framework attributes so we can start using them
        RPiProcessFramework.__init__(self, default_log_level='INFO')

        # Initialize all installed PiFace boards
        self.logger_instance.debug("RPiOutputVentilator - Initializing PiFace boards")
        RPiPiface.__init__(self)
        # Let's share some log information
        if RPiPiface.get_number_of_boards(self) == 0:
            self.logger_instance.critical(
                "RPiOutputVentilator - No PiFace boards detected. \
                Unable to process input signals"
                )
            self.run_process = False    # No need to continue
        elif RPiPiface.get_number_of_boards(self) == 1:
            self.logger_instance.info("RPiOutputVentilator - One PiFace boards detected")
        else:
            self.logger_instance.warning(
                "RPiOutputVentilator - More than one PiFace board detected." +\
                "Address of last detected board = {}".format(RPiPiface.get_number_of_boards(self)-1))

        # Initialize the output relay dictionary
        self.output_relays = self.create_output_relay_list(self.process_attributes.__repr__())
        # Initialize the relay timer dictionary
        self.relays_timer = self.create_relay_timer_list(self.process_attributes.__repr__())
        # Initialize the process logic dictionary
        self.process_logic = self.create_process_logic_dictionary()
Ejemplo n.º 3
0
 def _handle_output_relays(self):
     '''
     This method will scan all active relays and sets the 'state' value
     as stored in the attributes for each relay.
     '''
     for key in self.output_relays:
         if self._get_state(key) == 0:
             RPiPiface.reset_output_relay(self, self._get_board_number(key), self._get_relay_number(key))
         else:
             RPiPiface.set_output_relay(self, self._get_board_number(key), self._get_relay_number(key))
Ejemplo n.º 4
0
    def __init__(self):
        # Initialize process framework attributes so we can start using them
        RPiProcessFramework.__init__(self, default_log_level='INFO')

        # We make use of a PiFace, so let's initialize an instance
        RPiPiface.__init__(self)
        if self.get_number_of_boards() == 0:
            self.logger_instance.critical(
                "RPiOutputLights - No PiFace boards detected. \
                Unable to process input signals")
            self.run_process = False  # No need to continue
        elif self.get_number_of_boards() == 4:
            self.logger_instance.info(
                "RPiOutputLights - Four PiFace boards detected")
        else:
            self.logger_instance.warning(
                "RPiOutputLights - Potentially not all PiFace boards detected." +\
                "Address of last detected board = {}".format(self.get_number_of_boards()-1))

        # Initialize the output lights dictionary
        self.output_lights = self.create_output_lights_list(
            self.process_attributes.__repr__())
        # Initialize the process logic dictionary
        self.process_logic = self.create_process_logic_dictionary()
Ejemplo n.º 5
0
    def create_output_relay_list(self, process_attribute_list):
        '''
        Return value is a dictionary where
          - The key is set as the address consisting of the board and relay number
          - The corresponding values a list structure containing following attributes:
            - State => integer that is either 0 =>Relay in 'released' state or
              1 => Relay in 'pulled' state
            - Description => String value
            - Logic => logic that indicates what should happen based on the message
              send by an input handler (for example input buttons)
            - Pulse => integer that is either 0 (=Nothing going on) or 1 (=Pulse action ongoing)
            - PulseTimeStamp => timestamp when the pulse state was changed
        '''
        reply = {}

        for board in range(0, RPiPiface.get_number_of_boards(self)):
            for pin in range(0, 2):
                key = "Relay" + str(board) + str(pin)
                if key in process_attribute_list:
                    value = process_attribute_list[key]
                    attribute_key, description, logic = value.split(
                        ";")
                    logic_list = []
                    logic_list = logic.split(',')
                    if description != "Not Used":
                        reply[attribute_key] = [
                            0,  # State
                            description,
                            logic_list,
                            0,  # Pulse
                            0]  # Timestamp when pulse status was change
                        self.logger_instance.debug(
                            "RPiOutputVentilator - Initializing output_relay: {}".format(
                                attribute_key) +\
                            " - State: {}".format(
                                reply[attribute_key][0]) +\
                            " - Description: {}".format(
                                reply[attribute_key][1]) +\
                            " - Logic: {}".format(
                                reply[attribute_key][2]) +\
                            " - Pulse: {}".format(
                                reply[attribute_key][3]) +\
                            " - Pulse Time Stamp: {}".format(
                                reply[attribute_key][4])
                            )

        return reply
Ejemplo n.º 6
0
    def __str__(self):
        long_string = RPiProcessFramework.__str__(self)
        long_string += RPiPiface.__str__(self)
        if self.output_lights != {}:
            long_string += "output_lights:\n"
            for key, value in self.output_lights.items():
                long_string += "{} = {}\n".format(key, value)
        else:
            long_string += "No output_lights information found!\n"
        if self.process_logic != {}:
            long_string += "process_logic:\n"
            for key, value in self.process_logic.items():
                long_string += "{} = {}\n".format(key, value)
        else:
            long_string += "No output_lights process logic information found!\n"

        return long_string
Ejemplo n.º 7
0
    def __str__(self):
        long_string = RPiProcessFramework.__str__(self)
        long_string += RPiPiface.__str__(self)
        if self.input_buttons != {}:
            long_string += "input_buttons:\n"
            for key, value in self.input_buttons.items():
                long_string += "{} = {}\n".format(key, value)
        else:
            long_string += "No input_buttons information found!\n"
        if self.process_consumers != {}:
            long_string += "process consumers:\n"
            for key, value in self.process_consumers.items():
                long_string += "{} = {}\n".format(key, value)
        else:
            long_string += "No input_buttons process consumers information found!\n"

        return long_string
Ejemplo n.º 8
0
    def __str__(self):
        long_string = RPiProcessFramework.__str__(self)
        long_string += "Number of PiFace boards detected: {}\n".format(
            RPiPiface.get_number_of_boards(self))
        if self.output_relays != {}:
            long_string += "output_relays:\n"
            for key, value in self.output_relays.items():
                long_string += "{} = {}\n".format(key, value)
        else:
            long_string += "No output_relays information found!\n"
        if self.process_logic != {}:
            long_string += "process_logic:\n"
            for key, value in self.process_logic.items():
                long_string += "{} = {}\n".format(key, value)
        else:
            long_string += "No output_relays process logic found!\n"

        return long_string
Ejemplo n.º 9
0
    def create_relay_timer_list(self, process_attribute_list):
        '''
        Return value is a dictionary where
          - The key is set as the address consisting of the board and relay number
          - The corresponding values a list structure containing following attributes:
            - State => integer that is either 0 => Timer is not running or
              1 => Timer is running
            - Description => String value
            - lagtime => Number of seconds the ventilator will remain active after
                         "stop" event is received
            - runtime => Maximum number of seconds the ventilator should run
        '''
        reply = {}

        for board in range(0, RPiPiface.get_number_of_boards(self)):
            for pin in range(0, 2):
                key = "RelayTimer" + str(board) + str(pin)
                if key in process_attribute_list:
                    value = process_attribute_list[key]
                    attribute_key, description, lagtime, runtime = value.split(
                        ";")
                    if description != "Not Used":
                        reply[attribute_key] = [
                            0,  # State
                            description,
                            int(lagtime),
                            int(runtime),
                            0, # start_time
                            0] # stop_time
                        self.logger_instance.debug(
                            "RPiOutputVentilator - Initializing relay_timer: {}".format(
                                attribute_key) +\
                            " - State: {}".format(
                                reply[attribute_key][0]) +\
                            " - Description: {}".format(
                                reply[attribute_key][1]) +\
                            " - LagTime: {}".format(
                                reply[attribute_key][2]) +\
                            " - RunTime: {}".format(
                                reply[attribute_key][3])
                            )

        return reply
Ejemplo n.º 10
0
 def __repr__(self):
     return str(RPiPiface.get_number_of_boards(self))