Add "label_mode = attribute" for Map card (#24708)

* add "label_mode = attribute"

* add "label_mode = atribute"

* added "label_mode = attribute"

* add "attribute" property

* add "attribute" property to GeoLocationSourceConfig

* add "attribute" property

* add "attribute" in _getSourceEntities

* check for entity.attribute !== undefined

* prettier
This commit is contained in:
ildar170975 2025-03-25 15:57:53 +03:00 committed by GitHub
parent f7cb83482a
commit 3320cf1880
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 22 additions and 10 deletions

View File

@ -54,7 +54,8 @@ export interface HaMapPaths {
export interface HaMapEntity { export interface HaMapEntity {
entity_id: string; entity_id: string;
color: string; color: string;
label_mode?: "name" | "state" | "icon"; label_mode?: "name" | "state" | "attribute" | "icon";
attribute?: string;
name?: string; name?: string;
focus?: boolean; focus?: boolean;
} }
@ -531,6 +532,10 @@ export class HaMap extends ReactiveElement {
const entityName = const entityName =
typeof entity !== "string" && entity.label_mode === "state" typeof entity !== "string" && entity.label_mode === "state"
? this.hass.formatEntityState(stateObj) ? this.hass.formatEntityState(stateObj)
: typeof entity !== "string" &&
entity.label_mode === "attribute" &&
entity.attribute !== undefined
? this.hass.formatEntityAttributeValue(stateObj, entity.attribute)
: (customTitle ?? : (customTitle ??
title title
.split(" ") .split(" ")

View File

@ -43,13 +43,15 @@ export const DEFAULT_HOURS_TO_SHOW = 0;
export const DEFAULT_ZOOM = 14; export const DEFAULT_ZOOM = 14;
interface MapEntityConfig extends EntityConfig { interface MapEntityConfig extends EntityConfig {
label_mode?: "state" | "name"; label_mode?: "state" | "attribute" | "name";
attribute?: string;
focus?: boolean; focus?: boolean;
} }
interface GeoEntity { interface GeoEntity {
entity_id: string; entity_id: string;
label_mode?: "state" | "name" | "icon"; label_mode?: "state" | "attribute" | "name" | "icon";
attribute?: string;
focus: boolean; focus: boolean;
} }
@ -422,6 +424,7 @@ class HuiMapCard extends LitElement implements LovelaceCard {
geoEntities.push({ geoEntities.push({
entity_id: stateObj.entity_id, entity_id: stateObj.entity_id,
label_mode: sourceObj?.label_mode ?? allSource?.label_mode, label_mode: sourceObj?.label_mode ?? allSource?.label_mode,
attribute: sourceObj?.attribute ?? allSource?.attribute,
focus: sourceObj focus: sourceObj
? (sourceObj.focus ?? true) ? (sourceObj.focus ?? true)
: (allSource?.focus ?? true), : (allSource?.focus ?? true),
@ -437,6 +440,7 @@ class HuiMapCard extends LitElement implements LovelaceCard {
entity_id: entityConf.entity, entity_id: entityConf.entity,
color: this._getColor(entityConf.entity), color: this._getColor(entityConf.entity),
label_mode: entityConf.label_mode, label_mode: entityConf.label_mode,
attribute: entityConf.attribute,
focus: entityConf.focus, focus: entityConf.focus,
name: entityConf.name, name: entityConf.name,
})), })),

View File

@ -316,7 +316,8 @@ export interface LogbookCardConfig extends LovelaceCardConfig {
interface GeoLocationSourceConfig { interface GeoLocationSourceConfig {
source: string; source: string;
label_mode?: "name" | "state" | "icon"; label_mode?: "name" | "state" | "attribute" | "icon";
attribute?: string;
focus?: boolean; focus?: boolean;
} }

View File

@ -39,6 +39,7 @@ export const mapEntitiesConfigStruct = union([
object({ object({
entity: string(), entity: string(),
label_mode: optional(string()), label_mode: optional(string()),
attribute: optional(string()),
focus: optional(boolean()), focus: optional(boolean()),
name: optional(string()), name: optional(string()),
}), }),
@ -49,6 +50,7 @@ const geoSourcesConfigStruct = union([
object({ object({
source: string(), source: string(),
label_mode: optional(string()), label_mode: optional(string()),
attribute: optional(string()),
focus: optional(boolean()), focus: optional(boolean()),
}), }),
string(), string(),