mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Migrate state label badge to entity badge (#21507)
This commit is contained in:
parent
a88a7c5236
commit
da2e530601
@ -57,6 +57,9 @@ export class HuiBadge extends ReactiveElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _updateElement(config: LovelaceBadgeConfig) {
|
private _updateElement(config: LovelaceBadgeConfig) {
|
||||||
|
if (config.type === "state-label") {
|
||||||
|
config = { ...config, type: "entity" };
|
||||||
|
}
|
||||||
if (!this._element) {
|
if (!this._element) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -66,6 +69,9 @@ export class HuiBadge extends ReactiveElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _loadElement(config: LovelaceBadgeConfig) {
|
private _loadElement(config: LovelaceBadgeConfig) {
|
||||||
|
if (config.type === "state-label") {
|
||||||
|
config = { ...config, type: "entity" };
|
||||||
|
}
|
||||||
this._element = createBadgeElement(config);
|
this._element = createBadgeElement(config);
|
||||||
this._elementConfig = config;
|
this._elementConfig = config;
|
||||||
if (this.hass) {
|
if (this.hass) {
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { LovelaceBadgeConfig } from "../../../data/lovelace/config/badge";
|
import { LovelaceBadgeConfig } from "../../../data/lovelace/config/badge";
|
||||||
import "../badges/hui-entity-badge";
|
import "../badges/hui-entity-badge";
|
||||||
import "../badges/hui-state-label-badge";
|
|
||||||
import {
|
import {
|
||||||
createLovelaceElement,
|
createLovelaceElement,
|
||||||
getLovelaceElementClass,
|
getLovelaceElementClass,
|
||||||
tryCreateLovelaceElement,
|
tryCreateLovelaceElement,
|
||||||
} from "./create-element-base";
|
} from "./create-element-base";
|
||||||
|
|
||||||
const ALWAYS_LOADED_TYPES = new Set(["error", "state-label", "entity"]);
|
const ALWAYS_LOADED_TYPES = new Set(["error", "entity"]);
|
||||||
const LAZY_LOAD_TYPES = {
|
const LAZY_LOAD_TYPES = {
|
||||||
"entity-filter": () => import("../badges/hui-entity-filter-badge"),
|
"entity-filter": () => import("../badges/hui-entity-filter-badge"),
|
||||||
|
"state-label": () => import("../badges/hui-state-label-badge"),
|
||||||
};
|
};
|
||||||
|
|
||||||
// This will not return an error card but will throw the error
|
// This will not return an error card but will throw the error
|
||||||
@ -20,7 +20,7 @@ export const tryCreateBadgeElement = (config: LovelaceBadgeConfig) =>
|
|||||||
ALWAYS_LOADED_TYPES,
|
ALWAYS_LOADED_TYPES,
|
||||||
LAZY_LOAD_TYPES,
|
LAZY_LOAD_TYPES,
|
||||||
undefined,
|
undefined,
|
||||||
undefined
|
"entity"
|
||||||
);
|
);
|
||||||
|
|
||||||
export const createBadgeElement = (config: LovelaceBadgeConfig) =>
|
export const createBadgeElement = (config: LovelaceBadgeConfig) =>
|
||||||
|
@ -109,6 +109,10 @@ export class HuiDialogEditBadge
|
|||||||
this._badgeConfig = badge != null ? ensureBadgeConfig(badge) : badge;
|
this._badgeConfig = badge != null ? ensureBadgeConfig(badge) : badge;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this._badgeConfig?.type === "state-label") {
|
||||||
|
this._badgeConfig = { ...this._badgeConfig, type: "entity" };
|
||||||
|
}
|
||||||
|
|
||||||
this.large = false;
|
this.large = false;
|
||||||
if (this._badgeConfig && !Object.isFrozen(this._badgeConfig)) {
|
if (this._badgeConfig && !Object.isFrozen(this._badgeConfig)) {
|
||||||
this._badgeConfig = deepFreeze(this._badgeConfig);
|
this._badgeConfig = deepFreeze(this._badgeConfig);
|
||||||
|
@ -44,6 +44,8 @@ const badgeConfigStruct = assign(
|
|||||||
color: optional(string()),
|
color: optional(string()),
|
||||||
show_entity_picture: optional(boolean()),
|
show_entity_picture: optional(boolean()),
|
||||||
tap_action: optional(actionConfigStruct),
|
tap_action: optional(actionConfigStruct),
|
||||||
|
show_name: optional(boolean()),
|
||||||
|
image: optional(string()),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user