def _handle_device_command(args, cmd, atv, loop): # TODO: Add these to array and use a loop device = retrieve_commands(DeviceCommands) ctrl = retrieve_commands(interface.RemoteControl) metadata = retrieve_commands(interface.Metadata) playing = retrieve_commands(interface.Playing) airplay = retrieve_commands(interface.AirPlay) # Parse input command and argument from user cmd, cmd_args = _extract_command_with_args(cmd) if cmd in device: return (yield from _exec_command(DeviceCommands(atv, loop, args), cmd, False, *cmd_args)) elif cmd in ctrl: return (yield from _exec_command(atv.remote_control, cmd, True, *cmd_args)) elif cmd in metadata: return (yield from _exec_command(atv.metadata, cmd, True, *cmd_args)) elif cmd in playing: playing_resp = yield from atv.metadata.playing() return (yield from _exec_command(playing_resp, cmd, True, *cmd_args)) elif cmd in airplay: return (yield from _exec_command(atv.airplay, cmd, True, *cmd_args)) logging.error('Unknown command: %s', args.command[0]) return 1
def _handle_command(args, loop): details = pyatv.AppleTVDevice(args.name, args.address, args.hsgid) atv = pyatv.connect_to_apple_tv(details, loop) try: playing_resp = yield from atv.metadata.playing() ctrl = retrieve_commands(atv.remote_control, developer=args.developer) metadata = retrieve_commands(atv.metadata, developer=args.developer) playing = retrieve_commands(playing_resp, developer=args.developer) # Parse input command and argument from user cmd, cmd_args = _extract_command_with_args(args.command) if cmd == 'commands': _print_commands('Remote control', ctrl) _print_commands('Metadata', metadata) _print_commands('Playing commands', playing, newline=False) elif cmd in ctrl: yield from _exec_command(atv.remote_control, cmd, *cmd_args) elif cmd in metadata: yield from _exec_command(atv.metadata, cmd, *cmd_args) elif cmd in playing: yield from _exec_command(playing_resp, cmd, *cmd_args) else: logging.error('Unknown command: %s', args.command) finally: yield from atv.logout()
async def _handle_device_command(args, cmd, atv, loop): device = retrieve_commands(DeviceCommands) ctrl = retrieve_commands(interface.RemoteControl) metadata = retrieve_commands(interface.Metadata) playing = retrieve_commands(interface.Playing) stream = retrieve_commands(interface.Stream) # Parse input command and argument from user cmd, cmd_args = _extract_command_with_args(cmd) if cmd in device: return (await _exec_command(DeviceCommands(atv, loop, args), cmd, False, *cmd_args)) if cmd in ctrl: return (await _exec_command(atv.remote_control, cmd, True, *cmd_args)) if cmd in metadata: return (await _exec_command(atv.metadata, cmd, True, *cmd_args)) if cmd in playing: playing_resp = await atv.metadata.playing() return (await _exec_command(playing_resp, cmd, True, *cmd_args)) if cmd in stream: return (await _exec_command(atv.stream, cmd, True, *cmd_args)) logging.error('Unknown command: %s', cmd) return 1
def _handle_command(args, cmd, atv, loop): # TODO: Add these to array and use a loop playing_resp = yield from atv.metadata.playing() ctrl = retrieve_commands(atv.remote_control, developer=args.developer) metadata = retrieve_commands(atv.metadata, developer=args.developer) playing = retrieve_commands(playing_resp, developer=args.developer) airplay = retrieve_commands(atv.airplay, developer=args.developer) other = {'push_updates': 'Listen for push updates'} # Parse input command and argument from user cmd, cmd_args = _extract_command_with_args(cmd) if cmd == 'commands': _print_commands('Remote control', ctrl) _print_commands('Metadata', metadata) _print_commands('Playing', playing) _print_commands('AirPlay', airplay) _print_commands('Other', other, newline=False) elif cmd == 'artwork': artwork = yield from atv.metadata.artwork() if artwork is not None: with open('artwork.png', 'wb') as file: file.write(artwork) else: print('No artwork is currently available.') return 1 elif cmd == 'push_updates': print('Press ENTER to stop') atv.push_updater.start() yield from loop.run_in_executor(None, sys.stdin.readline) atv.push_updater.stop() elif cmd in ctrl: return (yield from _exec_command(atv.remote_control, cmd, *cmd_args)) elif cmd in metadata: return (yield from _exec_command(atv.metadata, cmd, *cmd_args)) elif cmd in playing: return (yield from _exec_command(playing_resp, cmd, *cmd_args)) elif cmd in airplay: return (yield from _exec_command(atv.airplay, cmd, *cmd_args)) else: logging.error('Unknown command: %s', args.command[0]) return 1 return 0
def _handle_command(args, loop): details = pyatv.AppleTVDevice(args.name, args.address, args.login_id) atv = pyatv.connect_to_apple_tv(details, loop) atv.push_updater.listener = PushListener() try: playing_resp = yield from atv.metadata.playing() ctrl = retrieve_commands(atv.remote_control, developer=args.developer) metadata = retrieve_commands(atv.metadata, developer=args.developer) playing = retrieve_commands(playing_resp, developer=args.developer) other = {'push_updates': 'Listen for push updates.'} # Parse input command and argument from user cmd, cmd_args = _extract_command_with_args(args.command) if cmd == 'commands': _print_commands('Remote control', ctrl) _print_commands('Metadata', metadata) _print_commands('Playing', playing) _print_commands('Other', other, newline=False) elif cmd == 'artwork': artwork = yield from atv.metadata.artwork() if artwork is not None: with open('artwork.png', 'wb') as file: file.write(artwork) else: print('No artwork is currently available.') elif cmd == 'push_updates': print('Press ENTER to stop') atv.push_updater.start() yield from loop.run_in_executor(None, sys.stdin.readline) atv.push_updater.stop() elif cmd in ctrl: yield from _exec_command(atv.remote_control, cmd, *cmd_args) elif cmd in metadata: yield from _exec_command(atv.metadata, cmd, *cmd_args) elif cmd in playing: yield from _exec_command(playing_resp, cmd, *cmd_args) else: logging.error('Unknown command: %s', args.command) finally: yield from atv.logout()
async def _handle_command(args, loop): if args.command == "scan": return await _scan_devices(loop) config = await _autodiscover_device(args, loop) if not config: return output(False, "device_not_found") atv = await connect(config, loop, protocol=Protocol.MRP) if args.command == "playing": return output_playing(await atv.metadata.playing()) if args.command == "push_updates": atv.push_updater.listener = PushPrinter(args.output) atv.push_updater.start() await loop.run_in_executor(None, sys.stdin.readline) return output(True, values={"push_updates": "finished"}) rc = retrieve_commands(RemoteControl) if args.command in rc: await getattr(atv.remote_control, args.command)() return output(True, values={"command": args.command}) return output(False, "unsupported_command")
async def _run_command(atv, args, abort_sem, loop): if args.command == "playing": return output_playing(await atv.metadata.playing(), atv.metadata.app) if args.command == "push_updates": power_listener = PowerPrinter(args.output) device_listener = DevicePrinter(args.output, abort_sem) push_listener = PushPrinter(args.output, atv) atv.power.listener = power_listener atv.listener = device_listener atv.push_updater.listener = push_listener atv.push_updater.start() print( args.output( output( True, values={"power_state": atv.power.power_state.name.lower()})), flush=True, ) await wait_for_input(loop, abort_sem) return output(True, values={"push_updates": "finished"}) if args.command in retrieve_commands(RemoteControl): await getattr(atv.remote_control, args.command)() return output(True, values={"command": args.command}) return output(False, "unsupported_command")
def output_playing(playing: Playing): """Produce output for what is currently playing.""" def _convert(field): if isinstance(field, Enum): return field.name.lower() return field commands = retrieve_commands(Playing) values = {k: _convert(getattr(playing, k)) for k in commands.keys()} return output(True, values=values)
async def _handle_device_command(args, cmd, atv, loop): device = retrieve_commands(DeviceCommands) ctrl = retrieve_commands(interface.RemoteControl) metadata = retrieve_commands(interface.Metadata) power = retrieve_commands(interface.Power) playing = retrieve_commands(interface.Playing) stream = retrieve_commands(interface.Stream) device_info = retrieve_commands(interface.DeviceInfo) apps = retrieve_commands(interface.Apps) audio = retrieve_commands(interface.Audio) # Parse input command and argument from user cmd, cmd_args = _extract_command_with_args(cmd) if cmd in device: return await _exec_command( DeviceCommands(atv, loop, args), cmd, False, *cmd_args ) # NB: Needs to be above RemoteControl for now as volume_up/down exists in both # but implementations in Audio shall be called if cmd in audio: return await _exec_command(atv.audio, cmd, True, *cmd_args) if cmd in ctrl: return await _exec_command(atv.remote_control, cmd, True, *cmd_args) if cmd in metadata: return await _exec_command(atv.metadata, cmd, True, *cmd_args) if cmd in power: return await _exec_command(atv.power, cmd, True, *cmd_args) if cmd in playing: playing_resp = await atv.metadata.playing() return await _exec_command(playing_resp, cmd, True, *cmd_args) if cmd in stream: return await _exec_command(atv.stream, cmd, True, *cmd_args) if cmd in device_info: return await _exec_command(atv.device_info, cmd, True, *cmd_args) if cmd in apps: return await _exec_command(atv.apps, cmd, True, *cmd_args) _LOGGER.error("Unknown command: %s", cmd) return 1
async def _handle_device_command(args, cmd, atv, loop): device = retrieve_commands(DeviceCommands) ctrl = retrieve_commands(interface.RemoteControl) metadata = retrieve_commands(interface.Metadata) power = retrieve_commands(interface.Power) playing = retrieve_commands(interface.Playing) stream = retrieve_commands(interface.Stream) device_info = retrieve_commands(interface.DeviceInfo) apps = retrieve_commands(interface.Apps) audio = retrieve_commands(interface.Audio) # Parse input command and argument from user cmd, cmd_args = _extract_command_with_args(cmd) if cmd in device: return await _exec_command(DeviceCommands(atv, loop, args), cmd, False, *cmd_args) if cmd in ctrl: return await _exec_command(atv.remote_control, cmd, True, *cmd_args) if cmd in metadata: return await _exec_command(atv.metadata, cmd, True, *cmd_args) if cmd in power: return await _exec_command(atv.power, cmd, True, *cmd_args) if cmd in playing: playing_resp = await atv.metadata.playing() return await _exec_command(playing_resp, cmd, True, *cmd_args) if cmd in stream: return await _exec_command(atv.stream, cmd, True, *cmd_args) if cmd in device_info: return await _exec_command(atv.device_info, cmd, True, *cmd_args) if cmd in apps: return await _exec_command(atv.apps, cmd, True, *cmd_args) if cmd in audio: return await _exec_command(atv.audio, cmd, True, *cmd_args) logging.error("Unknown command: %s", cmd) return 1
def output_playing(playing: Playing, app: App): """Produce output for what is currently playing.""" def _convert(field): if isinstance(field, Enum): return field.name.lower() return field if field else None commands = retrieve_commands(Playing) values = {k: _convert(getattr(playing, k)) for k in commands} if app: values["app"] = app.name values["app_id"] = app.identifier else: values["app"] = None values["app_id"] = None return output(True, values=values)
def _print_commands(title, api): cmd_list = retrieve_commands(api) commands = " - " + "\n - ".join( map(lambda x: x[0] + " - " + x[1], sorted(cmd_list.items()))) print("{} commands:\n{}\n".format(title, commands))
def _print_commands(title, api): cmd_list = retrieve_commands(api) commands = " - " + "\n - ".join( map(lambda x: x[0] + " - " + x[1], sorted(cmd_list.items())) ) print(f"{title} commands:\n{commands}\n")
def test_get_developer_command(self): methods = interface.retrieve_commands(self.obj, developer=True) self.assertEqual(6, len(methods)) self.assertEqual('Developer help', methods['dev_method'])
def setUp(self): self.obj = TestClass() self.methods = interface.retrieve_commands(self.obj)
def methods(): yield interface.retrieve_commands(TestClass)
async def cli_handler(loop): """Application starts here.""" parser = argparse.ArgumentParser() parser.add_argument("command", nargs="+", help="commands, help, ...") parser.add_argument( "-i", "--id", help="device identifier", dest="id", action=TransformIdentifiers, default=None, ) parser.add_argument("-n", "--name", help="apple tv name", dest="name", default=None) parser.add_argument( "--address", help="device ip address or hostname", dest="address", default=None ) parser.add_argument( "--protocol", action=TransformProtocol, help="protocol to use (values: dmap, mrp)", dest="protocol", default=None, ) parser.add_argument( "--port", help="port when connecting", dest="port", type=_in_range(0, 65535), default=0, ) parser.add_argument( "-t", "--scan-timeout", help="timeout when scanning", dest="scan_timeout", type=_in_range(1, 100), metavar="TIMEOUT", default=3, ) parser.add_argument( "-s", "--scan-hosts", help="scan specific hosts", dest="scan_hosts", default=None, action=VerifyScanHosts, ) parser.add_argument( "--scan-protocols", help="scan for specific protocols", dest="scan_protocols", default=None, action=VerifyScanProtocols, ) parser.add_argument( "--version", action="version", help="version of atvremote and pyatv", version=f"%(prog)s {const.__version__}", ) pairing = parser.add_argument_group("pairing") pairing.add_argument( "--remote-name", help="remote pairing name", dest="remote_name", default="pyatv" ) pairing.add_argument( "-p", "--pin", help="pairing pin code", dest="pin_code", metavar="PIN", default=1234, type=_in_range(0, 9999, allow_none=True), ) pairing.add_argument( "--pairing-guid", help="pairing guid (16 chars hex)", dest="pairing_guid", default=None, ) parser.add_argument( "-m", "--manual", action="store_true", help="use manual device details", dest="manual", default=False, ) parser.add_argument( "--raop-password", help="optional password for raop", dest="raop_password", default=None, ) creds = parser.add_argument_group("credentials") for prot in Protocol: creds.add_argument( f"--{prot.name.lower()}-credentials", help=f"credentials for {prot.name}", dest=f"{prot.name.lower()}_credentials", default=None, ) debug = parser.add_argument_group("debugging") debug.add_argument( "-v", "--verbose", help="increase output verbosity", action="store_true", dest="verbose", ) debug.add_argument( "--debug", help="print debug information", action="store_true", dest="debug" ) debug.add_argument( "--mdns-debug", help="print mdns debug data", action="store_true", dest="mdns_debug", ) args = parser.parse_args() if args.manual and isinstance(args.id, list): parser.error("--manual only supports one identifier to --id") loglevel = logging.WARNING if args.verbose: loglevel = logging.INFO if args.debug: loglevel = logging.DEBUG logging.basicConfig( level=loglevel, stream=sys.stdout, datefmt="%Y-%m-%d %H:%M:%S", format="%(asctime)s %(levelname)s [%(name)s]: %(message)s", ) logging.getLogger("requests").setLevel(logging.WARNING) log_current_version() if args.mdns_debug: # logging.TRAFFIC is set in runtime by support.mdns logging.getLogger( "pyatv.core.mdns" ).level = logging.TRAFFIC # pylint: disable=no-member cmds = retrieve_commands(GlobalCommands) if args.command[0] in cmds: glob_cmds = GlobalCommands(args, loop) return await _exec_command(glob_cmds, args.command[0], print_result=False) if not args.manual: config = await _autodiscover_device(args, loop) if not config: return 1 return await _handle_commands(args, config, loop) if args.port == 0 or args.address is None or args.protocol is None: _LOGGER.error("You must specify address, port and protocol in manual mode") return 1 config = _manual_device(args) return await _handle_commands(args, config, loop)
def cli_handler(loop, jargs): """Application starts here.""" parser = argparse.ArgumentParser() parser.add_argument('command', nargs='+', help='commands, help, ...') parser.add_argument('--name', help='apple tv name', dest='name', default='Apple TV') parser.add_argument('--address', help='device ip address or hostname', dest='address', default=None) parser.add_argument('-t', '--scan-timeout', help='timeout when scanning', dest='scan_timeout', type=_in_range(1, 10), metavar='TIMEOUT', default=3) parser.add_argument('--version', action='version', help='version of atvremote and pyatv', version='%(prog)s {0}'.format(const.__version__)) pairing = parser.add_argument_group('pairing') pairing.add_argument('--remote-name', help='remote pairing name', dest='remote_name', default='pyatv') pairing.add_argument('-p', '--pin', help='pairing pin code', dest='pin_code', metavar='PIN', default=1234, type=_in_range(0, 9999, allow_none=True)) pairing.add_argument('--pairing-guid', help='pairing guid (16 chars hex)', dest='pairing_guid', default=None) ident = parser.add_mutually_exclusive_group() # ident.add_argument('-a', '--autodiscover', # help='automatically find a device', # action='store_true', dest='autodiscover', default=False) ident.add_argument('--login_id', help='home sharing id or pairing guid', dest='login_id', default=None) airplay = parser.add_argument_group('airplay') airplay.add_argument('--airplay_credentials', help='credentials for airplay', dest='airplay_credentials', default=None) debug = parser.add_argument_group('debugging') debug.add_argument('-v', '--verbose', help='increase output verbosity', action='store_true', dest='verbose') debug.add_argument('--debug', help='print debug information', action='store_true', dest='debug') args = parser.parse_args(jargs) loglevel = logging.WARNING if args.verbose: loglevel = logging.INFO if args.debug: loglevel = logging.DEBUG logging.basicConfig(level=loglevel, format='%(levelname)s: %(message)s') logging.getLogger('requests').setLevel(logging.WARNING) # Sanity checks that not can be done natively by argparse if (args.login_id and not args.address) or \ (not args.login_id and args.address): parser.error('both --login_id and --address must be given') cmds = retrieve_commands(GlobalCommands) if args.command[0] in cmds: glob_cmds = GlobalCommands(args, loop) return (yield from _exec_command(glob_cmds, args.command[0], print_result=False)) # if args.autodiscover: # return (yield from _handle_autodiscover(args, loop)) if args.login_id: return (yield from _handle_commands(args, loop)) # logging.error('To autodiscover an Apple TV, add -a') return 1
def cli_handler(loop): """Application starts here.""" parser = argparse.ArgumentParser() parser.add_argument('command', nargs='+', help='commands, help, ...') parser.add_argument('--name', help='apple tv name', dest='name', default='Apple TV') parser.add_argument('--address', help='device ip address or hostname', dest='address', default=None) parser.add_argument('--protocol', action=TransformProtocol, help='protocol to use (values: dmap, mrp)', dest='protocol', default=None) parser.add_argument('--port', help='port when connecting', dest='port', type=_in_range(0, 65535), default=0) parser.add_argument('-t', '--scan-timeout', help='timeout when scanning', dest='scan_timeout', type=_in_range(1, 100), metavar='TIMEOUT', default=3) parser.add_argument('--version', action='version', help='version of atvremote and pyatv', version='%(prog)s {0}'.format(const.__version__)) pairing = parser.add_argument_group('pairing') pairing.add_argument('--remote-name', help='remote pairing name', dest='remote_name', default='pyatv') pairing.add_argument('-p', '--pin', help='pairing pin code', dest='pin_code', type=_in_range(0, 9999), metavar='PIN', default=1234) pairing.add_argument('--pairing-guid', help='pairing guid (16 chars hex)', dest='pairing_guid', default=None) ident = parser.add_mutually_exclusive_group() ident.add_argument('-a', '--autodiscover', help='automatically find a device', action='store_true', dest='autodiscover', default=False) ident.add_argument('--login_id', help='home sharing id or pairing guid', dest='login_id', default=None) airplay = parser.add_argument_group('airplay') airplay.add_argument('--airplay_credentials', help='credentials for airplay', dest='airplay_credentials', default=None) debug = parser.add_argument_group('debugging') debug.add_argument('-v', '--verbose', help='increase output verbosity', action='store_true', dest='verbose') debug.add_argument('--debug', help='print debug information', action='store_true', dest='debug') args = parser.parse_args() loglevel = logging.WARNING if args.verbose: loglevel = logging.INFO if args.debug: loglevel = logging.DEBUG logging.basicConfig(level=loglevel, format='%(levelname)s: %(message)s') logging.getLogger('requests').setLevel(logging.WARNING) cmds = retrieve_commands(GlobalCommands) if args.command[0] in cmds: glob_cmds = GlobalCommands(args, loop) return (yield from _exec_command(glob_cmds, args.command[0], print_result=False)) elif args.autodiscover: if not (yield from _autodiscover_device(args, loop)): return 1 return (yield from _handle_commands(args, loop)) elif args.login_id: return (yield from _handle_commands(args, loop)) else: logging.error('To autodiscover an Apple TV, add -a') return 1
def __str__(self): """Convert this playing object to a readable string.""" def _to_str(value_mapping): return '{}: {}'.format(value_mapping, getattr(self, value_mapping)) values = interface.retrieve_commands(self).keys() return '\n'.join(map(_to_str, sorted(values)))
async def cli_handler(loop): """Application starts here.""" parser = argparse.ArgumentParser() parser.add_argument("command", nargs="+", help="commands, help, ...") parser.add_argument("-i", "--id", help="device identifier", dest="id", default=None) parser.add_argument("-n", "--name", help="apple tv name", dest="name", default=None) parser.add_argument("--address", help="device ip address or hostname", dest="address", default=None) parser.add_argument( "--protocol", action=TransformProtocol, help="protocol to use (values: dmap, mrp)", dest="protocol", default=None, ) parser.add_argument( "--port", help="port when connecting", dest="port", type=_in_range(0, 65535), default=0, ) parser.add_argument( "-t", "--scan-timeout", help="timeout when scanning", dest="scan_timeout", type=_in_range(1, 100), metavar="TIMEOUT", default=3, ) parser.add_argument( "-s", "--scan-hosts", help="scan specific hosts", dest="scan_hosts", default=None, action=VerifyScanHosts, ) parser.add_argument( "--version", action="version", help="version of atvremote and pyatv", version="%(prog)s {0}".format(const.__version__), ) pairing = parser.add_argument_group("pairing") pairing.add_argument("--remote-name", help="remote pairing name", dest="remote_name", default="pyatv") pairing.add_argument( "-p", "--pin", help="pairing pin code", dest="pin_code", metavar="PIN", default=1234, type=_in_range(0, 9999, allow_none=True), ) pairing.add_argument( "--pairing-guid", help="pairing guid (16 chars hex)", dest="pairing_guid", default=None, ) parser.add_argument( "-m", "--manual", action="store_true", help="use manual device details", dest="manual", default=False, ) creds = parser.add_argument_group("credentials") creds.add_argument( "--dmap-credentials", help="DMAP credentials to device", dest="dmap_credentials", default=None, ) creds.add_argument( "--mrp-credentials", help="MRP credentials to device", dest="mrp_credentials", default=None, ) creds.add_argument( "--airplay-credentials", help="credentials for airplay", dest="airplay_credentials", default=None, ) debug = parser.add_argument_group("debugging") debug.add_argument( "-v", "--verbose", help="increase output verbosity", action="store_true", dest="verbose", ) debug.add_argument("--debug", help="print debug information", action="store_true", dest="debug") args = parser.parse_args() loglevel = logging.WARNING if args.verbose: loglevel = logging.INFO if args.debug: loglevel = logging.DEBUG logging.basicConfig( level=loglevel, datefmt="%Y-%m-%d %H:%M:%S", format="%(asctime)s %(levelname)s: %(message)s", ) logging.getLogger("requests").setLevel(logging.WARNING) cmds = retrieve_commands(GlobalCommands) if args.command[0] in cmds: glob_cmds = GlobalCommands(args, loop) return await _exec_command(glob_cmds, args.command[0], print_result=False) if not args.manual: config = await _autodiscover_device(args, loop) if not config: return 1 return await _handle_commands(args, config, loop) if args.port == 0 or args.address is None or args.protocol is None: logging.error( "You must specify address, port and protocol in manual mode") return 1 config = _manual_device(args) return await _handle_commands(args, config, loop)
async def cli_handler(loop): """Application starts here.""" parser = argparse.ArgumentParser() parser.add_argument('command', nargs='+', help='commands, help, ...') parser.add_argument('-i', '--id', help='device identifier', dest='id', default=None) parser.add_argument('-n', '--name', help='apple tv name', dest='name', default=None) parser.add_argument('--address', help='device ip address or hostname', dest='address', default=None) parser.add_argument('--protocol', action=TransformProtocol, help='protocol to use (values: dmap, mrp)', dest='protocol', default=None) parser.add_argument('--port', help='port when connecting', dest='port', type=_in_range(0, 65535), default=0) parser.add_argument('-t', '--scan-timeout', help='timeout when scanning', dest='scan_timeout', type=_in_range(1, 100), metavar='TIMEOUT', default=3) parser.add_argument('-s', '--scan-hosts', help='scan specific hosts', dest='scan_hosts', default=None, action=TransformScanHosts) parser.add_argument('--version', action='version', help='version of atvremote and pyatv', version='%(prog)s {0}'.format(const.__version__)) pairing = parser.add_argument_group('pairing') pairing.add_argument('--remote-name', help='remote pairing name', dest='remote_name', default='pyatv') pairing.add_argument('-p', '--pin', help='pairing pin code', dest='pin_code', metavar='PIN', default=1234, type=_in_range(0, 9999, allow_none=True)) pairing.add_argument('--pairing-guid', help='pairing guid (16 chars hex)', dest='pairing_guid', default=None) parser.add_argument('-m', '--manual', action='store_true', help='use manual device details', dest='manual', default=False) creds = parser.add_argument_group('credentials') creds.add_argument('--dmap-credentials', help='DMAP credentials to device', dest='dmap_credentials', default=None) creds.add_argument('--mrp-credentials', help='MRP credentials to device', dest='mrp_credentials', default=None) creds.add_argument('--airplay-credentials', help='credentials for airplay', dest='airplay_credentials', default=None) debug = parser.add_argument_group('debugging') debug.add_argument('-v', '--verbose', help='increase output verbosity', action='store_true', dest='verbose') debug.add_argument('--debug', help='print debug information', action='store_true', dest='debug') args = parser.parse_args() loglevel = logging.WARNING if args.verbose: loglevel = logging.INFO if args.debug: loglevel = logging.DEBUG logging.basicConfig(level=loglevel, datefmt='%Y-%m-%d %H:%M:%S', format='%(asctime)s %(levelname)s: %(message)s') logging.getLogger('requests').setLevel(logging.WARNING) cmds = retrieve_commands(GlobalCommands) if args.command[0] in cmds: glob_cmds = GlobalCommands(args, loop) return (await _exec_command(glob_cmds, args.command[0], print_result=False)) if not args.manual: config = await _autodiscover_device(args, loop) if not config: return 1 return await _handle_commands(args, config, loop) if args.port == 0 or args.address is None or args.protocol is None: logging.error( 'You must specify address, port and protocol in manual mode') return 1 config = _manual_device(args) return await _handle_commands(args, config, loop)
def setUp(self): self.methods = interface.retrieve_commands(TestClass)
def _print_commands(title, api): cmd_list = retrieve_commands(api) commands = ' - ' + '\n - '.join( map(lambda x: x[0] + ' - ' + x[1], sorted(cmd_list.items()))) print('{} commands:\n{}\n'.format(title, commands))