mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 03:06:41 +00:00
Expand groups in entitry row to check toggle (#6930)
This commit is contained in:
parent
76394ce341
commit
23a9b79320
@ -1,13 +1,14 @@
|
|||||||
import {
|
import {
|
||||||
customElement,
|
customElement,
|
||||||
html,
|
html,
|
||||||
|
internalProperty,
|
||||||
LitElement,
|
LitElement,
|
||||||
property,
|
property,
|
||||||
internalProperty,
|
|
||||||
PropertyValues,
|
PropertyValues,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
} from "lit-element";
|
} from "lit-element";
|
||||||
import { DOMAINS_TOGGLE } from "../../../common/const";
|
import { DOMAINS_TOGGLE } from "../../../common/const";
|
||||||
|
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||||
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
|
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
|
||||||
import "../../../components/entity/ha-entity-toggle";
|
import "../../../components/entity/ha-entity-toggle";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
@ -22,6 +23,19 @@ class HuiGroupEntityRow extends LitElement implements LovelaceRow {
|
|||||||
|
|
||||||
@internalProperty() private _config?: EntityConfig;
|
@internalProperty() private _config?: EntityConfig;
|
||||||
|
|
||||||
|
private _computeCanToggle(hass: HomeAssistant, entityIds: string[]): boolean {
|
||||||
|
return entityIds.some((entityId) => {
|
||||||
|
const domain = computeDomain(entityId);
|
||||||
|
if (domain === "group") {
|
||||||
|
return this._computeCanToggle(
|
||||||
|
hass,
|
||||||
|
this.hass?.states[entityId].attributes["entity_id"]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return DOMAINS_TOGGLE.has(domain);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public setConfig(config: EntityConfig): void {
|
public setConfig(config: EntityConfig): void {
|
||||||
if (!config) {
|
if (!config) {
|
||||||
throw new Error("Configuration error");
|
throw new Error("Configuration error");
|
||||||
@ -50,7 +64,7 @@ class HuiGroupEntityRow extends LitElement implements LovelaceRow {
|
|||||||
|
|
||||||
return html`
|
return html`
|
||||||
<hui-generic-entity-row .hass=${this.hass} .config=${this._config}>
|
<hui-generic-entity-row .hass=${this.hass} .config=${this._config}>
|
||||||
${this._computeCanToggle(stateObj.attributes.entity_id)
|
${this._computeCanToggle(this.hass, stateObj.attributes.entity_id)
|
||||||
? html`
|
? html`
|
||||||
<ha-entity-toggle
|
<ha-entity-toggle
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
@ -69,12 +83,6 @@ class HuiGroupEntityRow extends LitElement implements LovelaceRow {
|
|||||||
</hui-generic-entity-row>
|
</hui-generic-entity-row>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _computeCanToggle(entityIds): boolean {
|
|
||||||
return entityIds.some((entityId) =>
|
|
||||||
DOMAINS_TOGGLE.has(entityId.split(".", 1)[0])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user