Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont count unrecorded time for history_stats #126271

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

karwosts
Copy link
Contributor

Proposed change

History stats seems to have undesired behavior when the observed window starts earlier than what data is available in the recorder. Consider the following case:

  • Your recorder is set for 10 days history
  • You have a history stats to monitor "How long has the sprinkler been on in the last 7 days"
  • You haven't used sprinklers in a long time and all previous states are purged from the recorder.
  • You turn on the sprinklers for the first time.
  • The history stats sensor immediately jumps to 168 hours of on time, despite that it is actually only on for a few seconds.

I see this kind of bug reported many times and it's always difficult to explain why this happens. The reason is because history_stats currently looks for the first datapoint that it can find in the recorder, and it backdates this to the start of the observation window.

I would like to have a discussion if this is the correct behavior or not, since it seems pretty wrong to me.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant