Implement 'volume_set' service for Android TV devices ()

pull/31182/head
Jeff Irion 2020-01-26 01:39:19 -08:00 committed by Martin Hjelmare
parent 4c4f726323
commit cd72128a80
5 changed files with 33 additions and 3 deletions

View File

@ -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": [],

View File

@ -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."""

View File

@ -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

View File

@ -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

View File

@ -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)