def factory(cls, model, controller=None, port=None):
     subclass_dict = {clazz.model.lower(): clazz for clazz in cls.inheritors() if clazz.model is not None}
     try:
         dev = subclass_dict[model.lower()](controller, port)
         LOGGER.debug('created {} device'.format(dev.__class__.__name__))
         return dev
     except KeyError:
         LOGGER.warn(f'model {model} not found. controller: {controller} port: {port}')
示例#2
0
    def register_attached_device(self, unit, port, dev=None):
        if isinstance(dev, devices.ThermaltakeFanDevice):
            LOGGER.debug('  registering %s with fan manager', dev.model)
            self.fan_manager.attach_device(dev)
        if isinstance(dev, devices.ThermaltakeRGBDevice):
            LOGGER.debug('  registering %s with lighting manager', dev.model)
            self.lighting_manager.attach_device(dev)

        self.attached_devices[f'{unit}:{port}'] = dev
    def start(self):
        try:
            g, r, b = self._config['g'], self._config['r'], self._config['b']
        except KeyError as e:
            LOGGER.warn('%s not found in config item: lighting_controller', e)
            return

        for device in self._devices:
            device.set_lighting(mode=RGB.Mode.RIPPLE,
                                speed=self._speed,
                                values=[g, r, b])
    def start(self):
        values = []
        try:
            g, r, b = self._config['g'], self._config['r'], self._config['b']
            for i in range(12):
                values.extend([g, r, b])
        except KeyError as e:
            LOGGER.warn('%s not found in config item: lighting_controller', e)

        for device in self._devices:
            device.set_lighting(mode=RGB.Mode.FULL, speed=0x00, values=values)
示例#5
0
 def factory(cls, unit_type, unit_identifier=None):
     subclass_dict = {clazz.model: clazz for clazz in cls.inheritors()}
     try:
         # TODO: remove copy pasta
         if unit_identifier is not None:
             return subclass_dict.get(
                 unit_type.lower())(unit=unit_identifier)
         else:
             return subclass_dict.get(unit_type.lower())()
     except KeyError as e:
         LOGGER.warn('%s not a valid controller type', e)
示例#6
0
    def load_config(self):
        with open('{}/{}'.format(self.config_dir,
                                 self.config_file_name)) as cfg:
            cfg_str = cfg.readlines()
        cfg_lines = []
        for s in cfg_str:
            # remove comments and blank lines
            if not s.strip().startswith('#') and len(s) > 1:
                cfg_lines.append(s)

        cfg = ''.join(cfg_lines)
        LOGGER.debug('raw config file\n** start **\n\n%s\n** end **\n', cfg)
        return yaml.load(cfg)
    def start(self):
        try:
            g, r, b = self._config['g'], self._config['r'], self._config['b']
        except KeyError as e:
            LOGGER.warn('%s not found in config item: lighting_controller', e)
            return

        for device in self._devices:
            values = []
            for i in range(12):
                values.extend([g, r, b])
            device.set_lighting(mode=RGB.Mode.PULSE,
                                speed=self._speed,
                                values=values)
 def set_lighting(self, values: list = None, mode=0x18, speed=0x00) -> None:
     """
     for the sake of performance this will assume the data your passing in is correct.
     if it isnt the worst that will happen (i guess) is the lights wont show up as
     expected.
     :param values: [r,g,b...]
     :param mode: lighting mode(hex)
     :param speed: light update speed(hex)
     """
     data = [PROTOCOL_SET, PROTOCOL_LIGHT, self.port, mode + speed]
     if values:
         data.extend(values)
     LOGGER.debug('{} set lighting: raw hex: {}'.format(self.__class__.__name__, data))
     self.controller.driver.write_out(data)
示例#9
0
 def stop(self):
     LOGGER.debug('recieved exit command')
     self._continue = False
     LOGGER.debug('stopping lighting manager')
     self.lighting_manager.stop()
     LOGGER.debug('stopping fan manager')
     self.fan_manager.stop()
     LOGGER.debug('saving controller profiles')
     for controller in self.controllers.values():
         controller.save_profile()
