def __init__( self, loop: asyncio.AbstractEventLoop, session_manager: ClientSessionManager, config: conf.AppleTV, airplay: Stream, ) -> None: """Initialize a new Apple TV.""" super().__init__() self._session_manager = session_manager self._config = config self._mrp_service = config.get_service(Protocol.MRP) assert self._mrp_service is not None self._connection = MrpConnection(config.address, self._mrp_service.port, loop, atv=self) self._srp = SRPAuthHandler() self._protocol = MrpProtocol(self._connection, self._srp, self._mrp_service) self._psm = PlayerStateManager(self._protocol, loop) self._mrp_remote = MrpRemoteControl(loop, self._psm, self._protocol) self._mrp_metadata = MrpMetadata(self._protocol, self._psm, config.identifier) self._mrp_power = MrpPower(loop, self._protocol, self._mrp_remote) self._mrp_push_updater = MrpPushUpdater(loop, self._mrp_metadata, self._psm) self._mrp_features = MrpFeatures(self._config, self._psm) self._airplay = airplay
async def mrp_protocol(event_loop, mrp_atv): port = mrp_atv.get_port(Protocol.MRP) service = MrpService("mrp_id", port) connection = MrpConnection("127.0.0.1", port, event_loop) protocol = MrpProtocol(connection, SRPAuthHandler(), service) yield protocol protocol.stop()
async def start(self, address, port, credentials): """Start the proxy instance.""" self.connection = MrpConnection(address, port, self.loop) protocol = MrpProtocol( self.loop, self.connection, SRPAuthHandler(), MrpService(None, port, credentials=credentials)) await protocol.start(skip_initial_messages=True) self.connection.listener = self self._process_buffer()
def __init__(self, config, session_manager: ClientSessionManager, loop): """Initialize a new MrpPairingHandler.""" super().__init__(session_manager, config.get_service(Protocol.MRP)) self.connection = MrpConnection(config.address, self.service.port, loop) self.srp = SRPAuthHandler() self.protocol = MrpProtocol(self.connection, self.srp, self.service) self.pairing_procedure = MrpPairingProcedure(self.protocol, self.srp) self.pin_code = None self._has_paired = False
def setup( # pylint: disable=too-many-locals loop: asyncio.AbstractEventLoop, config: conf.AppleTV, interfaces: Dict[Any, Relayer], device_listener: StateProducer, session_manager: ClientSessionManager, ) -> Optional[ Tuple[Callable[[], Awaitable[None]], Callable[[], None], Set[FeatureName]] ]: """Set up a new MRP service.""" service = config.get_service(Protocol.MRP) assert service is not None connection = MrpConnection(config.address, service.port, loop, atv=device_listener) protocol = MrpProtocol(connection, SRPAuthHandler(), service) psm = PlayerStateManager(protocol) remote_control = MrpRemoteControl(loop, psm, protocol) metadata = MrpMetadata(protocol, psm, config.identifier) push_updater = MrpPushUpdater(loop, metadata, psm) power = MrpPower(loop, protocol, remote_control) interfaces[RemoteControl].register(remote_control, Protocol.MRP) interfaces[Metadata].register(metadata, Protocol.MRP) interfaces[Power].register(power, Protocol.MRP) interfaces[PushUpdater].register(push_updater, Protocol.MRP) interfaces[Features].register(MrpFeatures(config, psm), Protocol.MRP) # Forward power events to the facade instance power.listener = interfaces[Power] async def _connect() -> None: await protocol.start() def _close() -> None: push_updater.stop() protocol.stop() # Features managed by this protocol features = set( [ FeatureName.Artwork, FeatureName.VolumeDown, FeatureName.VolumeUp, FeatureName.App, ] ) features.update(_FEATURES_SUPPORTED) features.update(_FEATURE_COMMAND_MAP.keys()) features.update(_FIELD_FEATURES.keys()) return _connect, _close, features
def start(self, address, port): """Start the proxy instance.""" # Establish connection to ATV self.connection = MrpConnection(address, port, self.loop) protocol = MrpProtocol( self.loop, self.connection, SRPAuthHandler(), MrpService(None, port, credentials=self.credentials)) self.loop.run_until_complete( protocol.start(skip_initial_messages=True)) self.connection.listener = self # Setup server used to publish a fake MRP server coro = self.loop.create_server(lambda: self, '0.0.0.0') self.server = self.loop.run_until_complete(coro) _LOGGER.info('Started MRP server at port %d', self.port)
def __init__(self, loop, session, details, airplay): """Initialize a new Apple TV.""" super().__init__() self._session = session self._mrp_service = details.usable_service() self._connection = MrpConnection(details.address, self._mrp_service.port, loop) self._srp = SRPAuthHandler() self._protocol = MrpProtocol(loop, self._connection, self._srp, self._mrp_service) self._mrp_remote = MrpRemoteControl(loop, self._protocol) self._mrp_metadata = MrpMetadata(self._protocol) self._mrp_push_updater = MrpPushUpdater(loop, self._mrp_metadata, self._protocol) self._mrp_pairing = MrpPairingHandler(self._protocol, self._srp, self._mrp_service) self._airplay = airplay
def __init__(self, loop, session, config, airplay): """Initialize a new Apple TV.""" super().__init__() self._session = session self._mrp_service = config.get_service(Protocol.MRP) self._connection = MrpConnection(config.address, self._mrp_service.port, loop, atv=self) self._srp = SRPAuthHandler() self._protocol = MrpProtocol(loop, self._connection, self._srp, self._mrp_service) self._psm = PlayerStateManager(self._protocol, loop) self._mrp_remote = MrpRemoteControl(loop, self._protocol) self._mrp_metadata = MrpMetadata(self._protocol, self._psm, config.identifier) self._mrp_push_updater = MrpPushUpdater(loop, self._mrp_metadata, self._psm) self._airplay = airplay