How to use the androidtv.setup function in androidtv

To help you get started, we’ve selected a few androidtv 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 JeffLIrion / python-androidtv / tests / test_homeassistant_sync.py View on Github external
def test_adb_command(self):
        """Test sending a command via the `androidtv.adb_command` service."""
        patch_key = "server"
        command = "test command"
        response = "test response"

        with patchers.patch_connect(True)[patch_key], patchers.patch_shell("")[patch_key]:
            aftv = setup(
                "HOST", 5555, adb_server_ip="ADB_SERVER_IP", device_class="androidtv"
            )
            self.aftv = AndroidTVDevice(aftv, "Fake Android TV", {}, True, None, None)

        with patch("androidtv.basetv.basetv_sync.BaseTVSync.adb_shell", return_value=response) as patch_shell:
            self.aftv.adb_command(command)

            patch_shell.assert_called_with(command)
            assert self.aftv._adb_response == response
github JeffLIrion / python-androidtv / tests / test_homeassistant_sync.py View on Github external
def setUp(self):
        """Set up a `FireTVDevice` media player."""
        with patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell("")[self.PATCH_KEY]:
            aftv = setup(
                "HOST", 5555, adb_server_ip="ADB_SERVER_IP", device_class="firetv"
            )
            self.aftv = FireTVDevice(aftv, "Fake Fire TV", {}, True, None, None)
github JeffLIrion / python-androidtv / tests / test_homeassistant_sync.py View on Github external
def test_update_lock_not_acquired(self):
        """Test that the state does not get updated when a `LockNotAcquiredException` is raised."""
        patch_key = "server"

        with patchers.patch_connect(True)[patch_key], patchers.patch_shell("")[patch_key]:
            aftv = setup(
                "HOST", 5555, adb_server_ip="ADB_SERVER_IP", device_class="androidtv"
            )
            self.aftv = AndroidTVDevice(aftv, "Fake Android TV", {}, True, None, None)

        with patchers.patch_shell("")[patch_key]:
            self.aftv.update()
            assert self.aftv.state == STATE_OFF

        with patch("androidtv.androidtv.androidtv_sync.AndroidTVSync.update", side_effect=LockNotAcquiredException):
            with patchers.patch_shell("1")[patch_key]:
                self.aftv.update()
                assert self.aftv.state == STATE_OFF

        with patchers.patch_shell("1")[patch_key]:
            self.aftv.update()
            assert self.aftv.state == STATE_STANDBY
github JeffLIrion / python-androidtv / tests / test_homeassistant_sync.py View on Github external
def setUp(self):
        """Set up a `FireTVDevice` media player."""
        with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell("")[self.PATCH_KEY]:
            aftv = setup("HOST", 5555, device_class="firetv")
            self.aftv = FireTVDevice(aftv, "Fake Fire TV", {}, True, None, None)
github JeffLIrion / python-androidtv / tests / test_homeassistant_sync.py View on Github external
def test_adb_command_key(self):
        """Test sending a key command via the `androidtv.adb_command` service."""
        patch_key = "server"
        command = "HOME"
        response = None

        with patchers.patch_connect(True)[patch_key], patchers.patch_shell("")[patch_key]:
            aftv = setup(
                "HOST", 5555, adb_server_ip="ADB_SERVER_IP", device_class="androidtv"
            )
            self.aftv = AndroidTVDevice(aftv, "Fake Android TV", {}, True, None, None)

        with patch("androidtv.basetv.basetv_sync.BaseTVSync.adb_shell", return_value=response) as patch_shell:
            self.aftv.adb_command(command)

            patch_shell.assert_called_with("input keyevent {}".format(self.aftv._keys[command]))
            assert self.aftv._adb_response is None
github JeffLIrion / python-androidtv / tests / test_setup_sync.py View on Github external
def test_setup(self):
        """Test that the ``setup`` function works correctly.
        """
        with self.assertRaises(ValueError):
            setup('HOST', 5555, device_class='INVALID')

        with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT1)[self.PATCH_KEY]:
            ftv = setup('HOST', 5555)
            self.assertIsInstance(ftv, FireTVSync)
            self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1)

        with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT2)[self.PATCH_KEY]:
            atv = setup('HOST', 5555)
            self.assertIsInstance(atv, AndroidTVSync)
            self.assertDictEqual(atv.device_properties, DEVICE_PROPERTIES_DICT2)

        with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT1)[self.PATCH_KEY]:
            ftv = setup('HOST', 5555, device_class='androidtv')
            self.assertIsInstance(ftv, AndroidTVSync)
            self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1)

        with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT2)[self.PATCH_KEY]:
            atv = setup('HOST', 5555, device_class='firetv')
            self.assertIsInstance(atv, FireTVSync)
            self.assertDictEqual(atv.device_properties, DEVICE_PROPERTIES_DICT2)
github JeffLIrion / python-androidtv / tests / test_setup_sync.py View on Github external
def test_setup(self):
        """Test that the ``setup`` function works correctly.
        """
        with self.assertRaises(ValueError):
            setup('HOST', 5555, device_class='INVALID')

        with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT1)[self.PATCH_KEY]:
            ftv = setup('HOST', 5555)
            self.assertIsInstance(ftv, FireTVSync)
            self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1)

        with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT2)[self.PATCH_KEY]:
            atv = setup('HOST', 5555)
            self.assertIsInstance(atv, AndroidTVSync)
            self.assertDictEqual(atv.device_properties, DEVICE_PROPERTIES_DICT2)

        with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT1)[self.PATCH_KEY]:
            ftv = setup('HOST', 5555, device_class='androidtv')
            self.assertIsInstance(ftv, AndroidTVSync)
            self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1)
github JeffLIrion / python-androidtv / tests / test_setup_sync.py View on Github external
"""
        with self.assertRaises(ValueError):
            setup('HOST', 5555, device_class='INVALID')

        with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT1)[self.PATCH_KEY]:
            ftv = setup('HOST', 5555)
            self.assertIsInstance(ftv, FireTVSync)
            self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1)

        with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT2)[self.PATCH_KEY]:
            atv = setup('HOST', 5555)
            self.assertIsInstance(atv, AndroidTVSync)
            self.assertDictEqual(atv.device_properties, DEVICE_PROPERTIES_DICT2)

        with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT1)[self.PATCH_KEY]:
            ftv = setup('HOST', 5555, device_class='androidtv')
            self.assertIsInstance(ftv, AndroidTVSync)
            self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1)

        with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT2)[self.PATCH_KEY]:
            atv = setup('HOST', 5555, device_class='firetv')
            self.assertIsInstance(atv, FireTVSync)
            self.assertDictEqual(atv.device_properties, DEVICE_PROPERTIES_DICT2)
github JeffLIrion / python-androidtv / tests / test_homeassistant_sync.py View on Github external
def setUp(self):
        """Set up an `AndroidTVDevice` media player."""
        with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell("")[self.PATCH_KEY]:
            aftv = setup("HOST", 5555, device_class="androidtv")
            self.aftv = AndroidTVDevice(aftv, "Fake Android TV", {}, True, None, None)
github home-assistant / home-assistant / homeassistant / components / androidtv / media_player.py View on Github external
f"using Python ADB implementation with adbkey='{config[CONF_ADBKEY]}'"
            )

            aftv = setup(
                host,
                config[CONF_ADBKEY],
                device_class=config[CONF_DEVICE_CLASS],
                state_detection_rules=config[CONF_STATE_DETECTION_RULES],
                auth_timeout_s=10.0,
            )

    else:
        # Use "pure-python-adb" (communicate with ADB server)
        adb_log = f"using ADB server at {config[CONF_ADB_SERVER_IP]}:{config[CONF_ADB_SERVER_PORT]}"

        aftv = setup(
            host,
            adb_server_ip=config[CONF_ADB_SERVER_IP],
            adb_server_port=config[CONF_ADB_SERVER_PORT],
            device_class=config[CONF_DEVICE_CLASS],
            state_detection_rules=config[CONF_STATE_DETECTION_RULES],
        )

    if not aftv.available:
        # Determine the name that will be used for the device in the log
        if CONF_NAME in config:
            device_name = config[CONF_NAME]
        elif config[CONF_DEVICE_CLASS] == DEVICE_ANDROIDTV:
            device_name = "Android TV device"
        elif config[CONF_DEVICE_CLASS] == DEVICE_FIRETV:
            device_name = "Fire TV device"
        else: