From 7449f7e73f57e6a37d42e1cd8c7e6b861ecbf6ee Mon Sep 17 00:00:00 2001 From: Philip Allgaier Date: Sun, 7 Mar 2021 23:15:53 +0100 Subject: [PATCH] Handle delay templates properly + error handling tweaks (#8578) Co-authored-by: Bram Kragten --- src/data/script.ts | 2 +- .../action/ha-automation-action-row.ts | 21 ++++-- .../types/ha-automation-action-delay.ts | 67 ++++++++++++------- .../ha-automation-condition-editor.ts | 6 +- .../trigger/ha-automation-trigger-row.ts | 6 +- .../lovelace/editor/hui-element-editor.ts | 10 ++- src/translations/en.json | 13 ++-- 7 files changed, 83 insertions(+), 42 deletions(-) diff --git a/src/data/script.ts b/src/data/script.ts index 10f32a549e..bb04af28e5 100644 --- a/src/data/script.ts +++ b/src/data/script.ts @@ -55,7 +55,7 @@ export interface DelayActionParts { days?: number; } export interface DelayAction { - delay: number | Partial; + delay: number | Partial | string; } export interface SceneAction { diff --git a/src/panels/config/automation/action/ha-automation-action-row.ts b/src/panels/config/automation/action/ha-automation-action-row.ts index ed4f1be90c..61810c87e8 100644 --- a/src/panels/config/automation/action/ha-automation-action-row.ts +++ b/src/panels/config/automation/action/ha-automation-action-row.ts @@ -193,12 +193,16 @@ export default class HaAutomationActionRow extends LitElement { ${this._warnings ? html`
- UI editor is not supported for this config: + ${this.hass.localize("ui.errors.config.editor_not_supported")}:
-
    - ${this._warnings.map((warning) => html`
  • ${warning}
  • `)} -
- You can still edit your config in YAML. + ${this._warnings!.length > 0 && this._warnings![0] !== undefined + ? html`
    + ${this._warnings!.map( + (warning) => html`
  • ${warning}
  • ` + )} +
` + : ""} + ${this.hass.localize("ui.errors.config.edit_in_yaml_supported")}
` : ""} ${yamlMode @@ -212,7 +216,11 @@ export default class HaAutomationActionRow extends LitElement { )} ` : ""} -

Edit in YAML

+

+ ${this.hass.localize( + "ui.panel.config.automation.editor.edit_yaml" + )} +

- - `; + protected render() { + return html``; } private _valueChanged(ev: CustomEvent) { diff --git a/src/panels/config/automation/condition/ha-automation-condition-editor.ts b/src/panels/config/automation/condition/ha-automation-condition-editor.ts index 42dd2c34d8..e7a1c2f691 100644 --- a/src/panels/config/automation/condition/ha-automation-condition-editor.ts +++ b/src/panels/config/automation/condition/ha-automation-condition-editor.ts @@ -63,7 +63,11 @@ export default class HaAutomationConditionEditor extends LitElement { )} ` : ""} -

Edit in YAML

+

+ ${this.hass.localize( + "ui.panel.config.automation.editor.edit_yaml" + )} +

Edit in YAML +

+ ${this.hass.localize( + "ui.panel.config.automation.editor.edit_yaml" + )} +

extends LitElement {
${this.hass.localize("ui.errors.config.editor_not_supported")}:
-
    - ${this._warnings!.map((warning) => html`
  • ${warning}
  • `)} -
+ ${this._warnings!.length > 0 && this._warnings![0] !== undefined + ? html`
    + ${this._warnings!.map( + (warning) => html`
  • ${warning}
  • ` + )} +
` + : ""} ${this.hass.localize("ui.errors.config.edit_in_yaml_supported")}
` diff --git a/src/translations/en.json b/src/translations/en.json index 4c4ee6591a..bb8c6b5a14 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -797,7 +797,8 @@ "edit_in_yaml_supported": "You can still edit your config in YAML.", "key_missing": "Required key \"{key}\" is missing.", "key_not_expected": "Key \"{key}\" is not expected or not supported by the visual editor.", - "key_wrong_type": "The provided value for \"{key}\" is not supported by the visual editor. We support ({type_correct}) but received ({type_wrong})." + "key_wrong_type": "The provided value for \"{key}\" is not supported by the visual editor. We support ({type_correct}) but received ({type_wrong}).", + "no_template_editor_support": "Templates not supported in visual editor" } }, "login-form": { @@ -1232,8 +1233,8 @@ "queued": "Queue length", "parallel": "Max number of parallel runs" }, - "edit_yaml": "Edit as YAML", - "edit_ui": "Edit with UI", + "edit_yaml": "Edit in YAML", + "edit_ui": "Edit in visual editor", "copy_to_clipboard": "Copy to Clipboard", "triggers": { "name": "Trigger", @@ -1244,7 +1245,7 @@ "duplicate": "Duplicate", "delete": "[%key:ui::panel::mailbox::delete_button%]", "delete_confirm": "Are you sure you want to delete this?", - "unsupported_platform": "No UI support for platform: {platform}", + "unsupported_platform": "No visual editor support for platform: {platform}", "type_select": "Trigger type", "type": { "device": { @@ -1346,7 +1347,7 @@ "duplicate": "[%key:ui::panel::config::automation::editor::triggers::duplicate%]", "delete": "[%key:ui::panel::mailbox::delete_button%]", "delete_confirm": "[%key:ui::panel::config::automation::editor::triggers::delete_confirm%]", - "unsupported_condition": "No UI support for condition: {condition}", + "unsupported_condition": "No visual editor support for condition: {condition}", "type_select": "Condition type", "type": { "and": { @@ -1422,7 +1423,7 @@ "duplicate": "[%key:ui::panel::config::automation::editor::triggers::duplicate%]", "delete": "[%key:ui::panel::mailbox::delete_button%]", "delete_confirm": "[%key:ui::panel::config::automation::editor::triggers::delete_confirm%]", - "unsupported_action": "No UI support for action: {action}", + "unsupported_action": "No visual editor support for action: {action}", "type_select": "Action type", "type": { "service": {