Add support for supportedOperations to Alexa.PlaybackController (#28212)

* Added support for supportedOperations to Alexa.PlaybackController

* Added support for supportedOperations to Alexa.PlaybackController
pull/28063/head
ochlocracy 2019-10-25 16:34:52 -04:00 committed by Paulus Schoutsen
parent f2d6cc7329
commit da8a476142
2 changed files with 40 additions and 1 deletions

View File

@ -17,6 +17,7 @@ from homeassistant.const import (
STATE_UNKNOWN,
)
import homeassistant.components.climate.const as climate
import homeassistant.components.media_player.const as media_player
from homeassistant.components.alarm_control_panel import ATTR_CODE_FORMAT, FORMAT_NUMBER
from homeassistant.components import light, fan, cover
import homeassistant.util.color as color_util
@ -110,6 +111,11 @@ class AlexaCapability:
"""Return the Configuration object."""
return []
@staticmethod
def supported_operations():
"""Return the supportedOperations object."""
return []
def serialize_discovery(self):
"""Serialize according to the Discovery API."""
result = {"type": "AlexaInterface", "interface": self.name(), "version": "3"}
@ -150,6 +156,10 @@ class AlexaCapability:
if instance is not None:
result["instance"] = instance
supported_operations = self.supported_operations()
if supported_operations:
result["supportedOperations"] = supported_operations
return result
def serialize_properties(self):
@ -484,6 +494,28 @@ class AlexaPlaybackController(AlexaCapability):
"""Return the Alexa API name of this interface."""
return "Alexa.PlaybackController"
def supported_operations(self):
"""Return the supportedOperations object.
Supported Operations: FastForward, Next, Pause, Play, Previous, Rewind, StartOver, Stop
"""
supported_features = self.entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
operations = {
media_player.SUPPORT_NEXT_TRACK: "Next",
media_player.SUPPORT_PAUSE: "Pause",
media_player.SUPPORT_PLAY: "Play",
media_player.SUPPORT_PREVIOUS_TRACK: "Previous",
media_player.SUPPORT_STOP: "Stop",
}
supported_operations = []
for operation in operations:
if operation & supported_features:
supported_operations.append(operations[operation])
return supported_operations
class AlexaInputController(AlexaCapability):
"""Implements Alexa.InputController.

View File

@ -726,7 +726,7 @@ async def test_media_player(hass):
assert appliance["displayCategories"][0] == "TV"
assert appliance["friendlyName"] == "Test media player"
assert_endpoint_capabilities(
capabilities = assert_endpoint_capabilities(
appliance,
"Alexa.InputController",
"Alexa.PowerController",
@ -737,6 +737,13 @@ async def test_media_player(hass):
"Alexa.ChannelController",
)
playback_capability = get_capability(capabilities, "Alexa.PlaybackController")
assert playback_capability is not None
supported_operations = playback_capability["supportedOperations"]
operations = ["Play", "Pause", "Stop", "Next", "Previous"]
for operation in operations:
assert operation in supported_operations
await assert_power_controller_works(
"media_player#test", "media_player.turn_on", "media_player.turn_off", hass
)