8000 Move climate intent to homeassistant integration by synesthesiam · Pull Request #139371 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Move climate intent to homeassistant integration #139371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion homeassistant/components/climate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
FAN_ON,
FAN_TOP,
HVAC_MODES,
INTENT_GET_TEMPERATURE,
INTENT_SET_TEMPERATURE,
PRESET_ACTIVITY,
PRESET_AWAY,
Expand Down
1 change: 0 additions & 1 deletion homeassistant/components/climate/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ class HVACAction(StrEnum):

DOMAIN = "climate"

INTENT_GET_TEMPERATURE = "HassClimateGetTemperature"
INTENT_SET_TEMPERATURE = "HassClimateSetTemperature"

SERVICE_SET_AUX_HEAT = "set_aux_heat"
Expand Down
43 changes: 1 addition & 42 deletions homeassistant/components/climate/intent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Intents for the client integration."""
"""Intents for the climate integration."""

from __future__ import annotations

Expand All @@ -11,7 +11,6 @@
from . import (
ATTR_TEMPERATURE,
DOMAIN,
INTENT_GET_TEMPERATURE,
INTENT_SET_TEMPERATURE,
SERVICE_SET_TEMPERATURE,
ClimateEntityFeature,
Expand All @@ -20,49 +19,9 @@

async def async_setup_intents(hass: HomeAssistant) -> None:
"""Set up the climate intents."""
intent.async_register(hass, GetTemperatureIntent())
intent.async_register(hass, SetTemperatureIntent())


class GetTemperatureIntent(intent.IntentHandler):
"""Handle GetTemperature intents."""

intent_type = INTENT_GET_TEMPERATURE
description = "Gets the current temperature of a climate device or entity"
slot_schema = {
vol.Optional("area"): intent.non_empty_string,
vol.Optional("name"): intent.non_empty_string,
}
platforms = {DOMAIN}

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)

name: str | None = None
if "name" in slots:
name = slots["name"]["value"]

area: str | None = None
if "area" in slots:
area = slots["area"]["value"]

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
)

response = intent_obj.create_response()
response.response_type = intent.IntentResponseType.QUERY_ANSWER
response.async_set_states(matched_states=match_result.states)
return response


class SetTemperatureIntent(intent.IntentHandler):
"""Handle SetTemperature intents."""

Expand Down
44 changes: 44 additions & 0 deletions homeassistant/components/intent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import voluptuous as vol

from homeassistant.components import http
from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN
from homeassistant.components.cover import (
ATTR_POSITION,
DOMAIN as COVER_DOMAIN,
Expand Down Expand Up @@ -140,6 +141,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
intent.async_register(hass, GetCurrentDateIntentHandler())
intent.async_register(hass, GetCurrentTimeIntentHandler())
intent.async_register(hass, RespondIntentHandler())
intent.async_register(hass, GetTemperatureIntent())

return True

Expand Down Expand Up @@ -444,6 +446,48 @@ async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse
return response


class GetTemperatureIntent(intent.IntentHandler):
"""Handle GetTemperature intents."""

intent_type = intent.INTENT_GET_TEMPERATURE
description = "Gets the current temperature of a climate device or entity"
slot_schema = {
vol.Optional("area"): intent.non_empty_string,
vol.Optional("name"): intent.non_empty_string,
}
platforms = {CLIMATE_DOMAIN}

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)

name: str | None = None
if "name" in slots:
name = slots["name"]["value"]

area: str | None = None
if "area" in slots:
area = slots["area"]["value"]

match_constraints = intent.MatchTargetsConstraints(
name=name,
area_name=area,
domains=[CLIMATE_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
)

response = intent_obj.create_response()
response.response_type = intent.IntentResponseType.QUERY_ANSWER
response.async_set_states(matched_states=match_result.states)
return response


async def _async_process_intent(
hass: HomeAssistant, domain: str, platform: IntentPlatformProtocol
) -> None:
Expand Down
1 change: 1 addition & 0 deletions homeassistant/helpers/intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
INTENT_GET_CURRENT_TIME = "HassGetCurrentTime"
INTENT_RESPOND = "HassRespond"
INTENT_BROADCAST = "HassBroadcast"
INTENT_GET_TEMPERATURE = "HassClimateGetTemperature"

SLOT_SCHEMA = vol.Schema({}, extra=vol.ALLOW_EXTRA)

Expand Down
11 changes: 6 additions & 5 deletions homeassistant/helpers/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
DOMAIN as CALENDAR_DOMAIN,
SERVICE_GET_EVENTS,
)
from homeassistant.components.climate import INTENT_GET_TEMPERATURE
from homeassistant.components.cover import INTENT_CLOSE_COVER, INTENT_OPEN_COVER
from homeassistant.components.homeassistant import async_should_expose
from homeassistant.components.intent import async_device_supports_timers
Expand Down Expand Up @@ -285,7 +284,7 @@ class AssistAPI(API):
"""API exposing Assist API to LLMs."""

IGNORE_INTENTS = {
INTENT_GET_TEMPERATURE,
intent.INTENT_GET_TEMPERATURE,
INTENT_GET_WEATHER,
INTENT_OPEN_COVER, # deprecated
INTENT_CLOSE_COVER, # deprecated
Expand Down Expand Up @@ -530,9 +529,11 @@ def _get_exposed_entities(
info["areas"] = ", ".join(area_names)

if attributes := {
attr_name: str(attr_value)
if isinstance(attr_value, (Enum, Decimal, int))
else attr_value
attr_name: (
str(attr_value)
if isinstance(attr_value, (Enum, Decimal, int))
else attr_value
)
for attr_name, attr_value in state.attributes.items()
if attr_name in interesting_attributes
}:
Expand Down
Loading
0