mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 16:26:43 +00:00
Add entity filter to history panel (#7401)
This commit is contained in:
parent
baf31d1c1e
commit
8c8151be92
@ -85,11 +85,14 @@ export const fetchRecent = (
|
|||||||
export const fetchDate = (
|
export const fetchDate = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
startTime: Date,
|
startTime: Date,
|
||||||
endTime: Date
|
endTime: Date,
|
||||||
|
entityId
|
||||||
): Promise<HassEntity[][]> => {
|
): Promise<HassEntity[][]> => {
|
||||||
return hass.callApi(
|
return hass.callApi(
|
||||||
"GET",
|
"GET",
|
||||||
`history/period/${startTime.toISOString()}?end_time=${endTime.toISOString()}&minimal_response`
|
`history/period/${startTime.toISOString()}?end_time=${endTime.toISOString()}&minimal_response${
|
||||||
|
entityId ? `&filter_entity_id=${entityId}` : ``
|
||||||
|
}`
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import { haStyle } from "../../resources/styles";
|
|||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
import type { DateRangePickerRanges } from "../../components/ha-date-range-picker";
|
import type { DateRangePickerRanges } from "../../components/ha-date-range-picker";
|
||||||
import "../../components/ha-date-range-picker";
|
import "../../components/ha-date-range-picker";
|
||||||
|
import "../../components/entity/ha-entity-picker";
|
||||||
import { fetchDate, computeHistory } from "../../data/history";
|
import { fetchDate, computeHistory } from "../../data/history";
|
||||||
import "../../components/ha-circular-progress";
|
import "../../components/ha-circular-progress";
|
||||||
|
|
||||||
@ -77,6 +78,16 @@ class HaPanelHistory extends LitElement {
|
|||||||
.ranges=${this._ranges}
|
.ranges=${this._ranges}
|
||||||
@change=${this._dateRangeChanged}
|
@change=${this._dateRangeChanged}
|
||||||
></ha-date-range-picker>
|
></ha-date-range-picker>
|
||||||
|
|
||||||
|
<ha-entity-picker
|
||||||
|
.hass=${this.hass}
|
||||||
|
.value=${this._entityId}
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.components.entity.entity-picker.entity"
|
||||||
|
)}
|
||||||
|
.disabled=${this._isLoading}
|
||||||
|
@change=${this._entityPicked}
|
||||||
|
></ha-entity-picker>
|
||||||
</div>
|
</div>
|
||||||
${this._isLoading
|
${this._isLoading
|
||||||
? html`<div class="progress-wrapper">
|
? html`<div class="progress-wrapper">
|
||||||
@ -170,7 +181,8 @@ class HaPanelHistory extends LitElement {
|
|||||||
const dateHistory = await fetchDate(
|
const dateHistory = await fetchDate(
|
||||||
this.hass,
|
this.hass,
|
||||||
this._startDate,
|
this._startDate,
|
||||||
this._endDate
|
this._endDate,
|
||||||
|
this._entityId
|
||||||
);
|
);
|
||||||
this._stateHistory = computeHistory(
|
this._stateHistory = computeHistory(
|
||||||
this.hass,
|
this.hass,
|
||||||
@ -191,6 +203,10 @@ class HaPanelHistory extends LitElement {
|
|||||||
this._endDate = endDate;
|
this._endDate = endDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _entityPicked(ev) {
|
||||||
|
this._entityId = ev.target.value;
|
||||||
|
}
|
||||||
|
|
||||||
static get styles() {
|
static get styles() {
|
||||||
return [
|
return [
|
||||||
haStyle,
|
haStyle,
|
||||||
@ -211,12 +227,32 @@ class HaPanelHistory extends LitElement {
|
|||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ha-date-range-picker {
|
||||||
|
margin-right: 16px;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
:host([narrow]) ha-date-range-picker {
|
||||||
|
margin-right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
ha-circular-progress {
|
ha-circular-progress {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
transform: translate(-50%, -50%);
|
transform: translate(-50%, -50%);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ha-entity-picker {
|
||||||
|
display: inline-block;
|
||||||
|
flex-grow: 1;
|
||||||
|
max-width: 400px;
|
||||||
|
}
|
||||||
|
|
||||||
|
:host([narrow]) ha-entity-picker {
|
||||||
|
max-width: none;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -327,9 +327,6 @@ export class HaPanelLogbook extends LitElement {
|
|||||||
display: inline-block;
|
display: inline-block;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
max-width: 400px;
|
max-width: 400px;
|
||||||
--paper-input-suffix: {
|
|
||||||
height: 24px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
:host([narrow]) ha-entity-picker {
|
:host([narrow]) ha-entity-picker {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user