1 """Intents for the weather integration."""
3 from __future__
import annotations
5 import voluptuous
as vol
10 from .
import DOMAIN, INTENT_GET_WEATHER
14 """Set up the weather intents."""
19 """Handle GetWeather intents."""
21 intent_type = INTENT_GET_WEATHER
22 description =
"Gets the current weather"
23 slot_schema = {vol.Optional(
"name"): intent.non_empty_string}
26 async
def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
27 """Handle the intent."""
28 hass = intent_obj.hass
29 slots = self.async_validate_slots(intent_obj.slots)
31 weather_state: State |
None =
None
32 name: str |
None =
None
34 name = slots[
"name"][
"value"]
36 match_constraints = intent.MatchTargetsConstraints(
37 name=name, domains=[DOMAIN], assistant=intent_obj.assistant
39 match_result = intent.async_match_targets(hass, match_constraints)
40 if not match_result.is_match:
41 raise intent.MatchFailedError(
42 result=match_result, constraints=match_constraints
45 weather_state = match_result.states[0]
48 response = intent_obj.create_response()
49 response.response_type = intent.IntentResponseType.QUERY_ANSWER
50 response.async_set_results(
52 intent.IntentResponseTarget(
53 type=intent.IntentResponseTargetType.ENTITY,
54 name=weather_state.name,
55 id=weather_state.entity_id,
60 response.async_set_states(matched_states=[weather_state])
intent.IntentResponse async_handle(self, intent.Intent intent_obj)
None async_setup_intents(HomeAssistant hass)