hass-core/tests/components/light/test_intent.py
Michael Hansen 5aca996f22
HassTurnOn/Off intents to also handle cover entities ()
* Move entity/area resolution to async_match_states

* Special case for covers in HassTurnOn/Off

* Enable light color/brightness on areas

* Remove async_register from default agent

* Remove CONFIG_SCHEMA from conversation component

* Fix intent tests

* Fix light test

* Move entity/area resolution to async_match_states

* Special case for covers in HassTurnOn/Off

* Enable light color/brightness on areas

* Remove async_register from default agent

* Remove CONFIG_SCHEMA from conversation component

* Fix intent tests

* Fix light test

* Fix humidifier intent handlers

* Remove DATA_CONFIG for conversation

* Copy ServiceIntentHandler code to light

* Add proper errors to humidifier intent handlers
2023-01-19 17:15:01 -06:00

88 lines
2.8 KiB
Python

"""Tests for the light intents."""
from homeassistant.components import light
from homeassistant.components.light import ATTR_SUPPORTED_COLOR_MODES, ColorMode, intent
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_ON
from homeassistant.helpers.intent import async_handle
from tests.common import async_mock_service
async def test_intent_set_color(hass):
"""Test the set color intent."""
hass.states.async_set(
"light.hello_2", "off", {ATTR_SUPPORTED_COLOR_MODES: [ColorMode.HS]}
)
hass.states.async_set("switch.hello", "off")
calls = async_mock_service(hass, light.DOMAIN, light.SERVICE_TURN_ON)
await intent.async_setup_intents(hass)
result = await async_handle(
hass,
"test",
intent.INTENT_SET,
{"name": {"value": "Hello 2"}, "color": {"value": "blue"}},
)
await hass.async_block_till_done()
assert result.speech["plain"]["speech"] == "Changed hello 2 to the color blue"
assert len(calls) == 1
call = calls[0]
assert call.domain == light.DOMAIN
assert call.service == SERVICE_TURN_ON
assert call.data.get(ATTR_ENTITY_ID) == "light.hello_2"
assert call.data.get(light.ATTR_RGB_COLOR) == (0, 0, 255)
async def test_intent_set_color_tests_feature(hass):
"""Test the set color intent."""
hass.states.async_set("light.hello", "off")
calls = async_mock_service(hass, light.DOMAIN, light.SERVICE_TURN_ON)
await intent.async_setup_intents(hass)
response = await async_handle(
hass,
"test",
intent.INTENT_SET,
{"name": {"value": "Hello"}, "color": {"value": "blue"}},
)
# Response should contain one failed target
assert len(response.success_results) == 0
assert len(response.failed_results) == 1
assert len(calls) == 0
async def test_intent_set_color_and_brightness(hass):
"""Test the set color intent."""
hass.states.async_set(
"light.hello_2", "off", {ATTR_SUPPORTED_COLOR_MODES: [ColorMode.HS]}
)
hass.states.async_set("switch.hello", "off")
calls = async_mock_service(hass, light.DOMAIN, light.SERVICE_TURN_ON)
await intent.async_setup_intents(hass)
result = await async_handle(
hass,
"test",
intent.INTENT_SET,
{
"name": {"value": "Hello 2"},
"color": {"value": "blue"},
"brightness": {"value": "20"},
},
)
await hass.async_block_till_done()
assert (
result.speech["plain"]["speech"]
== "Changed hello 2 to the color blue and 20% brightness"
)
assert len(calls) == 1
call = calls[0]
assert call.domain == light.DOMAIN
assert call.service == SERVICE_TURN_ON
assert call.data.get(ATTR_ENTITY_ID) == "light.hello_2"
assert call.data.get(light.ATTR_RGB_COLOR) == (0, 0, 255)
assert call.data.get(light.ATTR_BRIGHTNESS_PCT) == 20