Fix rate of change calculation of statistics sensor (#32597)
* Fix rate of change of statistics sensor * Fix test
This commit is contained in:
parent
440c837eb6
commit
5216dc0ae1
2 changed files with 2 additions and 2 deletions
|
@ -267,7 +267,7 @@ class StatisticsSensor(Entity):
|
|||
|
||||
time_diff = (self.max_age - self.min_age).total_seconds()
|
||||
if time_diff > 0:
|
||||
self.change_rate = self.average_change / time_diff
|
||||
self.change_rate = self.change / time_diff
|
||||
|
||||
self.change = round(self.change, self._precision)
|
||||
self.average_change = round(self.average_change, self._precision)
|
||||
|
|
|
@ -36,7 +36,7 @@ class TestStatisticsSensor(unittest.TestCase):
|
|||
self.variance = round(statistics.variance(self.values), 2)
|
||||
self.change = round(self.values[-1] - self.values[0], 2)
|
||||
self.average_change = round(self.change / (len(self.values) - 1), 2)
|
||||
self.change_rate = round(self.average_change / (60 * (self.count - 1)), 2)
|
||||
self.change_rate = round(self.change / (60 * (self.count - 1)), 2)
|
||||
|
||||
def teardown_method(self, method):
|
||||
"""Stop everything that was started."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue