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

Switch statistics config to require either/both 'max_age' and 'sampling_size' #80999

Merged
merged 5 commits into from Nov 17, 2022

Conversation

ThomDietrich
Copy link
Contributor

@ThomDietrich ThomDietrich commented Oct 26, 2022

Breaking change

The configuration of statistics sensors has changed:

  • The state_characteristic configuration setting is now mandatory.
  • The sampling_size configuration setting is now optional and no longer defaults to the arbitrary value 20. Depending on your use case, you can now define sampling_size, max_age, or both. Existing sensors won't behave differently by the change. However, you might want to check whether your currently defined sensors have a meaningful sampling_size configured, or whether you want to remove this setting completely.

Proposed change

This change needs to go into Home Assistant version 2022.12.0.

So far, the statistics component had an implicit configuration of sampling_size: 20. This did (1) confuse users which didn't set any other often more meaningful and higher value for their use case, and did (2) require a user to decide on and configure a reasonable buffer size limit, which is rather tedious for use cases focused on time-bounds rather than sample-size-bounds. Users would work around this issue by e.g. sampling_size: 9999, which is not an acceptable situation.

This PR removes the default sampling_size. Users can now configure max_age OR sampling_size OR both options in the settings of a statistics sensor. If both limits are given, they will be applied equally.

This PR removes the deprecation warnings for sampling_size and state_characteristic. They served their purpose.

All test cases were adapted to the new configuration needs. No new test cases are necessary, as existing ones already check the correct workings of both sampling bounds.

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
  • The code has been formatted using Black (black --fast 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.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@home-assistant
Copy link

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

Code owner commands

Code owners of statistics can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Change the title of the issue.
  • @home-assistant unassign statistics Removes the current integration label and assignees on the issue, add the integration domain after the command.

@ThomDietrich ThomDietrich changed the title Switch statistics config to either/and max_age and sampling_size Switch statistics config to require either/both 'max_age' and 'sampling_size' Oct 26, 2022
@ThomDietrich
Copy link
Contributor Author

@emontnemery ready for review. Thanks!

Copy link
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

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

Thanks, @ThomDietrich 👍

@emontnemery emontnemery merged commit ad8b882 into home-assistant:dev Nov 17, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Nov 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Statistics Sensor has no attributes when measuring binary_sensor entities
4 participants