mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 17:26:42 +00:00
Group managed entities (#3268)
This commit is contained in:
parent
7b0fb949fd
commit
7fa4b18843
@ -54,6 +54,7 @@ class CloudGoogleAssistant extends LitElement {
|
|||||||
private _entityConfigs: CloudPreferences["google_entity_configs"] = {};
|
private _entityConfigs: CloudPreferences["google_entity_configs"] = {};
|
||||||
private _popstateSyncAttached = false;
|
private _popstateSyncAttached = false;
|
||||||
private _popstateReloadStatusAttached = false;
|
private _popstateReloadStatusAttached = false;
|
||||||
|
private _isInitialExposed?: Set<string>;
|
||||||
|
|
||||||
private _getEntityFilterFunc = memoizeOne((filter: EntityFilter) =>
|
private _getEntityFilterFunc = memoizeOne((filter: EntityFilter) =>
|
||||||
generateFilter(
|
generateFilter(
|
||||||
@ -74,8 +75,21 @@ class CloudGoogleAssistant extends LitElement {
|
|||||||
const filterFunc = this._getEntityFilterFunc(
|
const filterFunc = this._getEntityFilterFunc(
|
||||||
this.cloudStatus.google_entities
|
this.cloudStatus.google_entities
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// We will only generate `isInitialExposed` during first render.
|
||||||
|
// On each subsequent render we will use the same set so that cards
|
||||||
|
// will not jump around when we change the exposed setting.
|
||||||
|
const showInExposed = this._isInitialExposed || new Set();
|
||||||
|
const trackExposed = this._isInitialExposed === undefined;
|
||||||
|
|
||||||
let selected = 0;
|
let selected = 0;
|
||||||
const cards = this._entities.map((entity) => {
|
|
||||||
|
// On first render we decide which cards show in which category.
|
||||||
|
// That way cards won't jump around when changing values.
|
||||||
|
const exposedCards: TemplateResult[] = [];
|
||||||
|
const notExposedCards: TemplateResult[] = [];
|
||||||
|
|
||||||
|
this._entities.forEach((entity) => {
|
||||||
const stateObj = this.hass.states[entity.entity_id];
|
const stateObj = this.hass.states[entity.entity_id];
|
||||||
const config = this._entityConfigs[entity.entity_id] || {};
|
const config = this._entityConfigs[entity.entity_id] || {};
|
||||||
const isExposed = emptyFilter
|
const isExposed = emptyFilter
|
||||||
@ -83,9 +97,17 @@ class CloudGoogleAssistant extends LitElement {
|
|||||||
: filterFunc(entity.entity_id);
|
: filterFunc(entity.entity_id);
|
||||||
if (isExposed) {
|
if (isExposed) {
|
||||||
selected++;
|
selected++;
|
||||||
|
|
||||||
|
if (trackExposed) {
|
||||||
|
showInExposed.add(entity.entity_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return html`
|
const target = showInExposed.has(entity.entity_id)
|
||||||
|
? exposedCards
|
||||||
|
: notExposedCards;
|
||||||
|
|
||||||
|
target.push(html`
|
||||||
<ha-card>
|
<ha-card>
|
||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
<state-info
|
<state-info
|
||||||
@ -119,24 +141,31 @@ class CloudGoogleAssistant extends LitElement {
|
|||||||
: ""}
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
</ha-card>
|
</ha-card>
|
||||||
`;
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (trackExposed) {
|
||||||
|
this._isInitialExposed = showInExposed;
|
||||||
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<hass-subpage header="Google Assistant">
|
<hass-subpage header="Google Assistant">
|
||||||
<span slot="toolbar-icon">
|
<span slot="toolbar-icon">
|
||||||
${selected}${!this.narrow
|
${selected}${
|
||||||
|
!this.narrow
|
||||||
? html`
|
? html`
|
||||||
selected
|
selected
|
||||||
`
|
`
|
||||||
: ""}
|
: ""
|
||||||
|
}
|
||||||
</span>
|
</span>
|
||||||
<paper-icon-button
|
<paper-icon-button
|
||||||
slot="toolbar-icon"
|
slot="toolbar-icon"
|
||||||
icon="hass:tune"
|
icon="hass:tune"
|
||||||
@click=${this._openDomainToggler}
|
@click=${this._openDomainToggler}
|
||||||
></paper-icon-button>
|
></paper-icon-button>
|
||||||
${!emptyFilter
|
${
|
||||||
|
!emptyFilter
|
||||||
? html`
|
? html`
|
||||||
<div class="banner">
|
<div class="banner">
|
||||||
Editing which entities are exposed via this UI is disabled
|
Editing which entities are exposed via this UI is disabled
|
||||||
@ -144,9 +173,25 @@ class CloudGoogleAssistant extends LitElement {
|
|||||||
configuration.yaml.
|
configuration.yaml.
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
: ""}
|
: ""
|
||||||
<div class="content">
|
}
|
||||||
${cards}
|
|
||||||
|
${
|
||||||
|
exposedCards.length > 0
|
||||||
|
? html`
|
||||||
|
<h1>Exposed entities</h1>
|
||||||
|
<div class="content">${exposedCards}</div>
|
||||||
|
`
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
${
|
||||||
|
notExposedCards.length > 0
|
||||||
|
? html`
|
||||||
|
<h1>Not Exposed entities</h1>
|
||||||
|
<div class="content">${notExposedCards}</div>
|
||||||
|
`
|
||||||
|
: ""
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</hass-subpage>
|
</hass-subpage>
|
||||||
`;
|
`;
|
||||||
@ -285,6 +330,13 @@ class CloudGoogleAssistant extends LitElement {
|
|||||||
padding: 16px 8px;
|
padding: 16px 8px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
h1 {
|
||||||
|
color: var(--primary-text-color);
|
||||||
|
font-size: 24px;
|
||||||
|
letter-spacing: -0.012em;
|
||||||
|
margin-bottom: 0;
|
||||||
|
padding: 0 8px;
|
||||||
|
}
|
||||||
.content {
|
.content {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
@ -305,6 +357,12 @@ class CloudGoogleAssistant extends LitElement {
|
|||||||
paper-toggle-button {
|
paper-toggle-button {
|
||||||
padding: 8px 0;
|
padding: 8px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media all and (max-width: 450px) {
|
||||||
|
ha-card {
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user