Add new intents for cover, valve, vacuum, and media player (#110757)
* Add valve to HassTurnOn/Off * Add set position for valves * Add set position to covers * Add HassTurnOn/Off for vacuums * Add media player intents * Split out vacuum intents * Address comments * Extra test
This commit is contained in:
parent
015f9cdb35
commit
ec4bd9a421
11 changed files with 510 additions and 28 deletions
|
@ -1,9 +1,14 @@
|
|||
"""The tests for the cover platform."""
|
||||
|
||||
from homeassistant.components.cover import (
|
||||
ATTR_CURRENT_POSITION,
|
||||
DOMAIN,
|
||||
SERVICE_CLOSE_COVER,
|
||||
SERVICE_OPEN_COVER,
|
||||
SERVICE_SET_COVER_POSITION,
|
||||
intent as cover_intent,
|
||||
)
|
||||
from homeassistant.const import STATE_CLOSED, STATE_OPEN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import intent
|
||||
|
||||
|
@ -14,37 +19,66 @@ async def test_open_cover_intent(hass: HomeAssistant) -> None:
|
|||
"""Test HassOpenCover intent."""
|
||||
await cover_intent.async_setup_intents(hass)
|
||||
|
||||
hass.states.async_set("cover.garage_door", "closed")
|
||||
calls = async_mock_service(hass, "cover", SERVICE_OPEN_COVER)
|
||||
hass.states.async_set(f"{DOMAIN}.garage_door", STATE_CLOSED)
|
||||
calls = async_mock_service(hass, DOMAIN, SERVICE_OPEN_COVER)
|
||||
|
||||
response = await intent.async_handle(
|
||||
hass, "test", "HassOpenCover", {"name": {"value": "garage door"}}
|
||||
hass, "test", cover_intent.INTENT_OPEN_COVER, {"name": {"value": "garage door"}}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert response.speech["plain"]["speech"] == "Opened garage door"
|
||||
assert len(calls) == 1
|
||||
call = calls[0]
|
||||
assert call.domain == "cover"
|
||||
assert call.service == "open_cover"
|
||||
assert call.data == {"entity_id": "cover.garage_door"}
|
||||
assert call.domain == DOMAIN
|
||||
assert call.service == SERVICE_OPEN_COVER
|
||||
assert call.data == {"entity_id": f"{DOMAIN}.garage_door"}
|
||||
|
||||
|
||||
async def test_close_cover_intent(hass: HomeAssistant) -> None:
|
||||
"""Test HassCloseCover intent."""
|
||||
await cover_intent.async_setup_intents(hass)
|
||||
|
||||
hass.states.async_set("cover.garage_door", "open")
|
||||
calls = async_mock_service(hass, "cover", SERVICE_CLOSE_COVER)
|
||||
hass.states.async_set(f"{DOMAIN}.garage_door", STATE_OPEN)
|
||||
calls = async_mock_service(hass, DOMAIN, SERVICE_CLOSE_COVER)
|
||||
|
||||
response = await intent.async_handle(
|
||||
hass, "test", "HassCloseCover", {"name": {"value": "garage door"}}
|
||||
hass,
|
||||
"test",
|
||||
cover_intent.INTENT_CLOSE_COVER,
|
||||
{"name": {"value": "garage door"}},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert response.speech["plain"]["speech"] == "Closed garage door"
|
||||
assert len(calls) == 1
|
||||
call = calls[0]
|
||||
assert call.domain == "cover"
|
||||
assert call.service == "close_cover"
|
||||
assert call.data == {"entity_id": "cover.garage_door"}
|
||||
assert call.domain == DOMAIN
|
||||
assert call.service == SERVICE_CLOSE_COVER
|
||||
assert call.data == {"entity_id": f"{DOMAIN}.garage_door"}
|
||||
|
||||
|
||||
async def test_set_cover_position(hass: HomeAssistant) -> None:
|
||||
"""Test HassSetPosition intent for covers."""
|
||||
await cover_intent.async_setup_intents(hass)
|
||||
|
||||
entity_id = f"{DOMAIN}.test_cover"
|
||||
hass.states.async_set(
|
||||
entity_id, STATE_CLOSED, attributes={ATTR_CURRENT_POSITION: 0}
|
||||
)
|
||||
calls = async_mock_service(hass, DOMAIN, SERVICE_SET_COVER_POSITION)
|
||||
|
||||
response = await intent.async_handle(
|
||||
hass,
|
||||
"test",
|
||||
intent.INTENT_SET_POSITION,
|
||||
{"name": {"value": "test cover"}, "position": {"value": 50}},
|
||||
)
|
||||
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_SET_COVER_POSITION
|
||||
assert call.data == {"entity_id": entity_id, "position": 50}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue