mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-18 23:06:40 +00:00
Initial support for entity category (#10266)
This commit is contained in:
parent
7fc00ce1cb
commit
48948d5854
@ -187,6 +187,7 @@ const createEntityRegistryEntries = (
|
|||||||
device_id: "mock-device-id",
|
device_id: "mock-device-id",
|
||||||
area_id: null,
|
area_id: null,
|
||||||
disabled_by: null,
|
disabled_by: null,
|
||||||
|
entity_category: null,
|
||||||
entity_id: "binary_sensor.updater",
|
entity_id: "binary_sensor.updater",
|
||||||
name: null,
|
name: null,
|
||||||
icon: null,
|
icon: null,
|
||||||
|
@ -13,6 +13,7 @@ export interface EntityRegistryEntry {
|
|||||||
device_id: string | null;
|
device_id: string | null;
|
||||||
area_id: string | null;
|
area_id: string | null;
|
||||||
disabled_by: string | null;
|
disabled_by: string | null;
|
||||||
|
entity_category: "config" | "diagnostic" | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ExtEntityRegistryEntry extends EntityRegistryEntry {
|
export interface ExtEntityRegistryEntry extends EntityRegistryEntry {
|
||||||
|
@ -25,6 +25,8 @@ import { EntityRegistryStateEntry } from "../ha-config-device-page";
|
|||||||
|
|
||||||
@customElement("ha-device-entities-card")
|
@customElement("ha-device-entities-card")
|
||||||
export class HaDeviceEntitiesCard extends LitElement {
|
export class HaDeviceEntitiesCard extends LitElement {
|
||||||
|
@property() public header!: string;
|
||||||
|
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@property() public entities!: EntityRegistryStateEntry[];
|
@property() public entities!: EntityRegistryStateEntry[];
|
||||||
@ -47,11 +49,7 @@ export class HaDeviceEntitiesCard extends LitElement {
|
|||||||
const disabledEntities: EntityRegistryStateEntry[] = [];
|
const disabledEntities: EntityRegistryStateEntry[] = [];
|
||||||
this._entityRows = [];
|
this._entityRows = [];
|
||||||
return html`
|
return html`
|
||||||
<ha-card
|
<ha-card .header=${this.header}>
|
||||||
.header=${this.hass.localize(
|
|
||||||
"ui.panel.config.devices.entities.entities"
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
${this.entities.length
|
${this.entities.length
|
||||||
? html`
|
? html`
|
||||||
<div id="entities" @hass-more-info=${this._overrideMoreInfo}>
|
<div id="entities" @hass-more-info=${this._overrideMoreInfo}>
|
||||||
|
@ -8,6 +8,7 @@ import { isComponentLoaded } from "../../../common/config/is_component_loaded";
|
|||||||
import { computeStateDomain } from "../../../common/entity/compute_state_domain";
|
import { computeStateDomain } from "../../../common/entity/compute_state_domain";
|
||||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||||
import { stringCompare } from "../../../common/string/compare";
|
import { stringCompare } from "../../../common/string/compare";
|
||||||
|
import { groupBy } from "../../../common/util/group-by";
|
||||||
import { slugify } from "../../../common/string/slugify";
|
import { slugify } from "../../../common/string/slugify";
|
||||||
import "../../../components/entity/ha-battery-icon";
|
import "../../../components/entity/ha-battery-icon";
|
||||||
import "../../../components/ha-icon-button";
|
import "../../../components/ha-icon-button";
|
||||||
@ -112,6 +113,25 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
private _entitiesByCategory = memoizeOne(
|
||||||
|
(entities: EntityRegistryEntry[]) => {
|
||||||
|
const result = groupBy(
|
||||||
|
entities,
|
||||||
|
(entry) => entry.entity_category || "state"
|
||||||
|
) as Record<
|
||||||
|
"state" | NonNullable<EntityRegistryEntry["entity_category"]>,
|
||||||
|
EntityRegistryStateEntry[]
|
||||||
|
>;
|
||||||
|
for (const key of ["state", "diagnostic", "config"]) {
|
||||||
|
if (!(key in result)) {
|
||||||
|
result[key] = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
private _computeArea = memoizeOne(
|
private _computeArea = memoizeOne(
|
||||||
(areas, device): AreaRegistryEntry | undefined => {
|
(areas, device): AreaRegistryEntry | undefined => {
|
||||||
if (!areas || !device || !device.area_id) {
|
if (!areas || !device || !device.area_id) {
|
||||||
@ -159,6 +179,7 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
|
|
||||||
const integrations = this._integrations(device, this.entries);
|
const integrations = this._integrations(device, this.entries);
|
||||||
const entities = this._entities(this.deviceId, this.entities);
|
const entities = this._entities(this.deviceId, this.entities);
|
||||||
|
const entitiesByCategory = this._entitiesByCategory(entities);
|
||||||
const batteryEntity = this._batteryEntity(entities);
|
const batteryEntity = this._batteryEntity(entities);
|
||||||
const batteryChargingEntity = this._batteryChargingEntity(entities);
|
const batteryChargingEntity = this._batteryChargingEntity(entities);
|
||||||
const batteryState = batteryEntity
|
const batteryState = batteryEntity
|
||||||
@ -298,18 +319,22 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
${this._renderIntegrationInfo(device, integrations)}
|
${this._renderIntegrationInfo(device, integrations)}
|
||||||
</ha-device-info-card>
|
</ha-device-info-card>
|
||||||
|
|
||||||
${
|
${["state", "config", "diagnostic"].map((category) =>
|
||||||
entities.length
|
!entitiesByCategory[category].length
|
||||||
? html`
|
? ""
|
||||||
|
: html`
|
||||||
<ha-device-entities-card
|
<ha-device-entities-card
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.entities=${entities}
|
.header=${this.hass.localize(
|
||||||
|
`ui.panel.config.devices.entities.${category}`
|
||||||
|
)}
|
||||||
|
.entities=${entitiesByCategory[category]}
|
||||||
.showDisabled=${device.disabled_by !== null}
|
.showDisabled=${device.disabled_by !== null}
|
||||||
>
|
>
|
||||||
</ha-device-entities-card>
|
</ha-device-entities-card>
|
||||||
`
|
`
|
||||||
: html``
|
)}
|
||||||
}
|
|
||||||
</div>
|
</div>
|
||||||
<div class="column">
|
<div class="column">
|
||||||
${
|
${
|
||||||
|
@ -679,6 +679,7 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
|
|||||||
icon: null,
|
icon: null,
|
||||||
readonly: true,
|
readonly: true,
|
||||||
selectable: false,
|
selectable: false,
|
||||||
|
entity_category: null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (changed) {
|
if (changed) {
|
||||||
|
@ -189,6 +189,7 @@ const adjustName = (name: string): string =>
|
|||||||
hasUpperCase(name.substr(0, name.indexOf(" ")))
|
hasUpperCase(name.substr(0, name.indexOf(" ")))
|
||||||
? name
|
? name
|
||||||
: name[0].toUpperCase() + name.slice(1);
|
: name[0].toUpperCase() + name.slice(1);
|
||||||
|
|
||||||
const computeDefaultViewStates = (
|
const computeDefaultViewStates = (
|
||||||
entities: HassEntities,
|
entities: HassEntities,
|
||||||
entityEntries: EntityRegistryEntry[]
|
entityEntries: EntityRegistryEntry[]
|
||||||
@ -196,7 +197,9 @@ const computeDefaultViewStates = (
|
|||||||
const states = {};
|
const states = {};
|
||||||
const hiddenEntities = new Set(
|
const hiddenEntities = new Set(
|
||||||
entityEntries
|
entityEntries
|
||||||
.filter((entry) => HIDE_PLATFORM.has(entry.platform))
|
.filter(
|
||||||
|
(entry) => entry.entity_category || HIDE_PLATFORM.has(entry.platform)
|
||||||
|
)
|
||||||
.map((entry) => entry.entity_id)
|
.map((entry) => entry.entity_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -2170,6 +2170,9 @@
|
|||||||
"device_not_found": "Device not found.",
|
"device_not_found": "Device not found.",
|
||||||
"entities": {
|
"entities": {
|
||||||
"entities": "Entities",
|
"entities": "Entities",
|
||||||
|
"state": "State",
|
||||||
|
"diagnostic": "Diagnostic",
|
||||||
|
"config": "Config",
|
||||||
"add_entities_lovelace": "Add to Lovelace",
|
"add_entities_lovelace": "Add to Lovelace",
|
||||||
"none": "This device has no entities",
|
"none": "This device has no entities",
|
||||||
"hide_disabled": "Hide disabled",
|
"hide_disabled": "Hide disabled",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user