From c9931b3a3c189e1864f2d32b071a5233626ce625 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Thu, 25 Sep 2025 17:45:06 +0200 Subject: [PATCH] Disabled config badge (#27172) * Add disabled option for badge * Add disabled to struct --- src/data/lovelace/config/badge.ts | 1 + src/panels/lovelace/badges/hui-badge.ts | 15 ++++++++++++--- .../lovelace/editor/structs/base-badge-struct.ts | 3 ++- .../lovelace/editor/structs/base-card-struct.ts | 3 ++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/data/lovelace/config/badge.ts b/src/data/lovelace/config/badge.ts index a6b0734b43..0d58def141 100644 --- a/src/data/lovelace/config/badge.ts +++ b/src/data/lovelace/config/badge.ts @@ -4,6 +4,7 @@ export interface LovelaceBadgeConfig { type: string; [key: string]: any; visibility?: Condition[]; + disabled?: boolean; } export const ensureBadgeConfig = ( diff --git a/src/panels/lovelace/badges/hui-badge.ts b/src/panels/lovelace/badges/hui-badge.ts index 5384de37b6..d89d011c68 100644 --- a/src/panels/lovelace/badges/hui-badge.ts +++ b/src/panels/lovelace/badges/hui-badge.ts @@ -161,7 +161,7 @@ export class HuiBadge extends ReactiveElement { ); } - private _updateVisibility(forceVisible?: boolean) { + private _updateVisibility(ignoreConditions?: boolean) { if (!this._element || !this.hass) { return; } @@ -171,9 +171,18 @@ export class HuiBadge extends ReactiveElement { return; } + if (this.preview) { + this._setElementVisibility(true); + return; + } + + if (this.config?.disabled) { + this._setElementVisibility(false); + return; + } + const visible = - forceVisible || - this.preview || + ignoreConditions || !this.config?.visibility || checkConditionsMet(this.config.visibility, this.hass); this._setElementVisibility(visible); diff --git a/src/panels/lovelace/editor/structs/base-badge-struct.ts b/src/panels/lovelace/editor/structs/base-badge-struct.ts index b738119cef..3428c5b765 100644 --- a/src/panels/lovelace/editor/structs/base-badge-struct.ts +++ b/src/panels/lovelace/editor/structs/base-badge-struct.ts @@ -1,6 +1,7 @@ -import { object, string, any } from "superstruct"; +import { object, string, any, optional, boolean } from "superstruct"; export const baseLovelaceBadgeConfig = object({ type: string(), visibility: any(), + disabled: optional(boolean()), }); diff --git a/src/panels/lovelace/editor/structs/base-card-struct.ts b/src/panels/lovelace/editor/structs/base-card-struct.ts index bef404c39b..ba2f576611 100644 --- a/src/panels/lovelace/editor/structs/base-card-struct.ts +++ b/src/panels/lovelace/editor/structs/base-card-struct.ts @@ -1,4 +1,4 @@ -import { object, string, any } from "superstruct"; +import { object, string, any, optional, boolean } from "superstruct"; export const baseLovelaceCardConfig = object({ type: string(), @@ -6,4 +6,5 @@ export const baseLovelaceCardConfig = object({ layout_options: any(), grid_options: any(), visibility: any(), + disabled: optional(boolean()), });