diff --git a/src/components/ha-conversation-agent-picker.ts b/src/components/ha-conversation-agent-picker.ts index 2208b1555e..30a54871bc 100644 --- a/src/components/ha-conversation-agent-picker.ts +++ b/src/components/ha-conversation-agent-picker.ts @@ -1,3 +1,4 @@ +import { mdiCog } from "@mdi/js"; import { css, CSSResultGroup, @@ -10,7 +11,10 @@ import { customElement, property, state } from "lit/decorators"; import { fireEvent } from "../common/dom/fire_event"; import { stopPropagation } from "../common/dom/stop_propagation"; import { debounce } from "../common/util/debounce"; +import { ConfigEntry, getConfigEntry } from "../data/config_entries"; import { Agent, listAgents } from "../data/conversation"; +import { fetchIntegrationManifest } from "../data/integration"; +import { showOptionsFlowDialog } from "../dialogs/config-flow/show-dialog-options-flow"; import { HomeAssistant } from "../types"; import "./ha-list-item"; import "./ha-select"; @@ -34,6 +38,8 @@ export class HaConversationAgentPicker extends LitElement { @state() _agents?: Agent[]; + @state() private _configEntry?: ConfigEntry; + protected render() { if (!this._agents) { return nothing; @@ -77,8 +83,13 @@ export class HaConversationAgentPicker extends LitElement { > ${agent.name} ` - )} - + )}${this._configEntry?.supports_options + ? html`` + : ""} `; } @@ -89,6 +100,24 @@ export class HaConversationAgentPicker extends LitElement { } else if (changedProperties.has("language")) { this._debouncedUpdateAgents(); } + + if (changedProperties.has("value")) { + this._maybeFetchConfigEntry(); + } + } + + private async _maybeFetchConfigEntry() { + if (!this.value || this.value === "homeassistant") { + this._configEntry = undefined; + return; + } + try { + this._configEntry = ( + await getConfigEntry(this.hass, this.value) + ).config_entry; + } catch (err) { + this._configEntry = undefined; + } } private _debouncedUpdateAgents = debounce(() => this._updateAgents(), 500); @@ -122,11 +151,29 @@ export class HaConversationAgentPicker extends LitElement { } } + private async _openOptionsFlow() { + if (!this._configEntry) { + return; + } + showOptionsFlowDialog( + this, + this._configEntry, + await fetchIntegrationManifest(this.hass, this._configEntry.domain) + ); + } + static get styles(): CSSResultGroup { return css` + :host { + display: flex; + align-items: center; + } ha-select { width: 100%; } + ha-icon-button { + color: var(--secondary-text-color); + } `; }