mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 11:46:42 +00:00
More config/entities status filters (#20638)
This commit is contained in:
parent
ec3f63e8a3
commit
c99e0e846b
@ -28,6 +28,7 @@ import { customElement, property, query, state } from "lit/decorators";
|
|||||||
import { ifDefined } from "lit/directives/if-defined";
|
import { ifDefined } from "lit/directives/if-defined";
|
||||||
import { styleMap } from "lit/directives/style-map";
|
import { styleMap } from "lit/directives/style-map";
|
||||||
import memoize from "memoize-one";
|
import memoize from "memoize-one";
|
||||||
|
import { stringCompare } from "../../../common/string/compare";
|
||||||
import { computeCssColor } from "../../../common/color/compute-color";
|
import { computeCssColor } from "../../../common/color/compute-color";
|
||||||
import { storage } from "../../../common/decorators/storage";
|
import { storage } from "../../../common/decorators/storage";
|
||||||
import type { HASSDomEvent } from "../../../common/dom/fire_event";
|
import type { HASSDomEvent } from "../../../common/dom/fire_event";
|
||||||
@ -196,24 +197,40 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private _states = memoize((localize: LocalizeFunc) => [
|
private _states = memoize((localize: LocalizeFunc) =>
|
||||||
{
|
[
|
||||||
value: "disabled",
|
{
|
||||||
label: localize("ui.panel.config.entities.picker.status.disabled"),
|
value: "available",
|
||||||
},
|
label: localize("ui.panel.config.entities.picker.status.available"),
|
||||||
{
|
},
|
||||||
value: "hidden",
|
{
|
||||||
label: localize("ui.panel.config.entities.picker.status.hidden"),
|
value: "disabled",
|
||||||
},
|
label: localize("ui.panel.config.entities.picker.status.disabled"),
|
||||||
{
|
},
|
||||||
value: "unavailable",
|
{
|
||||||
label: localize("ui.panel.config.entities.picker.status.unavailable"),
|
value: "hidden",
|
||||||
},
|
label: localize("ui.panel.config.entities.picker.status.hidden"),
|
||||||
{
|
},
|
||||||
value: "readonly",
|
{
|
||||||
label: localize("ui.panel.config.entities.picker.status.readonly"),
|
value: "unavailable",
|
||||||
},
|
label: localize("ui.panel.config.entities.picker.status.unavailable"),
|
||||||
]);
|
},
|
||||||
|
{
|
||||||
|
value: "readonly",
|
||||||
|
label: localize("ui.panel.config.entities.picker.status.readonly"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: "restored",
|
||||||
|
label: localize("ui.panel.config.entities.picker.status.restored"),
|
||||||
|
},
|
||||||
|
].sort((a, b) =>
|
||||||
|
stringCompare(
|
||||||
|
a.label || a.value,
|
||||||
|
b.label || b.value,
|
||||||
|
this.hass.locale.language
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
private _columns = memoize(
|
private _columns = memoize(
|
||||||
(
|
(
|
||||||
@ -397,10 +414,12 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
|
|||||||
!stateFilters?.length || stateFilters.includes("hidden");
|
!stateFilters?.length || stateFilters.includes("hidden");
|
||||||
const showUnavailable =
|
const showUnavailable =
|
||||||
!stateFilters?.length || stateFilters.includes("unavailable");
|
!stateFilters?.length || stateFilters.includes("unavailable");
|
||||||
|
const showAvailable =
|
||||||
|
!stateFilters?.length || stateFilters.includes("available");
|
||||||
|
const showRestored =
|
||||||
|
!stateFilters?.length || stateFilters.includes("restored");
|
||||||
|
|
||||||
let filteredEntities = showReadOnly
|
let filteredEntities = entities.concat(stateEntities);
|
||||||
? entities.concat(stateEntities)
|
|
||||||
: entities;
|
|
||||||
|
|
||||||
let filteredConfigEntry: ConfigEntry | undefined;
|
let filteredConfigEntry: ConfigEntry | undefined;
|
||||||
const filteredDomains = new Set<string>();
|
const filteredDomains = new Set<string>();
|
||||||
@ -459,26 +478,33 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!showDisabled) {
|
|
||||||
filteredEntities = filteredEntities.filter(
|
|
||||||
(entity) => !entity.disabled_by
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!showHidden) {
|
|
||||||
filteredEntities = filteredEntities.filter(
|
|
||||||
(entity) => !entity.hidden_by
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const entry of filteredEntities) {
|
for (const entry of filteredEntities) {
|
||||||
const entity = this.hass.states[entry.entity_id];
|
const entity = this.hass.states[entry.entity_id];
|
||||||
const unavailable = entity?.state === UNAVAILABLE;
|
const unavailable = entity?.state === UNAVAILABLE;
|
||||||
const restored = entity?.attributes.restored === true;
|
const restored = entity?.attributes.restored === true;
|
||||||
const areaId = entry.area_id ?? devices[entry.device_id!]?.area_id;
|
const areaId = entry.area_id ?? devices[entry.device_id!]?.area_id;
|
||||||
const area = areaId ? areas[areaId] : undefined;
|
const area = areaId ? areas[areaId] : undefined;
|
||||||
|
const hidden = !!entry.hidden_by;
|
||||||
|
const disabled = !!entry.disabled_by;
|
||||||
|
const readonly = entry.readonly;
|
||||||
|
const available = !(
|
||||||
|
unavailable ||
|
||||||
|
readonly ||
|
||||||
|
restored ||
|
||||||
|
hidden ||
|
||||||
|
disabled
|
||||||
|
);
|
||||||
|
|
||||||
if (!showUnavailable && unavailable) {
|
if (
|
||||||
|
!(
|
||||||
|
(showAvailable && available) ||
|
||||||
|
(showUnavailable && unavailable) ||
|
||||||
|
(showRestored && restored) ||
|
||||||
|
(showHidden && hidden) ||
|
||||||
|
(showDisabled && disabled) ||
|
||||||
|
(showReadOnly && readonly)
|
||||||
|
)
|
||||||
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -503,11 +529,11 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
|
|||||||
? localize("ui.panel.config.entities.picker.status.restored")
|
? localize("ui.panel.config.entities.picker.status.restored")
|
||||||
: unavailable
|
: unavailable
|
||||||
? localize("ui.panel.config.entities.picker.status.unavailable")
|
? localize("ui.panel.config.entities.picker.status.unavailable")
|
||||||
: entry.disabled_by
|
: disabled
|
||||||
? localize("ui.panel.config.entities.picker.status.disabled")
|
? localize("ui.panel.config.entities.picker.status.disabled")
|
||||||
: entry.hidden_by
|
: hidden
|
||||||
? localize("ui.panel.config.entities.picker.status.hidden")
|
? localize("ui.panel.config.entities.picker.status.hidden")
|
||||||
: entry.readonly
|
: readonly
|
||||||
? localize(
|
? localize(
|
||||||
"ui.panel.config.entities.picker.status.readonly"
|
"ui.panel.config.entities.picker.status.readonly"
|
||||||
)
|
)
|
||||||
@ -861,7 +887,7 @@ ${
|
|||||||
protected firstUpdated() {
|
protected firstUpdated() {
|
||||||
this._filters = {
|
this._filters = {
|
||||||
"ha-filter-states": {
|
"ha-filter-states": {
|
||||||
value: ["unavailable", "readonly"],
|
value: ["unavailable", "readonly", "restored", "available"],
|
||||||
items: undefined,
|
items: undefined,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user