|
1 | 1 | """Tests for Intent component.""" |
2 | 2 |
|
| 3 | +from typing import Any |
| 4 | + |
3 | 5 | import pytest |
4 | 6 |
|
5 | 7 | from homeassistant.components.button import SERVICE_PRESS |
6 | | -from homeassistant.components.cover import SERVICE_CLOSE_COVER, SERVICE_OPEN_COVER |
| 8 | +from homeassistant.components.cover import ( |
| 9 | + DOMAIN as COVER_DOMAIN, |
| 10 | + SERVICE_CLOSE_COVER, |
| 11 | + SERVICE_OPEN_COVER, |
| 12 | + SERVICE_STOP_COVER, |
| 13 | + CoverState, |
| 14 | +) |
7 | 15 | from homeassistant.components.lock import SERVICE_LOCK, SERVICE_UNLOCK |
8 | | -from homeassistant.components.valve import SERVICE_CLOSE_VALVE, SERVICE_OPEN_VALVE |
| 16 | +from homeassistant.components.valve import ( |
| 17 | + DOMAIN as VALVE_DOMAIN, |
| 18 | + SERVICE_CLOSE_VALVE, |
| 19 | + SERVICE_OPEN_VALVE, |
| 20 | + SERVICE_STOP_VALVE, |
| 21 | + ValveState, |
| 22 | +) |
9 | 23 | from homeassistant.const import ( |
10 | 24 | ATTR_DEVICE_CLASS, |
11 | 25 | ATTR_FRIENDLY_NAME, |
@@ -594,3 +608,66 @@ async def test_intents_respond_intent(hass: HomeAssistant) -> None: |
594 | 608 | hass, "test", intent.INTENT_RESPOND, {"response": {"value": "Hello World"}} |
595 | 609 | ) |
596 | 610 | assert response.speech["plain"]["speech"] == "Hello World" |
| 611 | + |
| 612 | + |
| 613 | +async def test_stop_moving_valve(hass: HomeAssistant) -> None: |
| 614 | + """Test HassStopMoving intent for valves.""" |
| 615 | + assert await async_setup_component(hass, "intent", {}) |
| 616 | + |
| 617 | + entity_id = f"{VALVE_DOMAIN}.test_valve" |
| 618 | + hass.states.async_set(entity_id, ValveState.OPEN) |
| 619 | + calls = async_mock_service(hass, VALVE_DOMAIN, SERVICE_STOP_VALVE) |
| 620 | + |
| 621 | + response = await intent.async_handle( |
| 622 | + hass, "test", intent.INTENT_STOP_MOVING, {"name": {"value": "test valve"}} |
| 623 | + ) |
| 624 | + await hass.async_block_till_done() |
| 625 | + |
| 626 | + assert response.response_type == intent.IntentResponseType.ACTION_DONE |
| 627 | + assert len(calls) == 1 |
| 628 | + call = calls[0] |
| 629 | + assert call.domain == VALVE_DOMAIN |
| 630 | + assert call.service == SERVICE_STOP_VALVE |
| 631 | + assert call.data == {"entity_id": entity_id} |
| 632 | + |
| 633 | + |
| 634 | +@pytest.mark.parametrize( |
| 635 | + ("slots"), |
| 636 | + [ |
| 637 | + ({"name": {"value": "test cover"}}), |
| 638 | + ({"device_class": {"value": "shade"}}), |
| 639 | + ], |
| 640 | +) |
| 641 | +async def test_stop_moving_cover(hass: HomeAssistant, slots: dict[str, Any]) -> None: |
| 642 | + """Test HassStopMoving intent for covers.""" |
| 643 | + assert await async_setup_component(hass, "intent", {}) |
| 644 | + |
| 645 | + entity_id = f"{COVER_DOMAIN}.test_cover" |
| 646 | + hass.states.async_set( |
| 647 | + entity_id, CoverState.OPEN, attributes={"device_class": "shade"} |
| 648 | + ) |
| 649 | + calls = async_mock_service(hass, COVER_DOMAIN, SERVICE_STOP_COVER) |
| 650 | + |
| 651 | + response = await intent.async_handle(hass, "test", intent.INTENT_STOP_MOVING, slots) |
| 652 | + await hass.async_block_till_done() |
| 653 | + |
| 654 | + assert response.response_type == intent.IntentResponseType.ACTION_DONE |
| 655 | + assert len(calls) == 1 |
| 656 | + call = calls[0] |
| 657 | + assert call.domain == COVER_DOMAIN |
| 658 | + assert call.service == SERVICE_STOP_COVER |
| 659 | + assert call.data == {"entity_id": entity_id} |
| 660 | + |
| 661 | + |
| 662 | +async def test_stop_moving_intent_unsupported_domain(hass: HomeAssistant) -> None: |
| 663 | + """Test that HassStopMoving intent fails with unsupported domain.""" |
| 664 | + assert await async_setup_component(hass, "homeassistant", {}) |
| 665 | + assert await async_setup_component(hass, "intent", {}) |
| 666 | + |
| 667 | + # Can't stop lights |
| 668 | + hass.states.async_set("light.test_light", "on") |
| 669 | + |
| 670 | + with pytest.raises(intent.IntentHandleError): |
| 671 | + await intent.async_handle( |
| 672 | + hass, "test", intent.INTENT_STOP_MOVING, {"name": {"value": "test light"}} |
| 673 | + ) |
0 commit comments