Adding range filter#13390
Conversation
| lower_bound (float): band lower bound | ||
| """ | ||
|
|
||
| def __init__(self, window_size=1, precision=None, entity, |
There was a problem hiding this comment.
SyntaxError: non-default argument follows default argument
| upper = 20 | ||
| filt = BandPassFilter(entity=None, | ||
| lower_bound=lower, | ||
| upper_bound=upper) |
There was a problem hiding this comment.
continuation line under-indented for visual indent
| lower = 10 | ||
| upper = 20 | ||
| filt = BandPassFilter(entity=None, | ||
| lower_bound=lower, |
There was a problem hiding this comment.
continuation line under-indented for visual indent
|
|
||
| from homeassistant.components.sensor.filter import ( | ||
| LowPassFilter, OutlierFilter, ThrottleFilter, TimeSMAFilter) | ||
| LowPassFilter, OutlierFilter, ThrottleFilter, TimeSMAFilter, BandPassFilter) |
There was a problem hiding this comment.
line too long (80 > 79 characters)
| """Initialize common attributes.""" | ||
| super().__init__(FILTER_NAME_OUTLIER, precision, entity) | ||
| self.states = deque(maxlen=window_size) | ||
|
|
| self.states.append(filtered) | ||
| return filtered | ||
|
|
||
| class HistoricalFilter(Filter): |
|
I like the HistoricalFilter, but please keep the PR to one issue only. |
|
Also take into consideration that #13075 has rewritten the filters code to some extend |
8af6d02 to
f5ea55d
Compare
| self._stats_internal = Counter() | ||
|
|
||
| def _filter_state(self, new_state): | ||
| """Implement the outlier filter.""" |
| """ | ||
|
|
||
| def __init__(self, window_size=1, precision=None, entity, | ||
| lower_bound=math.inf, upper_bound=-math.inf): |
There was a problem hiding this comment.
Don't need to set defaults. This is already handled by voluptuous
There was a problem hiding this comment.
Don't need to set defaults, voluptuous handles that
There was a problem hiding this comment.
I would avoid using math.inf (saving the math import) by just defaulting to None
There was a problem hiding this comment.
I would like to keep this (or switch to float('inf') - saving a math import - or sth similar) because this is mathematically more elegant (the lower bound is negative infinite and thus not existant). With None more ugly comparisons are included in the source code.
Also since the newest update default values have to pass the voloptuous check too.
There was a problem hiding this comment.
if lower_bound and value < lower_bound:
return valueThere was a problem hiding this comment.
lets keep python 3.5 math.inf
There was a problem hiding this comment.
I disagree. If there is no bound, we shouldn't check it.
if lower_bound is not None and value < lower_bound
return valueThere was a problem hiding this comment.
Does None pass the validity check for float values in voluptuous?
There was a problem hiding this comment.
Yes, Just mark the key as vol.Optional and not give any default.
62434dc to
d0eafef
Compare
|
A bit nit-picky, but "bandpass" filter is not a good name for this. It's really more like a thresholding filter. Bandpass implies it's getting rid of both high frequency content (noisy info or something) as well as low frequency stuff (ie. maybe some constant value). Just figured I'd point that out seeing as we have a real lowpass filter already implemented, so sticking with the right nomenclature seems important (especially if a real bandpass filter is eventually implemented) |
|
I agree with @fronzbot, we should be rigorous with the naming to avoid misinterpretations by users. |
|
How about I split this filter into a minimum (/threshold) and a maximum value filter?Any name suggestions? Also what do you think of returning None for illegal values and letting the rest of the system do interpolation (instead of replacing the value with some specified value)
|
|
|
I think splitting would lead to a more natural way of applying the filters, setting a maximum and a minimum separately. On my opinion the next in chain filters (or filters in general) should be able to handle None values (if only forwarding them).Regarding filters as some kind of mathematical procedure applied to values there has to be a default / fallback value where I think None is a good choice (as also handled well by home-assistant)
|
|
Perhaps Range Filter or Bounded window |
There was a problem hiding this comment.
continuation line over-indented for visual indent
There was a problem hiding this comment.
continuation line over-indented for visual indent
There was a problem hiding this comment.
continuation line over-indented for visual indent
aed529f to
ee022b9
Compare
|
@nielstron history just got merged, you will need to fix the conflicts |
8aff8ce to
5a8b8eb
Compare
564fcd4 to
33990ba
Compare
|
@dgomes What do you mean "lets keep python 3.5 math.inf"? Is there still a change requested? |
|
I was accepting the use of math.inf but then balloob commented: #13390 (comment) I think you should follow the comment |
|
🎈 |
|
Any update on this? |
|
@nielstron can you make the change and we merge this :) ? |
|
Hello @nielstron, When attempting to inspect the commits of your pull request for CLA signature status among all authors we encountered commit(s) which were not linked to a GitHub account, thus not allowing us to determine their status(es). The commits that are missing a linked GitHub account are the following:
Unfortunately, we are unable to accept this pull request until this situation is corrected. Here are your options:
We apologize for this inconvenience, especially since it usually bites new contributors to Home Assistant. We hope you understand the need for us to protect ourselves and the great community we all have built legally. The best thing to come out of this is that you only need to fix this once and it benefits the entire Home Assistant and GitHub community. Thanks, I look forward to checking this PR again soon! ❤️ |
53976bd to
fb65276
Compare
|
|
||
| def __init__(self, entity, | ||
| lower_bound, upper_bound): | ||
| lower_bound=None, upper_bound=None): |
There was a problem hiding this comment.
There is no need to set *bound=None
|
Hello @nielstron, When attempting to inspect the commits of your pull request for CLA signature status among all authors we encountered commit(s) which were not linked to a GitHub account, thus not allowing us to determine their status(es). The commits that are missing a linked GitHub account are the following:
Unfortunately, we are unable to accept this pull request until this situation is corrected. Here are your options:
We apologize for this inconvenience, especially since it usually bites new contributors to Home Assistant. We hope you understand the need for us to protect ourselves and the great community we all have built legally. The best thing to come out of this is that you only need to fix this once and it benefits the entire Home Assistant and GitHub community. Thanks, I look forward to checking this PR again soon! ❤️ |
c5092f1 to
6420ab5
Compare
|
There you go, sorry for the delay |
|
🥇 |
Description:
As there were issues with the outlier filter this adds a range filter on its own. It only allows values in a given range to pass.
Related issue (if applicable): additional way to solve #13363
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#4985
Example entry for
configuration.yaml(if applicable):Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code does not interact with devices: