diff --git a/src/panels/config/automation/automation-save-dialog/dialog-automation-save.ts b/src/panels/config/automation/automation-save-dialog/dialog-automation-save.ts index 4df25b260c..99fd37e5ff 100644 --- a/src/panels/config/automation/automation-save-dialog/dialog-automation-save.ts +++ b/src/panels/config/automation/automation-save-dialog/dialog-automation-save.ts @@ -1,8 +1,9 @@ import "@material/mwc-button"; -import type { CSSResultGroup } from "lit"; +import type { CSSResultGroup, PropertyValues } from "lit"; import { css, html, LitElement, nothing } from "lit"; import { customElement, property, state } from "lit/decorators"; -import { mdiClose, mdiPlus } from "@mdi/js"; +import { mdiClose, mdiPlus, mdiStarFourPoints } from "@mdi/js"; +import { dump } from "js-yaml"; import { fireEvent } from "../../../../common/dom/fire_event"; import "../../../../components/ha-alert"; import "../../../../components/ha-domain-icon"; @@ -24,6 +25,11 @@ import type { SaveDialogParams, } from "./show-dialog-automation-save"; import { supportsMarkdownHelper } from "../../../../common/translations/markdown_support"; +import { + fetchAITaskPreferences, + generateTextAITask, +} from "../../../../data/ai_task"; +import { isComponentLoaded } from "../../../../common/config/is_component_loaded"; @customElement("ha-dialog-automation-save") class DialogAutomationSave extends LitElement implements HassDialog { @@ -37,9 +43,11 @@ class DialogAutomationSave extends LitElement implements HassDialog { @state() private _entryUpdates!: EntityRegistryUpdate; + @state() private _canSuggest = false; + private _params!: SaveDialogParams; - private _newName?: string; + @state() private _newName?: string; private _newIcon?: string; @@ -81,6 +89,15 @@ class DialogAutomationSave extends LitElement implements HassDialog { return true; } + protected firstUpdated(changedProperties: PropertyValues): void { + super.firstUpdated(changedProperties); + if (isComponentLoaded(this.hass, "ai_task")) { + fetchAITaskPreferences(this.hass).then((prefs) => { + this._canSuggest = prefs.gen_text_entity_id !== null; + }); + } + } + protected _renderOptionalChip(id: string, label: string) { if (this._visibleOptionals.includes(id)) { return nothing; @@ -250,6 +267,21 @@ class DialogAutomationSave extends LitElement implements HassDialog { .path=${mdiClose} > ${this._params.title || title} + ${this._canSuggest + ? html` + + + + ` + : nothing} ${this._error ? html` { if (!this._newName) { this._error = "Name is required"; @@ -381,6 +427,10 @@ class DialogAutomationSave extends LitElement implements HassDialog { .destructive { --mdc-theme-primary: var(--error-color); } + + #suggest { + margin: 8px 16px; + } `, ]; } diff --git a/src/translations/en.json b/src/translations/en.json index 9c4f45b55e..9b450560a1 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -380,7 +380,8 @@ "replace": "Replace", "append": "Append", "supports_markdown": "Supports {markdown_help_link}", - "markdown": "Markdown" + "markdown": "Markdown", + "suggest_ai": "Suggest with AI" }, "components": { "selectors": {