diff --git a/src/panels/config/automation/blueprint-automation-editor.ts b/src/panels/config/automation/blueprint-automation-editor.ts index 074bbf9c32..8446f2632e 100644 --- a/src/panels/config/automation/blueprint-automation-editor.ts +++ b/src/panels/config/automation/blueprint-automation-editor.ts @@ -77,15 +77,6 @@ export class HaBlueprintAutomationEditor extends LitElement {
- - ${this._showDescription ? html` - + + ${this.hass.localize("ui.panel.config.automation.editor.run")} + + + + ${stateObj + ? html` + + ${this.hass.localize( + "ui.panel.config.automation.editor.show_trace" + )} + + + ` + : ""} + + + ${this.hass.localize("ui.panel.config.automation.editor.rename")} + + + + + ${this.hass.localize("ui.panel.config.automation.picker.duplicate")} + + + +
  • + + ${this.hass.localize("ui.panel.config.automation.editor.edit_ui")} ${this._mode === "gui" ? html`` : ``} - + ${this.hass.localize("ui.panel.config.automation.editor.edit_yaml")} ${this._mode === "yaml" ? html` - ${this.hass.localize( - "ui.panel.config.automation.picker.duplicate_automation" - )} + ${!stateObj || stateObj.state === "off" + ? this.hass.localize("ui.panel.config.automation.editor.enable") + : this.hass.localize("ui.panel.config.automation.editor.disable")} - ${this.hass.localize( - "ui.panel.config.automation.picker.delete_automation" - )} + ${this.hass.localize("ui.panel.config.automation.picker.delete")} ${this._config?.alias}` - : ""}
    ${this._config!.alias || + this.hass.localize( + "ui.panel.config.automation.editor.default_name" + )}` + : html` +
    +

    + ${this._config!.alias || + this.hass.localize( + "ui.panel.config.automation.editor.default_name" + )} +

    + +
    + `} ${"use_blueprint" in this._config ? html`
    - ${this._config.alias} + ${this._config.alias || + this.hass.localize( + "ui.panel.config.automation.editor.default_name" + )}
    - ${stateObj - ? html` -
    - - - - ${this.hass.localize( - "ui.card.automation.trigger" - )} - -
    - ` - : ""} ` : ``} @@ -317,12 +350,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { if (changedProps.has("automationId") && !this.automationId && this.hass) { const initData = getAutomationEditorInitData(); - let baseConfig: Partial = { - alias: this.hass.localize( - "ui.panel.config.automation.editor.default_name" - ), - description: "", - }; + let baseConfig: Partial = { description: "" }; if (!initData || !("use_blueprint" in initData)) { baseConfig = { ...baseConfig, @@ -337,6 +365,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { ...initData, } as AutomationConfig; this._entityId = undefined; + this._dirty = true; } if ( @@ -401,8 +430,25 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { this._errors = undefined; } - private _runActions(ev: Event) { - triggerAutomationActions(this.hass, (ev.target as any).stateObj.entity_id); + private _runActions() { + if (!this.hass || !this._entityId) { + return; + } + triggerAutomationActions( + this.hass, + this.hass.states[this._entityId].entity_id + ); + } + + private async _toggle(): Promise { + if (!this.hass || !this._entityId) { + return; + } + const stateObj = this.hass.states[this._entityId]; + const service = stateObj.state === "off" ? "turn_on" : "turn_off"; + await this.hass.callService("automation", service, { + entity_id: stateObj.entity_id, + }); } private _preprocessYaml() { @@ -471,9 +517,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { showAutomationEditor({ ...this._config, id: undefined, - alias: `${this._config?.alias} (${this.hass.localize( - "ui.panel.config.automation.picker.duplicate" - )})`, + alias: undefined, }); } @@ -493,25 +537,50 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { history.back(); } - private async _handleMenuAction(ev: CustomEvent) { - switch (ev.detail.index) { - case 0: - this._mode = "gui"; - break; - case 1: - this._mode = "yaml"; - break; - case 2: - this._duplicate(); - break; - case 3: - this._deleteConfirm(); - break; - } + private _switchUiMode() { + this._mode = "gui"; } - private _saveAutomation(): void { + private _switchYamlMode() { + this._mode = "yaml"; + } + + private async _promptAutomationAlias(): Promise { + const result = await showPromptDialog(this, { + title: this.hass.localize( + "ui.panel.config.automation.editor.automation_alias" + ), + inputLabel: this.hass.localize("ui.panel.config.automation.editor.alias"), + inputType: "string", + placeholder: this.hass.localize( + "ui.panel.config.automation.editor.default_name" + ), + defaultValue: this._config!.alias, + confirmText: this.hass.localize("ui.common.submit"), + }); + if (result) { + this._config!.alias = result; + this._dirty = true; + this.requestUpdate(); + } + return result; + } + + private async _saveAutomation(): Promise { const id = this.automationId || String(Date.now()); + if (!this._config!.alias) { + const alias = await this._promptAutomationAlias(); + if (!alias) { + showAlertDialog(this, { + text: this.hass.localize( + "ui.panel.config.automation.editor.missing_name" + ), + }); + return; + } + this._config!.alias = alias; + } + this.hass!.callApi( "POST", "config/automation/config/" + id, @@ -603,6 +672,29 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { li[role="separator"] { border-bottom-color: var(--divider-color); } + ha-button-menu a { + text-decoration: none; + color: var(--primary-color); + } + h1 { + margin: 0; + font-family: var(--paper-font-headline_-_font-family); + -webkit-font-smoothing: var( + --paper-font-headline_-_-webkit-font-smoothing + ); + font-size: var(--paper-font-headline_-_font-size); + font-weight: var(--paper-font-headline_-_font-weight); + letter-spacing: var(--paper-font-headline_-_letter-spacing); + line-height: var(--paper-font-headline_-_line-height); + opacity: var(--dark-primary-opacity); + } + .header-name { + display: flex; + align-items: center; + margin: 0 auto; + max-width: 1040px; + padding: 28px 20px 0; + } `, ]; } diff --git a/src/panels/config/automation/manual-automation-editor.ts b/src/panels/config/automation/manual-automation-editor.ts index eb8b7ef3b1..851191ac2c 100644 --- a/src/panels/config/automation/manual-automation-editor.ts +++ b/src/panels/config/automation/manual-automation-editor.ts @@ -1,5 +1,5 @@ import "@material/mwc-button/mwc-button"; -import { mdiHelpCircle } from "@mdi/js"; +import { mdiHelpCircle, mdiRobot } from "@mdi/js"; import { HassEntity } from "home-assistant-js-websocket"; import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit"; import { customElement, property, state } from "lit/decorators"; @@ -14,7 +14,6 @@ import { Condition, ManualAutomationConfig, Trigger, - triggerAutomationActions, } from "../../../data/automation"; import { Action, isMaxMode, MODES } from "../../../data/script"; import { haStyle } from "../../../resources/styles"; @@ -41,115 +40,99 @@ export class HaManualAutomationEditor extends LitElement { protected render() { return html` -
    - + ${this.hass.localize( + "ui.panel.config.automation.editor.disabled" + )} +
    ` + : "" + } + + +
    + + ${this.hass.localize( + "ui.panel.config.automation.editor.automation_settings" )} - name="alias" - .value=${this.config.alias || ""} - @change=${this._valueChanged} - > - - ${this._showDescription - ? html` - - ` - : html` - - `} - ${this.hass.localize( - "ui.panel.config.automation.editor.modes.learn_more" - )} - `} - > - ${MODES.map( - (mode) => html` - - ${this.hass.localize( - `ui.panel.config.automation.editor.modes.${mode}` - ) || mode} - - ` - )} - - ${this.config.mode && isMaxMode(this.config.mode) - ? html` -
    - - ` - : html``} -
    - ${this.stateObj - ? html` -
    -
    - - ${this.hass.localize( - "ui.panel.config.automation.editor.enable_disable" - )} -
    - +
    + + ${ + this._showDescription + ? html` + - - - ${this.hass.localize("ui.card.automation.trigger")} - -
    -
    - ` - : ""} + .placeholder=${this.hass.localize( + "ui.panel.config.automation.editor.description.placeholder" + )} + name="description" + autogrow + .value=${this.config.description || ""} + @change=${this._valueChanged} + > + ` + : html` + + ` + } + ${this.hass.localize( + "ui.panel.config.automation.editor.modes.learn_more" + )} + `} + > + ${MODES.map( + (mode) => html` + + ${this.hass.localize( + `ui.panel.config.automation.editor.modes.${mode}` + ) || mode} + + ` + )} + + ${ + this.config.mode && isMaxMode(this.config.mode) + ? html` +
    + + ` + : html`` + } +
    +
    @@ -244,10 +227,6 @@ export class HaManualAutomationEditor extends LitElement { } } - private _runActions(ev: Event) { - triggerAutomationActions(this.hass, (ev.target as any).stateObj.entity_id); - } - private _valueChanged(ev: CustomEvent) { ev.stopPropagation(); const target = ev.target as any; @@ -360,6 +339,23 @@ export class HaManualAutomationEditor extends LitElement { .header a { color: var(--secondary-text-color); } + ha-expansion-panel { + --expansion-panel-summary-padding: 0 0 0 8px; + --expansion-panel-content-padding: 0; + } + .card-content { + padding: 16px; + } + .settings-icon { + color: var(--sidebar-icon-color); + padding-right: 8px; + } + .disabled-bar { + background: var(--divider-color, #e0e0e0); + text-align: center; + border-top-right-radius: var(--ha-card-border-radius); + border-top-left-radius: var(--ha-card-border-radius); + } `, ]; } diff --git a/src/translations/en.json b/src/translations/en.json index 77745250a4..c5cc008649 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -1788,9 +1788,8 @@ "edit_automation": "Edit automation", "dev_automation": "Debug automation", "show_info_automation": "Show info about automation", - "delete_automation": "Delete automation", + "delete": "Delete", "delete_confirm": "Are you sure you want to delete this automation?", - "duplicate_automation": "Duplicate automation", "duplicate": "Duplicate", "headers": { "toggle": "Enable/disable", @@ -1815,15 +1814,22 @@ "start_empty_description": "Create a new automation from scratch" }, "editor": { - "enable_disable": "Enable/Disable automation", - "show_trace": "Show trace", + "enable": "[%key:ui::common::enable%]", + "disable": "[%key:ui::common::disable%]", + "disabled": "Automation is disabled", + "run": "[%key:ui::panel::config::automation::editor::actions::run%]", + "rename": "[%key:ui::panel::config::automation::editor::triggers::rename%]", + "show_trace": "Traces", "introduction": "Use automations to bring your home to life.", "default_name": "New Automation", + "missing_name": "Cannot save automation without a name", "load_error_not_editable": "Only automations in automations.yaml are editable.", "load_error_unknown": "Error loading automation ({err_no}).", "save": "Save", "unsaved_confirm": "You have unsaved changes. Are you sure you want to leave?", "alias": "Name", + "automation_alias": "Automation name", + "automation_settings": "Automation settings", "move_up": "Move up", "move_down": "Move down", "description": {