Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TypeError #21734

Merged
merged 5 commits into from Mar 9, 2019
Merged
Diff settings

Always

Just for now

@@ -6,6 +6,7 @@
"""
import asyncio
from datetime import timedelta
from decimal import Decimal
from functools import partial
import logging

@@ -351,7 +352,7 @@ def state(self):
# Recalculate the rate
diff = current_reading - self._previous_reading
timediff = timestamp - self._previous_timestamp
self._state = diff / timediff * 3600
self._state = round(diff / Decimal(timediff.total_seconds()) * 3600, 3)
This conversation was marked as resolved by wburgers

This comment has been minimized.

Copy link
@houndci-bot

houndci-bot Mar 8, 2019

line too long (87 > 79 characters)


self._previous_reading = current_reading
self._previous_timestamp = timestamp
@@ -6,6 +6,7 @@
"""

import asyncio
import datetime
from decimal import Decimal
from unittest.mock import Mock

@@ -104,8 +105,8 @@ def test_derivative():

entity.telegram = {
'1.0.0': MBusObject([
{'value': 1551642213},
{'value': 745.695, 'unit': 'm3'},
{'value': datetime.datetime.fromtimestamp(1551642213)},
{'value': Decimal(745.695), 'unit': 'm3'},
])
}
yield from entity.async_update()
@@ -115,13 +116,13 @@ def test_derivative():

entity.telegram = {
'1.0.0': MBusObject([
{'value': 1551642543},
{'value': 745.698, 'unit': 'm3'},
{'value': datetime.datetime.fromtimestamp(1551642543)},
{'value': Decimal(745.698), 'unit': 'm3'},
])
}
yield from entity.async_update()

assert abs(entity.state - 0.03272) < 0.00001, \
assert abs(entity.state - Decimal(0.033)) < 0.00001, \
'state should be hourly usage calculated from first and second update'

assert entity.unit_of_measurement == 'm3/h'
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.