Beispiel #1
0
    async def _wait_for_media_to_end(self):
        attempts = WAIT_RETRIES
        video_started = False

        while True:
            data, status = await self.http.get_data('playback-info')

            if status == 403:
                raise exceptions.NoCredentialsError(
                    'device authentication required')

            _LOGGER.debug('Playback-info (%d): %s', status, data)

            parsed = plistlib.loads(data)

            # duration is only available if something is playing
            if 'duration' in parsed:
                video_started = True
                attempts = -1
            else:
                video_started = False
                if attempts >= 0:
                    attempts -= 1

            if not video_started and attempts < 0:
                _LOGGER.debug('media playback ended')
                break

            await asyncio.sleep(1, loop=self.loop)
Beispiel #2
0
    async def _connect(self):
        if self._protocol:
            return

        service = self.config.get_service(Protocol.Companion)
        if service is None:
            raise exceptions.NoCredentialsError(
                "No Companion credentials loaded")

        _LOGGER.debug("Connect to Companion from API")
        connection = CompanionConnection(self.loop, str(self.config.address),
                                         service.port, self)

        protocol = CompanionProtocol(connection, SRPAuthHandler(), service)
        await protocol.start()

        self._connection = connection
        self._protocol = protocol

        await self._session_start()
Beispiel #3
0
    def _wait_for_media_to_end(self):
        address = self._url(self.port, 'playback-info')
        attempts = 5
        video_started = False
        while True:
            info = None
            try:
                info = yield from self.session.get(address)
                data = yield from info.content.read()

                if info.status == 403:
                    raise exceptions.NoCredentialsError(
                        'device authentication required')

                _LOGGER.debug('Playback-info (%d): %s', info.status, data)

                parsed = plistlib.loads(data)

                # duration is only available if something is playing
                if 'duration' in parsed:
                    video_started = True
                    attempts = -1
                else:
                    video_started = False
                    if attempts >= 0:
                        attempts -= 1

                if not video_started and attempts < 0:
                    _LOGGER.debug('media playback ended')
                    break

            finally:
                if info is not None:
                    info.close()

            yield from asyncio.sleep(1, loop=self.loop)
Beispiel #4
0
 def encryption_keys(self) -> Tuple[str, str]:
     """Return derived encryption keys."""
     if self._output_key is None or self._input_key is None:
         raise exceptions.NoCredentialsError(
             "verification has not succeeded")
     return self._output_key, self._input_key