Esempio n. 1
0
async def mock_pairing(event_loop):
    obj = MagicMock()

    service = conf.DmapService(None, None)
    config = conf.AppleTV("Apple TV", "127.0.0.1")
    config.add_service(service)
    zeroconf = zeroconf_stub.stub(pairing)

    async def _start(pin_code=PIN_CODE,
                     pairing_guid=PAIRING_GUID,
                     name=REMOTE_NAME):
        options = {"zeroconf": zeroconf}
        if pairing_guid:
            options["pairing_guid"] = pairing_guid
        if name:
            options["name"] = name

        obj.pairing = pairing.DmapPairingHandler(config, await
                                                 http.create_session(),
                                                 event_loop, **options)
        await obj.pairing.begin()
        obj.pairing.pin(pin_code)
        return obj.pairing, zeroconf, service

    yield _start
    await obj.pairing.finish()
    await obj.pairing.close()
Esempio n. 2
0
def pair_with_device(loop):
    """Make it possible to pair with device."""
    my_zeroconf = Zeroconf()
    details = conf.AppleTV('127.0.0.1', 'Apple TV')
    details.add_service(conf.DmapService('login_id'))
    atv = pyatv.connect_to_apple_tv(details, loop)

    yield from atv.pairing.start(zeroconf=my_zeroconf,
                                 name=REMOTE_NAME,
                                 pin=PIN_CODE)
    print('You can now pair with pyatv')

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

    yield from atv.pairing.stop()

    # Give some feedback about the process
    if atv.pairing.has_paired:
        pairing_guid = yield from atv.pairing.get('pairing_gui')
        print('Paired with device!')
        print('Pairing guid: ' + pairing_guid)
    else:
        print('Did not pair with device!')

    my_zeroconf.close()
Esempio n. 3
0
 def _hs_service(self, service_name, address, port, properties):
     """Add a new device to discovered list."""
     identifier = service_name.split('.')[0]
     name = _property_decode(properties, 'Name')
     hsgid = _property_decode(properties, 'hG')
     service = conf.DmapService(identifier, hsgid, port=port)
     self._handle_service(address, name, service)
Esempio n. 4
0
    def add_non_hs_service(self, info, address):
        """Add a new device without Home Sharing to discovered list."""
        if self.protocol and self.protocol != PROTOCOL_DMAP:
            return

        name = info.properties[b'CtlN'].decode('utf-8')
        self._handle_service(address, name,
                             conf.DmapService(None, port=info.port))
Esempio n. 5
0
 def setUp(self):
     self.config = conf.AppleTV(ADDRESS_1, NAME)
     self.dmap_service = conf.DmapService(IDENTIFIER_1, None, port=PORT_1)
     self.mrp_service = conf.MrpService(
         IDENTIFIER_2, PORT_2, properties=MRP_PROPERTIES
     )
     self.airplay_service = conf.AirPlayService(
         IDENTIFIER_3, PORT_1, properties=AIRPLAY_PROPERTIES
     )
Esempio n. 6
0
def dmap_device_with_credentials(mock_scan):
    """Mock pyatv.scan."""
    mock_scan.result.append(
        create_conf(
            "127.0.0.1",
            "DMAP Device",
            conf.DmapService("dmap_id", "dummy_creds", port=6666),
        ))
    yield mock_scan
Esempio n. 7
0
def dmap_device(mock_scan):
    """Mock pyatv.scan."""
    mock_scan.result.append(
        create_conf(
            "127.0.0.1",
            "DMAP Device",
            conf.DmapService("dmap_id", None, port=6666),
        ))
    yield mock_scan
Esempio n. 8
0
 def _non_hs_service(self, service_name, address, port, properties):
     """Add a new device without Home Sharing to discovered list."""
     identifier = service_name.split(".")[0]
     name = properties.get("CtlN")
     service = conf.DmapService(identifier,
                                None,
                                port=port,
                                properties=properties)
     self._handle_service(address, name, service)
Esempio n. 9
0
    def add_hs_service(self, info, address):
        """Add a new device to discovered list."""
        if self.protocol and self.protocol != PROTOCOL_DMAP:
            return

        name = info.properties[b'Name'].decode('utf-8')
        hsgid = info.properties[b'hG'].decode('utf-8')
        self._handle_service(address, name,
                             conf.DmapService(hsgid, port=info.port))
Esempio n. 10
0
 def _hs_service(self, service_name, address, port, properties):
     """Add a new device to discovered list."""
     identifier = service_name.split(".")[0]
     name = properties.get("Name")
     hsgid = properties.get("hG")
     service = conf.DmapService(identifier,
                                hsgid,
                                port=port,
                                properties=properties)
     self._handle_service(address, name, service)
Esempio n. 11
0
 def _hs_service(self, mdns_service: mdns.Service, response: mdns.Response) -> None:
     """Add a new device to discovered list."""
     name = mdns_service.properties.get("Name", "Unknown")
     service = conf.DmapService(
         mdns_service.name,
         mdns_service.properties.get("hG"),
         port=mdns_service.port,
         properties=mdns_service.properties,
     )
     self._handle_service(mdns_service.address, name, service, response)
Esempio n. 12
0
File: scan.py Progetto: NebzHB/pyatv
 def _non_hs_service(self, mdns_service: mdns.Service,
                     response: mdns.Response) -> None:
     """Add a new device without Home Sharing to discovered list."""
     name = mdns_service.properties.get("CtlN", "Unknown")
     service = conf.DmapService(
         mdns_service.name,
         None,
         port=mdns_service.port,
         properties=mdns_service.properties,
     )
     self._handle_service(mdns_service.address, name, service, response)
