Add previous track intent (#113222)
* add previous track intent * add stop and clear playlist * Remove clear_playlist and stop * Remove clear_playlist and stop * Use extra constraints --------- Co-authored-by: Michael Hansen <mike@rhasspy.org>
This commit is contained in:
parent
440185be25
commit
aa121ebf73
2 changed files with 69 additions and 0 deletions
|
@ -7,6 +7,7 @@ from homeassistant.components.media_player import (
|
|||
SERVICE_MEDIA_NEXT_TRACK,
|
||||
SERVICE_MEDIA_PAUSE,
|
||||
SERVICE_MEDIA_PLAY,
|
||||
SERVICE_MEDIA_PREVIOUS_TRACK,
|
||||
SERVICE_VOLUME_SET,
|
||||
intent as media_player_intent,
|
||||
)
|
||||
|
@ -173,6 +174,59 @@ async def test_next_media_player_intent(hass: HomeAssistant) -> None:
|
|||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def test_previous_media_player_intent(hass: HomeAssistant) -> None:
|
||||
"""Test HassMediaPrevious intent for media players."""
|
||||
await media_player_intent.async_setup_intents(hass)
|
||||
|
||||
entity_id = f"{DOMAIN}.test_media_player"
|
||||
attributes = {ATTR_SUPPORTED_FEATURES: MediaPlayerEntityFeature.PREVIOUS_TRACK}
|
||||
|
||||
hass.states.async_set(entity_id, STATE_PLAYING, attributes=attributes)
|
||||
|
||||
calls = async_mock_service(hass, DOMAIN, SERVICE_MEDIA_PREVIOUS_TRACK)
|
||||
|
||||
response = await intent.async_handle(
|
||||
hass,
|
||||
"test",
|
||||
media_player_intent.INTENT_MEDIA_PREVIOUS,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert response.response_type == intent.IntentResponseType.ACTION_DONE
|
||||
assert len(calls) == 1
|
||||
call = calls[0]
|
||||
assert call.domain == DOMAIN
|
||||
assert call.service == SERVICE_MEDIA_PREVIOUS_TRACK
|
||||
assert call.data == {"entity_id": entity_id}
|
||||
|
||||
# Test if not playing
|
||||
hass.states.async_set(entity_id, STATE_IDLE, attributes=attributes)
|
||||
|
||||
with pytest.raises(intent.MatchFailedError):
|
||||
response = await intent.async_handle(
|
||||
hass,
|
||||
"test",
|
||||
media_player_intent.INTENT_MEDIA_PREVIOUS,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Test feature not supported
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
STATE_PLAYING,
|
||||
attributes={ATTR_SUPPORTED_FEATURES: MediaPlayerEntityFeature(0)},
|
||||
)
|
||||
|
||||
with pytest.raises(intent.MatchFailedError):
|
||||
response = await intent.async_handle(
|
||||
hass,
|
||||
"test",
|
||||
media_player_intent.INTENT_MEDIA_PREVIOUS,
|
||||
{"name": {"value": "test media player"}},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def test_volume_media_player_intent(hass: HomeAssistant) -> None:
|
||||
"""Test HassSetVolume intent for media players."""
|
||||
await media_player_intent.async_setup_intents(hass)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue