mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Add name slot to HassClimateGetTemperature intent (#105585)
This commit is contained in:
parent
22f0e09b8c
commit
431a44ab67
@ -21,7 +21,7 @@ class GetTemperatureIntent(intent.IntentHandler):
|
|||||||
"""Handle GetTemperature intents."""
|
"""Handle GetTemperature intents."""
|
||||||
|
|
||||||
intent_type = INTENT_GET_TEMPERATURE
|
intent_type = INTENT_GET_TEMPERATURE
|
||||||
slot_schema = {vol.Optional("area"): str}
|
slot_schema = {vol.Optional("area"): str, vol.Optional("name"): str}
|
||||||
|
|
||||||
async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
|
async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
|
||||||
"""Handle the intent."""
|
"""Handle the intent."""
|
||||||
@ -49,6 +49,20 @@ class GetTemperatureIntent(intent.IntentHandler):
|
|||||||
if climate_state is None:
|
if climate_state is None:
|
||||||
raise intent.IntentHandleError(f"No climate entity in area {area_name}")
|
raise intent.IntentHandleError(f"No climate entity in area {area_name}")
|
||||||
|
|
||||||
|
climate_entity = component.get_entity(climate_state.entity_id)
|
||||||
|
elif "name" in slots:
|
||||||
|
# Filter by name
|
||||||
|
entity_name = slots["name"]["value"]
|
||||||
|
|
||||||
|
for maybe_climate in intent.async_match_states(
|
||||||
|
hass, name=entity_name, domains=[DOMAIN]
|
||||||
|
):
|
||||||
|
climate_state = maybe_climate
|
||||||
|
break
|
||||||
|
|
||||||
|
if climate_state is None:
|
||||||
|
raise intent.IntentHandleError(f"No climate entity named {entity_name}")
|
||||||
|
|
||||||
climate_entity = component.get_entity(climate_state.entity_id)
|
climate_entity = component.get_entity(climate_state.entity_id)
|
||||||
else:
|
else:
|
||||||
# First entity
|
# First entity
|
||||||
|
@ -153,7 +153,7 @@ async def test_get_temperature(
|
|||||||
state = response.matched_states[0]
|
state = response.matched_states[0]
|
||||||
assert state.attributes["current_temperature"] == 10.0
|
assert state.attributes["current_temperature"] == 10.0
|
||||||
|
|
||||||
# Select by area instead (climate_2)
|
# Select by area (climate_2)
|
||||||
response = await intent.async_handle(
|
response = await intent.async_handle(
|
||||||
hass,
|
hass,
|
||||||
"test",
|
"test",
|
||||||
@ -166,6 +166,19 @@ async def test_get_temperature(
|
|||||||
state = response.matched_states[0]
|
state = response.matched_states[0]
|
||||||
assert state.attributes["current_temperature"] == 22.0
|
assert state.attributes["current_temperature"] == 22.0
|
||||||
|
|
||||||
|
# Select by name (climate_2)
|
||||||
|
response = await intent.async_handle(
|
||||||
|
hass,
|
||||||
|
"test",
|
||||||
|
climate_intent.INTENT_GET_TEMPERATURE,
|
||||||
|
{"name": {"value": "Climate 2"}},
|
||||||
|
)
|
||||||
|
assert response.response_type == intent.IntentResponseType.QUERY_ANSWER
|
||||||
|
assert len(response.matched_states) == 1
|
||||||
|
assert response.matched_states[0].entity_id == climate_2.entity_id
|
||||||
|
state = response.matched_states[0]
|
||||||
|
assert state.attributes["current_temperature"] == 22.0
|
||||||
|
|
||||||
|
|
||||||
async def test_get_temperature_no_entities(
|
async def test_get_temperature_no_entities(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user