Clean up core services (#31509)

* Clean up core services

* Fix conversation test
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2020-02-08 13:10:59 +01:00
1 parent 57ab30d534
commit 111050bea9
7 files changed
+222 -121

No files matched your search

+94
View File
@@ -2,6 +2,7 @@
import pytest
from homeassistant.components.cover import SERVICE_OPEN_COVER
from homeassistant.const import SERVICE_TOGGLE, SERVICE_TURN_OFF, SERVICE_TURN_ON
from homeassistant.helpers import intent
from homeassistant.setup import async_setup_component
@@ -74,3 +75,96 @@ async def test_cover_intents_loading(hass):
assert call.domain == "cover"
assert call.service == "open_cover"
assert call.data == {"entity_id": "cover.garage_door"}
async def test_turn_on_intent(hass):
"""Test HassTurnOn intent."""
result = await async_setup_component(hass, "homeassistant", {})
result = await async_setup_component(hass, "intent", {})
assert result
hass.states.async_set("light.test_light", "off")
calls = async_mock_service(hass, "light", SERVICE_TURN_ON)
response = await intent.async_handle(
hass, "test", "HassTurnOn", {"name": {"value": "test light"}}
)
await hass.async_block_till_done()
assert response.speech["plain"]["speech"] == "Turned test light on"
assert len(calls) == 1
call = calls[0]
assert call.domain == "light"
assert call.service == "turn_on"
assert call.data == {"entity_id": ["light.test_light"]}
async def test_turn_off_intent(hass):
"""Test HassTurnOff intent."""
result = await async_setup_component(hass, "homeassistant", {})
result = await async_setup_component(hass, "intent", {})
assert result
hass.states.async_set("light.test_light", "on")
calls = async_mock_service(hass, "light", SERVICE_TURN_OFF)
response = await intent.async_handle(
hass, "test", "HassTurnOff", {"name": {"value": "test light"}}
)
await hass.async_block_till_done()
assert response.speech["plain"]["speech"] == "Turned test light off"
assert len(calls) == 1
call = calls[0]
assert call.domain == "light"
assert call.service == "turn_off"
assert call.data == {"entity_id": ["light.test_light"]}
async def test_toggle_intent(hass):
"""Test HassToggle intent."""
result = await async_setup_component(hass, "homeassistant", {})
result = await async_setup_component(hass, "intent", {})
assert result
hass.states.async_set("light.test_light", "off")
calls = async_mock_service(hass, "light", SERVICE_TOGGLE)
response = await intent.async_handle(
hass, "test", "HassToggle", {"name": {"value": "test light"}}
)
await hass.async_block_till_done()
assert response.speech["plain"]["speech"] == "Toggled test light"
assert len(calls) == 1
call = calls[0]
assert call.domain == "light"
assert call.service == "toggle"
assert call.data == {"entity_id": ["light.test_light"]}
async def test_turn_on_multiple_intent(hass):
"""Test HassTurnOn intent with multiple similar entities.
This tests that matching finds the proper entity among similar names.
"""
result = await async_setup_component(hass, "homeassistant", {})
result = await async_setup_component(hass, "intent", {})
assert result
hass.states.async_set("light.test_light", "off")
hass.states.async_set("light.test_lights_2", "off")
hass.states.async_set("light.test_lighter", "off")
calls = async_mock_service(hass, "light", SERVICE_TURN_ON)
response = await intent.async_handle(
hass, "test", "HassTurnOn", {"name": {"value": "test lights"}}
)
await hass.async_block_till_done()
assert response.speech["plain"]["speech"] == "Turned test lights 2 on"
assert len(calls) == 1
call = calls[0]
assert call.domain == "light"
assert call.service == "turn_on"
assert call.data == {"entity_id": ["light.test_lights_2"]}