Fix rate of change calculation of statistics sensor (#32597)

* Fix rate of change of statistics sensor

* Fix test
This commit is contained in:
Florian Werner 2020-03-11 17:33:00 +01:00 committed by GitHub
parent 440c837eb6
commit 5216dc0ae1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View file

@ -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)

View file

@ -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."""