Alexa media player only include equalizer if supported sound mode (#36285)
This commit is contained in:
parent
5920f3379c
commit
2a86d52dba
3 changed files with 38 additions and 23 deletions
|
@ -1803,6 +1803,13 @@ class AlexaEqualizerController(AlexaCapability):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
supported_locales = {"en-US"}
|
supported_locales = {"en-US"}
|
||||||
|
VALID_SOUND_MODES = {
|
||||||
|
"MOVIE",
|
||||||
|
"MUSIC",
|
||||||
|
"NIGHT",
|
||||||
|
"SPORT",
|
||||||
|
"TV",
|
||||||
|
}
|
||||||
|
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the Alexa API name of this interface."""
|
"""Return the Alexa API name of this interface."""
|
||||||
|
@ -1821,35 +1828,34 @@ class AlexaEqualizerController(AlexaCapability):
|
||||||
raise UnsupportedProperty(name)
|
raise UnsupportedProperty(name)
|
||||||
|
|
||||||
sound_mode = self.entity.attributes.get(media_player.ATTR_SOUND_MODE)
|
sound_mode = self.entity.attributes.get(media_player.ATTR_SOUND_MODE)
|
||||||
if sound_mode and sound_mode.upper() in (
|
if sound_mode and sound_mode.upper() in self.VALID_SOUND_MODES:
|
||||||
"MOVIE",
|
|
||||||
"MUSIC",
|
|
||||||
"NIGHT",
|
|
||||||
"SPORT",
|
|
||||||
"TV",
|
|
||||||
):
|
|
||||||
return sound_mode.upper()
|
return sound_mode.upper()
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def configurations(self):
|
def configurations(self):
|
||||||
"""Return the sound modes supported in the configurations object.
|
"""Return the sound modes supported in the configurations object."""
|
||||||
|
|
||||||
Valid Values for modes are: MOVIE, MUSIC, NIGHT, SPORT, TV.
|
|
||||||
"""
|
|
||||||
configurations = None
|
configurations = None
|
||||||
sound_mode_list = self.entity.attributes.get(media_player.ATTR_SOUND_MODE_LIST)
|
supported_sound_modes = self.get_valid_inputs(
|
||||||
if sound_mode_list:
|
self.entity.attributes.get(media_player.ATTR_SOUND_MODE_LIST, [])
|
||||||
supported_sound_modes = [
|
)
|
||||||
{"name": sound_mode.upper()}
|
if supported_sound_modes:
|
||||||
for sound_mode in sound_mode_list
|
|
||||||
if sound_mode.upper() in ("MOVIE", "MUSIC", "NIGHT", "SPORT", "TV")
|
|
||||||
]
|
|
||||||
|
|
||||||
configurations = {"modes": {"supported": supported_sound_modes}}
|
configurations = {"modes": {"supported": supported_sound_modes}}
|
||||||
|
|
||||||
return configurations
|
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):
|
class AlexaTimeHoldController(AlexaCapability):
|
||||||
"""Implements Alexa.TimeHoldController.
|
"""Implements Alexa.TimeHoldController.
|
||||||
|
|
|
@ -547,7 +547,11 @@ class MediaPlayerCapabilities(AlexaEntity):
|
||||||
yield AlexaChannelController(self.entity)
|
yield AlexaChannelController(self.entity)
|
||||||
|
|
||||||
if supported & media_player.const.SUPPORT_SELECT_SOUND_MODE:
|
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 AlexaEndpointHealth(self.hass, self.entity)
|
||||||
yield Alexa(self.hass)
|
yield Alexa(self.hass)
|
||||||
|
|
|
@ -3297,8 +3297,8 @@ async def test_media_player_eq_modes(hass):
|
||||||
assert call.data["sound_mode"] == mode.lower()
|
assert call.data["sound_mode"] == mode.lower()
|
||||||
|
|
||||||
|
|
||||||
async def test_media_player_sound_mode_list_none(hass):
|
async def test_media_player_sound_mode_list_unsupported(hass):
|
||||||
"""Test EqualizerController bands directive not supported."""
|
"""Test EqualizerController with unsupported sound modes."""
|
||||||
device = (
|
device = (
|
||||||
"media_player.test",
|
"media_player.test",
|
||||||
"on",
|
"on",
|
||||||
|
@ -3306,13 +3306,18 @@ async def test_media_player_sound_mode_list_none(hass):
|
||||||
"friendly_name": "Test media player",
|
"friendly_name": "Test media player",
|
||||||
"supported_features": SUPPORT_SELECT_SOUND_MODE,
|
"supported_features": SUPPORT_SELECT_SOUND_MODE,
|
||||||
"sound_mode": "unknown",
|
"sound_mode": "unknown",
|
||||||
"sound_mode_list": None,
|
"sound_mode_list": ["unsupported", "non-existing"],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
appliance = await discovery_test(device, hass)
|
appliance = await discovery_test(device, hass)
|
||||||
assert appliance["endpointId"] == "media_player#test"
|
assert appliance["endpointId"] == "media_player#test"
|
||||||
assert appliance["friendlyName"] == "Test media player"
|
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):
|
async def test_media_player_eq_bands_not_supported(hass):
|
||||||
"""Test EqualizerController bands directive not supported."""
|
"""Test EqualizerController bands directive not supported."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue