Пример #1
0
    def parse_config(self, config_file):
        """
        Parse the configuration file

        XXX: This could be much better
        """
        config = None
        with open(config_file, 'rb') as fh:  # pylint: disable=invalid-name
            config = yaml.safe_load(fh)

        if 'timing' in config:
            if 'double_click' in config['timing']:
                self.sc_threshold = config['timing']['double_click'] / 1000
            if 'hold_time' in config['timing']:
                self.hold_time = config['timing']['hold_time'] / 1000

        for button_number, b_conf in config['buttons'].items():
            button = LifxButton(button_number, hold_time=self.hold_time)
            button.when_held = self.held
            button.when_released = self.released
            button.single_click = b_conf.get('single', None)
            button.double_click = b_conf.get('double', None)
            button.long_click = b_conf.get('long', None)
            button.scenes = b_conf['scenes']
            button.sc_timer = self.get_sc_timer(button)
            self.buttons[button_number] = button

            group_name = b_conf['group'].lower()
            group = self.groups.get(group_name, None)
            if not group:
                group = lifxlan.Group()
                self.groups[group_name] = group

            button.lifx_group = {
                'name': group_name,
                'group': group,
            }