mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Fix powercontrol media player alexa (#25080)
This commit is contained in:
parent
04b4284746
commit
78a5dc71ac
@ -339,16 +339,12 @@ class MediaPlayerCapabilities(AlexaEntity):
|
|||||||
def interfaces(self):
|
def interfaces(self):
|
||||||
"""Yield the supported interfaces."""
|
"""Yield the supported interfaces."""
|
||||||
yield AlexaEndpointHealth(self.hass, self.entity)
|
yield AlexaEndpointHealth(self.hass, self.entity)
|
||||||
|
yield AlexaPowerController(self.entity)
|
||||||
|
|
||||||
supported = self.entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
|
supported = self.entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
|
||||||
if supported & media_player.const.SUPPORT_VOLUME_SET:
|
if supported & media_player.const.SUPPORT_VOLUME_SET:
|
||||||
yield AlexaSpeaker(self.entity)
|
yield AlexaSpeaker(self.entity)
|
||||||
|
|
||||||
power_features = (media_player.SUPPORT_TURN_ON |
|
|
||||||
media_player.SUPPORT_TURN_OFF)
|
|
||||||
if supported & power_features:
|
|
||||||
yield AlexaPowerController(self.entity)
|
|
||||||
|
|
||||||
step_volume_features = (media_player.const.SUPPORT_VOLUME_MUTE |
|
step_volume_features = (media_player.const.SUPPORT_VOLUME_MUTE |
|
||||||
media_player.const.SUPPORT_VOLUME_STEP)
|
media_player.const.SUPPORT_VOLUME_STEP)
|
||||||
if supported & step_volume_features:
|
if supported & step_volume_features:
|
||||||
|
@ -4,45 +4,26 @@ import logging
|
|||||||
import math
|
import math
|
||||||
|
|
||||||
from homeassistant import core as ha
|
from homeassistant import core as ha
|
||||||
from homeassistant.util.decorator import Registry
|
|
||||||
import homeassistant.util.color as color_util
|
|
||||||
from homeassistant.const import (
|
|
||||||
ATTR_ENTITY_ID,
|
|
||||||
ATTR_TEMPERATURE,
|
|
||||||
SERVICE_LOCK,
|
|
||||||
SERVICE_MEDIA_NEXT_TRACK,
|
|
||||||
SERVICE_MEDIA_PAUSE,
|
|
||||||
SERVICE_MEDIA_PLAY,
|
|
||||||
SERVICE_MEDIA_PREVIOUS_TRACK,
|
|
||||||
SERVICE_MEDIA_STOP,
|
|
||||||
SERVICE_SET_COVER_POSITION,
|
|
||||||
SERVICE_TURN_OFF,
|
|
||||||
SERVICE_TURN_ON,
|
|
||||||
SERVICE_UNLOCK,
|
|
||||||
SERVICE_VOLUME_DOWN,
|
|
||||||
SERVICE_VOLUME_MUTE,
|
|
||||||
SERVICE_VOLUME_SET,
|
|
||||||
SERVICE_VOLUME_UP,
|
|
||||||
TEMP_CELSIUS,
|
|
||||||
TEMP_FAHRENHEIT,
|
|
||||||
)
|
|
||||||
from homeassistant.components.climate import const as climate
|
|
||||||
from homeassistant.components import cover, fan, group, light, media_player
|
from homeassistant.components import cover, fan, group, light, media_player
|
||||||
|
from homeassistant.components.climate import const as climate
|
||||||
|
from homeassistant.const import (
|
||||||
|
ATTR_ENTITY_ID, ATTR_SUPPORTED_FEATURES, ATTR_TEMPERATURE, SERVICE_LOCK,
|
||||||
|
SERVICE_MEDIA_NEXT_TRACK, SERVICE_MEDIA_PAUSE, SERVICE_MEDIA_PLAY,
|
||||||
|
SERVICE_MEDIA_PREVIOUS_TRACK, SERVICE_MEDIA_STOP,
|
||||||
|
SERVICE_SET_COVER_POSITION, SERVICE_TURN_OFF, SERVICE_TURN_ON,
|
||||||
|
SERVICE_UNLOCK, SERVICE_VOLUME_DOWN, SERVICE_VOLUME_MUTE,
|
||||||
|
SERVICE_VOLUME_SET, SERVICE_VOLUME_UP, TEMP_CELSIUS, TEMP_FAHRENHEIT)
|
||||||
|
import homeassistant.util.color as color_util
|
||||||
|
from homeassistant.util.decorator import Registry
|
||||||
from homeassistant.util.temperature import convert as convert_temperature
|
from homeassistant.util.temperature import convert as convert_temperature
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
API_TEMP_UNITS,
|
API_TEMP_UNITS, API_THERMOSTAT_MODES, API_THERMOSTAT_PRESETS, Cause)
|
||||||
API_THERMOSTAT_MODES,
|
|
||||||
API_THERMOSTAT_PRESETS,
|
|
||||||
Cause,
|
|
||||||
)
|
|
||||||
from .entities import async_get_entities
|
from .entities import async_get_entities
|
||||||
from .state_report import async_enable_proactive_mode
|
|
||||||
from .errors import (
|
from .errors import (
|
||||||
AlexaInvalidValueError,
|
AlexaInvalidValueError, AlexaTempRangeError,
|
||||||
AlexaTempRangeError,
|
AlexaUnsupportedThermostatModeError)
|
||||||
AlexaUnsupportedThermostatModeError,
|
from .state_report import async_enable_proactive_mode
|
||||||
)
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
HANDLERS = Registry()
|
HANDLERS = Registry()
|
||||||
@ -99,6 +80,12 @@ async def async_api_turn_on(hass, config, directive, context):
|
|||||||
service = SERVICE_TURN_ON
|
service = SERVICE_TURN_ON
|
||||||
if domain == cover.DOMAIN:
|
if domain == cover.DOMAIN:
|
||||||
service = cover.SERVICE_OPEN_COVER
|
service = cover.SERVICE_OPEN_COVER
|
||||||
|
elif domain == media_player.DOMAIN:
|
||||||
|
supported = entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
|
||||||
|
power_features = (media_player.SUPPORT_TURN_ON |
|
||||||
|
media_player.SUPPORT_TURN_OFF)
|
||||||
|
if not supported & power_features:
|
||||||
|
service = media_player.SERVICE_MEDIA_PLAY
|
||||||
|
|
||||||
await hass.services.async_call(domain, service, {
|
await hass.services.async_call(domain, service, {
|
||||||
ATTR_ENTITY_ID: entity.entity_id
|
ATTR_ENTITY_ID: entity.entity_id
|
||||||
@ -118,6 +105,12 @@ async def async_api_turn_off(hass, config, directive, context):
|
|||||||
service = SERVICE_TURN_OFF
|
service = SERVICE_TURN_OFF
|
||||||
if entity.domain == cover.DOMAIN:
|
if entity.domain == cover.DOMAIN:
|
||||||
service = cover.SERVICE_CLOSE_COVER
|
service = cover.SERVICE_CLOSE_COVER
|
||||||
|
elif domain == media_player.DOMAIN:
|
||||||
|
supported = entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
|
||||||
|
power_features = (media_player.SUPPORT_TURN_ON |
|
||||||
|
media_player.SUPPORT_TURN_OFF)
|
||||||
|
if not supported & power_features:
|
||||||
|
service = media_player.SERVICE_MEDIA_STOP
|
||||||
|
|
||||||
await hass.services.async_call(domain, service, {
|
await hass.services.async_call(domain, service, {
|
||||||
ATTR_ENTITY_ID: entity.entity_id
|
ATTR_ENTITY_ID: entity.entity_id
|
||||||
|
@ -558,12 +558,23 @@ async def test_media_player_power(hass):
|
|||||||
assert_endpoint_capabilities(
|
assert_endpoint_capabilities(
|
||||||
appliance,
|
appliance,
|
||||||
'Alexa.InputController',
|
'Alexa.InputController',
|
||||||
|
'Alexa.PowerController',
|
||||||
'Alexa.Speaker',
|
'Alexa.Speaker',
|
||||||
'Alexa.StepSpeaker',
|
'Alexa.StepSpeaker',
|
||||||
'Alexa.PlaybackController',
|
'Alexa.PlaybackController',
|
||||||
'Alexa.EndpointHealth',
|
'Alexa.EndpointHealth',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await assert_request_calls_service(
|
||||||
|
'Alexa.PowerController', 'TurnOn', 'media_player#test',
|
||||||
|
'media_player.media_play',
|
||||||
|
hass)
|
||||||
|
|
||||||
|
await assert_request_calls_service(
|
||||||
|
'Alexa.PowerController', 'TurnOff', 'media_player#test',
|
||||||
|
'media_player.media_stop',
|
||||||
|
hass)
|
||||||
|
|
||||||
|
|
||||||
async def test_alert(hass):
|
async def test_alert(hass):
|
||||||
"""Test alert discovery."""
|
"""Test alert discovery."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user