mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 03:36:44 +00:00
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:
parent
f7cb83482a
commit
3320cf1880
@ -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,12 +532,16 @@ 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)
|
||||||
: (customTitle ??
|
: typeof entity !== "string" &&
|
||||||
title
|
entity.label_mode === "attribute" &&
|
||||||
.split(" ")
|
entity.attribute !== undefined
|
||||||
.map((part) => part[0])
|
? this.hass.formatEntityAttributeValue(stateObj, entity.attribute)
|
||||||
.join("")
|
: (customTitle ??
|
||||||
.substr(0, 3));
|
title
|
||||||
|
.split(" ")
|
||||||
|
.map((part) => part[0])
|
||||||
|
.join("")
|
||||||
|
.substr(0, 3));
|
||||||
|
|
||||||
const entityMarker = document.createElement("ha-entity-marker");
|
const entityMarker = document.createElement("ha-entity-marker");
|
||||||
entityMarker.hass = this.hass;
|
entityMarker.hass = this.hass;
|
||||||
|
@ -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,
|
||||||
})),
|
})),
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user