Fix TypeError (#21734)

* timediff is of type timedelta. Divide by timedelta does not work.

- convert a timedelta to int
- make sure the test inputs real timestamps

* Convert the total_seconds to decimal and round the result

readings are of type Decimal, so fix test to reflect that

* split line into multiple statements

Line too long

* use total_seconds instead of timediff

* Make both values float instead of Decimal
This commit is contained in:
Willem Burgers authored and Anders Melchiorsen committed 2019-03-09 17:51:15 +01:00
1 parent be989ebb7e
commit 458548daec
2 files changed
+8 -6

No files matched your search

+2 -1
View File
@@ -351,7 +351,8 @@ class DerivativeDSMREntity(DSMREntity):
# Recalculate the rate
diff = current_reading - self._previous_reading
timediff = timestamp - self._previous_timestamp
self._state = diff / timediff * 3600
total_seconds = timediff.total_seconds()
self._state = round(float(diff) / total_seconds * 3600, 3)
self._previous_reading = current_reading
self._previous_timestamp = timestamp