Skip to content

Commit 56967bc

Browse files
committed
Add support for sub config flows in conversation agent picker (#26336)
1 parent b01ab92 commit 56967bc

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

src/components/ha-conversation-agent-picker.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { customElement, property, state } from "lit/decorators";
55
import { fireEvent } from "../common/dom/fire_event";
66
import { stopPropagation } from "../common/dom/stop_propagation";
77
import { debounce } from "../common/util/debounce";
8-
import type { ConfigEntry } from "../data/config_entries";
9-
import { getConfigEntry } from "../data/config_entries";
8+
import type { ConfigEntry, SubEntry } from "../data/config_entries";
9+
import { getConfigEntry, getSubEntries } from "../data/config_entries";
1010
import type { Agent } from "../data/conversation";
1111
import { listAgents } from "../data/conversation";
1212
import { fetchIntegrationManifest } from "../data/integration";
@@ -16,6 +16,7 @@ import "./ha-list-item";
1616
import "./ha-select";
1717
import type { HaSelect } from "./ha-select";
1818
import { getExtendedEntityRegistryEntry } from "../data/entity_registry";
19+
import { showSubConfigFlowDialog } from "../dialogs/config-flow/show-dialog-sub-config-flow";
1920

2021
const NONE = "__NONE_OPTION__";
2122

@@ -37,6 +38,8 @@ export class HaConversationAgentPicker extends LitElement {
3738

3839
@state() private _configEntry?: ConfigEntry;
3940

41+
@state() private _subConfigEntry?: SubEntry;
42+
4043
protected render() {
4144
if (!this._agents) {
4245
return nothing;
@@ -101,7 +104,11 @@ export class HaConversationAgentPicker extends LitElement {
101104
${agent.name}
102105
</ha-list-item>`
103106
)}</ha-select
104-
>${this._configEntry?.supports_options
107+
>${(this._subConfigEntry &&
108+
this._configEntry?.supported_subentry_types[
109+
this._subConfigEntry.subentry_type
110+
]?.supports_reconfigure) ||
111+
this._configEntry?.supports_options
105112
? html`<ha-icon-button
106113
.path=${mdiCog}
107114
@click=${this._openOptionsFlow}
@@ -142,8 +149,17 @@ export class HaConversationAgentPicker extends LitElement {
142149
this._configEntry = (
143150
await getConfigEntry(this.hass, regEntry.config_entry_id)
144151
).config_entry;
152+
153+
if (!regEntry.config_subentry_id) {
154+
this._subConfigEntry = undefined;
155+
} else {
156+
this._subConfigEntry = (
157+
await getSubEntries(this.hass, regEntry.config_entry_id)
158+
).find((entry) => entry.subentry_id === regEntry.config_subentry_id);
159+
}
145160
} catch (_err) {
146161
this._configEntry = undefined;
162+
this._subConfigEntry = undefined;
147163
}
148164
}
149165

@@ -182,6 +198,25 @@ export class HaConversationAgentPicker extends LitElement {
182198
if (!this._configEntry) {
183199
return;
184200
}
201+
202+
if (
203+
this._subConfigEntry &&
204+
this._configEntry.supported_subentry_types[
205+
this._subConfigEntry.subentry_type
206+
]?.supports_reconfigure
207+
) {
208+
showSubConfigFlowDialog(
209+
this,
210+
this._configEntry,
211+
this._subConfigEntry.subentry_type,
212+
{
213+
startFlowHandler: this._configEntry.entry_id,
214+
subEntryId: this._subConfigEntry.subentry_id,
215+
}
216+
);
217+
return;
218+
}
219+
185220
showOptionsFlowDialog(this, this._configEntry, {
186221
manifest: await fetchIntegrationManifest(
187222
this.hass,

0 commit comments

Comments
 (0)