Add support for Alexa.StepSpeaker (#12183)
This commit is contained in:
parent
bdaf9cfae2
commit
e7a0759e1c
2 changed files with 63 additions and 0 deletions
|
@ -352,6 +352,11 @@ class _AlexaSpeaker(_AlexaInterface):
|
|||
return 'Alexa.Speaker'
|
||||
|
||||
|
||||
class _AlexaStepSpeaker(_AlexaInterface):
|
||||
def name(self):
|
||||
return 'Alexa.StepSpeaker'
|
||||
|
||||
|
||||
class _AlexaPlaybackController(_AlexaInterface):
|
||||
def name(self):
|
||||
return 'Alexa.PlaybackController'
|
||||
|
@ -472,6 +477,11 @@ class _MediaPlayerCapabilities(_AlexaEntity):
|
|||
if supported & media_player.SUPPORT_VOLUME_SET:
|
||||
yield _AlexaSpeaker(self.entity)
|
||||
|
||||
step_volume_features = (media_player.SUPPORT_VOLUME_MUTE |
|
||||
media_player.SUPPORT_VOLUME_STEP)
|
||||
if supported & step_volume_features:
|
||||
yield _AlexaStepSpeaker(self.entity)
|
||||
|
||||
playback_features = (media_player.SUPPORT_PLAY |
|
||||
media_player.SUPPORT_PAUSE |
|
||||
media_player.SUPPORT_STOP |
|
||||
|
@ -1153,6 +1163,30 @@ def async_api_adjust_volume(hass, config, request, entity):
|
|||
return api_message(request)
|
||||
|
||||
|
||||
@HANDLERS.register(('Alexa.StepSpeaker', 'AdjustVolume'))
|
||||
@extract_entity
|
||||
@asyncio.coroutine
|
||||
def async_api_adjust_volume_step(hass, config, request, entity):
|
||||
"""Process an adjust volume step request."""
|
||||
volume_step = round(float(request[API_PAYLOAD]['volume'] / 100), 2)
|
||||
|
||||
current_level = entity.attributes.get(media_player.ATTR_MEDIA_VOLUME_LEVEL)
|
||||
|
||||
volume = current_level + volume_step
|
||||
|
||||
data = {
|
||||
ATTR_ENTITY_ID: entity.entity_id,
|
||||
media_player.ATTR_MEDIA_VOLUME_LEVEL: volume,
|
||||
}
|
||||
|
||||
yield from hass.services.async_call(
|
||||
entity.domain, media_player.SERVICE_VOLUME_SET,
|
||||
data, blocking=False)
|
||||
|
||||
return api_message(request)
|
||||
|
||||
|
||||
@HANDLERS.register(('Alexa.StepSpeaker', 'SetMute'))
|
||||
@HANDLERS.register(('Alexa.Speaker', 'SetMute'))
|
||||
@extract_entity
|
||||
@asyncio.coroutine
|
||||
|
|
|
@ -429,6 +429,7 @@ def test_media_player(hass):
|
|||
'Alexa.InputController',
|
||||
'Alexa.PowerController',
|
||||
'Alexa.Speaker',
|
||||
'Alexa.StepSpeaker',
|
||||
'Alexa.PlaybackController',
|
||||
)
|
||||
|
||||
|
@ -492,6 +493,34 @@ def test_media_player(hass):
|
|||
'media_player.volume_set',
|
||||
'volume_level')
|
||||
|
||||
call, _ = yield from assert_request_calls_service(
|
||||
'Alexa.StepSpeaker', 'SetMute', 'media_player#test',
|
||||
'media_player.volume_mute',
|
||||
hass,
|
||||
payload={'mute': True})
|
||||
assert call.data['is_volume_muted']
|
||||
|
||||
call, _, = yield from assert_request_calls_service(
|
||||
'Alexa.StepSpeaker', 'SetMute', 'media_player#test',
|
||||
'media_player.volume_mute',
|
||||
hass,
|
||||
payload={'mute': False})
|
||||
assert not call.data['is_volume_muted']
|
||||
|
||||
call, _ = yield from assert_request_calls_service(
|
||||
'Alexa.StepSpeaker', 'AdjustVolume', 'media_player#test',
|
||||
'media_player.volume_set',
|
||||
hass,
|
||||
payload={'volume': 20})
|
||||
assert call.data['volume_level'] == 0.95
|
||||
|
||||
call, _ = yield from assert_request_calls_service(
|
||||
'Alexa.StepSpeaker', 'AdjustVolume', 'media_player#test',
|
||||
'media_player.volume_set',
|
||||
hass,
|
||||
payload={'volume': -20})
|
||||
assert call.data['volume_level'] == 0.55
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_alert(hass):
|
||||
|
|
Loading…
Add table
Reference in a new issue