Beispiel #1
0
 def __init__(
     self,
     config: interface.BaseConfig,
     session_manager: ClientSessionManager,
     core_dispatcher: CoreStateDispatcher,
 ):
     """Initialize a new FacadeAppleTV instance."""
     super().__init__(max_calls=1)  # To StateProducer via interface.AppleTV
     self._config = config
     self._session_manager = session_manager
     self._protocols_to_setup: Queue[SetupData] = Queue()
     self._protocol_handlers: Dict[Protocol, SetupData] = {}
     self._push_updates = FacadePushUpdater()
     self._features = FacadeFeatures(self._push_updates)
     self._pending_tasks: Optional[set] = None
     self._device_info = interface.DeviceInfo({})
     self._interfaces = {
         interface.Features: self._features,
         interface.RemoteControl: FacadeRemoteControl(),
         interface.Metadata: FacadeMetadata(),
         interface.Power: FacadePower(core_dispatcher),
         interface.PushUpdater: self._push_updates,
         interface.Stream: FacadeStream(self._features),
         interface.Apps: FacadeApps(),
         interface.Audio: FacadeAudio(),
     }
     self._shield_everything()
Beispiel #2
0
def test_tvos_str():
    dev_info = interface.DeviceInfo(
        OperatingSystem.TvOS,
        "1.2.3",
        "19A123",
        DeviceModel.Gen4K,
        "aa:bb:cc:dd:ee:ff",
    )

    assert str(dev_info) == "Gen4K tvOS 1.2.3 build 19A123"
Beispiel #3
0
def test_apple_tv_software_str():
    dev_info = interface.DeviceInfo(
        OperatingSystem.Legacy,
        "2.2.3",
        "13D333",
        DeviceModel.Gen3,
        "aa:bb:cc:dd:ee:ff",
    )

    assert str(dev_info) == "Gen3 ATV SW 2.2.3 build 13D333"
Beispiel #4
0
    def test_tvos_str(self):
        dev_info = interface.DeviceInfo(
            OperatingSystem.TvOS,
            "1.2.3",
            "19A123",
            DeviceModel.Gen4K,
            "aa:bb:cc:dd:ee:ff",
        )

        self.assertEqual(str(dev_info), "4K tvOS 1.2.3 build 19A123")
Beispiel #5
0
def test_fields_set():
    dev_info = interface.DeviceInfo(
        OperatingSystem.TvOS,
        "1.2.3",
        "19A123",
        DeviceModel.Gen4K,
        "aa:bb:cc:dd:ee:ff",
    )

    assert dev_info.operating_system == OperatingSystem.TvOS
    assert dev_info.version == "1.2.3"
    assert dev_info.build_number == "19A123"
    assert dev_info.model == DeviceModel.Gen4K
    assert dev_info.mac == "aa:bb:cc:dd:ee:ff"
Beispiel #6
0
    def test_fields_set(self):
        dev_info = interface.DeviceInfo(
            OperatingSystem.TvOS,
            "1.2.3",
            "19A123",
            DeviceModel.Gen4K,
            "aa:bb:cc:dd:ee:ff",
        )

        self.assertEqual(dev_info.operating_system, OperatingSystem.TvOS)
        self.assertEqual(dev_info.version, "1.2.3")
        self.assertEqual(dev_info.build_number, "19A123")
        self.assertEqual(dev_info.model, DeviceModel.Gen4K)
        self.assertEqual(dev_info.mac, "aa:bb:cc:dd:ee:ff")
Beispiel #7
0
    async def connect(self) -> None:
        """Initiate connection to device."""
        # No protocols to setup + no protocols previously set up => no service
        if self._protocols_to_setup.empty() and not self._protocol_handlers:
            raise exceptions.NoServiceError("no service to connect to")

        # Protocols set up already => we have already connected
        if self._protocol_handlers:
            raise exceptions.InvalidStateError("already connected")

        devinfo: Dict[str, Any] = {}

        # Set up protocols, ignoring duplicates
        while not self._protocols_to_setup.empty():
            setup_data = self._protocols_to_setup.get()

            if setup_data.protocol in self._protocol_handlers:
                _LOGGER.debug("Protocol %s already set up, ignoring",
                              setup_data.protocol)
                continue

            _LOGGER.debug("Connecting to protocol: %s", setup_data.protocol)
            if await setup_data.connect():
                _LOGGER.debug("Connected to protocol: %s", setup_data.protocol)
                self._protocol_handlers[setup_data.protocol] = setup_data

                for iface, instance in setup_data.interfaces.items():
                    self._interfaces[iface].register(instance,
                                                     setup_data.protocol)

                self._features.add_mapping(setup_data.protocol,
                                           setup_data.features)
                dict_merge(devinfo, setup_data.device_info())

        self._device_info = interface.DeviceInfo(devinfo)

        # Forward power events in case an interface exists for it
        try:
            power = cast(interface.Power,
                         self._interfaces[interface.Power].main_instance)
            power.listener = self._interfaces[interface.Power]
        except exceptions.NotSupportedError:
            _LOGGER.debug("Power management not supported by any protocols")
Beispiel #8
0
def test_unknown_str():
    dev_info = interface.DeviceInfo(OperatingSystem.Unknown, None, None,
                                    DeviceModel.Unknown, None)

    assert str(dev_info) == "Unknown Model Unknown OS"
Beispiel #9
0
    def test_unknown_str(self):
        dev_info = interface.DeviceInfo(OperatingSystem.Unknown, None, None,
                                        DeviceModel.Unknown, None)

        self.assertEqual(str(dev_info), "Unknown Model Unknown OS")