Exemplo n.º 1
0
def run(config, root_allowed, ignore_perms):
    click.secho(
        'Listening for events. Amazon-dash will execute the events associated with '
        'the registered buttons.',
        fg='yellow')
    from amazon_dash.listener import Listener
    Listener(config, ignore_perms).run(root_allowed=root_allowed)
Exemplo n.º 2
0
def execute_args(args):
    """Execute args.which command

    :param args: argparse args
    :return: None
    """
    if not getattr(args, 'which', None) or args.which == 'run':
        Listener(args.config).run(root_allowed=args.root_allowed)
    elif args.which == 'check-config':
        check_config(args.config)
    elif args.which == 'test-device':
        test_device(args.device, args.config, args.root_allowed)
    elif args.which == 'discovery':
        from amazon_dash.discovery import discover
        discover()
Exemplo n.º 3
0
def execute_from_command_line(argv=None):
    """
    A simple method that runs a ManagementUtility.
    """
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--config', default=CONFIG_FILE, help='Path to config file.')

    parser.add_argument('--warning', help='set logging to warning', action='store_const', dest='loglevel',
                        const=logging.WARNING, default=logging.INFO)
    parser.add_argument('--quiet', help='set logging to ERROR', action='store_const', dest='loglevel',
                        const=logging.ERROR, default=logging.INFO)
    parser.add_argument('--debug', help='set logging to DEBUG',
                        action='store_const', dest='loglevel',
                        const=logging.DEBUG, default=logging.INFO)
    parser.add_argument('--verbose', help='set logging to COMM',
                        action='store_const', dest='loglevel',
                        const=5, default=logging.INFO)
    parser.sub = parser.add_subparsers()

    parse_service = parser.sub.add_parser('discovery', help='Discover Amazon Dash device on network.')
    parse_service.set_defaults(which='discovery')

    parse_oneshot = parser.sub.add_parser('run', help='Run server')
    parse_oneshot.set_defaults(which='run')
    parse_oneshot.add_argument('--root-allowed', action='store_true')


    parser.set_default_subparser('run')
    args = parser.parse_args(argv[1:])

    create_logger('amazon-dash', args.loglevel)

    if not getattr(args, 'which', None) or args.which == 'run':
        Listener(args.config).run(root_allowed=args.root_allowed)
    elif args.which == 'discovery':
        from amazon_dash.discovery import discover
        discover()
Exemplo n.º 4
0
 def test_double_called(self):
     last_execution.clear()
     listener = Listener(self.file)
     listener.on_push(Device('0C:47:C9:98:4A:12'))
     listener.on_push(Device('0C:47:C9:98:4A:12'))
     self.execute_mock_req.assert_called_once()
Exemplo n.º 5
0
 def test_create(self):
     listener = Listener(self.file)
     self.assertEqual(len(listener.devices), 2)