OpenAI to rely on built-in areas variable (#90481)

This commit is contained in:
Paulus Schoutsen 2023-03-30 09:21:45 -04:00
parent 2a627e63f1
commit b83cb5d1b1
2 changed files with 4 additions and 5 deletions

View File

@ -12,7 +12,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_API_KEY from homeassistant.const import CONF_API_KEY
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady, TemplateError from homeassistant.exceptions import ConfigEntryNotReady, TemplateError
from homeassistant.helpers import area_registry as ar, intent, template from homeassistant.helpers import intent, template
from homeassistant.util import ulid from homeassistant.util import ulid
from .const import ( from .const import (
@ -138,7 +138,6 @@ class OpenAIAgent(conversation.AbstractConversationAgent):
return template.Template(raw_prompt, self.hass).async_render( return template.Template(raw_prompt, self.hass).async_render(
{ {
"ha_name": self.hass.config.location_name, "ha_name": self.hass.config.location_name,
"areas": list(ar.async_get(self.hass).areas.values()),
}, },
parse_result=False, parse_result=False,
) )

View File

@ -5,13 +5,13 @@ CONF_PROMPT = "prompt"
DEFAULT_PROMPT = """This smart home is controlled by Home Assistant. DEFAULT_PROMPT = """This smart home is controlled by Home Assistant.
An overview of the areas and the devices in this smart home: An overview of the areas and the devices in this smart home:
{%- for area in areas %} {%- for area in areas() %}
{%- set area_info = namespace(printed=false) %} {%- set area_info = namespace(printed=false) %}
{%- for device in area_devices(area.name) -%} {%- for device in area_devices(area) -%}
{%- if not device_attr(device, "disabled_by") and not device_attr(device, "entry_type") and device_attr(device, "name") %} {%- if not device_attr(device, "disabled_by") and not device_attr(device, "entry_type") and device_attr(device, "name") %}
{%- if not area_info.printed %} {%- if not area_info.printed %}
{{ area.name }}: {{ area_name(area) }}:
{%- set area_info.printed = true %} {%- set area_info.printed = true %}
{%- endif %} {%- endif %}
- {{ device_attr(device, "name") }}{% if device_attr(device, "model") and (device_attr(device, "model") | string) not in (device_attr(device, "name") | string) %} ({{ device_attr(device, "model") }}){% endif %} - {{ device_attr(device, "name") }}{% if device_attr(device, "model") and (device_attr(device, "model") | string) not in (device_attr(device, "name") | string) %} ({{ device_attr(device, "model") }}){% endif %}