mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
* fix derived rate, fixes #20097 * fix derived rate, fixes #20097 * Fix typo thnx @amelchio * Make the test more realistic Took values from my own smart meter for the test * Update test to ignore rounding issues
This commit is contained in:
parent
818776d2b4
commit
2017e45d78
@ -350,7 +350,8 @@ class DerivativeDSMREntity(DSMREntity):
|
|||||||
else:
|
else:
|
||||||
# Recalculate the rate
|
# Recalculate the rate
|
||||||
diff = current_reading - self._previous_reading
|
diff = current_reading - self._previous_reading
|
||||||
self._state = diff
|
timediff = timestamp - self._previous_timestamp
|
||||||
|
self._state = diff / timediff * 3600
|
||||||
|
|
||||||
self._previous_reading = current_reading
|
self._previous_reading = current_reading
|
||||||
self._previous_timestamp = timestamp
|
self._previous_timestamp = timestamp
|
||||||
|
@ -104,8 +104,8 @@ def test_derivative():
|
|||||||
|
|
||||||
entity.telegram = {
|
entity.telegram = {
|
||||||
'1.0.0': MBusObject([
|
'1.0.0': MBusObject([
|
||||||
{'value': 1},
|
{'value': 1551642213},
|
||||||
{'value': 1, 'unit': 'm3'},
|
{'value': 745.695, 'unit': 'm3'},
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
yield from entity.async_update()
|
yield from entity.async_update()
|
||||||
@ -115,14 +115,14 @@ def test_derivative():
|
|||||||
|
|
||||||
entity.telegram = {
|
entity.telegram = {
|
||||||
'1.0.0': MBusObject([
|
'1.0.0': MBusObject([
|
||||||
{'value': 2},
|
{'value': 1551642543},
|
||||||
{'value': 2, 'unit': 'm3'},
|
{'value': 745.698, 'unit': 'm3'},
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
yield from entity.async_update()
|
yield from entity.async_update()
|
||||||
|
|
||||||
assert entity.state == 1, \
|
assert abs(entity.state - 0.03272) < 0.00001, \
|
||||||
'state should be difference between first and second update'
|
'state should be hourly usage calculated from first and second update'
|
||||||
|
|
||||||
assert entity.unit_of_measurement == 'm3/h'
|
assert entity.unit_of_measurement == 'm3/h'
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user