mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 16:26:43 +00:00
Fixes logbook (#12740)
This commit is contained in:
parent
9a9eec40b2
commit
fae1bcf0e0
@ -10,6 +10,7 @@ const LOGBOOK_LOCALIZE_PATH = "ui.components.logbook.messages";
|
|||||||
export const CONTINUOUS_DOMAINS = ["proximity", "sensor"];
|
export const CONTINUOUS_DOMAINS = ["proximity", "sensor"];
|
||||||
|
|
||||||
export interface LogbookEntry {
|
export interface LogbookEntry {
|
||||||
|
// Python timestamp. Do *1000 to get JS timestamp.
|
||||||
when: number;
|
when: number;
|
||||||
name: string;
|
name: string;
|
||||||
message?: string;
|
message?: string;
|
||||||
|
@ -19,7 +19,12 @@ import "./ha-logbook-renderer";
|
|||||||
export class HaLogbook extends LitElement {
|
export class HaLogbook extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@property() public time!: { range: [Date, Date] } | { recent: number };
|
@property() public time!:
|
||||||
|
| { range: [Date, Date] }
|
||||||
|
| {
|
||||||
|
// Seconds
|
||||||
|
recent: number;
|
||||||
|
};
|
||||||
|
|
||||||
@property() public entityIds?: string[];
|
@property() public entityIds?: string[];
|
||||||
|
|
||||||
@ -211,17 +216,19 @@ export class HaLogbook extends LitElement {
|
|||||||
|
|
||||||
let startTime: Date;
|
let startTime: Date;
|
||||||
let endTime: Date;
|
let endTime: Date;
|
||||||
let appendData = false;
|
let purgeBeforePythonTime: number | undefined;
|
||||||
|
|
||||||
if ("range" in this.time) {
|
if ("range" in this.time) {
|
||||||
[startTime, endTime] = this.time.range;
|
[startTime, endTime] = this.time.range;
|
||||||
} else {
|
} else if ("recent" in this.time) {
|
||||||
// Recent data
|
purgeBeforePythonTime =
|
||||||
appendData = true;
|
new Date(new Date().getTime() - this.time.recent * 1000).getTime() /
|
||||||
|
1000;
|
||||||
startTime =
|
startTime =
|
||||||
this._lastLogbookDate ||
|
this._lastLogbookDate || new Date(purgeBeforePythonTime * 1000);
|
||||||
new Date(new Date().getTime() - 24 * 60 * 60 * 1000);
|
|
||||||
endTime = new Date();
|
endTime = new Date();
|
||||||
|
} else {
|
||||||
|
throw new Error("Unexpected time specified");
|
||||||
}
|
}
|
||||||
|
|
||||||
let newEntries: LogbookEntry[];
|
let newEntries: LogbookEntry[];
|
||||||
@ -251,8 +258,13 @@ export class HaLogbook extends LitElement {
|
|||||||
newEntries = [...newEntries].reverse();
|
newEntries = [...newEntries].reverse();
|
||||||
|
|
||||||
this._logbookEntries =
|
this._logbookEntries =
|
||||||
appendData && this._logbookEntries
|
// If we have a purgeBeforeTime, it means we're in recent-mode and fetch batches
|
||||||
? newEntries.concat(...this._logbookEntries)
|
purgeBeforePythonTime && this._logbookEntries
|
||||||
|
? newEntries.concat(
|
||||||
|
...this._logbookEntries.filter(
|
||||||
|
(entry) => entry.when > purgeBeforePythonTime!
|
||||||
|
)
|
||||||
|
)
|
||||||
: newEntries;
|
: newEntries;
|
||||||
this._lastLogbookDate = endTime;
|
this._lastLogbookDate = endTime;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ export class HuiLogbookCard extends LitElement implements LovelaceCard {
|
|||||||
...config,
|
...config,
|
||||||
};
|
};
|
||||||
this._time = {
|
this._time = {
|
||||||
recent: this._config!.hours_to_show! * 60 * 60 * 1000,
|
recent: this._config!.hours_to_show! * 60 * 60,
|
||||||
};
|
};
|
||||||
this._entityId = processConfigEntities<EntityConfig>(config.entities).map(
|
this._entityId = processConfigEntities<EntityConfig>(config.entities).map(
|
||||||
(entity) => entity.entity
|
(entity) => entity.entity
|
||||||
|
Loading…
x
Reference in New Issue
Block a user