Skip to content

Conversation

dbuezas
Copy link
Owner

@dbuezas dbuezas commented Nov 5, 2022

Update reactively when an entity changes its state.

refresh_interval: auto

dup.last_updated = Math.min(+end, Date.now());
history.push(dup);
range = [startT, history[history.length - 1].timestamp];
history[0].fake_boundary_datapoint = true;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zanna-37 I was doing something else, but it required me to review the code that handles the invented points.
I had remembered it incorrectly and thought HA sent a fake datapoint at the end of the requested interval. Instead (and I think you mentioned this already), HA sends a fake datapoint at the start of the requested interval.

What I did as part of this WIP PR seems to work really well:

  • Fetch from startT-1: this way the first datapoint is either fake, or irrelevant for the requested range.
  • Mark it for deletion (which will only happen if the datapoint is not the first one in the cache)
  • And then (this is below), when clearing old data from the cache, don't modify the first and last datapoints so they match the visible range. Instead, leave them as they are. This is now possible because the visible range is now set explicitely.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean by "clearing old data from the cache"? When does this happen?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happens when one is not "browsing" i.e if one doesn't zoom/scroll or after clicking reset. To avoid accumulating datapoints in ram for ever, the caches is cleared of all data out of the hours_to_show.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also changed how the traces are extended to the present: Instead of doing it inside of the cache, the extra datapoint is only created during plotting. This means that there is nothing to manage or remove later, as far as the cache is concerned, those "fake" points don't exist.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, well done!

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that now that the axis rang is set explicitly, there's no need for it to be this aggressive

@dbuezas dbuezas force-pushed the feat/automatic-refresh branch from 8690682 to 44fb86e Compare November 6, 2022 17:18
@dbuezas dbuezas changed the title WIP Add refresh_interval: auto Add refresh_interval: auto Nov 6, 2022
@dbuezas dbuezas marked this pull request as ready for review November 6, 2022 22:18
@dbuezas dbuezas merged commit 5933916 into master Nov 6, 2022
@dbuezas dbuezas deleted the feat/automatic-refresh branch November 6, 2022 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants