async def test_derivative(): """Test calculation of derivative value.""" from dsmr_parser.objects import MBusObject config = {"platform": "dsmr"} entity = DerivativeDSMREntity("test", "test_device", "5678", "1.0.0", config, False) await entity.async_update() assert entity.state is None, "initial state not unknown" entity.telegram = { "1.0.0": MBusObject([ { "value": datetime.datetime.fromtimestamp(1551642213) }, { "value": Decimal(745.695), "unit": VOLUME_CUBIC_METERS }, ]) } await entity.async_update() assert entity.state is None, "state after first update should still be unknown" entity.telegram = { "1.0.0": MBusObject([ { "value": datetime.datetime.fromtimestamp(1551642543) }, { "value": Decimal(745.698), "unit": VOLUME_CUBIC_METERS }, ]) } await entity.async_update() assert ( abs(entity.state - 0.033) < 0.00001 ), "state should be hourly usage calculated from first and second update" assert entity.unit_of_measurement == VOLUME_FLOW_RATE_CUBIC_METERS_PER_HOUR
def test_derivative(): """Test calculation of derivative value.""" from dsmr_parser.objects import MBusObject config = {'platform': 'dsmr'} entity = DerivativeDSMREntity('test', '1.0.0', config) yield from entity.async_update() assert entity.state is None, 'initial state not unknown' entity.telegram = { '1.0.0': MBusObject([ {'value': datetime.datetime.fromtimestamp(1551642213)}, {'value': Decimal(745.695), 'unit': 'm3'}, ]) } yield from entity.async_update() assert entity.state is None, \ 'state after first update should still be unknown' entity.telegram = { '1.0.0': MBusObject([ {'value': datetime.datetime.fromtimestamp(1551642543)}, {'value': Decimal(745.698), 'unit': 'm3'}, ]) } yield from entity.async_update() assert abs(entity.state - 0.033) < 0.00001, \ 'state should be hourly usage calculated from first and second update' assert entity.unit_of_measurement == 'm3/h'
def test_derivative(): """Test calculation of derivative value.""" from dsmr_parser.objects import MBusObject config = {'platform': 'dsmr'} entity = DerivativeDSMREntity('test', '1.0.0', config) yield from entity.async_update() assert entity.state is None, 'initial state not unknown' entity.telegram = { '1.0.0': MBusObject([ { 'value': datetime.datetime.fromtimestamp(1551642213) }, { 'value': Decimal(745.695), 'unit': 'm3' }, ]) } yield from entity.async_update() assert entity.state is None, \ 'state after first update should still be unknown' entity.telegram = { '1.0.0': MBusObject([ { 'value': datetime.datetime.fromtimestamp(1551642543) }, { 'value': Decimal(745.698), 'unit': 'm3' }, ]) } yield from entity.async_update() assert abs(entity.state - 0.033) < 0.00001, \ 'state should be hourly usage calculated from first and second update' assert entity.unit_of_measurement == 'm3/h'