Пример #1
0
 def stop(self):
     if not self.__stop.is_set():
         self.__stop.set()
     self.__stop_manual_runner()
     self.__stop_cycle_runner()
     state.run_zone_action((ZoneAction.TERMINATE, 0))
     self.join()
Пример #2
0
    def run(self):
        logging.info('Button Controller started')
        current_state = get_button_status()
        while not self.__stop.is_set():
            time.sleep(0.1)
            button_state = get_button_status()
            if current_state != button_state:
                self.__state_stack.append((time.time(), button_state))
                # Initial delay for key press
                if in_development():
                    time.sleep(0.5)
                logging.debug('Button state change to {0}.'.format(button_state))
                current_state = button_state

            time_delta = 0 if len(self.__state_stack) is 0 else time.time() - self.__state_stack[-1][0]

            # Check for stop command
            if current_state == 1 and time_delta > TIME_DELTA_STOP:
                self.__state_stack.clear()
                state.run_zone_action((ZoneAction.STOP, 0))

            # Check for move/zone command
            if current_state == 0 and time_delta > TIME_DELTA_NEXT:
                count = int(len(self.__state_stack) / 2)
                self.__state_stack.clear()
                if count == 1:
                    state.run_zone_action((ZoneAction.NEXT, 0))
                elif count > 0:
                    state.run_zone_action((ZoneAction.RUN_CYCLE, 0))

        logging.info('Button Controller stopped')
Пример #3
0
        def process_message(client, user_data, message):
            topic = message.topic
            status = str(message.payload.decode('utf-8'))
            controller = user_data['controller']
            conf = user_data['conf']
            logging.debug('Status update on {0} with status {1}.'.format(
                topic, status))

            # FIXME: too many if else!
            cmd = topic[len(conf.topic) + 1:]
            if cmd == 'stop':
                state.run_zone_action((ZoneAction.STOP, 0))
            elif cmd == 'cycle':
                state.run_zone_action((ZoneAction.RUN_CYCLE, 0))
            elif cmd.startswith('zone'):
                try:
                    zone = int(cmd[5:6])
                    if 1 <= zone <= 8:
                        action = cmd[7:]
                        if action == 'status':
                            logging.info(
                                'Zone {0} received status {1}.'.format(
                                    zone, status))
                        elif action == 'set' and state.active_controller_mode(
                        ) is ControllerMode.MQTT:
                            logging.info('Zone {0} received set {1}.'.format(
                                zone, status))
                            if status == CMD.ON.name:
                                state.run_zone_action(
                                    (ZoneAction.ZONE, int(zone)))
                            else:
                                state.run_zone_action((ZoneAction.STOP, 0))
                        elif action == 'available':
                            logging.info(
                                'Zone {0} received available status {1}.'.
                                format(zone, status))
                    else:
                        logging.error(
                            'Zone {0} out of range [1..8]'.format(zone))
                except ValueError:
                    logging.error('Invalid zone command {0}.'.format(cmd))
            else:
                logging.warning('Invalid topic {0}.'.format(topic))
Пример #4
0
 def __run_cycle(self):
     state.run_zone_action((ZoneAction.RUN_CYCLE, 0))
Пример #5
0
 def POST(self, **kwargs):
     logging.debug('Activate zone request {0}'.format(kwargs))
     zone = kwargs.get('zone', '0')
     if int(zone) > 0:
         state.run_zone_action((ZoneAction.ZONE, int(zone)))
     return True
Пример #6
0
 def POST(self, **kwargs):
     logging.debug('POST run cycle')
     state.run_zone_action((ZoneAction.RUN_CYCLE, 0))
Пример #7
0
 def POST(self, **kwargs):
     state.run_zone_action((ZoneAction.STOP, 0))
Пример #8
0
 def control_mode_changed(self):
     if state.active_controller_mode() is ControllerMode.OFF:
         state.run_zone_action((ZoneAction.STOP, 0))