mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Import media player constants at integration level for alexa smart home (#143767)
This commit is contained in:
parent
f94af84f2a
commit
7a0580eff5
@ -719,7 +719,7 @@ class LockCapabilities(AlexaEntity):
|
|||||||
yield Alexa(self.entity)
|
yield Alexa(self.entity)
|
||||||
|
|
||||||
|
|
||||||
@ENTITY_ADAPTERS.register(media_player.const.DOMAIN)
|
@ENTITY_ADAPTERS.register(media_player.DOMAIN)
|
||||||
class MediaPlayerCapabilities(AlexaEntity):
|
class MediaPlayerCapabilities(AlexaEntity):
|
||||||
"""Class to represent MediaPlayer capabilities."""
|
"""Class to represent MediaPlayer capabilities."""
|
||||||
|
|
||||||
@ -757,9 +757,7 @@ class MediaPlayerCapabilities(AlexaEntity):
|
|||||||
|
|
||||||
if supported & media_player.MediaPlayerEntityFeature.SELECT_SOURCE:
|
if supported & media_player.MediaPlayerEntityFeature.SELECT_SOURCE:
|
||||||
inputs = AlexaInputController.get_valid_inputs(
|
inputs = AlexaInputController.get_valid_inputs(
|
||||||
self.entity.attributes.get(
|
self.entity.attributes.get(media_player.ATTR_INPUT_SOURCE_LIST, [])
|
||||||
media_player.const.ATTR_INPUT_SOURCE_LIST, []
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
if len(inputs) > 0:
|
if len(inputs) > 0:
|
||||||
yield AlexaInputController(self.entity)
|
yield AlexaInputController(self.entity)
|
||||||
@ -776,8 +774,7 @@ class MediaPlayerCapabilities(AlexaEntity):
|
|||||||
and domain != "denonavr"
|
and domain != "denonavr"
|
||||||
):
|
):
|
||||||
inputs = AlexaEqualizerController.get_valid_inputs(
|
inputs = AlexaEqualizerController.get_valid_inputs(
|
||||||
self.entity.attributes.get(media_player.const.ATTR_SOUND_MODE_LIST)
|
self.entity.attributes.get(media_player.ATTR_SOUND_MODE_LIST) or []
|
||||||
or []
|
|
||||||
)
|
)
|
||||||
if len(inputs) > 0:
|
if len(inputs) > 0:
|
||||||
yield AlexaEqualizerController(self.entity)
|
yield AlexaEqualizerController(self.entity)
|
||||||
|
@ -566,7 +566,7 @@ async def async_api_set_volume(
|
|||||||
|
|
||||||
data: dict[str, Any] = {
|
data: dict[str, Any] = {
|
||||||
ATTR_ENTITY_ID: entity.entity_id,
|
ATTR_ENTITY_ID: entity.entity_id,
|
||||||
media_player.const.ATTR_MEDIA_VOLUME_LEVEL: volume,
|
media_player.ATTR_MEDIA_VOLUME_LEVEL: volume,
|
||||||
}
|
}
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
@ -589,7 +589,7 @@ async def async_api_select_input(
|
|||||||
|
|
||||||
# Attempt to map the ALL UPPERCASE payload name to a source.
|
# Attempt to map the ALL UPPERCASE payload name to a source.
|
||||||
# Strips trailing 1 to match single input devices.
|
# Strips trailing 1 to match single input devices.
|
||||||
source_list = entity.attributes.get(media_player.const.ATTR_INPUT_SOURCE_LIST) or []
|
source_list = entity.attributes.get(media_player.ATTR_INPUT_SOURCE_LIST) or []
|
||||||
for source in source_list:
|
for source in source_list:
|
||||||
formatted_source = (
|
formatted_source = (
|
||||||
source.lower().replace("-", "").replace("_", "").replace(" ", "")
|
source.lower().replace("-", "").replace("_", "").replace(" ", "")
|
||||||
@ -611,7 +611,7 @@ async def async_api_select_input(
|
|||||||
|
|
||||||
data: dict[str, Any] = {
|
data: dict[str, Any] = {
|
||||||
ATTR_ENTITY_ID: entity.entity_id,
|
ATTR_ENTITY_ID: entity.entity_id,
|
||||||
media_player.const.ATTR_INPUT_SOURCE: media_input,
|
media_player.ATTR_INPUT_SOURCE: media_input,
|
||||||
}
|
}
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
@ -636,7 +636,7 @@ async def async_api_adjust_volume(
|
|||||||
volume_delta = int(directive.payload["volume"])
|
volume_delta = int(directive.payload["volume"])
|
||||||
|
|
||||||
entity = directive.entity
|
entity = directive.entity
|
||||||
current_level = entity.attributes[media_player.const.ATTR_MEDIA_VOLUME_LEVEL]
|
current_level = entity.attributes[media_player.ATTR_MEDIA_VOLUME_LEVEL]
|
||||||
|
|
||||||
# read current state
|
# read current state
|
||||||
try:
|
try:
|
||||||
@ -648,7 +648,7 @@ async def async_api_adjust_volume(
|
|||||||
|
|
||||||
data: dict[str, Any] = {
|
data: dict[str, Any] = {
|
||||||
ATTR_ENTITY_ID: entity.entity_id,
|
ATTR_ENTITY_ID: entity.entity_id,
|
||||||
media_player.const.ATTR_MEDIA_VOLUME_LEVEL: volume,
|
media_player.ATTR_MEDIA_VOLUME_LEVEL: volume,
|
||||||
}
|
}
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
@ -709,7 +709,7 @@ async def async_api_set_mute(
|
|||||||
entity = directive.entity
|
entity = directive.entity
|
||||||
data: dict[str, Any] = {
|
data: dict[str, Any] = {
|
||||||
ATTR_ENTITY_ID: entity.entity_id,
|
ATTR_ENTITY_ID: entity.entity_id,
|
||||||
media_player.const.ATTR_MEDIA_VOLUME_MUTED: mute,
|
media_player.ATTR_MEDIA_VOLUME_MUTED: mute,
|
||||||
}
|
}
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
@ -1708,13 +1708,13 @@ async def async_api_changechannel(
|
|||||||
|
|
||||||
data: dict[str, Any] = {
|
data: dict[str, Any] = {
|
||||||
ATTR_ENTITY_ID: entity.entity_id,
|
ATTR_ENTITY_ID: entity.entity_id,
|
||||||
media_player.const.ATTR_MEDIA_CONTENT_ID: channel,
|
media_player.ATTR_MEDIA_CONTENT_ID: channel,
|
||||||
media_player.const.ATTR_MEDIA_CONTENT_TYPE: media_player.MediaType.CHANNEL,
|
media_player.ATTR_MEDIA_CONTENT_TYPE: (media_player.MediaType.CHANNEL),
|
||||||
}
|
}
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
entity.domain,
|
entity.domain,
|
||||||
media_player.const.SERVICE_PLAY_MEDIA,
|
media_player.SERVICE_PLAY_MEDIA,
|
||||||
data,
|
data,
|
||||||
blocking=False,
|
blocking=False,
|
||||||
context=context,
|
context=context,
|
||||||
@ -1823,13 +1823,13 @@ async def async_api_set_eq_mode(
|
|||||||
context: ha.Context,
|
context: ha.Context,
|
||||||
) -> AlexaResponse:
|
) -> AlexaResponse:
|
||||||
"""Process a SetMode request for EqualizerController."""
|
"""Process a SetMode request for EqualizerController."""
|
||||||
mode = directive.payload["mode"]
|
mode: str = directive.payload["mode"]
|
||||||
entity = directive.entity
|
entity = directive.entity
|
||||||
data: dict[str, Any] = {ATTR_ENTITY_ID: entity.entity_id}
|
data: dict[str, Any] = {ATTR_ENTITY_ID: entity.entity_id}
|
||||||
|
|
||||||
sound_mode_list = entity.attributes.get(media_player.const.ATTR_SOUND_MODE_LIST)
|
sound_mode_list = entity.attributes.get(media_player.ATTR_SOUND_MODE_LIST)
|
||||||
if sound_mode_list and mode.lower() in sound_mode_list:
|
if sound_mode_list and mode.lower() in sound_mode_list:
|
||||||
data[media_player.const.ATTR_SOUND_MODE] = mode.lower()
|
data[media_player.ATTR_SOUND_MODE] = mode.lower()
|
||||||
else:
|
else:
|
||||||
msg = f"failed to map sound mode {mode} to a mode on {entity.entity_id}"
|
msg = f"failed to map sound mode {mode} to a mode on {entity.entity_id}"
|
||||||
raise AlexaInvalidValueError(msg)
|
raise AlexaInvalidValueError(msg)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user