import { mdiHelpCircleOutline } from "@mdi/js"; import type { CSSResultGroup } from "lit"; import { LitElement, css, html, nothing } from "lit"; import { customElement, property, state } from "lit/decorators"; import { fireEvent } from "../../../../common/dom/fire_event"; import "../../../../components/ha-dialog"; import "../../../../components/ha-dialog-footer"; import "../../../../components/ha-icon-button"; import "../../../../components/ha-md-list-item"; import "../../../../components/ha-md-list"; import "../../../../components/ha-radio"; import "../../../../components/ha-button"; import "../../../../components/ha-textfield"; import { AUTOMATION_DEFAULT_MAX, AUTOMATION_DEFAULT_MODE, } from "../../../../data/automation"; import { MODES, isMaxMode } from "../../../../data/script"; import type { HassDialog } from "../../../../dialogs/make-dialog-manager"; import { haStyle, haStyleDialog } from "../../../../resources/styles"; import type { HomeAssistant } from "../../../../types"; import { documentationUrl } from "../../../../util/documentation-url"; import type { AutomationModeDialog } from "./show-dialog-automation-mode"; @customElement("ha-dialog-automation-mode") class DialogAutomationMode extends LitElement implements HassDialog { @property({ attribute: false }) public hass!: HomeAssistant; @state() private _open = false; @state() private _params?: AutomationModeDialog; @state() private _newMode: (typeof MODES)[number] = AUTOMATION_DEFAULT_MODE; @state() private _newMax?: number; public showDialog(params: AutomationModeDialog): void { this._open = true; this._params = params; this._newMode = params.config.mode || AUTOMATION_DEFAULT_MODE; this._newMax = isMaxMode(this._newMode) ? params.config.max || AUTOMATION_DEFAULT_MAX : undefined; } public closeDialog(): boolean { this._open = false; return true; } private _dialogClosed() { if (this._params?.onClose) { this._params.onClose(); } this._params = undefined; fireEvent(this, "dialog-closed", { dialog: this.localName }); } protected render() { if (!this._params) { return nothing; } const title = this.hass.localize( "ui.panel.config.automation.editor.change_mode" ); return html` ${MODES.map((mode) => { const label = this.hass.localize( `ui.panel.config.automation.editor.modes.${mode}` ); return html`
${this.hass.localize( `ui.panel.config.automation.editor.modes.${mode}` )}
${this.hass.localize( `ui.panel.config.automation.editor.modes.${mode}_description` )}
`; })}
${isMaxMode(this._newMode) ? html`
` : nothing} ${this.hass.localize("ui.common.cancel")} ${this.hass.localize( "ui.panel.config.automation.editor.change_mode" )}
`; } private _modeChanged(ev) { const mode = ev.currentTarget.value; this._newMode = mode; if (!isMaxMode(mode)) { this._newMax = undefined; } else if (!this._newMax) { this._newMax = AUTOMATION_DEFAULT_MAX; } } private _valueChanged(ev: CustomEvent) { ev.stopPropagation(); const target = ev.target as any; if (target.name === "max") { this._newMax = Number(target.value); } } private _save(): void { if (!this._params) { return; } this._params.updateConfig({ ...this._params.config, mode: this._newMode, max: this._newMax, }); this.closeDialog(); } static get styles(): CSSResultGroup { return [ haStyle, haStyleDialog, css` ha-textfield { display: block; } ha-dialog { --dialog-content-padding: 0; } .options { padding: 0 24px 24px 24px; } `, ]; } } declare global { interface HTMLElementTagNameMap { "ha-dialog-automation-mode": DialogAutomationMode; } }