1 """Intents for the humidifier integration."""
3 from __future__
import annotations
5 import voluptuous
as vol
19 HumidifierEntityFeature,
22 INTENT_HUMIDITY =
"HassHumidifierSetpoint"
23 INTENT_MODE =
"HassHumidifierMode"
27 """Set up the humidifier intents."""
33 """Handle set humidity intents."""
35 intent_type = INTENT_HUMIDITY
36 description =
"Set desired humidity level"
38 vol.Required(
"name"): intent.non_empty_string,
39 vol.Required(
"humidity"): vol.All(vol.Coerce(int), vol.Range(0, 100)),
43 async
def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
44 """Handle the hass intent."""
45 hass = intent_obj.hass
46 slots = self.async_validate_slots(intent_obj.slots)
48 match_constraints = intent.MatchTargetsConstraints(
49 name=slots[
"name"][
"value"],
51 assistant=intent_obj.assistant,
53 match_result = intent.async_match_targets(hass, match_constraints)
54 if not match_result.is_match:
55 raise intent.MatchFailedError(
56 result=match_result, constraints=match_constraints
59 state = match_result.states[0]
60 service_data = {ATTR_ENTITY_ID: state.entity_id}
62 humidity = slots[
"humidity"][
"value"]
64 if state.state == STATE_OFF:
65 await hass.services.async_call(
66 DOMAIN, SERVICE_TURN_ON, service_data, context=intent_obj.context
68 speech = f
"Turned {state.name} on and set humidity to {humidity}%"
70 speech = f
"The {state.name} is set to {humidity}%"
72 service_data[ATTR_HUMIDITY] = humidity
73 await hass.services.async_call(
77 context=intent_obj.context,
81 response = intent_obj.create_response()
83 response.async_set_speech(speech)
88 """Handle set humidity intents."""
90 intent_type = INTENT_MODE
91 description =
"Set humidifier mode"
93 vol.Required(
"name"): intent.non_empty_string,
94 vol.Required(
"mode"): cv.string,
98 async
def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
99 """Handle the hass intent."""
100 hass = intent_obj.hass
101 slots = self.async_validate_slots(intent_obj.slots)
102 match_constraints = intent.MatchTargetsConstraints(
103 name=slots[
"name"][
"value"],
105 assistant=intent_obj.assistant,
107 match_result = intent.async_match_targets(hass, match_constraints)
108 if not match_result.is_match:
109 raise intent.MatchFailedError(
110 result=match_result, constraints=match_constraints
113 state = match_result.states[0]
114 service_data = {ATTR_ENTITY_ID: state.entity_id}
116 intent.async_test_feature(state, HumidifierEntityFeature.MODES,
"modes")
117 mode = slots[
"mode"][
"value"]
119 if mode
not in (state.attributes.get(ATTR_AVAILABLE_MODES)
or []):
120 raise intent.IntentHandleError(
121 f
"Entity {state.name} does not support {mode} mode"
124 if state.state == STATE_OFF:
125 await hass.services.async_call(
129 context=intent_obj.context,
132 speech = f
"Turned {state.name} on and set {mode} mode"
134 speech = f
"The mode for {state.name} is set to {mode}"
136 service_data[ATTR_MODE] = mode
137 await hass.services.async_call(
141 context=intent_obj.context,
145 response = intent_obj.create_response()
147 response.async_set_speech(speech)
intent.IntentResponse async_handle(self, intent.Intent intent_obj)
intent.IntentResponse async_handle(self, intent.Intent intent_obj)
None async_setup_intents(HomeAssistant hass)