mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-11 11:26:35 +00:00
Cleanup of partial-cards (#798)
This commit is contained in:
parent
58b2a28fe5
commit
fbe44598ac
@ -317,49 +317,47 @@
|
|||||||
|
|
||||||
hassChanged(hass) {
|
hassChanged(hass) {
|
||||||
if (!hass) return;
|
if (!hass) return;
|
||||||
var views = window.HAWS.extractViews(hass.states);
|
const views = window.HAWS.extractViews(hass.states);
|
||||||
|
let defaultView = null;
|
||||||
// If default view present, it's in first index.
|
// If default view present, it's in first index.
|
||||||
if (views.length > 0 && views[0].entity_id === DEFAULT_VIEW_ENTITY_ID) {
|
if (views.length > 0 && views[0].entity_id === DEFAULT_VIEW_ENTITY_ID) {
|
||||||
this.defaultView = views.shift();
|
defaultView = views.shift();
|
||||||
} else {
|
|
||||||
this.defaultView = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.views = views;
|
this.setProperties({ views, defaultView });
|
||||||
}
|
}
|
||||||
|
|
||||||
isView(currentView, defaultView) {
|
isView(currentView, defaultView) {
|
||||||
return currentView || defaultView;
|
return currentView || defaultView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_defaultViewFilter(hass, entityId) {
|
||||||
|
// Filter out hidden
|
||||||
|
return !hass.states[entityId].attributes.hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
_computeDefaultViewStates(hass, entityIds) {
|
||||||
|
const states = {};
|
||||||
|
entityIds.filter(this._defaultViewFilter.bind(null, hass)).forEach((entityId) => {
|
||||||
|
states[entityId] = hass.states[entityId];
|
||||||
|
});
|
||||||
|
return states;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Compute the states to show for current view.
|
Compute the states to show for current view.
|
||||||
|
|
||||||
Will make sure we always show entities from ALWAYS_SHOW_DOMAINS domains.
|
Will make sure we always show entities from ALWAYS_SHOW_DOMAINS domains.
|
||||||
*/
|
*/
|
||||||
computeViewStates(currentView, hass, defaultView) {
|
computeViewStates(currentView, hass, defaultView) {
|
||||||
var i;
|
const entityIds = Object.keys(hass.states);
|
||||||
var entityId;
|
|
||||||
var state;
|
|
||||||
var states;
|
|
||||||
var entityIds = Object.keys(hass.states);
|
|
||||||
|
|
||||||
// If we base off all entities, only have to filter out hidden
|
// If we base off all entities, only have to filter out hidden
|
||||||
if (!this.isView(currentView, defaultView)) {
|
if (!this.isView(currentView, defaultView)) {
|
||||||
states = {};
|
return this._computeDefaultViewStates(hass, entityIds);
|
||||||
for (i = 0; i < entityIds.length; i++) {
|
|
||||||
entityId = entityIds[i];
|
|
||||||
state = hass.states[entityId];
|
|
||||||
|
|
||||||
// We can filter out hidden and domain at the same time.
|
|
||||||
if (!state.attributes.hidden) {
|
|
||||||
states[entityId] = state;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return states;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let states;
|
||||||
if (currentView) {
|
if (currentView) {
|
||||||
states = window.HAWS.getViewEntities(hass.states, hass.states[currentView]);
|
states = window.HAWS.getViewEntities(hass.states, hass.states[currentView]);
|
||||||
} else {
|
} else {
|
||||||
@ -367,14 +365,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make sure certain domains are always shown.
|
// Make sure certain domains are always shown.
|
||||||
for (i = 0; i < entityIds.length; i++) {
|
entityIds.forEach((entityId) => {
|
||||||
entityId = entityIds[i];
|
const state = hass.states[entityId];
|
||||||
state = hass.states[entityId];
|
|
||||||
|
|
||||||
if (ALWAYS_SHOW_DOMAIN.indexOf(window.hassUtil.computeDomain(state)) !== -1) {
|
if (ALWAYS_SHOW_DOMAIN.includes(window.hassUtil.computeDomain(state))) {
|
||||||
states[entityId] = state;
|
states[entityId] = state;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
return states;
|
return states;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user