${this.hass.localize(
"ui.panel.lovelace.editor.edit_card.edit_ui"
@@ -206,24 +222,75 @@ export class HaCardConditionEditor extends LitElement {
}
+
+ ${
+ this._testingResult
+ ? this.hass.localize(
+ "ui.panel.lovelace.editor.condition-editor.testing_pass"
+ )
+ : this.hass.localize(
+ "ui.panel.lovelace.editor.condition-editor.testing_error"
+ )
+ }
+
`;
}
- private _handleAction(ev: CustomEvent) {
+ private async _handleAction(ev: CustomEvent) {
switch (ev.detail.index) {
case 0:
- this._yamlMode = false;
+ await this._testCondition();
break;
case 1:
- this._yamlMode = true;
+ this._yamlMode = false;
break;
case 2:
+ this._yamlMode = true;
+ break;
+ case 3:
this._delete();
break;
}
}
+ private _timeout?: number;
+
+ private async _testCondition() {
+ if (this._timeout) {
+ window.clearTimeout(this._timeout);
+ this._timeout = undefined;
+ }
+ this._testingResult = undefined;
+ const condition = this.condition;
+
+ const validateResult = validateConditionalConfig([this.condition]);
+
+ if (!validateResult) {
+ showAlertDialog(this, {
+ title: this.hass.localize(
+ "ui.panel.lovelace.editor.condition-editor.invalid_config_title"
+ ),
+ text: this.hass.localize(
+ "ui.panel.lovelace.editor.condition-editor.invalid_config_text"
+ ),
+ });
+ return;
+ }
+
+ this._testingResult = checkConditionsMet([condition], this.hass);
+
+ this._timeout = window.setTimeout(() => {
+ this._testingResult = undefined;
+ }, 2500);
+ }
+
private _delete() {
fireEvent(this, "value-changed", { value: null });
}
@@ -274,6 +341,32 @@ export class HaCardConditionEditor extends LitElement {
opacity: 0.5;
pointer-events: none;
}
+ .testing {
+ position: absolute;
+ top: 0px;
+ right: 0px;
+ left: 0px;
+ text-transform: uppercase;
+ font-weight: bold;
+ font-size: 14px;
+ background-color: var(--divider-color, #e0e0e0);
+ color: var(--text-primary-color);
+ max-height: 0px;
+ overflow: hidden;
+ transition: max-height 0.3s;
+ text-align: center;
+ border-top-right-radius: var(--ha-card-border-radius, 12px);
+ border-top-left-radius: var(--ha-card-border-radius, 12px);
+ }
+ .testing.active {
+ max-height: 100px;
+ }
+ .testing.error {
+ background-color: var(--accent-color);
+ }
+ .testing.pass {
+ background-color: var(--success-color);
+ }
`,
];
}
diff --git a/src/translations/en.json b/src/translations/en.json
index 4b7444cb2de8..c254bbbc791e 100644
--- a/src/translations/en.json
+++ b/src/translations/en.json
@@ -4810,6 +4810,11 @@
"condition-editor": {
"explanation": "The card will be shown when ALL conditions below are fulfilled.",
"add": "Add condition",
+ "test": "[%key:ui::panel::config::automation::editor::conditions::test%]",
+ "testing_pass": "[%key:ui::panel::config::automation::editor::conditions::testing_pass%]",
+ "testing_error": "[%key:ui::panel::config::automation::editor::conditions::testing_error%]",
+ "invalid_config_title": "Invalid configuration",
+ "invalid_config_text": "The condition can not be tested because the configuration is not valid.",
"condition": {
"numeric_state": {
"label": "Entity numeric state",