diff --git a/src/components/map/ha-entity-marker.ts b/src/components/map/ha-entity-marker.ts index 9337184bdc..fd72d2c65a 100644 --- a/src/components/map/ha-entity-marker.ts +++ b/src/components/map/ha-entity-marker.ts @@ -12,6 +12,8 @@ class HaEntityMarker extends LitElement { @property({ attribute: "entity-name" }) public entityName?: string; + @property({ attribute: "entity-unit" }) public entityUnit?: string; + @property({ attribute: "entity-picture" }) public entityPicture?: string; @property({ attribute: "entity-color" }) public entityColor?: string; @@ -37,7 +39,16 @@ class HaEntityMarker extends LitElement { .hass=${this.hass} .stateObj=${this.hass?.states[this.entityId]} >` - : this.entityName} + : !this.entityUnit + ? this.entityName + : html` + ${this.entityName} + ${this.entityUnit} + `} `; } @@ -72,6 +83,9 @@ class HaEntityMarker extends LitElement { height: 100%; width: 100%; } + .unit { + margin-left: 2px; + } `; } diff --git a/src/components/map/ha-map.ts b/src/components/map/ha-map.ts index 53a40ce836..d8a2f1c102 100644 --- a/src/components/map/ha-map.ts +++ b/src/components/map/ha-map.ts @@ -56,6 +56,7 @@ export interface HaMapEntity { color: string; label_mode?: "name" | "state" | "attribute" | "icon"; attribute?: string; + unit?: string; name?: string; focus?: boolean; } @@ -549,6 +550,12 @@ export class HaMap extends ReactiveElement { typeof entity !== "string" && entity.label_mode === "icon"; entityMarker.entityId = getEntityId(entity); entityMarker.entityName = entityName; + entityMarker.entityUnit = + typeof entity !== "string" && + entity.unit && + entity.label_mode === "attribute" + ? entity.unit + : ""; entityMarker.entityPicture = entityPicture && (typeof entity === "string" || !entity.label_mode) ? this.hass.hassUrl(entityPicture) diff --git a/src/panels/lovelace/cards/hui-map-card.ts b/src/panels/lovelace/cards/hui-map-card.ts index d6eacfc376..7c0de67ea7 100644 --- a/src/panels/lovelace/cards/hui-map-card.ts +++ b/src/panels/lovelace/cards/hui-map-card.ts @@ -45,6 +45,7 @@ export const DEFAULT_ZOOM = 14; interface MapEntityConfig extends EntityConfig { label_mode?: "state" | "attribute" | "name"; attribute?: string; + unit?: string; focus?: boolean; } @@ -52,6 +53,7 @@ interface GeoEntity { entity_id: string; label_mode?: "state" | "attribute" | "name" | "icon"; attribute?: string; + unit?: string; focus: boolean; } @@ -430,6 +432,7 @@ class HuiMapCard extends LitElement implements LovelaceCard { entity_id: stateObj.entity_id, label_mode: sourceObj?.label_mode ?? allSource?.label_mode, attribute: sourceObj?.attribute ?? allSource?.attribute, + unit: sourceObj?.unit ?? allSource?.unit, focus: sourceObj ? (sourceObj.focus ?? true) : (allSource?.focus ?? true), @@ -446,6 +449,7 @@ class HuiMapCard extends LitElement implements LovelaceCard { color: this._getColor(entityConf.entity), label_mode: entityConf.label_mode, attribute: entityConf.attribute, + unit: entityConf.unit, focus: entityConf.focus, name: entityConf.name, })), diff --git a/src/panels/lovelace/cards/types.ts b/src/panels/lovelace/cards/types.ts index 39e7ca7d55..52466b2de8 100644 --- a/src/panels/lovelace/cards/types.ts +++ b/src/panels/lovelace/cards/types.ts @@ -323,6 +323,7 @@ interface GeoLocationSourceConfig { source: string; label_mode?: "name" | "state" | "attribute" | "icon"; attribute?: string; + unit?: string; focus?: boolean; } diff --git a/src/panels/lovelace/editor/config-elements/hui-map-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-map-card-editor.ts index 2b05930ddb..365daf51ed 100644 --- a/src/panels/lovelace/editor/config-elements/hui-map-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-map-card-editor.ts @@ -40,6 +40,7 @@ export const mapEntitiesConfigStruct = union([ entity: string(), label_mode: optional(string()), attribute: optional(string()), + unit: optional(string()), focus: optional(boolean()), name: optional(string()), }), @@ -51,6 +52,7 @@ const geoSourcesConfigStruct = union([ source: string(), label_mode: optional(string()), attribute: optional(string()), + unit: optional(string()), focus: optional(boolean()), }), string(),