mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 09:16:38 +00:00
Fix device entities not updating (#5983)
This commit is contained in:
parent
b8d2c551e0
commit
6bb3b84377
@ -9,7 +9,6 @@ import {
|
|||||||
LitElement,
|
LitElement,
|
||||||
property,
|
property,
|
||||||
PropertyValues,
|
PropertyValues,
|
||||||
queryAll,
|
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
} from "lit-element";
|
} from "lit-element";
|
||||||
import { computeDomain } from "../../../../common/entity/compute_domain";
|
import { computeDomain } from "../../../../common/entity/compute_domain";
|
||||||
@ -23,6 +22,7 @@ import { addEntitiesToLovelaceView } from "../../../lovelace/editor/add-entities
|
|||||||
import { LovelaceRow } from "../../../lovelace/entity-rows/types";
|
import { LovelaceRow } from "../../../lovelace/entity-rows/types";
|
||||||
import { showEntityEditorDialog } from "../../entities/show-dialog-entity-editor";
|
import { showEntityEditorDialog } from "../../entities/show-dialog-entity-editor";
|
||||||
import { EntityRegistryStateEntry } from "../ha-config-device-page";
|
import { EntityRegistryStateEntry } from "../ha-config-device-page";
|
||||||
|
import { HuiErrorCard } from "../../../lovelace/cards/hui-error-card";
|
||||||
|
|
||||||
@customElement("ha-device-entities-card")
|
@customElement("ha-device-entities-card")
|
||||||
export class HaDeviceEntitiesCard extends LitElement {
|
export class HaDeviceEntitiesCard extends LitElement {
|
||||||
@ -32,20 +32,21 @@ export class HaDeviceEntitiesCard extends LitElement {
|
|||||||
|
|
||||||
@property() private _showDisabled = false;
|
@property() private _showDisabled = false;
|
||||||
|
|
||||||
@queryAll("#entities > *") private _entityRows?: LovelaceRow[];
|
private _entityRows: Array<LovelaceRow | HuiErrorCard> = [];
|
||||||
|
|
||||||
protected shouldUpdate(changedProps: PropertyValues) {
|
protected shouldUpdate(changedProps: PropertyValues) {
|
||||||
if (changedProps.has("hass")) {
|
if (changedProps.has("hass") && changedProps.size === 1) {
|
||||||
this._entityRows?.forEach((element) => {
|
this._entityRows.forEach((element) => {
|
||||||
element.hass = this.hass;
|
element.hass = this.hass;
|
||||||
});
|
});
|
||||||
return changedProps.size > 1;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
const disabledEntities: EntityRegistryStateEntry[] = [];
|
const disabledEntities: EntityRegistryStateEntry[] = [];
|
||||||
|
this._entityRows = [];
|
||||||
return html`
|
return html`
|
||||||
<ha-card
|
<ha-card
|
||||||
.header=${this.hass.localize(
|
.header=${this.hass.localize(
|
||||||
@ -54,7 +55,7 @@ export class HaDeviceEntitiesCard extends LitElement {
|
|||||||
>
|
>
|
||||||
${this.entities.length
|
${this.entities.length
|
||||||
? html`
|
? html`
|
||||||
<div id="entities">
|
<div id="entities" @hass-more-info=${this._overrideMoreInfo}>
|
||||||
${this.entities.map((entry: EntityRegistryStateEntry) => {
|
${this.entities.map((entry: EntityRegistryStateEntry) => {
|
||||||
if (entry.disabled_by) {
|
if (entry.disabled_by) {
|
||||||
disabledEntities.push(entry);
|
disabledEntities.push(entry);
|
||||||
@ -127,8 +128,7 @@ export class HaDeviceEntitiesCard extends LitElement {
|
|||||||
}
|
}
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
element.entry = entry;
|
element.entry = entry;
|
||||||
element.addEventListener("hass-more-info", (ev) => this._openEditEntry(ev));
|
this._entityRows.push(element);
|
||||||
|
|
||||||
return html` <div>${element}</div> `;
|
return html` <div>${element}</div> `;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,8 +148,16 @@ export class HaDeviceEntitiesCard extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _openEditEntry(ev: Event): void {
|
private _overrideMoreInfo(ev: Event): void {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
|
const entry = (ev.target! as any).entry;
|
||||||
|
showEntityEditorDialog(this, {
|
||||||
|
entry,
|
||||||
|
entity_id: entry.entity_id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private _openEditEntry(ev: Event): void {
|
||||||
const entry = (ev.currentTarget! as any).entry;
|
const entry = (ev.currentTarget! as any).entry;
|
||||||
showEntityEditorDialog(this, {
|
showEntityEditorDialog(this, {
|
||||||
entry,
|
entry,
|
||||||
@ -173,7 +181,7 @@ export class HaDeviceEntitiesCard extends LitElement {
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
ha-icon {
|
ha-icon {
|
||||||
width: 40px;
|
margin-left: 8px;
|
||||||
}
|
}
|
||||||
.entity-id {
|
.entity-id {
|
||||||
color: var(--secondary-text-color);
|
color: var(--secondary-text-color);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user