コード例 #1
0
ファイル: __main__.py プロジェクト: gooftroop/homeassistant
    def pair(self):
        """Pair pyatv as a remote control with an Apple TV."""
        handler = pyatv.pair_with_apple_tv(self.loop,
                                           self.args.pin_code,
                                           self.args.remote_name,
                                           pairing_guid=self.args.pairing_guid)
        if self.args.pin_code is None:
            print('Use any pin to pair with "{}" (press ENTER to stop)'.format(
                self.args.remote_name))
        else:
            print('Use pin {} to pair with "{}" (press ENTER to stop)'.format(
                self.args.pin_code, self.args.remote_name))
        print('Using pairing guid: 0x' + handler.pairing_guid)
        print('Note: If remote does not show up, try rebooting your Apple TV')

        yield from handler.start(Zeroconf())
        yield from self.loop.run_in_executor(None, sys.stdin.readline)
        yield from handler.stop()

        # Give some feedback to the user
        if handler.has_paired:
            print('Pairing seems to have succeeded, yey!')
            print('You may now use this login id: 0x{}'.format(
                handler.pairing_guid))
        else:
            print('No response from Apple TV!')
            return 1

        return 0
コード例 #2
0
    def test_pairing_with_device(self):
        zeroconf = zeroconf_stub.stub(pairing)
        self.usecase.pairing_response(REMOTE_NAME, PAIRINGCODE)

        handler = pyatv.pair_with_apple_tv(
            self.loop, PIN_CODE, REMOTE_NAME,
            pairing_guid=pairing.DEFAULT_PAIRING_GUID)
        yield from handler.start(zeroconf)
        yield from self.usecase.act_on_bonjour_services(zeroconf)
        yield from handler.stop()

        self.assertTrue(handler.has_paired, msg='did not pair with device')
コード例 #3
0
def _handle_pairing(args, loop):
    handler = pyatv.pair_with_apple_tv(loop, args.pin_code, args.remote_name)
    print('Use pin {} to pair with "{}" (press ENTER to stop)'.format(
        args.pin_code, args.remote_name))
    print('Note: If remote does not show up, try rebooting your Apple TV')

    yield from handler.start(Zeroconf())
    yield from loop.run_in_executor(None, sys.stdin.readline)
    yield from handler.stop()

    # Give some feedback to the user
    if handler.has_paired:
        print('Pairing seems to have succeeded, yey!')
        print('You may now use this login id 0x{}'.format(
            pyatv.pairing.DEFAULT_PAIRING_GUID))
    else:
        print('No response from Apple TV!')
コード例 #4
0
def pair_with_device(loop):
    """Make it possible to pair with device."""
    my_zeroconf = Zeroconf()
    handler = pyatv.pair_with_apple_tv(loop, PIN_CODE, REMOTE_NAME)

    yield from handler.start(my_zeroconf)
    print('You can now pair with pyatv')

    # Wait for a minute to allow pairing
    yield from asyncio.sleep(60, loop=loop)

    yield from handler.stop()

    # Give some feedback about the process
    if handler.has_paired:
        print('Paired with device!')
        print('Pairing guid: ' + handler.pairing_guid)
    else:
        print('Did not pair with device!')

    my_zeroconf.close()
コード例 #5
0
    def pair(self):
        """Pair pyatv as a remote control with an Apple TV."""
        global javaHandler
        handler = pyatv.pair_with_apple_tv(self.loop,
                                           self.args.pin_code,
                                           self.args.remote_name,
                                           pairing_guid=self.args.pairing_guid)
        javaHandler.info('Using pairing guid: 0x' + handler.pairing_guid)
        if self.args.pin_code is None:
            #print('Use any pin to pair with "{}" (press ENTER to stop)'.format(
            #    self.args.remote_name))
            javaHandler.info("ERROR: PIN missing!")
            raise AuthenticationError('PIN missing!')
        else:
            message = 'Use pin {} to pair with "{}"'.format(
                self.args.pin_code, self.args.remote_name)
            javaHandler.info(message)
        javaHandler.info(
            'Note: If remote does not show up, try rebooting your Apple TV')

        yield from handler.start(Zeroconf())
        yield from self.loop.run_in_executor(None, sys.stdin.readline)
        yield from handler.stop()

        # Give some feedback to the user
        if handler.has_paired:
            javaHandler.info('Pairing seems to have succeeded, yey!')
            javaHandler.info('Login id from paring: 0x{}'.format(
                handler.pairing_guid))
            javaHandler.statusEvent("login_id", handler.pairing_guid())
        else:
            javaHandler.info('ERROR: Timeout on pairing!')
            raise AuthenticationError('Timeout on pairing!')
            return 1

        return 0
コード例 #6
0
def cli_handler(loop):
    """Application starts here."""
    parser = argparse.ArgumentParser()

    parser.add_argument('command')
    parser.add_argument('-v',
                        '--verbose',
                        help='increase output verbosity',
                        action='store_const',
                        dest='loglevel',
                        const=logging.INFO)
    parser.add_argument('--developer',
                        help='show developer commands',
                        action='store_true',
                        dest='developer',
                        default=False)
    parser.add_argument('--debug',
                        help='print debug information',
                        action='store_const',
                        dest='loglevel',
                        const=logging.DEBUG,
                        default=logging.WARNING)
    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)
    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('--hsgid',
                       help='home sharing id',
                       dest='hsgid',
                       default=None)

    args = parser.parse_args()

    logging.basicConfig(level=args.loglevel,
                        format='%(levelname)s: %(message)s')
    logging.getLogger('requests').setLevel(logging.WARNING)

    # Sanity checks that not can be done natively by argparse
    if (args.hsgid and not args.address) or (not args.hsgid and args.address):
        parser.error('both --hsgid and --address must be given')

    if args.command == 'scan':
        yield from _handle_scan(args)
    elif args.command == 'pair':
        pyatv.pair_with_apple_tv()
    elif args.autodiscover:
        return (yield from _handle_autodiscover(args, loop))
    elif args.hsgid:
        return (yield from _handle_command(args, loop))
    else:
        logging.error('To autodiscover an Apple TV, add -a')
        return 1

    return 0