Alexa media player only include equalizer if supported sound mode (#36285)

This commit is contained in:
Paulus Schoutsen 2020-05-30 21:42:40 -07:00 committed by GitHub
parent 5920f3379c
commit 2a86d52dba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 23 deletions

View file

@ -1803,6 +1803,13 @@ class AlexaEqualizerController(AlexaCapability):
"""
supported_locales = {"en-US"}
VALID_SOUND_MODES = {
"MOVIE",
"MUSIC",
"NIGHT",
"SPORT",
"TV",
}
def name(self):
"""Return the Alexa API name of this interface."""
@ -1821,35 +1828,34 @@ class AlexaEqualizerController(AlexaCapability):
raise UnsupportedProperty(name)
sound_mode = self.entity.attributes.get(media_player.ATTR_SOUND_MODE)
if sound_mode and sound_mode.upper() in (
"MOVIE",
"MUSIC",
"NIGHT",
"SPORT",
"TV",
):
if sound_mode and sound_mode.upper() in self.VALID_SOUND_MODES:
return sound_mode.upper()
return None
def configurations(self):
"""Return the sound modes supported in the configurations object.
Valid Values for modes are: MOVIE, MUSIC, NIGHT, SPORT, TV.
"""
"""Return the sound modes supported in the configurations object."""
configurations = None
sound_mode_list = self.entity.attributes.get(media_player.ATTR_SOUND_MODE_LIST)
if sound_mode_list:
supported_sound_modes = [
{"name": sound_mode.upper()}
for sound_mode in sound_mode_list
if sound_mode.upper() in ("MOVIE", "MUSIC", "NIGHT", "SPORT", "TV")
]
supported_sound_modes = self.get_valid_inputs(
self.entity.attributes.get(media_player.ATTR_SOUND_MODE_LIST, [])
)
if supported_sound_modes:
configurations = {"modes": {"supported": supported_sound_modes}}
return configurations
@classmethod
def get_valid_inputs(cls, sound_mode_list):
"""Return list of supported inputs."""
input_list = []
for sound_mode in sound_mode_list:
sound_mode = sound_mode.upper()
if sound_mode in cls.VALID_SOUND_MODES:
input_list.append({"name": sound_mode})
return input_list
class AlexaTimeHoldController(AlexaCapability):
"""Implements Alexa.TimeHoldController.

View file

@ -547,7 +547,11 @@ class MediaPlayerCapabilities(AlexaEntity):
yield AlexaChannelController(self.entity)
if supported & media_player.const.SUPPORT_SELECT_SOUND_MODE:
yield AlexaEqualizerController(self.entity)
inputs = AlexaInputController.get_valid_inputs(
self.entity.attributes.get(media_player.const.ATTR_SOUND_MODE_LIST, [])
)
if len(inputs) > 0:
yield AlexaEqualizerController(self.entity)
yield AlexaEndpointHealth(self.hass, self.entity)
yield Alexa(self.hass)

View file

@ -3297,8 +3297,8 @@ async def test_media_player_eq_modes(hass):
assert call.data["sound_mode"] == mode.lower()
async def test_media_player_sound_mode_list_none(hass):
"""Test EqualizerController bands directive not supported."""
async def test_media_player_sound_mode_list_unsupported(hass):
"""Test EqualizerController with unsupported sound modes."""
device = (
"media_player.test",
"on",
@ -3306,13 +3306,18 @@ async def test_media_player_sound_mode_list_none(hass):
"friendly_name": "Test media player",
"supported_features": SUPPORT_SELECT_SOUND_MODE,
"sound_mode": "unknown",
"sound_mode_list": None,
"sound_mode_list": ["unsupported", "non-existing"],
},
)
appliance = await discovery_test(device, hass)
assert appliance["endpointId"] == "media_player#test"
assert appliance["friendlyName"] == "Test media player"
# Test equalizer controller is not there
assert_endpoint_capabilities(
appliance, "Alexa", "Alexa.PowerController", "Alexa.EndpointHealth",
)
async def test_media_player_eq_bands_not_supported(hass):
"""Test EqualizerController bands directive not supported."""