Ejemplo n.º 1
0
    def evaluate(self, feature, notification, device, status, last_result):
        import solaar.ui.window as _window
        # importing here to avoid circular imports

        if len(self.args) < 3:
            return None
        if _log.isEnabledFor(_INFO):
            _log.info('Set action: %s', self.args)
        dev = _window.find_device(
            self.args[0]) if self.args[0] is not None else device
        if dev is None:
            _log.error('Set action: device %s is not known', self.args[0])
            return None
        setting = next((s for s in dev.settings if s.name == self.args[1]),
                       None)
        if setting is None:
            _log.error(
                'Set action: setting %s is not the name of a setting for %s',
                self.args[1], dev.name)
            return None
        args = setting.acceptable(self.args[2:], setting.read())
        if args is None:
            _log.error('Set Action: invalid args %s for setting %s of %s',
                       self.args[2:], self.args[1], self.args[0])
            return None
        _change_setting(dev, setting, args)
        return None
Ejemplo n.º 2
0
 def evaluate(self, report, notification, device, status, last_result):
     import solaar.ui.window as _window
     if len(self.args) < 3:
         return None
     dev = _window.find_device(
         self.args[0]) if self.args[0] is not None else device
     if dev is None:
         _log.warn('Setting condition: device %s is not known',
                   self.args[0])
         return False
     setting = next((s for s in dev.settings if s.name == self.args[1]),
                    None)
     if setting is None:
         _log.warn(
             'Setting condition: setting %s is not the name of a setting for %s',
             self.args[1], dev.name)
         return None
     # should the value argument be checked to be sure it is acceptable?? needs to be careful about boolean toggle
     # TODO add compare  methods for more validators
     try:
         result = setting.compare(self.args[2:], setting.read())
     except Exception as e:
         _log.warn('Setting condition: error when checking setting %s: %s',
                   self.args, e)
         result = False
     return result
Ejemplo n.º 3
0
def _command_line(app, command_line):
    args = command_line.get_arguments()
    args = _yaml.safe_load(''.join(args)) if args else args
    if not args:
        _activate(app)
    elif args[0] == 'config':  # config call from remote instance
        if _log.isEnabledFor(_INFO):
            _log.info('remote command line %s', args)
        from solaar.ui.config_panel import change_setting  # prevent circular import
        from solaar.ui.window import find_device  # prevent circular import
        dev = find_device(args[1])
        if dev:
            setting = next((s for s in dev.settings if s.name == args[2]), None)
            if setting:
                change_setting(dev, setting, args[3:])
    return 0