1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Hassil intents (#85156)

* Add hassil to requirements

* Add intent sentences

* Update sentences

* Use hassil to recognize intents in conversation

* Fix tests

* Bump hassil due to dependency conflict

* Add dataclasses-json package contraints

* Bump hassil (removes dataclasses-json dependency)

* Remove climate sentences until intents are supported

* Move I/O outside event loop

* Bump hassil to 0.2.3

* Fix light tests

* Handle areas in intents

* Clean up code according to suggestions

* Remove sentences from repo

* Use home-assistant-intents package

* Apply suggestions from code review

* Flake8

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
Michael Hansen
2023-01-07 15:20:21 -06:00
committed by GitHub
parent 3a905f80df
commit ecaec0332d
9 changed files with 329 additions and 388 deletions

View File

@@ -3,8 +3,9 @@
import pytest
import voluptuous as vol
from homeassistant.const import ATTR_FRIENDLY_NAME
from homeassistant.core import State
from homeassistant.helpers import config_validation as cv, intent
from homeassistant.helpers import config_validation as cv, entity_registry, intent
class MockIntentHandler(intent.IntentHandler):
@@ -15,14 +16,26 @@ class MockIntentHandler(intent.IntentHandler):
self.slot_schema = slot_schema
def test_async_match_state():
async def test_async_match_state(hass):
"""Test async_match_state helper."""
state1 = State("light.kitchen", "on")
state2 = State("switch.kitchen", "on")
state1 = State(
"light.kitchen", "on", attributes={ATTR_FRIENDLY_NAME: "kitchen light"}
)
state2 = State(
"switch.kitchen", "on", attributes={ATTR_FRIENDLY_NAME: "kitchen switch"}
)
registry = entity_registry.async_get(hass)
registry.async_get_or_create(
"switch", "demo", "1234", suggested_object_id="kitchen"
)
registry.async_update_entity(state2.entity_id, aliases={"kill switch"})
state = intent.async_match_state(None, "kitch", [state1, state2])
state = intent.async_match_state(hass, "kitchen light", [state1, state2])
assert state is state1
state = intent.async_match_state(hass, "kill switch", [state1, state2])
assert state is state2
def test_async_validate_slots():
"""Test async_validate_slots of IntentHandler."""
@@ -38,21 +51,3 @@ def test_async_validate_slots():
handler1.async_validate_slots(
{"name": {"value": "kitchen"}, "probability": {"value": "0.5"}}
)
def test_fuzzy_match():
"""Test _fuzzymatch."""
state1 = State("light.living_room_northwest", "off")
state2 = State("light.living_room_north", "off")
state3 = State("light.living_room_northeast", "off")
state4 = State("light.living_room_west", "off")
state5 = State("light.living_room", "off")
states = [state1, state2, state3, state4, state5]
state = intent._fuzzymatch("Living Room", states, lambda state: state.name)
assert state == state5
state = intent._fuzzymatch(
"Living Room Northwest", states, lambda state: state.name
)
assert state == state1