From 92b116c0da141e9f31c5f6c970d34816c8d2cc78 Mon Sep 17 00:00:00 2001 From: Philip Allgaier Date: Sat, 30 Jan 2021 22:49:48 +0100 Subject: [PATCH] More precise name handling for auto-generated dashboards (#8289) Co-authored-by: Bram Kragten --- .../lovelace/common/generate-lovelace-config.ts | 14 +++++++++++++- .../lovelace/components/hui-generic-entity-row.ts | 3 --- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/panels/lovelace/common/generate-lovelace-config.ts b/src/panels/lovelace/common/generate-lovelace-config.ts index cf2c1797cb..26e6337213 100644 --- a/src/panels/lovelace/common/generate-lovelace-config.ts +++ b/src/panels/lovelace/common/generate-lovelace-config.ts @@ -184,7 +184,7 @@ export const computeCards = ( (name = computeStateName(stateObj)).startsWith(titlePrefix) ? { entity: entityId, - name: name.substr(titlePrefix.length), + name: adjustName(name.substr(titlePrefix.length)), } : entityId; @@ -203,6 +203,18 @@ export const computeCards = ( return cards; }; +const hasUpperCase = (str: string): boolean => { + return str.toLowerCase() !== str; +}; + +const adjustName = (name: string): string => { + // If first word already has an upper case letter (e.g. from brand name) + // leave as-is, otherwise capitalize the first word. + return hasUpperCase(name.substr(0, name.indexOf(" "))) + ? name + : name[0].toUpperCase() + name.slice(1); +}; + const computeDefaultViewStates = ( entities: HassEntities, entityEntries: EntityRegistryEntry[] diff --git a/src/panels/lovelace/components/hui-generic-entity-row.ts b/src/panels/lovelace/components/hui-generic-entity-row.ts index ddc4b8040d..8bf4b1abbd 100644 --- a/src/panels/lovelace/components/hui-generic-entity-row.ts +++ b/src/panels/lovelace/components/hui-generic-entity-row.ts @@ -173,9 +173,6 @@ class HuiGenericEntityRow extends LitElement { overflow: hidden; text-overflow: ellipsis; } - .info::first-letter { - text-transform: uppercase; - } .flex ::slotted(*) { margin-left: 8px; min-width: 0;