@pytest.mark.parametrize('units, attributes, state, value', [(IMPERIAL_SYSTEM, POWER_SENSOR_ATTRIBUTES, 10, 10000), (METRIC_SYSTEM, POWER_SENSOR_ATTRIBUTES, 10, 10000), (IMPERIAL_SYSTEM, TEMPERATURE_SENSOR_ATTRIBUTES, 10, 50), (METRIC_SYSTEM, TEMPERATURE_SENSOR_ATTRIBUTES, 10, 10), (IMPERIAL_SYSTEM, PRESSURE_SENSOR_ATTRIBUTES, 1000, 14.503774389728312), (METRIC_SYSTEM, PRESSURE_SENSOR_ATTRIBUTES, 1000, 100000)])
async def test_statistics_during_period(hass, hass_ws_client, units, attributes, state, value):
    'Test statistics_during_period.'
    now = dt_util.utcnow()
    hass.config.units = units
    (await hass.async_add_executor_job(init_recorder_component, hass))
    (await async_setup_component(hass, 'history', {}))
    (await async_setup_component(hass, 'sensor', {}))
    (await hass.async_add_executor_job(hass.data[recorder.DATA_INSTANCE].block_till_done))
    hass.states.async_set('sensor.test', state, attributes=attributes)
    (await hass.async_block_till_done())
    (await hass.async_add_executor_job(trigger_db_commit, hass))
    (await hass.async_block_till_done())
    hass.data[recorder.DATA_INSTANCE].do_adhoc_statistics(period='hourly', start=now)
    (await hass.async_add_executor_job(hass.data[recorder.DATA_INSTANCE].block_till_done))
    client = (await hass_ws_client())
    (await client.send_json({'id': 1, 'type': 'history/statistics_during_period', 'start_time': now.isoformat(), 'end_time': now.isoformat(), 'statistic_ids': ['sensor.test']}))
    response = (await client.receive_json())
    assert response['success']
    assert (response['result'] == {})
    client = (await hass_ws_client())
    (await client.send_json({'id': 1, 'type': 'history/statistics_during_period', 'start_time': now.isoformat(), 'statistic_ids': ['sensor.test']}))
    response = (await client.receive_json())
    assert response['success']
    assert (response['result'] == {'sensor.test': [{'statistic_id': 'sensor.test', 'start': now.isoformat(), 'mean': approx(value), 'min': approx(value), 'max': approx(value), 'last_reset': None, 'state': None, 'sum': None}]})
Test statistics_during_period.
@pytest.mark.parametrize('units, attributes, state, value', [(IMPERIAL_SYSTEM, POWER_SENSOR_ATTRIBUTES, 10, 10000), (METRIC_SYSTEM, POWER_SENSOR_ATTRIBUTES, 10, 10000), (IMPERIAL_SYSTEM, TEMPERATURE_SENSOR_ATTRIBUTES, 10, 50), (METRIC_SYSTEM, TEMPERATURE_SENSOR_ATTRIBUTES, 10, 10), (IMPERIAL_SYSTEM, PRESSURE_SENSOR_ATTRIBUTES, 1000, 14.503774389728312), (METRIC_SYSTEM, PRESSURE_SENSOR_ATTRIBUTES, 1000, 100000)])
async def test_statistics_during_period(hass, hass_ws_client, units, attributes, state, value):
    
    now = dt_util.utcnow()
    hass.config.units = units
    (await hass.async_add_executor_job(init_recorder_component, hass))
    (await async_setup_component(hass, 'history', {}))
    (await async_setup_component(hass, 'sensor', {}))
    (await hass.async_add_executor_job(hass.data[recorder.DATA_INSTANCE].block_till_done))
    hass.states.async_set('sensor.test', state, attributes=attributes)
    (await hass.async_block_till_done())
    (await hass.async_add_executor_job(trigger_db_commit, hass))
    (await hass.async_block_till_done())
    hass.data[recorder.DATA_INSTANCE].do_adhoc_statistics(period='hourly', start=now)
    (await hass.async_add_executor_job(hass.data[recorder.DATA_INSTANCE].block_till_done))
    client = (await hass_ws_client())
    (await client.send_json({'id': 1, 'type': 'history/statistics_during_period', 'start_time': now.isoformat(), 'end_time': now.isoformat(), 'statistic_ids': ['sensor.test']}))
    response = (await client.receive_json())
    assert response['success']
    assert (response['result'] == {})
    client = (await hass_ws_client())
    (await client.send_json({'id': 1, 'type': 'history/statistics_during_period', 'start_time': now.isoformat(), 'statistic_ids': ['sensor.test']}))
    response = (await client.receive_json())
    assert response['success']
    assert (response['result'] == {'sensor.test': [{'statistic_id': 'sensor.test', 'start': now.isoformat(), 'mean': approx(value), 'min': approx(value), 'max': approx(value), 'last_reset': None, 'state': None, 'sum': None}]})