Fix the Android TV volume mute service (#64403)
* Fix the Android TV volume mute service * Update homeassistant/components/androidtv/media_player.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * assert mute_volume.called Co-authored-by: Martin Hjelmare <marhje52@gmail.com>pull/64313/head^2
parent
6176bb954c
commit
1e9a0c0609
|
@ -609,7 +609,11 @@ class AndroidTVDevice(ADBDevice):
|
|||
@adb_decorator()
|
||||
async def async_mute_volume(self, mute):
|
||||
"""Mute the volume."""
|
||||
await self.aftv.mute_volume()
|
||||
is_muted = await self.aftv.is_volume_muted()
|
||||
|
||||
# `None` indicates that the muted status could not be determined
|
||||
if is_muted is not None and is_muted != mute:
|
||||
await self.aftv.mute_volume()
|
||||
|
||||
@adb_decorator()
|
||||
async def async_set_volume_level(self, volume):
|
||||
|
|
|
@ -1111,13 +1111,6 @@ async def test_services_androidtv(hass):
|
|||
await _test_service(
|
||||
hass, entity_id, SERVICE_VOLUME_DOWN, "volume_down", return_value=0.1
|
||||
)
|
||||
await _test_service(
|
||||
hass,
|
||||
entity_id,
|
||||
SERVICE_VOLUME_MUTE,
|
||||
"mute_volume",
|
||||
{ATTR_MEDIA_VOLUME_MUTED: False},
|
||||
)
|
||||
await _test_service(
|
||||
hass,
|
||||
entity_id,
|
||||
|
@ -1152,6 +1145,49 @@ async def test_services_firetv(hass):
|
|||
await _test_service(hass, entity_id, SERVICE_TURN_ON, "adb_shell")
|
||||
|
||||
|
||||
async def test_volume_mute(hass):
|
||||
"""Test the volume mute service."""
|
||||
patch_key, entity_id, config_entry = _setup(CONFIG_ANDROIDTV_ADB_SERVER)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[patch_key]:
|
||||
with patchers.patch_shell(SHELL_RESPONSE_OFF)[patch_key]:
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
with patchers.patch_shell(SHELL_RESPONSE_STANDBY)[patch_key]:
|
||||
service_data = {ATTR_ENTITY_ID: entity_id, ATTR_MEDIA_VOLUME_MUTED: True}
|
||||
with patch(
|
||||
"androidtv.androidtv.androidtv_async.AndroidTVAsync.mute_volume",
|
||||
return_value=None,
|
||||
) as mute_volume:
|
||||
# Don't send the mute key if the volume is already muted
|
||||
with patch(
|
||||
"androidtv.androidtv.androidtv_async.AndroidTVAsync.is_volume_muted",
|
||||
return_value=True,
|
||||
):
|
||||
await hass.services.async_call(
|
||||
MP_DOMAIN,
|
||||
SERVICE_VOLUME_MUTE,
|
||||
service_data=service_data,
|
||||
blocking=True,
|
||||
)
|
||||
assert not mute_volume.called
|
||||
|
||||
# Send the mute key because the volume is not already muted
|
||||
with patch(
|
||||
"androidtv.androidtv.androidtv_async.AndroidTVAsync.is_volume_muted",
|
||||
return_value=False,
|
||||
):
|
||||
await hass.services.async_call(
|
||||
MP_DOMAIN,
|
||||
SERVICE_VOLUME_MUTE,
|
||||
service_data=service_data,
|
||||
blocking=True,
|
||||
)
|
||||
assert mute_volume.called
|
||||
|
||||
|
||||
async def test_connection_closed_on_ha_stop(hass):
|
||||
"""Test that the ADB socket connection is closed when HA stops."""
|
||||
patch_key, entity_id, config_entry = _setup(CONFIG_ANDROIDTV_ADB_SERVER)
|
||||
|
|
Loading…
Reference in New Issue