How to use the pyatv.dmap.parser.first function in pyatv

To help you get started, we’ve selected a few pyatv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github postlund / pyatv / tests / dmap / test_parser.py View on Github external
def test_parse_uint_of_various_lengths(self):
        in_data = tags.uint8_tag('uuu8', 12) + \
                  tags.uint16_tag('uu16', 37888) + \
                  tags.uint32_tag('uu32', 305419896) + \
                  tags.uint64_tag('uu64', 8982983289232)
        parsed = parser.parse(in_data, lookup_tag)
        self.assertEqual(4, len(parsed))
        self.assertEqual(12, parser.first(parsed, 'uuu8'))
        self.assertEqual(37888, parser.first(parsed, 'uu16'))
        self.assertEqual(305419896, parser.first(parsed, 'uu32'))
        self.assertEqual(8982983289232, parser.first(parsed, 'uu64'))
github postlund / pyatv / tests / dmap / test_parser.py View on Github external
def test_parse_value_in_container(self):
        in_data = tags.container_tag('cona',
                                     tags.uint8_tag('uuu8', 36) +
                                     tags.uint16_tag('uu16', 13000))
        parsed = parser.parse(in_data, lookup_tag)
        self.assertEqual(1, len(parsed))
        inner = parser.first(parsed, 'cona')
        self.assertEqual(2, len(inner))
        self.assertEqual(36, parser.first(inner, 'uuu8'))
        self.assertEqual(13000, parser.first(inner, 'uu16'))
github postlund / pyatv / tests / dmap / test_parser.py View on Github external
def test_parse_strings(self):
        in_data = tags.string_tag('stra', '') + \
                  tags.string_tag('strb', 'test string')
        parsed = parser.parse(in_data, lookup_tag)
        self.assertEqual(2, len(parsed))
        self.assertEqual('', parser.first(parsed, 'stra'))
        self.assertEqual('test string', parser.first(parsed, 'strb'))
github postlund / pyatv / tests / dmap / test_parser.py View on Github external
def test_parse_bool(self):
        in_data = tags.bool_tag('bola', True) + \
                  tags.bool_tag('bolb', False)
        parsed = parser.parse(in_data, lookup_tag)
        self.assertEqual(2, len(parsed))
        self.assertTrue(parser.first(parsed, 'bola'))
        self.assertFalse(parser.first(parsed, 'bolb'))
github postlund / pyatv / tests / dmap / fake_dmap_atv.py View on Github external
def _convert_button(self, data):
        value = parser.first(data, 'cmbe')

        # Consider navigation buttons if six commands have been received
        if self.buttons_press_count == 6:
            if value == 'touchUp&time=6&point=20,250':
                return 'up'
            elif value == 'touchUp&time=6&point=20,275':
                return 'down'
            elif value == 'touchUp&time=7&point=50,100':
                return 'left'
            elif value == 'touchUp&time=7&point=75,100':
                return 'right'

        return value
github postlund / pyatv / tests / fake_daap_atv.py View on Github external
def perform_pairing(self, pairing_response, port):
        """Pair with a remote client.

        This will perform a GET-request to the specified port and hand over
        information to the client (pyatv) so that the pairing process can be
        completed.
        """
        server = 'http://127.0.0.1:{}'.format(port)
        url = '{}/pairing?pairingcode={}&servicename=test'.format(
            server, pairing_response.pairing_code)
        data, _ = yield from utils.simple_get(url, self.loop)

        # Verify content returned in pairingresponse
        parsed = parser.parse(data, tag_definitions.lookup_tag)
        self.tc.assertEqual(parser.first(parsed, 'cmpa', 'cmpg'), 1)
        self.tc.assertEqual(parser.first(parsed, 'cmpa', 'cmnm'),
                            pairing_response.remote_name)
        self.tc.assertEqual(parser.first(parsed, 'cmpa', 'cmty'), 'ipod')
github postlund / pyatv / tests / dmap / test_parser.py View on Github external
def test_extract_simplified_container(self):
        elem = tags.uint8_tag('uuu8', 12)
        inner = tags.container_tag('conb', elem)
        in_data = tags.container_tag('cona', inner)
        parsed = parser.parse(in_data, lookup_tag)
        self.assertEqual(12, parser.first(parsed, 'cona', 'conb', 'uuu8'))
github postlund / pyatv / tests / fake_daap_atv.py View on Github external
def perform_pairing(self, pairing_response, port):
        """Pair with a remote client.

        This will perform a GET-request to the specified port and hand over
        information to the client (pyatv) so that the pairing process can be
        completed.
        """
        server = 'http://127.0.0.1:{}'.format(port)
        url = '{}/pairing?pairingcode={}&servicename=test'.format(
            server, pairing_response.pairing_code)
        data, _ = yield from utils.simple_get(url, self.loop)

        # Verify content returned in pairingresponse
        parsed = parser.parse(data, tag_definitions.lookup_tag)
        self.tc.assertEqual(parser.first(parsed, 'cmpa', 'cmpg'), 1)
        self.tc.assertEqual(parser.first(parsed, 'cmpa', 'cmnm'),
                            pairing_response.remote_name)
        self.tc.assertEqual(parser.first(parsed, 'cmpa', 'cmty'), 'ipod')
github postlund / pyatv / pyatv / dmap / daap.py View on Github external
async def login(self):
        """Login to Apple TV using specified login id."""
        # Do not use session.get_data(...) in login as that would end up in
        # an infinte loop.
        def _login_request():
            return self.http.get_data(
                self._mkurl('login?[AUTH]&hasFP=1',
                            session=False, login_id=True),
                headers=_DMAP_HEADERS)

        resp = await self._do(_login_request, is_login=True)
        self._session_id = parser.first(resp, 'mlog', 'mlid')

        _LOGGER.info('Logged in and got session id %s', self._session_id)
        return self._session_id
github postlund / pyatv / pyatv / dmap / __init__.py View on Github external
def shuffle(self):
        """If shuffle is enabled or not."""
        return bool(parser.first(self.playstatus, 'cmst', 'cash'))