mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-22 16:56:35 +00:00
Filter entities that will never have entries in the logbook card editor (#12876)
This commit is contained in:
parent
4922e575f8
commit
f464bcfc14
@ -6,7 +6,9 @@ import {
|
||||
} from "../common/const";
|
||||
import { computeDomain } from "../common/entity/compute_domain";
|
||||
import { computeStateDisplay } from "../common/entity/compute_state_display";
|
||||
import { computeStateDomain } from "../common/entity/compute_state_domain";
|
||||
import { LocalizeFunc } from "../common/translations/localize";
|
||||
import { HaEntityPickerEntityFilterFunc } from "../components/entity/ha-entity-picker";
|
||||
import { HomeAssistant } from "../types";
|
||||
import { UNAVAILABLE_STATES } from "./entity";
|
||||
|
||||
@ -425,3 +427,10 @@ export const localizeStateMessage = (
|
||||
: state
|
||||
);
|
||||
};
|
||||
|
||||
export const filterLogbookCompatibleEntities: HaEntityPickerEntityFilterFunc = (
|
||||
entity
|
||||
) =>
|
||||
computeStateDomain(entity) !== "sensor" ||
|
||||
(entity.attributes.unit_of_measurement === undefined &&
|
||||
entity.attributes.state_class === undefined);
|
||||
|
@ -12,7 +12,6 @@ import {
|
||||
} from "date-fns/esm";
|
||||
import { css, html, LitElement, PropertyValues } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
||||
import { navigate } from "../../common/navigate";
|
||||
import {
|
||||
createSearchParam,
|
||||
@ -20,11 +19,11 @@ import {
|
||||
} from "../../common/url/search-params";
|
||||
import { computeRTL } from "../../common/util/compute_rtl";
|
||||
import "../../components/entity/ha-entity-picker";
|
||||
import type { HaEntityPickerEntityFilterFunc } from "../../components/entity/ha-entity-picker";
|
||||
import "../../components/ha-date-range-picker";
|
||||
import type { DateRangePickerRanges } from "../../components/ha-date-range-picker";
|
||||
import "../../components/ha-icon-button";
|
||||
import "../../components/ha-menu-button";
|
||||
import { filterLogbookCompatibleEntities } from "../../data/logbook";
|
||||
import "../../layouts/ha-app-layout";
|
||||
import { haStyle } from "../../resources/styles";
|
||||
import { HomeAssistant } from "../../types";
|
||||
@ -89,7 +88,7 @@ export class HaPanelLogbook extends LitElement {
|
||||
.label=${this.hass.localize(
|
||||
"ui.components.entity.entity-picker.entity"
|
||||
)}
|
||||
.entityFilter=${this._entityFilter}
|
||||
.entityFilter=${filterLogbookCompatibleEntities}
|
||||
@change=${this._entityPicked}
|
||||
></ha-entity-picker>
|
||||
</div>
|
||||
@ -242,17 +241,6 @@ export class HaPanelLogbook extends LitElement {
|
||||
this.shadowRoot!.querySelector("ha-logbook")?.refresh();
|
||||
}
|
||||
|
||||
private _entityFilter: HaEntityPickerEntityFilterFunc = (entity) => {
|
||||
if (computeStateDomain(entity) !== "sensor") {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (
|
||||
entity.attributes.unit_of_measurement === undefined &&
|
||||
entity.attributes.state_class === undefined
|
||||
);
|
||||
};
|
||||
|
||||
static get styles() {
|
||||
return [
|
||||
haStyle,
|
||||
|
@ -17,6 +17,7 @@ import type { HomeAssistant } from "../../../../types";
|
||||
import type { LogbookCardConfig } from "../../cards/types";
|
||||
import type { LovelaceCardEditor } from "../../types";
|
||||
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||
import { filterLogbookCompatibleEntities } from "../../../../data/logbook";
|
||||
|
||||
const cardConfigStruct = assign(
|
||||
baseLovelaceCardConfig,
|
||||
@ -81,6 +82,7 @@ export class HuiLogbookCardEditor
|
||||
<ha-entities-picker
|
||||
.hass=${this.hass}
|
||||
.value=${this._entities}
|
||||
.entityFilter=${filterLogbookCompatibleEntities}
|
||||
@value-changed=${this._entitiesChanged}
|
||||
>
|
||||
</ha-entities-picker>
|
||||
|
Loading…
x
Reference in New Issue
Block a user