mirror of
https://github.com/home-assistant/core.git
synced 2025-07-30 02:38:10 +02:00
Add start and docker intents for lawn mower
This commit is contained in:
35
homeassistant/components/lawn_mower/intent.py
Normal file
35
homeassistant/components/lawn_mower/intent.py
Normal file
@ -0,0 +1,35 @@
|
||||
"""Intents for the lawn mower integration."""
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import intent
|
||||
|
||||
from . import DOMAIN, SERVICE_DOCK, SERVICE_START_MOWING
|
||||
|
||||
INTENT_LANW_MOWER_START_MOWING = "HassLawnMowerStartMowing"
|
||||
INTENT_LANW_MOWER_DOCK = "HassLawnMowerDock"
|
||||
|
||||
|
||||
async def async_setup_intents(hass: HomeAssistant) -> None:
|
||||
"""Set up the lawn mower intents."""
|
||||
intent.async_register(
|
||||
hass,
|
||||
intent.ServiceIntentHandler(
|
||||
INTENT_LANW_MOWER_START_MOWING,
|
||||
DOMAIN,
|
||||
SERVICE_START_MOWING,
|
||||
description="Starts a lawn mower",
|
||||
required_domains={DOMAIN},
|
||||
platforms={DOMAIN},
|
||||
),
|
||||
)
|
||||
intent.async_register(
|
||||
hass,
|
||||
intent.ServiceIntentHandler(
|
||||
INTENT_LANW_MOWER_DOCK,
|
||||
DOMAIN,
|
||||
SERVICE_DOCK,
|
||||
description="Sends a lawn mower to dock",
|
||||
required_domains={DOMAIN},
|
||||
platforms={DOMAIN},
|
||||
),
|
||||
)
|
103
tests/components/lawn_mower/test_intent.py
Normal file
103
tests/components/lawn_mower/test_intent.py
Normal file
@ -0,0 +1,103 @@
|
||||
"""The tests for the lawn mower platform."""
|
||||
|
||||
from homeassistant.components.lawn_mower import (
|
||||
DOMAIN,
|
||||
SERVICE_DOCK,
|
||||
SERVICE_START_MOWING,
|
||||
LawnMowerActivity,
|
||||
intent as lawn_mower_intent,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import intent
|
||||
|
||||
from tests.common import async_mock_service
|
||||
|
||||
|
||||
async def test_start_lawn_mower_intent(hass: HomeAssistant) -> None:
|
||||
"""Test HassLawnMowerStartMowing intent for lawn mowers."""
|
||||
await lawn_mower_intent.async_setup_intents(hass)
|
||||
|
||||
entity_id = f"{DOMAIN}.test_lawn_mower"
|
||||
hass.states.async_set(entity_id, LawnMowerActivity.DOCKED)
|
||||
calls = async_mock_service(hass, DOMAIN, SERVICE_START_MOWING)
|
||||
|
||||
response = await intent.async_handle(
|
||||
hass,
|
||||
"test",
|
||||
lawn_mower_intent.INTENT_LANW_MOWER_START_MOWING,
|
||||
{"name": {"value": "test lawn mower"}},
|
||||
)
|
||||
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_START_MOWING
|
||||
assert call.data == {"entity_id": entity_id}
|
||||
|
||||
|
||||
async def test_start_lawn_mower_without_name(hass: HomeAssistant) -> None:
|
||||
"""Test starting a lawn mower without specifying the name."""
|
||||
await lawn_mower_intent.async_setup_intents(hass)
|
||||
|
||||
entity_id = f"{DOMAIN}.test_lawn_mower"
|
||||
hass.states.async_set(entity_id, LawnMowerActivity.DOCKED)
|
||||
calls = async_mock_service(hass, DOMAIN, SERVICE_START_MOWING)
|
||||
|
||||
response = await intent.async_handle(
|
||||
hass, "test", lawn_mower_intent.INTENT_LANW_MOWER_START_MOWING, {}
|
||||
)
|
||||
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_START_MOWING
|
||||
assert call.data == {"entity_id": entity_id}
|
||||
|
||||
|
||||
async def test_stop_lawn_mower_intent(hass: HomeAssistant) -> None:
|
||||
"""Test HassLawnMowerDock intent for lawn mowers."""
|
||||
await lawn_mower_intent.async_setup_intents(hass)
|
||||
|
||||
entity_id = f"{DOMAIN}.test_lawn_mower"
|
||||
hass.states.async_set(entity_id, LawnMowerActivity.MOWING)
|
||||
calls = async_mock_service(hass, DOMAIN, SERVICE_DOCK)
|
||||
|
||||
response = await intent.async_handle(
|
||||
hass,
|
||||
"test",
|
||||
lawn_mower_intent.INTENT_LANW_MOWER_DOCK,
|
||||
{"name": {"value": "test lawn mower"}},
|
||||
)
|
||||
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_DOCK
|
||||
assert call.data == {"entity_id": entity_id}
|
||||
|
||||
|
||||
async def test_stop_lawn_mower_without_name(hass: HomeAssistant) -> None:
|
||||
"""Test stopping a lawn mower without specifying the name."""
|
||||
await lawn_mower_intent.async_setup_intents(hass)
|
||||
|
||||
entity_id = f"{DOMAIN}.test_lawn_mower"
|
||||
hass.states.async_set(entity_id, LawnMowerActivity.MOWING)
|
||||
calls = async_mock_service(hass, DOMAIN, SERVICE_DOCK)
|
||||
|
||||
response = await intent.async_handle(
|
||||
hass, "test", lawn_mower_intent.INTENT_LANW_MOWER_DOCK, {}
|
||||
)
|
||||
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_DOCK
|
||||
assert call.data == {"entity_id": entity_id}
|
Reference in New Issue
Block a user