mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 08:16:36 +00:00
Add the "add all device entities to Lovelace" functionality to ZHA device card (#4521)
* fix race condition * add all entities
This commit is contained in:
parent
02fe5144d8
commit
22c8e4a455
@ -42,6 +42,7 @@ import { navigate } from "../../../common/navigate";
|
|||||||
import { UnsubscribeFunc, HassEvent } from "home-assistant-js-websocket";
|
import { UnsubscribeFunc, HassEvent } from "home-assistant-js-websocket";
|
||||||
import { formatAsPaddedHex } from "./functions";
|
import { formatAsPaddedHex } from "./functions";
|
||||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||||
|
import { addEntitiesToLovelaceView } from "../../lovelace/editor/add-entities-to-view";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
// for fire event
|
// for fire event
|
||||||
@ -109,9 +110,6 @@ class ZHADeviceCard extends LitElement {
|
|||||||
this.addEventListener("hass-service-called", (ev) =>
|
this.addEventListener("hass-service-called", (ev) =>
|
||||||
this.serviceCalled(ev)
|
this.serviceCalled(ev)
|
||||||
);
|
);
|
||||||
this._serviceData = {
|
|
||||||
ieee_address: this.device!.ieee,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected updated(changedProperties: PropertyValues): void {
|
protected updated(changedProperties: PropertyValues): void {
|
||||||
@ -125,6 +123,9 @@ class ZHADeviceCard extends LitElement {
|
|||||||
) + 1;
|
) + 1;
|
||||||
}
|
}
|
||||||
this._userGivenName = this.device!.user_given_name;
|
this._userGivenName = this.device!.user_given_name;
|
||||||
|
this._serviceData = {
|
||||||
|
ieee_address: this.device!.ieee,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
super.update(changedProperties);
|
super.update(changedProperties);
|
||||||
}
|
}
|
||||||
@ -223,6 +224,13 @@ class ZHADeviceCard extends LitElement {
|
|||||||
`
|
`
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="card-actions">
|
||||||
|
<mwc-button @click=${this._addToLovelaceView}>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.devices.entities.add_entities_lovelace"
|
||||||
|
)}
|
||||||
|
</mwc-button>
|
||||||
|
</div>
|
||||||
${
|
${
|
||||||
this.showEditableInfo
|
this.showEditableInfo
|
||||||
? html`
|
? html`
|
||||||
@ -396,6 +404,14 @@ class ZHADeviceCard extends LitElement {
|
|||||||
navigate(this, "/config/zha/add/" + this.device!.ieee);
|
navigate(this, "/config/zha/add/" + this.device!.ieee);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _addToLovelaceView(): void {
|
||||||
|
addEntitiesToLovelaceView(
|
||||||
|
this,
|
||||||
|
this.hass,
|
||||||
|
this.device!.entities.map((entity) => entity.entity_id)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static get styles(): CSSResult[] {
|
static get styles(): CSSResult[] {
|
||||||
return [
|
return [
|
||||||
haStyle,
|
haStyle,
|
||||||
|
@ -56,17 +56,26 @@ export class ZHANode extends LitElement {
|
|||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<zha-device-card
|
${this.device
|
||||||
class="card"
|
? html`
|
||||||
.hass=${this.hass}
|
<zha-device-card
|
||||||
.device=${this.device}
|
class="card"
|
||||||
.narrow=${!this.isWide}
|
.hass=${this.hass}
|
||||||
.showHelp=${this._showHelp}
|
.device=${this.device}
|
||||||
showName
|
.narrow=${!this.isWide}
|
||||||
showModelInfo
|
.showHelp=${this._showHelp}
|
||||||
.showEntityDetail=${false}
|
showName
|
||||||
@zha-device-removed=${this._onDeviceRemoved}
|
showModelInfo
|
||||||
></zha-device-card>
|
.showEntityDetail=${false}
|
||||||
|
@zha-device-removed=${this._onDeviceRemoved}
|
||||||
|
></zha-device-card>
|
||||||
|
`
|
||||||
|
: html`
|
||||||
|
<paper-spinner
|
||||||
|
active
|
||||||
|
alt=${this.hass!.localize("ui.common.loading")}
|
||||||
|
></paper-spinner>
|
||||||
|
`}
|
||||||
</div>
|
</div>
|
||||||
</ha-config-section>
|
</ha-config-section>
|
||||||
`;
|
`;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user