From de57b025e6c4bce42187a13676b11581fc610dd6 Mon Sep 17 00:00:00 2001
From: karwosts <32912880+karwosts@users.noreply.github.com>
Date: Tue, 12 Nov 2024 02:47:12 -0800
Subject: [PATCH] Warn on switching to automation UI mode with yaml errors
(#22780)
---
.../config/automation/ha-automation-editor.ts | 15 ++++++++++++++-
src/translations/en.json | 1 +
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/panels/config/automation/ha-automation-editor.ts b/src/panels/config/automation/ha-automation-editor.ts
index 62f0f127a565..6be64adc0417 100644
--- a/src/panels/config/automation/ha-automation-editor.ts
+++ b/src/panels/config/automation/ha-automation-editor.ts
@@ -756,7 +756,20 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
}
}
- private _switchUiMode() {
+ private async _switchUiMode() {
+ if (this._yamlErrors) {
+ const result = await showConfirmationDialog(this, {
+ text: html`${this.hass.localize(
+ "ui.panel.config.automation.editor.switch_ui_yaml_error"
+ )}
${this._yamlErrors}`,
+ confirmText: this.hass!.localize("ui.common.continue"),
+ destructive: true,
+ dismissText: this.hass!.localize("ui.common.cancel"),
+ });
+ if (!result) {
+ return;
+ }
+ }
this._yamlErrors = undefined;
this._mode = "gui";
}
diff --git a/src/translations/en.json b/src/translations/en.json
index 230b82a49097..d5d68728d1fc 100644
--- a/src/translations/en.json
+++ b/src/translations/en.json
@@ -2942,6 +2942,7 @@
"search_in": "Search ยท {group}",
"unknown_entity": "unknown entity",
"edit_unknown_device": "Editor not available for unknown device",
+ "switch_ui_yaml_error": "There are currently YAML errors in the automation, and it cannot be parsed. Switching to UI mode may cause pending changes to be lost. Press cancel to correct any errors before proceeding to prevent loss of pending changes, or continue if you are sure.",
"triggers": {
"name": "Triggers",
"header": "When",