2018-02-28 21:39:01 +00:00
|
|
|
"""Tests for the intent helpers."""
|
2018-07-01 15:51:40 +00:00
|
|
|
|
|
|
|
import voluptuous as vol
|
|
|
|
|
2019-04-30 16:20:38 +00:00
|
|
|
import pytest
|
|
|
|
|
2018-02-28 21:39:01 +00:00
|
|
|
from homeassistant.core import State
|
2018-07-01 15:51:40 +00:00
|
|
|
from homeassistant.helpers import (intent, config_validation as cv)
|
|
|
|
|
|
|
|
|
|
|
|
class MockIntentHandler(intent.IntentHandler):
|
|
|
|
"""Provide a mock intent handler."""
|
|
|
|
|
|
|
|
def __init__(self, slot_schema):
|
|
|
|
"""Initialize the mock handler."""
|
|
|
|
self.slot_schema = slot_schema
|
2018-02-28 21:39:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_async_match_state():
|
|
|
|
"""Test async_match_state helper."""
|
|
|
|
state1 = State('light.kitchen', 'on')
|
|
|
|
state2 = State('switch.kitchen', 'on')
|
|
|
|
|
|
|
|
state = intent.async_match_state(None, 'kitch', [state1, state2])
|
|
|
|
assert state is state1
|
2018-07-01 15:51:40 +00:00
|
|
|
|
|
|
|
|
2019-04-30 16:20:38 +00:00
|
|
|
def test_async_validate_slots():
|
|
|
|
"""Test async_validate_slots of IntentHandler."""
|
|
|
|
handler1 = MockIntentHandler({
|
|
|
|
vol.Required('name'): cv.string,
|
|
|
|
})
|
|
|
|
|
|
|
|
with pytest.raises(vol.error.MultipleInvalid):
|
|
|
|
handler1.async_validate_slots({})
|
|
|
|
with pytest.raises(vol.error.MultipleInvalid):
|
|
|
|
handler1.async_validate_slots({'name': 1})
|
|
|
|
with pytest.raises(vol.error.MultipleInvalid):
|
|
|
|
handler1.async_validate_slots({'name': 'kitchen'})
|
|
|
|
handler1.async_validate_slots({'name': {'value': 'kitchen'}})
|
|
|
|
handler1.async_validate_slots({
|
|
|
|
'name': {'value': 'kitchen'},
|
|
|
|
'probability': {'value': '0.5'}
|
|
|
|
})
|