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

Add Update by time filter #131745

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from

Conversation

dbrand666
Copy link

@dbrand666 dbrand666 commented Nov 27, 2024

Proposed change

As currently implemented, the Time Simple Moving Average filter only gets updated when it receives a new value. This is counter to most people's expectations. See, for example, #57337 "the Time Simple Moving Average shows wrong state when the input sensor doesn't change state".

This is an old issue and Daniel Hjelseth Høyer had created and then abandoned #53053 as an enhancement to let the user ask HA to update the state periodically. That was about 3 years ago.

I rebased that deleted branch, fixed it a bit, and added a test. I think it's time we get this merged.

I followed his lead and left the old behavior intact and added a new flag update_by_time to the existing SMA filter that tells it to update as the time changes - not just on new data.

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:

Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hi @dbrand666

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant
Copy link

Hey there @dgomes, mind taking a look at this pull request as it has been labeled with an integration (filter) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of filter can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign filter Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

Based on deleted branch by Daniel Hjelseth Høyer <[email protected]>
Based on deleted branch by Daniel Hjelseth Høyer <[email protected]>
@dbrand666 dbrand666 force-pushed the update_by_time branch 4 times, most recently from c71bbc8 to b5fa0b0 Compare December 5, 2024 15:46
Note: Since we can't set SCAN_INTERVAL per filter, I'm just letting it default.
@dbrand666 dbrand666 marked this pull request as ready for review December 5, 2024 16:02
@dbrand666 dbrand666 requested review from dgomes and a team as code owners December 5, 2024 16:02
Copy link
Contributor

@dgomes dgomes left a comment

Choose a reason for hiding this comment

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

Not sure if update by time should be considered a filter

homeassistant/components/filter/sensor.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
homeassistant/components/filter/sensor.py Outdated Show resolved Hide resolved
@dbrand666
Copy link
Author

Not sure if update by time should be considered a filter

I'm not sure what you mean. Are you thinking that I should create a new filter for this rather than adding the flag to TimeSMAFilter? What would I call it? TimeSMAFilterV2? TimedTimeSMAFilter? Just TimedSMAFilter?

My own preference would be to treat this as a bugfix and get rid of the update_by_time flag - I really can't see anyone actually expecting the current behavior.

@dgomes
Copy link
Contributor

dgomes commented Dec 5, 2024

Filter is something that processes the output of a source sensor, this is more like a sampler (therefore the need to update by time which is not commanded by the source)

That's also the reason I created https://github.com/dgomes/ha_sampler to keep it separate.

But lets listen to other folks

@MartinHjelmare MartinHjelmare changed the title Update by time Add Update by time filter Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants