From cd72128a8011369e1bf702d2b6af8f1f17543754 Mon Sep 17 00:00:00 2001 From: Jeff Irion Date: Sun, 26 Jan 2020 01:39:19 -0800 Subject: [PATCH] Implement 'volume_set' service for Android TV devices (#31161) --- .../components/androidtv/manifest.json | 2 +- .../components/androidtv/media_player.py | 7 ++++++ requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- .../components/androidtv/test_media_player.py | 23 +++++++++++++++++++ 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/androidtv/manifest.json b/homeassistant/components/androidtv/manifest.json index d81e7863503..5fea6c3f2e2 100644 --- a/homeassistant/components/androidtv/manifest.json +++ b/homeassistant/components/androidtv/manifest.json @@ -4,7 +4,7 @@ "documentation": "https://www.home-assistant.io/integrations/androidtv", "requirements": [ "adb-shell==0.1.1", - "androidtv==0.0.38", + "androidtv==0.0.39", "pure-python-adb==0.2.2.dev0" ], "dependencies": [], diff --git a/homeassistant/components/androidtv/media_player.py b/homeassistant/components/androidtv/media_player.py index 63b27f17bb2..ff6359f54b3 100644 --- a/homeassistant/components/androidtv/media_player.py +++ b/homeassistant/components/androidtv/media_player.py @@ -26,6 +26,7 @@ from homeassistant.components.media_player.const import ( SUPPORT_TURN_OFF, SUPPORT_TURN_ON, SUPPORT_VOLUME_MUTE, + SUPPORT_VOLUME_SET, SUPPORT_VOLUME_STEP, ) from homeassistant.const import ( @@ -59,6 +60,7 @@ SUPPORT_ANDROIDTV = ( | SUPPORT_SELECT_SOURCE | SUPPORT_STOP | SUPPORT_VOLUME_MUTE + | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_STEP ) @@ -631,6 +633,11 @@ class AndroidTVDevice(ADBDevice): """Mute the volume.""" self.aftv.mute_volume() + @adb_decorator() + def set_volume_level(self, volume): + """Set the volume level.""" + self.aftv.set_volume_level(volume) + @adb_decorator() def volume_down(self): """Send volume down command.""" diff --git a/requirements_all.txt b/requirements_all.txt index 6e8536bd2c3..ab4afb72bad 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -220,7 +220,7 @@ ambiclimate==0.2.1 amcrest==1.5.3 # homeassistant.components.androidtv -androidtv==0.0.38 +androidtv==0.0.39 # homeassistant.components.anel_pwrctrl anel_pwrctrl-homeassistant==0.0.1.dev2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 7581173b534..a3e2f8a03cc 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -87,7 +87,7 @@ airly==0.0.2 ambiclimate==0.2.1 # homeassistant.components.androidtv -androidtv==0.0.38 +androidtv==0.0.39 # homeassistant.components.apns apns2==0.3.0 diff --git a/tests/components/androidtv/test_media_player.py b/tests/components/androidtv/test_media_player.py index 0aaa870c57b..f076b461119 100644 --- a/tests/components/androidtv/test_media_player.py +++ b/tests/components/androidtv/test_media_player.py @@ -28,6 +28,7 @@ from homeassistant.const import ( CONF_HOST, CONF_NAME, CONF_PLATFORM, + SERVICE_VOLUME_SET, STATE_IDLE, STATE_OFF, STATE_PLAYING, @@ -820,3 +821,25 @@ async def test_upload(hass): blocking=True, ) patch_push.assert_called_with(local_path, device_path) + + +async def test_androidtv_volume_set(hass): + """Test setting the volume for an Android TV device.""" + patch_key, entity_id = _setup(CONFIG_ANDROIDTV_ADB_SERVER) + + with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[ + patch_key + ], patchers.patch_shell("")[patch_key]: + assert await async_setup_component(hass, DOMAIN, CONFIG_ANDROIDTV_ADB_SERVER) + + with patch( + "androidtv.basetv.BaseTV.set_volume_level", return_value=0.5 + ) as patch_set_volume_level: + await hass.services.async_call( + DOMAIN, + SERVICE_VOLUME_SET, + {ATTR_ENTITY_ID: entity_id, "volume_level": 0.5}, + blocking=True, + ) + + patch_set_volume_level.assert_called_with(0.5)