mirror of
https://github.com/home-assistant/frontend.git
synced 2025-08-04 06:57:47 +00:00
Merge branch 'streaming_history_hui-graph-header-footer' into streaming_history_hui-graph-header-footer_maps
This commit is contained in:
commit
be741feb2a
@ -231,37 +231,38 @@ class HistoryStream {
|
|||||||
const purgeBeforePythonTime =
|
const purgeBeforePythonTime =
|
||||||
(new Date().getTime() - 60 * 60 * this.hoursToShow * 1000) / 1000;
|
(new Date().getTime() - 60 * 60 * this.hoursToShow * 1000) / 1000;
|
||||||
const newHistory: HistoryStates = {};
|
const newHistory: HistoryStates = {};
|
||||||
Object.keys(this.combinedHistory).forEach((entityId) => {
|
for (const entityId of Object.keys(this.combinedHistory)) {
|
||||||
newHistory[entityId] = [];
|
newHistory[entityId] = [];
|
||||||
});
|
}
|
||||||
Object.keys(streamMessage.states).forEach((entityId) => {
|
for (const entityId of Object.keys(streamMessage.states)) {
|
||||||
newHistory[entityId] = [];
|
newHistory[entityId] = [];
|
||||||
});
|
}
|
||||||
Object.keys(newHistory).forEach((entityId) => {
|
for (const entityId of Object.keys(newHistory)) {
|
||||||
let purgeOld = false;
|
|
||||||
if (
|
if (
|
||||||
entityId in this.combinedHistory &&
|
entityId in this.combinedHistory &&
|
||||||
entityId in streamMessage.states
|
entityId in streamMessage.states
|
||||||
) {
|
) {
|
||||||
newHistory[entityId] = this.combinedHistory[entityId].concat(
|
const entityCombinedHistory = this.combinedHistory[entityId];
|
||||||
|
const lastEntityCombinedHistory =
|
||||||
|
entityCombinedHistory[entityCombinedHistory.length - 1];
|
||||||
|
newHistory[entityId] = entityCombinedHistory.concat(
|
||||||
streamMessage.states[entityId]
|
streamMessage.states[entityId]
|
||||||
);
|
);
|
||||||
if (
|
if (
|
||||||
streamMessage.states[entityId][0] > this.combinedHistory[entityId][-1]
|
streamMessage.states[entityId][0].lu < lastEntityCombinedHistory.lu
|
||||||
) {
|
) {
|
||||||
// If the history is out of order we have to sort it.
|
// If the history is out of order we have to sort it.
|
||||||
newHistory[entityId] = newHistory[entityId].sort(
|
newHistory[entityId] = newHistory[entityId].sort(
|
||||||
(a, b) => a.lu - b.lu
|
(a, b) => a.lu - b.lu
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
purgeOld = true;
|
|
||||||
} else if (entityId in this.combinedHistory) {
|
} else if (entityId in this.combinedHistory) {
|
||||||
newHistory[entityId] = this.combinedHistory[entityId];
|
newHistory[entityId] = this.combinedHistory[entityId];
|
||||||
purgeOld = true;
|
|
||||||
} else {
|
} else {
|
||||||
newHistory[entityId] = streamMessage.states[entityId];
|
newHistory[entityId] = streamMessage.states[entityId];
|
||||||
}
|
}
|
||||||
if (purgeOld) {
|
// Remove old history
|
||||||
|
if (entityId in this.combinedHistory) {
|
||||||
const entityHistory = newHistory[entityId];
|
const entityHistory = newHistory[entityId];
|
||||||
while (entityHistory[0].lu < purgeBeforePythonTime) {
|
while (entityHistory[0].lu < purgeBeforePythonTime) {
|
||||||
if (entityHistory.length > 1) {
|
if (entityHistory.length > 1) {
|
||||||
@ -277,7 +278,7 @@ class HistoryStream {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
this.combinedHistory = newHistory;
|
this.combinedHistory = newHistory;
|
||||||
return this.combinedHistory;
|
return this.combinedHistory;
|
||||||
}
|
}
|
||||||
|
@ -164,6 +164,9 @@ export class MoreInfoHistory extends LitElement {
|
|||||||
if (!isComponentLoaded(this.hass, "history") || this._subscribed) {
|
if (!isComponentLoaded(this.hass, "history") || this._subscribed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (this._subscribed) {
|
||||||
|
this._unsubscribeHistoryTimeWindow();
|
||||||
|
}
|
||||||
this._subscribed = subscribeHistoryStatesTimeWindow(
|
this._subscribed = subscribeHistoryStatesTimeWindow(
|
||||||
this.hass!,
|
this.hass!,
|
||||||
(combinedHistory) => {
|
(combinedHistory) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user