Use entity name in device info page (#13165)

* Use entity name in device info page

* Adjust to new format

* Use latest API

* Fix types

* Fix CI?

Co-authored-by: Zack <zackbarett@hey.com>
This commit is contained in:
Paulus Schoutsen 2022-07-11 19:07:07 -07:00 committed by GitHub
parent 437723c6a6
commit 729e2f5248
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 16 deletions

View File

@ -1,5 +1,4 @@
// Compat needs to be first import
import "../../src/resources/compatibility";
import { isNavigationClick } from "../../src/common/dom/is-navigation-click";
import { navigate } from "../../src/common/navigate";
import {
@ -7,9 +6,14 @@ import {
provideHass,
} from "../../src/fake_data/provide_hass";
import { HomeAssistantAppEl } from "../../src/layouts/home-assistant";
import "../../src/resources/compatibility";
import { HomeAssistant } from "../../src/types";
import { selectedDemoConfig } from "./configs/demo-configs";
import { mockAuth } from "./stubs/auth";
import { mockConfigEntries } from "./stubs/config_entries";
import { mockEnergy } from "./stubs/energy";
import { energyEntities } from "./stubs/entities";
import { mockEntityRegistry } from "./stubs/entity_registry";
import { mockEvents } from "./stubs/events";
import { mockFrontend } from "./stubs/frontend";
import { mockHistory } from "./stubs/history";
@ -20,10 +24,6 @@ import { mockShoppingList } from "./stubs/shopping_list";
import { mockSystemLog } from "./stubs/system_log";
import { mockTemplate } from "./stubs/template";
import { mockTranslations } from "./stubs/translations";
import { mockEnergy } from "./stubs/energy";
import { energyEntities } from "./stubs/entities";
import { mockConfigEntries } from "./stubs/config_entries";
import { mockEntityRegistry } from "./stubs/entity_registry";
class HaDemo extends HomeAssistantAppEl {
protected async _initializeHass() {
@ -66,6 +66,7 @@ class HaDemo extends HomeAssistantAppEl {
platform: "co2signal",
hidden_by: null,
entity_category: null,
has_entity_name: false,
},
{
config_entry_id: "co2signal",
@ -78,6 +79,7 @@ class HaDemo extends HomeAssistantAppEl {
platform: "co2signal",
hidden_by: null,
entity_category: null,
has_entity_name: false,
},
]);

View File

@ -194,6 +194,7 @@ const createEntityRegistryEntries = (
name: null,
icon: null,
platform: "updater",
has_entity_name: false,
},
];

View File

@ -16,12 +16,13 @@ export interface EntityRegistryEntry {
disabled_by: string | null;
hidden_by: string | null;
entity_category: "config" | "diagnostic" | null;
has_entity_name: boolean;
original_name?: string;
}
export interface ExtEntityRegistryEntry extends EntityRegistryEntry {
unique_id: string;
capabilities: Record<string, unknown>;
original_name?: string;
original_icon?: string;
device_class?: string;
original_device_class?: string;

View File

@ -163,17 +163,27 @@ export class HaDeviceEntitiesCard extends LitElement {
if (this.hass) {
element.hass = this.hass;
const stateObj = this.hass.states[entry.entity_id];
const name = stripPrefixFromEntityName(
let name = entry.name
? entry.name
: entry.has_entity_name
? entry.original_name || this.deviceName
: stripPrefixFromEntityName(
computeStateName(stateObj),
this.deviceName.toLowerCase()
);
if (entry.hidden_by) {
config.name = `${
name || computeStateName(stateObj)
} (${this.hass.localize("ui.panel.config.devices.entities.hidden")})`;
} else if (name) {
config.name = name;
if (!name) {
name = computeStateName(stateObj);
}
if (entry.hidden_by) {
name += ` (${this.hass.localize(
"ui.panel.config.devices.entities.hidden"
)})`;
}
config.name = name;
}
// @ts-ignore
element.entry = entry;

View File

@ -736,6 +736,7 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
readonly: true,
selectable: false,
entity_category: null,
has_entity_name: false,
});
}
if (changed) {