示例#10
0
    def _initialize_device(self):
        self.device = usb.core.find(idVendor=self.vendor_id,
                                    idProduct=self.product_id)
        # fail safe incase last device usage was dirty
        self.device.reset()

        if self.device is None:
            raise ValueError('Device not found')

        # Linux kernel sets up a device driver for USB device, which you have
        # to detach. Otherwise trying to interact with the device gives a
        # 'Resource Busy' error.
        try:
            self.device.detach_kernel_driver(0)
        except Exception:
            LOGGER.warning('kernel driver already detached')

        self.device.set_configuration()

        # claim the device
        try:
            usb.util.claim_interface(self.device, 0)
        except usb.core.USBError as e:
            LOGGER.error('{} while claiming interface for device'.format(e))
            raise e

        self.cfg = self.device.get_active_configuration()
        self.interface = self.cfg[(0, 0)]
        self.endpoint_out = usb.util.find_descriptor(
            self.interface,
            custom_match=lambda e: usb.util.endpoint_direction(
                e.bEndpointAddress) == usb.util.ENDPOINT_OUT)
        assert self.endpoint_out is not None

        self.endpoint_in = usb.util.find_descriptor(
            self.interface,
            custom_match=lambda e: usb.util.endpoint_direction(
                e.bEndpointAddress) == usb.util.ENDPOINT_IN)
        assert self.endpoint_in is not None

        # initialize/reset the device
        self.init_controller()
示例#11
0
 def parse_config(self, config):
     self.controllers = config.get('controllers')
     LOGGER.debug(config.get('controllers'))
     # self.devices = config.get('devices')
     LOGGER.debug(config.get('fan_manager'))
     self.fan_manager = config.get('fan_manager')
     LOGGER.debug(config.get('lighting_manager'))
     self.lighting_manager = config.get('lighting_manager')
    def test_basic_startup(self, init_dev):
        LOGGER.setLevel(logging.DEBUG)
        stream = StringIO()
        stream_handler = logging.StreamHandler(stream)
        # stream_handler = logging.StreamHandler(sys.stdout)

        LOGGER.addHandler(stream_handler)
        try:
            daemon = ThermaltakeDaemon()
        finally:
            stream_handler.flush()
            LOGGER.removeHandler(stream_handler)
        self.assertIsNotNone(daemon)
        self.assertIsNotNone(daemon.config.controllers)
        self.assertTrue(init_dev.called)

        logging_output = stream.getvalue()
        print(logging_output)
        for keyword in ('** start **', '** end **'):
            self.assertIn(keyword, logging_output)
 def factory(cls, config: dict):
     subclass_dict = {clazz.model: clazz for clazz in cls.inheritors()}
     try:
         return subclass_dict.get(config.pop('model').lower())(config)
     except KeyError as e:
         LOGGER.warn('%s not found in config item', e)
 def __init__(self, config):
     self._config = config
     self._devices = []
     LOGGER.info(f'initializing {self.__class__.__name__} light controller')
示例#15
0
 def run(self):
     self._continue = True
     LOGGER.debug('starting lighting manager')
     self.lighting_manager.start()
     LOGGER.debug('starting fan manager')
     self.fan_manager.start()
示例#16
0
    def __init__(self):
        LOGGER.info('initializing thermaltake rgb daemon')

        LOGGER.debug('loading config')
        self.config = Config()

        LOGGER.debug('creating fan manager')
        fan_model = FanModel.factory(self.config.fan_manager)
        self.fan_manager = FanManager(fan_model)

        LOGGER.debug('creating lighting manager')
        self.lighting_manager = LightingEffect.factory(self.config.lighting_manager)

        self.attached_devices = {}
        self.controllers = {}

        LOGGER.debug('configuring controllers')
        for controller in self.config.controllers:
            self.controllers[controller['unit']] = ThermaltakeController.factory(controller['type'], controller.get('unit'))
            for id, model in controller['devices'].items():
                LOGGER.debug(' configuring devices for controller %s: %s', controller['type'], controller.get('unit'))
                dev = ThermaltakeDevice.factory(model, self.controllers[controller['unit']], id)
                self.controllers[controller['unit']].attach_device(id, dev)
                self.register_attached_device(controller['unit'], id, dev)

        self._continue = False