2023-11-25 13:50:44 +00:00
|
|
|
"""Intents for the client integration."""
|
2024-02-07 21:13:42 +00:00
|
|
|
|
2023-11-25 13:50:44 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
import voluptuous as vol
|
|
|
|
|
2024-06-07 01:41:25 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2023-11-25 13:50:44 +00:00
|
|
|
from homeassistant.helpers import intent
|
|
|
|
|
2024-06-07 01:41:25 +00:00
|
|
|
from . import DOMAIN
|
2023-11-25 13:50:44 +00:00
|
|
|
|
|
|
|
INTENT_GET_TEMPERATURE = "HassClimateGetTemperature"
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_intents(hass: HomeAssistant) -> None:
|
|
|
|
"""Set up the climate intents."""
|
|
|
|
intent.async_register(hass, GetTemperatureIntent())
|
|
|
|
|
|
|
|
|
|
|
|
class GetTemperatureIntent(intent.IntentHandler):
|
|
|
|
"""Handle GetTemperature intents."""
|
|
|
|
|
|
|
|
intent_type = INTENT_GET_TEMPERATURE
|
2024-05-21 16:54:34 +00:00
|
|
|
description = "Gets the current temperature of a climate device or entity"
|
2024-06-07 01:41:25 +00:00
|
|
|
slot_schema = {
|
|
|
|
vol.Optional("area"): intent.non_empty_string,
|
|
|
|
vol.Optional("name"): intent.non_empty_string,
|
|
|
|
}
|
2024-05-28 20:46:08 +00:00
|
|
|
platforms = {DOMAIN}
|
2023-11-25 13:50:44 +00:00
|
|
|
|
|
|
|
async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
|
|
|
|
"""Handle the intent."""
|
|
|
|
hass = intent_obj.hass
|
|
|
|
slots = self.async_validate_slots(intent_obj.slots)
|
|
|
|
|
2024-06-07 01:41:25 +00:00
|
|
|
name: str | None = None
|
|
|
|
if "name" in slots:
|
|
|
|
name = slots["name"]["value"]
|
2023-11-25 13:50:44 +00:00
|
|
|
|
2024-06-07 01:41:25 +00:00
|
|
|
area: str | None = None
|
|
|
|
if "area" in slots:
|
|
|
|
area = slots["area"]["value"]
|
2023-11-25 13:50:44 +00:00
|
|
|
|
2024-06-07 01:41:25 +00:00
|
|
|
match_constraints = intent.MatchTargetsConstraints(
|
|
|
|
name=name, area_name=area, domains=[DOMAIN], assistant=intent_obj.assistant
|
|
|
|
)
|
|
|
|
match_result = intent.async_match_targets(hass, match_constraints)
|
|
|
|
if not match_result.is_match:
|
|
|
|
raise intent.MatchFailedError(
|
|
|
|
result=match_result, constraints=match_constraints
|
|
|
|
)
|
2023-11-25 13:50:44 +00:00
|
|
|
|
|
|
|
response = intent_obj.create_response()
|
|
|
|
response.response_type = intent.IntentResponseType.QUERY_ANSWER
|
2024-06-07 01:41:25 +00:00
|
|
|
response.async_set_states(matched_states=match_result.states)
|
2023-11-25 13:50:44 +00:00
|
|
|
return response
|