-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Sensor filter to round to significant digits #11157
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
base: dev
Are you sure you want to change the base?
Conversation
|
To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file: external_components:
- source: github://pr#11157
components: [const, sensor]
refresh: 1h(Added by the PR bot) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #11157 +/- ##
==========================================
- Coverage 71.74% 71.71% -0.03%
==========================================
Files 53 53
Lines 11031 11031
Branches 1482 1482
==========================================
- Hits 7914 7911 -3
- Misses 2719 2721 +2
- Partials 398 399 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
👋 Hi there! I've automatically requested reviews from codeowners based on the files changed in this PR. @clydebarrow - You've been requested to review this PR as codeowner(s) of 5 file(s) that were modified. Thanks for your time! 🙏 |
|
| "round_to_sigfig", | ||
| RoundSigfigFilter, | ||
| cv.maybe_simple_value( | ||
| { | ||
| cv.Required(CONF_DIGITS): cv.positive_not_null_int, | ||
| }, | ||
| key=CONF_DIGITS, | ||
| ), | ||
| ) | ||
| async def round_sigfig_filter_to_code(config, filter_id): | ||
| return cg.new_Pvariable( | ||
| filter_id, | ||
| config[CONF_DIGITS], | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this is the best name for the filter - "fig" doesn't gel with the "digits" used in the config, and generally speaking abbreviating words in config options is not ideal. Maybe "maximum_significant_digits"? It's wordy, but clear, and eliminates the need to have "digits" as a sub-key.
| "round_to_sigfig", | |
| RoundSigfigFilter, | |
| cv.maybe_simple_value( | |
| { | |
| cv.Required(CONF_DIGITS): cv.positive_not_null_int, | |
| }, | |
| key=CONF_DIGITS, | |
| ), | |
| ) | |
| async def round_sigfig_filter_to_code(config, filter_id): | |
| return cg.new_Pvariable( | |
| filter_id, | |
| config[CONF_DIGITS], | |
| ) | |
| "maximum_significant_digits", | |
| RoundSigfigFilter, | |
| cv.positive_not_null_int, | |
| ) | |
| async def round_sigfig_filter_to_code(config, filter_id): | |
| return cg.new_Pvariable( | |
| filter_id, | |
| config, | |
| ) |
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
What does this implement/fix?
Add a filter to round sensor values to a configured number of significant digits.
Useful for sensors like ambient light which use variable measurement interval and gain to cover a wide value range (0.0072 to 120000 lx), and the current
roundorround_to_multiplefilters aren't effective.round_to_sigfig: 2round_to_sigfig: 4Types of changes
Related issue or feature (if applicable):
Pull request in esphome-docs with documentation (if applicable):
Test Environment
Example entry for
config.yaml:Checklist:
tests/folder).If user exposed functionality or configuration variables are added/changed: