Fix powercontrol media player alexa (#25080)
This commit is contained in:
parent
53a701b12c
commit
53111f6426
3 changed files with 38 additions and 38 deletions
|
@ -339,16 +339,12 @@ class MediaPlayerCapabilities(AlexaEntity):
|
|||
def interfaces(self):
|
||||
"""Yield the supported interfaces."""
|
||||
yield AlexaEndpointHealth(self.hass, self.entity)
|
||||
yield AlexaPowerController(self.entity)
|
||||
|
||||
supported = self.entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
|
||||
if supported & media_player.const.SUPPORT_VOLUME_SET:
|
||||
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 |
|
||||
media_player.const.SUPPORT_VOLUME_STEP)
|
||||
if supported & step_volume_features:
|
||||
|
|
|
@ -4,45 +4,26 @@ import logging
|
|||
import math
|
||||
|
||||
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.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 .const import (
|
||||
API_TEMP_UNITS,
|
||||
API_THERMOSTAT_MODES,
|
||||
API_THERMOSTAT_PRESETS,
|
||||
Cause,
|
||||
)
|
||||
API_TEMP_UNITS, API_THERMOSTAT_MODES, API_THERMOSTAT_PRESETS, Cause)
|
||||
from .entities import async_get_entities
|
||||
from .state_report import async_enable_proactive_mode
|
||||
from .errors import (
|
||||
AlexaInvalidValueError,
|
||||
AlexaTempRangeError,
|
||||
AlexaUnsupportedThermostatModeError,
|
||||
)
|
||||
AlexaInvalidValueError, AlexaTempRangeError,
|
||||
AlexaUnsupportedThermostatModeError)
|
||||
from .state_report import async_enable_proactive_mode
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
HANDLERS = Registry()
|
||||
|
@ -99,6 +80,12 @@ async def async_api_turn_on(hass, config, directive, context):
|
|||
service = SERVICE_TURN_ON
|
||||
if domain == cover.DOMAIN:
|
||||
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, {
|
||||
ATTR_ENTITY_ID: entity.entity_id
|
||||
|
@ -118,6 +105,12 @@ async def async_api_turn_off(hass, config, directive, context):
|
|||
service = SERVICE_TURN_OFF
|
||||
if entity.domain == cover.DOMAIN:
|
||||
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, {
|
||||
ATTR_ENTITY_ID: entity.entity_id
|
||||
|
|
|
@ -558,12 +558,23 @@ async def test_media_player_power(hass):
|
|||
assert_endpoint_capabilities(
|
||||
appliance,
|
||||
'Alexa.InputController',
|
||||
'Alexa.PowerController',
|
||||
'Alexa.Speaker',
|
||||
'Alexa.StepSpeaker',
|
||||
'Alexa.PlaybackController',
|
||||
'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):
|
||||
"""Test alert discovery."""
|
||||
|
|
Loading…
Add table
Reference in a new issue