Esempio n. 13
0
    async def setUp(self):
        self.service = conf.DmapService(None, None)
        self.config = conf.AppleTV('Apple TV', '127.0.0.1')
        self.config.add_service(self.service)
        self.zeroconf = zeroconf_stub.stub(pairing)
        self.pairing = None

        # TODO: currently stubs internal method, should provide stub
        # for netifaces later
        pairing._get_private_ip_addresses = \
            lambda: [ipaddress.ip_address('10.0.0.1')]
Esempio n. 14
0
def full_device(mock_scan, dmap_pin):
    """Mock pyatv.scan."""
    mock_scan.result.append(
        create_conf(
            "127.0.0.1",
            "MRP Device",
            conf.MrpService("mrp_id", 5555),
            conf.DmapService("dmap_id", None, port=6666),
            conf.AirPlayService("airplay_id", port=7777),
        ))
    yield mock_scan
Esempio n. 15
0
    def test_to_str(self):
        self.config.add_service(conf.DmapService(IDENTIFIER_1, "LOGIN_ID"))
        self.config.add_service(conf.MrpService(IDENTIFIER_2, PORT_2))

        # Check for some keywords to not lock up format too much
        output = str(self.config)
        self.assertIn(ADDRESS_1, output)
        self.assertIn(NAME, output)
        self.assertIn("LOGIN_ID", output)
        self.assertIn(str(PORT_2), output)
        self.assertIn("3689", output)
Esempio n. 16
0
    def test_to_str(self):
        self.atv.add_service(conf.DmapService('LOGIN_ID'))
        self.atv.add_service(conf.MrpService(PORT_2))

        # Check for some keywords to not lock up format too much
        output = str(self.atv)
        self.assertIn(ADDRESS_1, output)
        self.assertIn(NAME, output)
        self.assertIn('LOGIN_ID', output)
        self.assertIn(str(PORT_2), output)
        self.assertIn('3689', output)
Esempio n. 17
0
def test_to_str(config):
    config.add_service(conf.DmapService(IDENTIFIER_1, "LOGIN_ID"))
    config.add_service(conf.MrpService(IDENTIFIER_2, PORT_2))

    # Check for some keywords to not lock up format too much
    output = str(config)
    assert ADDRESS_1 in output
    assert NAME in output
    assert "LOGIN_ID" in output
    assert str(PORT_2) in output
    assert "3689" in output
    assert "Deep Sleep: True" in output
Esempio n. 18
0
async def print_what_is_playing(loop):
    """Connect to device and print what is playing."""
    config = conf.AppleTV(ADDRESS, NAME)
    config.add_service(conf.DmapService("some_id", HSGID))

    print("Connecting to {0}".format(config.address))
    atv = await connect(config, loop)

    try:
        print(await atv.metadata.playing())
    finally:
        # Do not forget to close
        await atv.close()
Esempio n. 19
0
def print_what_is_playing(loop):
    """Connect to device and print what is playing."""
    details = conf.AppleTV(ADDRESS, NAME)
    details.add_service(conf.DmapService(HSGID))

    print('Connecting to {}'.format(details.address))
    atv = pyatv.connect_to_apple_tv(details, loop)

    try:
        print((yield from atv.metadata.playing()))
    finally:
        # Do not forget to logout
        yield from atv.logout()
Esempio n. 20
0
def test_dmap_identifier_strip():
    service = conf.DmapService("abcd_2", "dummy")
    assert service.identifier == "abcd"
Esempio n. 21
0
AIRPLAY_PROPERTIES = {
    "model": "AppleTV6,2",
    "deviceid": "ff:ee:dd:cc:bb:aa",
    "osvers": "8.0.0",
}

RAOP_PROPERTIES = {
    "am": "AudioAccessory5,1",
    "ov": "14.5",
}

AIRPORT_PROPERTIES = {
    "am": "AirPort10,115",
}

DMAP_SERVICE = conf.DmapService(IDENTIFIER_1, None, port=PORT_1)
MRP_SERVICE = conf.MrpService(IDENTIFIER_2, PORT_2, properties=MRP_PROPERTIES)
AIRPLAY_SERVICE = conf.AirPlayService(IDENTIFIER_3,
                                      PORT_1,
                                      properties=AIRPLAY_PROPERTIES)
COMPANION_SERVICE = conf.CompanionService(PORT_3)
RAOP_SERVICE = conf.RaopService(IDENTIFIER_4,
                                PORT_4,
                                properties=RAOP_PROPERTIES)
AIRPORT_SERVICE = conf.RaopService(IDENTIFIER_1,
                                   PORT_1,
                                   properties=AIRPORT_PROPERTIES)


@pytest.fixture
def config():
Esempio n. 22
0
 def _non_hs_service(self, service_name, address, port, properties):
     """Add a new device without Home Sharing to discovered list."""
     identifier = service_name.split('.')[0]
     name = _property_decode(properties, 'CtlN')
     service = conf.DmapService(identifier, None, port=port)
     self._handle_service(address, name, service)
Esempio n. 23
0
 def setUp(self):
     self.config = conf.AppleTV(ADDRESS_1, NAME)
     self.dmap_service = conf.DmapService(IDENTIFIER_1, None, port=PORT_1)
     self.mrp_service = conf.MrpService(IDENTIFIER_2, PORT_2)
     self.airplay_service = conf.AirPlayService(IDENTIFIER_3, PORT_1)