Ensure recorder test fixture is setup before hass fixture (#80528)

* Ensure recorder test fixture is setup before hass fixture

* Adjust more tests
pull/80584/head
Erik Montnemery 2022-10-19 07:58:47 +02:00 committed by GitHub
parent c0be1d9fad
commit 31a787558f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
54 changed files with 293 additions and 284 deletions

View File

@ -451,7 +451,7 @@ async def test_send_with_no_energy(hass, aioclient_mock):
assert "energy" not in postdata
async def test_send_with_no_energy_config(hass, aioclient_mock, recorder_mock):
async def test_send_with_no_energy_config(recorder_mock, hass, aioclient_mock):
"""Test send base preferences are defined."""
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200)
analytics = Analytics(hass)
@ -473,7 +473,7 @@ async def test_send_with_no_energy_config(hass, aioclient_mock, recorder_mock):
assert not postdata["energy"]["configured"]
async def test_send_with_energy_config(hass, aioclient_mock, recorder_mock):
async def test_send_with_energy_config(recorder_mock, hass, aioclient_mock):
"""Test send base preferences are defined."""
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200)
analytics = Analytics(hass)

View File

@ -27,7 +27,7 @@ def calls(hass):
return async_mock_service(hass, "test", "automation")
async def test_exclude_attributes(hass, recorder_mock, calls):
async def test_exclude_attributes(recorder_mock, hass, calls):
"""Test automation registered attributes to be excluded."""
assert await async_setup_component(
hass,

View File

@ -13,7 +13,7 @@ from tests.common import async_fire_time_changed
from tests.components.recorder.common import async_wait_recording_done
async def test_events_http_api(hass, recorder_mock):
async def test_events_http_api(recorder_mock, hass):
"""Test the calendar demo view."""
await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}})
await hass.async_block_till_done()

View File

@ -20,7 +20,7 @@ from tests.common import async_fire_time_changed
from tests.components.recorder.common import async_wait_recording_done
async def test_exclude_attributes(hass, recorder_mock):
async def test_exclude_attributes(recorder_mock, hass):
"""Test camera registered attributes to be excluded."""
await async_setup_component(
hass, camera.DOMAIN, {camera.DOMAIN: {"platform": "demo"}}

View File

@ -26,7 +26,7 @@ from tests.common import async_fire_time_changed
from tests.components.recorder.common import async_wait_recording_done
async def test_exclude_attributes(hass, recorder_mock):
async def test_exclude_attributes(recorder_mock, hass):
"""Test climate registered attributes to be excluded."""
await async_setup_component(
hass, climate.DOMAIN, {climate.DOMAIN: {"platform": "demo"}}

View File

@ -22,20 +22,20 @@ from homeassistant.util.unit_system import IMPERIAL_SYSTEM
from tests.components.recorder.common import async_wait_recording_done
@pytest.fixture(autouse=True)
@pytest.fixture
def mock_history(hass):
"""Mock history component loaded."""
hass.config.components.add("history")
@pytest.fixture(autouse=True)
def mock_device_tracker_update_config(hass):
def mock_device_tracker_update_config():
"""Prevent device tracker from creating known devices file."""
with patch("homeassistant.components.device_tracker.legacy.update_config"):
yield
async def test_setting_up_demo(hass):
async def test_setting_up_demo(mock_history, hass):
"""Test if we can set up the demo and dump it to JSON."""
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
await hass.async_block_till_done()
@ -52,7 +52,7 @@ async def test_setting_up_demo(hass):
)
async def test_demo_statistics(hass, recorder_mock):
async def test_demo_statistics(recorder_mock, mock_history, hass):
"""Test that the demo components makes some statistics available."""
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
await hass.async_block_till_done()
@ -82,7 +82,7 @@ async def test_demo_statistics(hass, recorder_mock):
} in statistic_ids
async def test_demo_statistics_growth(hass, recorder_mock):
async def test_demo_statistics_growth(recorder_mock, mock_history, hass):
"""Test that the demo sum statistics adds to the previous state."""
hass.config.units = IMPERIAL_SYSTEM
@ -120,7 +120,7 @@ async def test_demo_statistics_growth(hass, recorder_mock):
assert statistics[statistic_id][0]["sum"] <= (2**20 + 24)
async def test_issues_created(hass, hass_client, hass_ws_client):
async def test_issues_created(mock_history, hass, hass_client, hass_ws_client):
"""Test issues are created and can be fixed."""
assert await async_setup_component(hass, REPAIRS_DOMAIN, {REPAIRS_DOMAIN: {}})
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})

View File

@ -49,7 +49,7 @@ def get_statistics_for_entity(statistics_results, entity_id):
return None
async def test_cost_sensor_no_states(hass, hass_storage, setup_integration) -> None:
async def test_cost_sensor_no_states(setup_integration, hass, hass_storage) -> None:
"""Test sensors are created."""
energy_data = data.EnergyManager.default_preferences()
energy_data["energy_sources"].append(
@ -75,7 +75,7 @@ async def test_cost_sensor_no_states(hass, hass_storage, setup_integration) -> N
# TODO: No states, should the cost entity refuse to setup?
async def test_cost_sensor_attributes(hass, hass_storage, setup_integration) -> None:
async def test_cost_sensor_attributes(setup_integration, hass, hass_storage) -> None:
"""Test sensor attributes."""
energy_data = data.EnergyManager.default_preferences()
energy_data["energy_sources"].append(
@ -124,10 +124,10 @@ async def test_cost_sensor_attributes(hass, hass_storage, setup_integration) ->
],
)
async def test_cost_sensor_price_entity_total_increasing(
setup_integration,
hass,
hass_storage,
hass_ws_client,
setup_integration,
initial_energy,
initial_cost,
price_entity,
@ -327,10 +327,10 @@ async def test_cost_sensor_price_entity_total_increasing(
)
@pytest.mark.parametrize("energy_state_class", ["total", "measurement"])
async def test_cost_sensor_price_entity_total(
setup_integration,
hass,
hass_storage,
hass_ws_client,
setup_integration,
initial_energy,
initial_cost,
price_entity,
@ -533,10 +533,10 @@ async def test_cost_sensor_price_entity_total(
)
@pytest.mark.parametrize("energy_state_class", ["total"])
async def test_cost_sensor_price_entity_total_no_reset(
setup_integration,
hass,
hass_storage,
hass_ws_client,
setup_integration,
initial_energy,
initial_cost,
price_entity,
@ -706,7 +706,7 @@ async def test_cost_sensor_price_entity_total_no_reset(
],
)
async def test_cost_sensor_handle_energy_units(
hass, hass_storage, setup_integration, energy_unit, factor
setup_integration, hass, hass_storage, energy_unit, factor
) -> None:
"""Test energy cost price from sensor entity."""
energy_attributes = {
@ -771,7 +771,7 @@ async def test_cost_sensor_handle_energy_units(
],
)
async def test_cost_sensor_handle_price_units(
hass, hass_storage, setup_integration, price_unit, factor
setup_integration, hass, hass_storage, price_unit, factor
) -> None:
"""Test energy cost price from sensor entity."""
energy_attributes = {
@ -834,7 +834,7 @@ async def test_cost_sensor_handle_price_units(
@pytest.mark.parametrize("unit", (VOLUME_CUBIC_FEET, VOLUME_CUBIC_METERS))
async def test_cost_sensor_handle_gas(
hass, hass_storage, setup_integration, unit
setup_integration, hass, hass_storage, unit
) -> None:
"""Test gas cost price from sensor entity."""
energy_attributes = {
@ -884,7 +884,7 @@ async def test_cost_sensor_handle_gas(
async def test_cost_sensor_handle_gas_kwh(
hass, hass_storage, setup_integration
setup_integration, hass, hass_storage
) -> None:
"""Test gas cost price from sensor entity."""
energy_attributes = {
@ -935,7 +935,7 @@ async def test_cost_sensor_handle_gas_kwh(
@pytest.mark.parametrize("state_class", [None])
async def test_cost_sensor_wrong_state_class(
hass, hass_storage, setup_integration, caplog, state_class
setup_integration, hass, hass_storage, caplog, state_class
) -> None:
"""Test energy sensor rejects sensor with wrong state_class."""
energy_attributes = {
@ -996,7 +996,7 @@ async def test_cost_sensor_wrong_state_class(
@pytest.mark.parametrize("state_class", [SensorStateClass.MEASUREMENT])
async def test_cost_sensor_state_class_measurement_no_reset(
hass, hass_storage, setup_integration, caplog, state_class
setup_integration, hass, hass_storage, caplog, state_class
) -> None:
"""Test energy sensor rejects state_class measurement with no last_reset."""
energy_attributes = {
@ -1051,7 +1051,7 @@ async def test_cost_sensor_state_class_measurement_no_reset(
assert state.state == STATE_UNKNOWN
async def test_inherit_source_unique_id(hass, hass_storage, setup_integration):
async def test_inherit_source_unique_id(setup_integration, hass, hass_storage):
"""Test sensor inherits unique ID from source."""
energy_data = data.EnergyManager.default_preferences()
energy_data["energy_sources"].append(

View File

@ -48,7 +48,7 @@ def mock_get_metadata():
@pytest.fixture(autouse=True)
async def mock_energy_manager(hass, recorder_mock):
async def mock_energy_manager(recorder_mock, hass):
"""Set up energy."""
assert await async_setup_component(hass, "energy", {"energy": {}})
manager = await async_get_manager(hass)

View File

@ -16,7 +16,7 @@ from tests.components.recorder.common import (
@pytest.fixture(autouse=True)
async def setup_integration(hass, recorder_mock):
async def setup_integration(recorder_mock, hass):
"""Set up the integration."""
assert await async_setup_component(hass, "energy", {})
@ -289,7 +289,7 @@ async def test_get_solar_forecast(hass, hass_ws_client, mock_energy_platform) ->
@pytest.mark.freeze_time("2021-08-01 00:00:00+00:00")
async def test_fossil_energy_consumption_no_co2(hass, hass_ws_client, recorder_mock):
async def test_fossil_energy_consumption_no_co2(recorder_mock, hass, hass_ws_client):
"""Test fossil_energy_consumption when co2 data is missing."""
now = dt_util.utcnow()
later = dt_util.as_utc(dt_util.parse_datetime("2022-09-01 00:00:00"))
@ -450,7 +450,7 @@ async def test_fossil_energy_consumption_no_co2(hass, hass_ws_client, recorder_m
@pytest.mark.freeze_time("2021-08-01 00:00:00+00:00")
async def test_fossil_energy_consumption_hole(hass, hass_ws_client, recorder_mock):
async def test_fossil_energy_consumption_hole(recorder_mock, hass, hass_ws_client):
"""Test fossil_energy_consumption when some data points lack sum."""
now = dt_util.utcnow()
later = dt_util.as_utc(dt_util.parse_datetime("2022-09-01 00:00:00"))
@ -611,7 +611,7 @@ async def test_fossil_energy_consumption_hole(hass, hass_ws_client, recorder_moc
@pytest.mark.freeze_time("2021-08-01 00:00:00+00:00")
async def test_fossil_energy_consumption_no_data(hass, hass_ws_client, recorder_mock):
async def test_fossil_energy_consumption_no_data(recorder_mock, hass, hass_ws_client):
"""Test fossil_energy_consumption when there is no data."""
now = dt_util.utcnow()
later = dt_util.as_utc(dt_util.parse_datetime("2022-09-01 00:00:00"))
@ -759,7 +759,7 @@ async def test_fossil_energy_consumption_no_data(hass, hass_ws_client, recorder_
@pytest.mark.freeze_time("2021-08-01 00:00:00+00:00")
async def test_fossil_energy_consumption(hass, hass_ws_client, recorder_mock):
async def test_fossil_energy_consumption(recorder_mock, hass, hass_ws_client):
"""Test fossil_energy_consumption with co2 sensor data."""
now = dt_util.utcnow()
later = dt_util.as_utc(dt_util.parse_datetime("2022-09-01 00:00:00"))

View File

@ -16,7 +16,7 @@ from tests.common import async_fire_time_changed
from tests.components.recorder.common import async_wait_recording_done
async def test_exclude_attributes(hass, recorder_mock):
async def test_exclude_attributes(recorder_mock, hass):
"""Test fan registered attributes to be excluded."""
await async_setup_component(hass, fan.DOMAIN, {fan.DOMAIN: {"platform": "demo"}})
await hass.async_block_till_done()

View File

@ -59,7 +59,7 @@ async def test_setup_fail(hass):
await hass.async_block_till_done()
async def test_chain(hass, recorder_mock, values):
async def test_chain(recorder_mock, hass, values):
"""Test if filter chaining works."""
config = {
"sensor": {
@ -87,7 +87,7 @@ async def test_chain(hass, recorder_mock, values):
@pytest.mark.parametrize("missing", (True, False))
async def test_chain_history(hass, recorder_mock, values, missing):
async def test_chain_history(recorder_mock, hass, values, missing):
"""Test if filter chaining works, when a source is and isn't recorded."""
config = {
"sensor": {
@ -141,7 +141,7 @@ async def test_chain_history(hass, recorder_mock, values, missing):
assert state.state == "17.05"
async def test_source_state_none(hass, recorder_mock, values):
async def test_source_state_none(recorder_mock, hass, values):
"""Test is source sensor state is null and sets state to STATE_UNKNOWN."""
config = {
@ -201,7 +201,7 @@ async def test_source_state_none(hass, recorder_mock, values):
assert state.state == STATE_UNKNOWN
async def test_history_time(hass, recorder_mock):
async def test_history_time(recorder_mock, hass):
"""Test loading from history based on a time window."""
config = {
"sensor": {
@ -239,7 +239,7 @@ async def test_history_time(hass, recorder_mock):
assert state.state == "18.0"
async def test_setup(hass, recorder_mock):
async def test_setup(recorder_mock, hass):
"""Test if filter attributes are inherited."""
config = {
"sensor": {
@ -280,7 +280,7 @@ async def test_setup(hass, recorder_mock):
assert entity_id == "sensor.test"
async def test_invalid_state(hass, recorder_mock):
async def test_invalid_state(recorder_mock, hass):
"""Test if filter attributes are inherited."""
config = {
"sensor": {
@ -310,7 +310,7 @@ async def test_invalid_state(hass, recorder_mock):
assert state.state == STATE_UNAVAILABLE
async def test_timestamp_state(hass, recorder_mock):
async def test_timestamp_state(recorder_mock, hass):
"""Test if filter state is a datetime."""
config = {
"sensor": {
@ -469,7 +469,7 @@ def test_time_sma(values):
assert filtered.state == 21.5
async def test_reload(hass, recorder_mock):
async def test_reload(recorder_mock, hass):
"""Verify we can reload filter sensors."""
hass.states.async_set("sensor.test_monitored", 12345)
await async_setup_component(

View File

@ -16,7 +16,7 @@ from tests.common import async_fire_time_changed
from tests.components.recorder.common import async_wait_recording_done
async def test_exclude_attributes(hass, recorder_mock):
async def test_exclude_attributes(recorder_mock, hass):
"""Test number registered attributes to be excluded."""
hass.states.async_set("light.bowl", STATE_ON)

View File

@ -587,7 +587,7 @@ def record_states(hass):
return zero, four, states
async def test_fetch_period_api(hass, hass_client, recorder_mock):
async def test_fetch_period_api(recorder_mock, hass, hass_client):
"""Test the fetch period view for history."""
await async_setup_component(hass, "history", {})
client = await hass_client()
@ -596,7 +596,7 @@ async def test_fetch_period_api(hass, hass_client, recorder_mock):
async def test_fetch_period_api_with_use_include_order(
hass, hass_client, recorder_mock
recorder_mock, hass, hass_client
):
"""Test the fetch period view for history with include order."""
await async_setup_component(
@ -607,7 +607,7 @@ async def test_fetch_period_api_with_use_include_order(
assert response.status == HTTPStatus.OK
async def test_fetch_period_api_with_minimal_response(hass, recorder_mock, hass_client):
async def test_fetch_period_api_with_minimal_response(recorder_mock, hass, hass_client):
"""Test the fetch period view for history with minimal_response."""
now = dt_util.utcnow()
await async_setup_component(hass, "history", {})
@ -647,7 +647,7 @@ async def test_fetch_period_api_with_minimal_response(hass, recorder_mock, hass_
).replace('"', "")
async def test_fetch_period_api_with_no_timestamp(hass, hass_client, recorder_mock):
async def test_fetch_period_api_with_no_timestamp(recorder_mock, hass, hass_client):
"""Test the fetch period view for history with no timestamp."""
await async_setup_component(hass, "history", {})
client = await hass_client()
@ -655,7 +655,7 @@ async def test_fetch_period_api_with_no_timestamp(hass, hass_client, recorder_mo
assert response.status == HTTPStatus.OK
async def test_fetch_period_api_with_include_order(hass, hass_client, recorder_mock):
async def test_fetch_period_api_with_include_order(recorder_mock, hass, hass_client):
"""Test the fetch period view for history."""
await async_setup_component(
hass,
@ -676,7 +676,7 @@ async def test_fetch_period_api_with_include_order(hass, hass_client, recorder_m
async def test_fetch_period_api_with_entity_glob_include(
hass, hass_client, recorder_mock
recorder_mock, hass, hass_client
):
"""Test the fetch period view for history."""
await async_setup_component(
@ -704,7 +704,7 @@ async def test_fetch_period_api_with_entity_glob_include(
async def test_fetch_period_api_with_entity_glob_exclude(
hass, hass_client, recorder_mock
recorder_mock, hass, hass_client
):
"""Test the fetch period view for history."""
await async_setup_component(
@ -744,7 +744,7 @@ async def test_fetch_period_api_with_entity_glob_exclude(
async def test_fetch_period_api_with_entity_glob_include_and_exclude(
hass, hass_client, recorder_mock
recorder_mock, hass, hass_client
):
"""Test the fetch period view for history."""
await async_setup_component(
@ -786,7 +786,7 @@ async def test_fetch_period_api_with_entity_glob_include_and_exclude(
assert response_json[3][0]["entity_id"] == "switch.match"
async def test_entity_ids_limit_via_api(hass, hass_client, recorder_mock):
async def test_entity_ids_limit_via_api(recorder_mock, hass, hass_client):
"""Test limiting history to entity_ids."""
await async_setup_component(
hass,
@ -811,7 +811,7 @@ async def test_entity_ids_limit_via_api(hass, hass_client, recorder_mock):
async def test_entity_ids_limit_via_api_with_skip_initial_state(
hass, hass_client, recorder_mock
recorder_mock, hass, hass_client
):
"""Test limiting history to entity_ids with skip_initial_state."""
await async_setup_component(
@ -844,7 +844,7 @@ async def test_entity_ids_limit_via_api_with_skip_initial_state(
assert response_json[1][0]["entity_id"] == "light.cow"
async def test_statistics_during_period(hass, hass_ws_client, recorder_mock, caplog):
async def test_statistics_during_period(recorder_mock, hass, hass_ws_client, caplog):
"""Test history/statistics_during_period forwards to recorder."""
now = dt_util.utcnow()
await async_setup_component(hass, "history", {})
@ -889,7 +889,7 @@ async def test_statistics_during_period(hass, hass_ws_client, recorder_mock, cap
ws_mock.assert_awaited_once()
async def test_list_statistic_ids(hass, hass_ws_client, recorder_mock, caplog):
async def test_list_statistic_ids(recorder_mock, hass, hass_ws_client, caplog):
"""Test history/list_statistic_ids forwards to recorder."""
await async_setup_component(hass, "history", {})
client = await hass_ws_client()
@ -914,7 +914,7 @@ async def test_list_statistic_ids(hass, hass_ws_client, recorder_mock, caplog):
ws_mock.assert_called_once()
async def test_history_during_period(hass, hass_ws_client, recorder_mock):
async def test_history_during_period(recorder_mock, hass, hass_ws_client):
"""Test history_during_period."""
now = dt_util.utcnow()
@ -1047,7 +1047,7 @@ async def test_history_during_period(hass, hass_ws_client, recorder_mock):
async def test_history_during_period_impossible_conditions(
hass, hass_ws_client, recorder_mock
recorder_mock, hass, hass_ws_client
):
"""Test history_during_period returns when condition cannot be true."""
await async_setup_component(hass, "history", {})
@ -1109,7 +1109,7 @@ async def test_history_during_period_impossible_conditions(
"time_zone", ["UTC", "Europe/Berlin", "America/Chicago", "US/Hawaii"]
)
async def test_history_during_period_significant_domain(
time_zone, hass, hass_ws_client, recorder_mock
time_zone, recorder_mock, hass, hass_ws_client
):
"""Test history_during_period with climate domain."""
hass.config.set_time_zone(time_zone)
@ -1274,7 +1274,7 @@ async def test_history_during_period_significant_domain(
async def test_history_during_period_bad_start_time(
hass, hass_ws_client, recorder_mock
recorder_mock, hass, hass_ws_client
):
"""Test history_during_period bad state time."""
await async_setup_component(
@ -1296,7 +1296,7 @@ async def test_history_during_period_bad_start_time(
assert response["error"]["code"] == "invalid_start_time"
async def test_history_during_period_bad_end_time(hass, hass_ws_client, recorder_mock):
async def test_history_during_period_bad_end_time(recorder_mock, hass, hass_ws_client):
"""Test history_during_period bad end time."""
now = dt_util.utcnow()
@ -1321,7 +1321,7 @@ async def test_history_during_period_bad_end_time(hass, hass_ws_client, recorder
async def test_history_during_period_with_use_include_order(
hass, hass_ws_client, recorder_mock
recorder_mock, hass, hass_ws_client
):
"""Test history_during_period."""
now = dt_util.utcnow()

View File

@ -136,7 +136,7 @@ class TestHistoryStatsSensor(unittest.TestCase):
self.hass.start()
async def test_invalid_date_for_start(hass, recorder_mock):
async def test_invalid_date_for_start(recorder_mock, hass):
"""Verify with an invalid date for start."""
await async_setup_component(
hass,
@ -161,7 +161,7 @@ async def test_invalid_date_for_start(hass, recorder_mock):
assert hass.states.get("sensor.test") is None
async def test_invalid_date_for_end(hass, recorder_mock):
async def test_invalid_date_for_end(recorder_mock, hass):
"""Verify with an invalid date for end."""
await async_setup_component(
hass,
@ -186,7 +186,7 @@ async def test_invalid_date_for_end(hass, recorder_mock):
assert hass.states.get("sensor.test") is None
async def test_invalid_entity_in_template(hass, recorder_mock):
async def test_invalid_entity_in_template(recorder_mock, hass):
"""Verify with an invalid entity in the template."""
await async_setup_component(
hass,
@ -211,7 +211,7 @@ async def test_invalid_entity_in_template(hass, recorder_mock):
assert hass.states.get("sensor.test") is None
async def test_invalid_entity_returning_none_in_template(hass, recorder_mock):
async def test_invalid_entity_returning_none_in_template(recorder_mock, hass):
"""Verify with an invalid entity returning none in the template."""
await async_setup_component(
hass,
@ -236,7 +236,7 @@ async def test_invalid_entity_returning_none_in_template(hass, recorder_mock):
assert hass.states.get("sensor.test") is None
async def test_reload(hass, recorder_mock):
async def test_reload(recorder_mock, hass):
"""Verify we can reload history_stats sensors."""
hass.state = ha.CoreState.not_running
hass.states.async_set("binary_sensor.test_id", "on")
@ -279,7 +279,7 @@ async def test_reload(hass, recorder_mock):
assert hass.states.get("sensor.second_test")
async def test_measure_multiple(hass, recorder_mock):
async def test_measure_multiple(recorder_mock, hass):
"""Test the history statistics sensor measure for multiple ."""
start_time = dt_util.utcnow() - timedelta(minutes=60)
t0 = start_time + timedelta(minutes=20)
@ -361,7 +361,7 @@ async def test_measure_multiple(hass, recorder_mock):
assert hass.states.get("sensor.sensor4").state == "50.0"
async def test_measure(hass, recorder_mock):
async def test_measure(recorder_mock, hass):
"""Test the history statistics sensor measure."""
start_time = dt_util.utcnow() - timedelta(minutes=60)
t0 = start_time + timedelta(minutes=20)
@ -440,7 +440,7 @@ async def test_measure(hass, recorder_mock):
assert hass.states.get("sensor.sensor4").state == "83.3"
async def test_async_on_entire_period(hass, recorder_mock):
async def test_async_on_entire_period(recorder_mock, hass):
"""Test the history statistics sensor measuring as on the entire period."""
start_time = dt_util.utcnow() - timedelta(minutes=60)
t0 = start_time + timedelta(minutes=20)
@ -520,7 +520,7 @@ async def test_async_on_entire_period(hass, recorder_mock):
assert hass.states.get("sensor.on_sensor4").state == "100.0"
async def test_async_off_entire_period(hass, recorder_mock):
async def test_async_off_entire_period(recorder_mock, hass):
"""Test the history statistics sensor measuring as off the entire period."""
start_time = dt_util.utcnow() - timedelta(minutes=60)
t0 = start_time + timedelta(minutes=20)
@ -602,8 +602,8 @@ async def test_async_off_entire_period(hass, recorder_mock):
async def test_async_start_from_history_and_switch_to_watching_state_changes_single(
hass,
recorder_mock,
hass,
):
"""Test we startup from history and switch to watching state changes."""
hass.config.set_time_zone("UTC")
@ -702,8 +702,8 @@ async def test_async_start_from_history_and_switch_to_watching_state_changes_sin
async def test_async_start_from_history_and_switch_to_watching_state_changes_single_expanding_window(
hass,
recorder_mock,
hass,
):
"""Test we startup from history and switch to watching state changes with an expanding end time."""
hass.config.set_time_zone("UTC")
@ -801,8 +801,8 @@ async def test_async_start_from_history_and_switch_to_watching_state_changes_sin
async def test_async_start_from_history_and_switch_to_watching_state_changes_multiple(
hass,
recorder_mock,
hass,
):
"""Test we startup from history and switch to watching state changes."""
hass.config.set_time_zone("UTC")
@ -938,7 +938,7 @@ async def test_async_start_from_history_and_switch_to_watching_state_changes_mul
assert hass.states.get("sensor.sensor4").state == "87.5"
async def test_does_not_work_into_the_future(hass, recorder_mock):
async def test_does_not_work_into_the_future(recorder_mock, hass):
"""Test history cannot tell the future.
Verifies we do not regress https://github.com/home-assistant/core/pull/20589
@ -1078,7 +1078,7 @@ async def test_does_not_work_into_the_future(hass, recorder_mock):
assert hass.states.get("sensor.sensor1").state == "0.0"
async def test_reload_before_start_event(hass, recorder_mock):
async def test_reload_before_start_event(recorder_mock, hass):
"""Verify we can reload history_stats sensors before the start event."""
hass.state = ha.CoreState.not_running
hass.states.async_set("binary_sensor.test_id", "on")
@ -1119,7 +1119,7 @@ async def test_reload_before_start_event(hass, recorder_mock):
assert hass.states.get("sensor.second_test")
async def test_measure_sliding_window(hass, recorder_mock):
async def test_measure_sliding_window(recorder_mock, hass):
"""Test the history statistics sensor with a moving end and a moving start."""
start_time = dt_util.utcnow() - timedelta(minutes=60)
t0 = start_time + timedelta(minutes=20)
@ -1212,7 +1212,7 @@ async def test_measure_sliding_window(hass, recorder_mock):
assert hass.states.get("sensor.sensor4").state == "41.7"
async def test_measure_from_end_going_backwards(hass, recorder_mock):
async def test_measure_from_end_going_backwards(recorder_mock, hass):
"""Test the history statistics sensor with a moving end and a duration to find the start."""
start_time = dt_util.utcnow() - timedelta(minutes=60)
t0 = start_time + timedelta(minutes=20)
@ -1304,7 +1304,7 @@ async def test_measure_from_end_going_backwards(hass, recorder_mock):
assert hass.states.get("sensor.sensor4").state == "83.3"
async def test_measure_cet(hass, recorder_mock):
async def test_measure_cet(recorder_mock, hass):
"""Test the history statistics sensor measure with a non-UTC timezone."""
hass.config.set_time_zone("Europe/Berlin")
start_time = dt_util.utcnow() - timedelta(minutes=60)
@ -1385,7 +1385,7 @@ async def test_measure_cet(hass, recorder_mock):
@pytest.mark.parametrize("time_zone", ["Europe/Berlin", "America/Chicago", "US/Hawaii"])
async def test_end_time_with_microseconds_zeroed(time_zone, hass, recorder_mock):
async def test_end_time_with_microseconds_zeroed(time_zone, recorder_mock, hass):
"""Test the history statistics sensor that has the end time microseconds zeroed out."""
hass.config.set_time_zone(time_zone)
start_of_today = dt_util.now().replace(hour=0, minute=0, second=0, microsecond=0)
@ -1498,7 +1498,7 @@ async def test_end_time_with_microseconds_zeroed(time_zone, hass, recorder_mock)
assert hass.states.get("sensor.heatpump_compressor_today").state == "16.0"
async def test_device_classes(hass, recorder_mock):
async def test_device_classes(recorder_mock, hass):
"""Test the device classes."""
await async_setup_component(
hass,

View File

@ -20,7 +20,7 @@ from tests.common import async_fire_time_changed
from tests.components.recorder.common import async_wait_recording_done
async def test_exclude_attributes(hass, recorder_mock):
async def test_exclude_attributes(recorder_mock, hass):
"""Test humidifier registered attributes to be excluded."""
await async_setup_component(
hass, humidifier.DOMAIN, {humidifier.DOMAIN: {"platform": "demo"}}

View File

@ -16,7 +16,7 @@ from tests.components.recorder.common import async_wait_recording_done
async def test_exclude_attributes(
hass: HomeAssistant, recorder_mock, enable_custom_integrations: None
recorder_mock, hass: HomeAssistant, enable_custom_integrations: None
):
"""Test attributes to be excluded."""
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {"test": {}}})

View File

@ -16,7 +16,7 @@ from tests.components.recorder.common import async_wait_recording_done
async def test_exclude_attributes(
hass: HomeAssistant, recorder_mock, enable_custom_integrations: None
recorder_mock, hass: HomeAssistant, enable_custom_integrations: None
):
"""Test attributes to be excluded."""
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {"test": {}}})

View File

@ -16,7 +16,7 @@ from tests.components.recorder.common import async_wait_recording_done
async def test_exclude_attributes(
hass: HomeAssistant, recorder_mock, enable_custom_integrations: None
recorder_mock, hass: HomeAssistant, enable_custom_integrations: None
):
"""Test attributes to be excluded."""
assert await async_setup_component(

View File

@ -22,7 +22,7 @@ from tests.components.recorder.common import async_wait_recording_done
async def test_exclude_attributes(
hass: HomeAssistant, recorder_mock, enable_custom_integrations: None
recorder_mock, hass: HomeAssistant, enable_custom_integrations: None
):
"""Test attributes to be excluded."""
assert await async_setup_component(

View File

@ -16,7 +16,7 @@ from tests.components.recorder.common import async_wait_recording_done
async def test_exclude_attributes(
hass: HomeAssistant, recorder_mock, enable_custom_integrations: None
recorder_mock, hass: HomeAssistant, enable_custom_integrations: None
):
"""Test attributes to be excluded."""
assert await async_setup_component(

View File

@ -23,7 +23,7 @@ from tests.components.recorder.common import async_wait_recording_done
async def test_exclude_attributes(
hass: HomeAssistant, recorder_mock, enable_custom_integrations: None
recorder_mock, hass: HomeAssistant, enable_custom_integrations: None
):
"""Test attributes to be excluded."""
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {"test": {}}})

View File

@ -21,7 +21,7 @@ from tests.common import async_fire_time_changed
from tests.components.recorder.common import async_wait_recording_done
async def test_exclude_attributes(hass, recorder_mock):
async def test_exclude_attributes(recorder_mock, hass):
"""Test light registered attributes to be excluded."""
await async_setup_component(
hass, light.DOMAIN, {light.DOMAIN: {"platform": "demo"}}

View File

@ -58,7 +58,7 @@ EMPTY_CONFIG = logbook.CONFIG_SCHEMA({logbook.DOMAIN: {}})
@pytest.fixture
async def hass_(hass, recorder_mock):
async def hass_(recorder_mock, hass):
"""Set up things to be run when tests are started."""
assert await async_setup_component(hass, logbook.DOMAIN, EMPTY_CONFIG)
return hass
@ -123,7 +123,7 @@ async def test_service_call_create_logbook_entry(hass_):
assert last_call.data.get(logbook.ATTR_DOMAIN) == "logbook"
async def test_service_call_create_logbook_entry_invalid_entity_id(hass, recorder_mock):
async def test_service_call_create_logbook_entry_invalid_entity_id(recorder_mock, hass):
"""Test if service call create log book entry with an invalid entity id."""
await async_setup_component(hass, "logbook", {})
await hass.async_block_till_done()
@ -352,7 +352,7 @@ def create_state_changed_event_from_old_new(
return LazyEventPartialState(row, {})
async def test_logbook_view(hass, hass_client, recorder_mock):
async def test_logbook_view(recorder_mock, hass, hass_client):
"""Test the logbook view."""
await async_setup_component(hass, "logbook", {})
await async_recorder_block_till_done(hass)
@ -361,7 +361,7 @@ async def test_logbook_view(hass, hass_client, recorder_mock):
assert response.status == HTTPStatus.OK
async def test_logbook_view_invalid_start_date_time(hass, hass_client, recorder_mock):
async def test_logbook_view_invalid_start_date_time(recorder_mock, hass, hass_client):
"""Test the logbook view with an invalid date time."""
await async_setup_component(hass, "logbook", {})
await async_recorder_block_till_done(hass)
@ -370,7 +370,7 @@ async def test_logbook_view_invalid_start_date_time(hass, hass_client, recorder_
assert response.status == HTTPStatus.BAD_REQUEST
async def test_logbook_view_invalid_end_date_time(hass, hass_client, recorder_mock):
async def test_logbook_view_invalid_end_date_time(recorder_mock, hass, hass_client):
"""Test the logbook view."""
await async_setup_component(hass, "logbook", {})
await async_recorder_block_till_done(hass)
@ -381,7 +381,7 @@ async def test_logbook_view_invalid_end_date_time(hass, hass_client, recorder_mo
assert response.status == HTTPStatus.BAD_REQUEST
async def test_logbook_view_period_entity(hass, hass_client, recorder_mock, set_utc):
async def test_logbook_view_period_entity(recorder_mock, hass, hass_client, set_utc):
"""Test the logbook view with period and entity."""
await async_setup_component(hass, "logbook", {})
await async_recorder_block_till_done(hass)
@ -462,7 +462,7 @@ async def test_logbook_view_period_entity(hass, hass_client, recorder_mock, set_
assert response_json[0]["entity_id"] == entity_id_test
async def test_logbook_describe_event(hass, hass_client, recorder_mock):
async def test_logbook_describe_event(recorder_mock, hass, hass_client):
"""Test teaching logbook about a new event."""
def _describe(event):
@ -498,7 +498,7 @@ async def test_logbook_describe_event(hass, hass_client, recorder_mock):
assert event["domain"] == "test_domain"
async def test_exclude_described_event(hass, hass_client, recorder_mock):
async def test_exclude_described_event(recorder_mock, hass, hass_client):
"""Test exclusions of events that are described by another integration."""
name = "My Automation Rule"
entity_id = "automation.excluded_rule"
@ -561,7 +561,7 @@ async def test_exclude_described_event(hass, hass_client, recorder_mock):
assert event["entity_id"] == "automation.included_rule"
async def test_logbook_view_end_time_entity(hass, hass_client, recorder_mock):
async def test_logbook_view_end_time_entity(recorder_mock, hass, hass_client):
"""Test the logbook view with end_time and entity."""
await async_setup_component(hass, "logbook", {})
await async_recorder_block_till_done(hass)
@ -616,7 +616,7 @@ async def test_logbook_view_end_time_entity(hass, hass_client, recorder_mock):
assert response_json[0]["entity_id"] == entity_id_test
async def test_logbook_entity_filter_with_automations(hass, hass_client, recorder_mock):
async def test_logbook_entity_filter_with_automations(recorder_mock, hass, hass_client):
"""Test the logbook view with end_time and entity with automations and scripts."""
await asyncio.gather(
*[
@ -692,7 +692,7 @@ async def test_logbook_entity_filter_with_automations(hass, hass_client, recorde
async def test_logbook_entity_no_longer_in_state_machine(
hass, hass_client, recorder_mock
recorder_mock, hass, hass_client
):
"""Test the logbook view with an entity that hass been removed from the state machine."""
await async_setup_component(hass, "logbook", {})
@ -730,7 +730,7 @@ async def test_logbook_entity_no_longer_in_state_machine(
async def test_filter_continuous_sensor_values(
hass, hass_client, recorder_mock, set_utc
recorder_mock, hass, hass_client, set_utc
):
"""Test remove continuous sensor events from logbook."""
await async_setup_component(hass, "logbook", {})
@ -770,7 +770,7 @@ async def test_filter_continuous_sensor_values(
assert response_json[1]["entity_id"] == entity_id_third
async def test_exclude_new_entities(hass, hass_client, recorder_mock, set_utc):
async def test_exclude_new_entities(recorder_mock, hass, hass_client, set_utc):
"""Test if events are excluded on first update."""
await asyncio.gather(
*[
@ -807,7 +807,7 @@ async def test_exclude_new_entities(hass, hass_client, recorder_mock, set_utc):
assert response_json[1]["message"] == "started"
async def test_exclude_removed_entities(hass, hass_client, recorder_mock, set_utc):
async def test_exclude_removed_entities(recorder_mock, hass, hass_client, set_utc):
"""Test if events are excluded on last update."""
await asyncio.gather(
*[
@ -851,7 +851,7 @@ async def test_exclude_removed_entities(hass, hass_client, recorder_mock, set_ut
assert response_json[2]["entity_id"] == entity_id2
async def test_exclude_attribute_changes(hass, hass_client, recorder_mock, set_utc):
async def test_exclude_attribute_changes(recorder_mock, hass, hass_client, set_utc):
"""Test if events of attribute changes are filtered."""
await asyncio.gather(
*[
@ -891,7 +891,7 @@ async def test_exclude_attribute_changes(hass, hass_client, recorder_mock, set_u
assert response_json[2]["entity_id"] == "light.kitchen"
async def test_logbook_entity_context_id(hass, recorder_mock, hass_client):
async def test_logbook_entity_context_id(recorder_mock, hass, hass_client):
"""Test the logbook view with end_time and entity with automations and scripts."""
await asyncio.gather(
*[
@ -1042,7 +1042,7 @@ async def test_logbook_entity_context_id(hass, recorder_mock, hass_client):
async def test_logbook_context_id_automation_script_started_manually(
hass, recorder_mock, hass_client
recorder_mock, hass, hass_client
):
"""Test the logbook populates context_ids for scripts and automations started manually."""
await asyncio.gather(
@ -1132,7 +1132,7 @@ async def test_logbook_context_id_automation_script_started_manually(
assert json_dict[4]["context_domain"] == "script"
async def test_logbook_entity_context_parent_id(hass, hass_client, recorder_mock):
async def test_logbook_entity_context_parent_id(recorder_mock, hass, hass_client):
"""Test the logbook view links events via context parent_id."""
await asyncio.gather(
*[
@ -1311,7 +1311,7 @@ async def test_logbook_entity_context_parent_id(hass, hass_client, recorder_mock
assert json_dict[8]["context_user_id"] == "485cacf93ef84d25a99ced3126b921d2"
async def test_logbook_context_from_template(hass, hass_client, recorder_mock):
async def test_logbook_context_from_template(recorder_mock, hass, hass_client):
"""Test the logbook view with end_time and entity with automations and scripts."""
await asyncio.gather(
*[
@ -1398,7 +1398,7 @@ async def test_logbook_context_from_template(hass, hass_client, recorder_mock):
assert json_dict[5]["context_user_id"] == "9400facee45711eaa9308bfd3d19e474"
async def test_logbook_(hass, hass_client, recorder_mock):
async def test_logbook_(recorder_mock, hass, hass_client):
"""Test the logbook view with a single entity and ."""
await async_setup_component(hass, "logbook", {})
assert await async_setup_component(
@ -1467,7 +1467,7 @@ async def test_logbook_(hass, hass_client, recorder_mock):
assert json_dict[1]["context_user_id"] == "9400facee45711eaa9308bfd3d19e474"
async def test_logbook_many_entities_multiple_calls(hass, hass_client, recorder_mock):
async def test_logbook_many_entities_multiple_calls(recorder_mock, hass, hass_client):
"""Test the logbook view with a many entities called multiple times."""
await async_setup_component(hass, "logbook", {})
await async_setup_component(hass, "automation", {})
@ -1537,7 +1537,7 @@ async def test_logbook_many_entities_multiple_calls(hass, hass_client, recorder_
assert len(json_dict) == 0
async def test_custom_log_entry_discoverable_via_(hass, hass_client, recorder_mock):
async def test_custom_log_entry_discoverable_via_(recorder_mock, hass, hass_client):
"""Test if a custom log entry is later discoverable via ."""
await async_setup_component(hass, "logbook", {})
await async_recorder_block_till_done(hass)
@ -1572,7 +1572,7 @@ async def test_custom_log_entry_discoverable_via_(hass, hass_client, recorder_mo
assert json_dict[0]["entity_id"] == "switch.test_switch"
async def test_logbook_multiple_entities(hass, hass_client, recorder_mock):
async def test_logbook_multiple_entities(recorder_mock, hass, hass_client):
"""Test the logbook view with a multiple entities."""
await async_setup_component(hass, "logbook", {})
assert await async_setup_component(
@ -1696,7 +1696,7 @@ async def test_logbook_multiple_entities(hass, hass_client, recorder_mock):
assert json_dict[3]["context_user_id"] == "9400facee45711eaa9308bfd3d19e474"
async def test_logbook_invalid_entity(hass, hass_client, recorder_mock):
async def test_logbook_invalid_entity(recorder_mock, hass, hass_client):
"""Test the logbook view with requesting an invalid entity."""
await async_setup_component(hass, "logbook", {})
await hass.async_block_till_done()
@ -1714,7 +1714,7 @@ async def test_logbook_invalid_entity(hass, hass_client, recorder_mock):
assert response.status == HTTPStatus.INTERNAL_SERVER_ERROR
async def test_icon_and_state(hass, hass_client, recorder_mock):
async def test_icon_and_state(recorder_mock, hass, hass_client):
"""Test to ensure state and custom icons are returned."""
await asyncio.gather(
*[
@ -1757,7 +1757,7 @@ async def test_icon_and_state(hass, hass_client, recorder_mock):
assert response_json[2]["state"] == STATE_OFF
async def test_fire_logbook_entries(hass, hass_client, recorder_mock):
async def test_fire_logbook_entries(recorder_mock, hass, hass_client):
"""Test many logbook entry calls."""
await async_setup_component(hass, "logbook", {})
await async_recorder_block_till_done(hass)
@ -1793,7 +1793,7 @@ async def test_fire_logbook_entries(hass, hass_client, recorder_mock):
assert len(response_json) == 11
async def test_exclude_events_domain(hass, hass_client, recorder_mock):
async def test_exclude_events_domain(recorder_mock, hass, hass_client):
"""Test if events are filtered if domain is excluded in config."""
entity_id = "switch.bla"
entity_id2 = "sensor.blu"
@ -1827,7 +1827,7 @@ async def test_exclude_events_domain(hass, hass_client, recorder_mock):
_assert_entry(entries[1], name="blu", entity_id=entity_id2)
async def test_exclude_events_domain_glob(hass, hass_client, recorder_mock):
async def test_exclude_events_domain_glob(recorder_mock, hass, hass_client):
"""Test if events are filtered if domain or glob is excluded in config."""
entity_id = "switch.bla"
entity_id2 = "sensor.blu"
@ -1870,7 +1870,7 @@ async def test_exclude_events_domain_glob(hass, hass_client, recorder_mock):
_assert_entry(entries[1], name="blu", entity_id=entity_id2)
async def test_include_events_entity(hass, hass_client, recorder_mock):
async def test_include_events_entity(recorder_mock, hass, hass_client):
"""Test if events are filtered if entity is included in config."""
entity_id = "sensor.bla"
entity_id2 = "sensor.blu"
@ -1910,7 +1910,7 @@ async def test_include_events_entity(hass, hass_client, recorder_mock):
_assert_entry(entries[1], name="blu", entity_id=entity_id2)
async def test_exclude_events_entity(hass, hass_client, recorder_mock):
async def test_exclude_events_entity(recorder_mock, hass, hass_client):
"""Test if events are filtered if entity is excluded in config."""
entity_id = "sensor.bla"
entity_id2 = "sensor.blu"
@ -1944,7 +1944,7 @@ async def test_exclude_events_entity(hass, hass_client, recorder_mock):
_assert_entry(entries[1], name="blu", entity_id=entity_id2)
async def test_include_events_domain(hass, hass_client, recorder_mock):
async def test_include_events_domain(recorder_mock, hass, hass_client):
"""Test if events are filtered if domain is included in config."""
assert await async_setup_component(hass, "alexa", {})
entity_id = "switch.bla"
@ -1986,7 +1986,7 @@ async def test_include_events_domain(hass, hass_client, recorder_mock):
_assert_entry(entries[2], name="blu", entity_id=entity_id2)
async def test_include_events_domain_glob(hass, hass_client, recorder_mock):
async def test_include_events_domain_glob(recorder_mock, hass, hass_client):
"""Test if events are filtered if domain or glob is included in config."""
assert await async_setup_component(hass, "alexa", {})
entity_id = "switch.bla"
@ -2043,7 +2043,7 @@ async def test_include_events_domain_glob(hass, hass_client, recorder_mock):
_assert_entry(entries[3], name="included", entity_id=entity_id3)
async def test_include_exclude_events_no_globs(hass, hass_client, recorder_mock):
async def test_include_exclude_events_no_globs(recorder_mock, hass, hass_client):
"""Test if events are filtered if include and exclude is configured."""
entity_id = "switch.bla"
entity_id2 = "sensor.blu"
@ -2100,7 +2100,7 @@ async def test_include_exclude_events_no_globs(hass, hass_client, recorder_mock)
async def test_include_exclude_events_with_glob_filters(
hass, hass_client, recorder_mock
recorder_mock, hass, hass_client
):
"""Test if events are filtered if include and exclude is configured."""
entity_id = "switch.bla"
@ -2165,7 +2165,7 @@ async def test_include_exclude_events_with_glob_filters(
_assert_entry(entries[6], name="included", entity_id=entity_id5, state="30")
async def test_empty_config(hass, hass_client, recorder_mock):
async def test_empty_config(recorder_mock, hass, hass_client):
"""Test we can handle an empty entity filter."""
entity_id = "sensor.blu"
@ -2197,7 +2197,7 @@ async def test_empty_config(hass, hass_client, recorder_mock):
_assert_entry(entries[1], name="blu", entity_id=entity_id)
async def test_context_filter(hass, hass_client, recorder_mock):
async def test_context_filter(recorder_mock, hass, hass_client):
"""Test we can filter by context."""
assert await async_setup_component(hass, "logbook", {})
await async_recorder_block_till_done(hass)
@ -2269,7 +2269,7 @@ def _assert_entry(
assert state == entry["state"]
async def test_get_events(hass, hass_ws_client, recorder_mock):
async def test_get_events(recorder_mock, hass, hass_ws_client):
"""Test logbook get_events."""
now = dt_util.utcnow()
await asyncio.gather(
@ -2387,7 +2387,7 @@ async def test_get_events(hass, hass_ws_client, recorder_mock):
assert isinstance(results[0]["when"], float)
async def test_get_events_future_start_time(hass, hass_ws_client, recorder_mock):
async def test_get_events_future_start_time(recorder_mock, hass, hass_ws_client):
"""Test get_events with a future start time."""
await async_setup_component(hass, "logbook", {})
await async_recorder_block_till_done(hass)
@ -2410,7 +2410,7 @@ async def test_get_events_future_start_time(hass, hass_ws_client, recorder_mock)
assert len(results) == 0
async def test_get_events_bad_start_time(hass, hass_ws_client, recorder_mock):
async def test_get_events_bad_start_time(recorder_mock, hass, hass_ws_client):
"""Test get_events bad start time."""
await async_setup_component(hass, "logbook", {})
await async_recorder_block_till_done(hass)
@ -2428,7 +2428,7 @@ async def test_get_events_bad_start_time(hass, hass_ws_client, recorder_mock):
assert response["error"]["code"] == "invalid_start_time"
async def test_get_events_bad_end_time(hass, hass_ws_client, recorder_mock):
async def test_get_events_bad_end_time(recorder_mock, hass, hass_ws_client):
"""Test get_events bad end time."""
now = dt_util.utcnow()
await async_setup_component(hass, "logbook", {})
@ -2448,7 +2448,7 @@ async def test_get_events_bad_end_time(hass, hass_ws_client, recorder_mock):
assert response["error"]["code"] == "invalid_end_time"
async def test_get_events_invalid_filters(hass, hass_ws_client, recorder_mock):
async def test_get_events_invalid_filters(recorder_mock, hass, hass_ws_client):
"""Test get_events invalid filters."""
await async_setup_component(hass, "logbook", {})
await async_recorder_block_till_done(hass)
@ -2476,7 +2476,7 @@ async def test_get_events_invalid_filters(hass, hass_ws_client, recorder_mock):
assert response["error"]["code"] == "invalid_format"
async def test_get_events_with_device_ids(hass, hass_ws_client, recorder_mock):
async def test_get_events_with_device_ids(recorder_mock, hass, hass_ws_client):
"""Test logbook get_events for device ids."""
now = dt_util.utcnow()
await asyncio.gather(
@ -2613,7 +2613,7 @@ async def test_get_events_with_device_ids(hass, hass_ws_client, recorder_mock):
assert isinstance(results[3]["when"], float)
async def test_logbook_select_entities_context_id(hass, recorder_mock, hass_client):
async def test_logbook_select_entities_context_id(recorder_mock, hass, hass_client):
"""Test the logbook view with end_time and entity with automations and scripts."""
await asyncio.gather(
*[
@ -2746,7 +2746,7 @@ async def test_logbook_select_entities_context_id(hass, recorder_mock, hass_clie
assert json_dict[3]["context_user_id"] == "9400facee45711eaa9308bfd3d19e474"
async def test_get_events_with_context_state(hass, hass_ws_client, recorder_mock):
async def test_get_events_with_context_state(recorder_mock, hass, hass_ws_client):
"""Test logbook get_events with a context state."""
now = dt_util.utcnow()
await asyncio.gather(
@ -2809,7 +2809,7 @@ async def test_get_events_with_context_state(hass, hass_ws_client, recorder_mock
assert "context_event_type" not in results[3]
async def test_logbook_with_empty_config(hass, recorder_mock):
async def test_logbook_with_empty_config(recorder_mock, hass):
"""Test we handle a empty configuration."""
assert await async_setup_component(
hass,
@ -2822,7 +2822,7 @@ async def test_logbook_with_empty_config(hass, recorder_mock):
await hass.async_block_till_done()
async def test_logbook_with_non_iterable_entity_filter(hass, recorder_mock):
async def test_logbook_with_non_iterable_entity_filter(recorder_mock, hass):
"""Test we handle a non-iterable entity filter."""
assert await async_setup_component(
hass,

View File

@ -123,7 +123,7 @@ async def _async_mock_devices_with_logbook_platform(hass):
return [device, device2]
async def test_get_events(hass, hass_ws_client, recorder_mock):
async def test_get_events(recorder_mock, hass, hass_ws_client):
"""Test logbook get_events."""
now = dt_util.utcnow()
await asyncio.gather(
@ -241,7 +241,7 @@ async def test_get_events(hass, hass_ws_client, recorder_mock):
assert isinstance(results[0]["when"], float)
async def test_get_events_entities_filtered_away(hass, hass_ws_client, recorder_mock):
async def test_get_events_entities_filtered_away(recorder_mock, hass, hass_ws_client):
"""Test logbook get_events all entities filtered away."""
now = dt_util.utcnow()
await asyncio.gather(
@ -303,7 +303,7 @@ async def test_get_events_entities_filtered_away(hass, hass_ws_client, recorder_
assert len(results) == 0
async def test_get_events_future_start_time(hass, hass_ws_client, recorder_mock):
async def test_get_events_future_start_time(recorder_mock, hass, hass_ws_client):
"""Test get_events with a future start time."""
await async_setup_component(hass, "logbook", {})
await async_recorder_block_till_done(hass)
@ -326,7 +326,7 @@ async def test_get_events_future_start_time(hass, hass_ws_client, recorder_mock)
assert len(results) == 0
async def test_get_events_bad_start_time(hass, hass_ws_client, recorder_mock):
async def test_get_events_bad_start_time(recorder_mock, hass, hass_ws_client):
"""Test get_events bad start time."""
await async_setup_component(hass, "logbook", {})
await async_recorder_block_till_done(hass)
@ -344,7 +344,7 @@ async def test_get_events_bad_start_time(hass, hass_ws_client, recorder_mock):
assert response["error"]["code"] == "invalid_start_time"
async def test_get_events_bad_end_time(hass, hass_ws_client, recorder_mock):
async def test_get_events_bad_end_time(recorder_mock, hass, hass_ws_client):
"""Test get_events bad end time."""
now = dt_util.utcnow()
await async_setup_component(hass, "logbook", {})
@ -364,7 +364,7 @@ async def test_get_events_bad_end_time(hass, hass_ws_client, recorder_mock):
assert response["error"]["code"] == "invalid_end_time"
async def test_get_events_invalid_filters(hass, hass_ws_client, recorder_mock):
async def test_get_events_invalid_filters(recorder_mock, hass, hass_ws_client):
"""Test get_events invalid filters."""
await async_setup_component(hass, "logbook", {})
await async_recorder_block_till_done(hass)
@ -392,7 +392,7 @@ async def test_get_events_invalid_filters(hass, hass_ws_client, recorder_mock):
assert response["error"]["code"] == "invalid_format"
async def test_get_events_with_device_ids(hass, hass_ws_client, recorder_mock):
async def test_get_events_with_device_ids(recorder_mock, hass, hass_ws_client):
"""Test logbook get_events for device ids."""
now = dt_util.utcnow()
await asyncio.gather(
@ -504,7 +504,7 @@ async def test_get_events_with_device_ids(hass, hass_ws_client, recorder_mock):
@patch("homeassistant.components.logbook.websocket_api.EVENT_COALESCE_TIME", 0)
async def test_subscribe_unsubscribe_logbook_stream_excluded_entities(
hass, recorder_mock, hass_ws_client
recorder_mock, hass, hass_ws_client
):
"""Test subscribe/unsubscribe logbook stream with excluded entities."""
now = dt_util.utcnow()
@ -689,7 +689,7 @@ async def test_subscribe_unsubscribe_logbook_stream_excluded_entities(
@patch("homeassistant.components.logbook.websocket_api.EVENT_COALESCE_TIME", 0)
async def test_subscribe_unsubscribe_logbook_stream_included_entities(
hass, recorder_mock, hass_ws_client
recorder_mock, hass, hass_ws_client
):
"""Test subscribe/unsubscribe logbook stream with included entities."""
test_entities = (
@ -897,7 +897,7 @@ async def test_subscribe_unsubscribe_logbook_stream_included_entities(
@patch("homeassistant.components.logbook.websocket_api.EVENT_COALESCE_TIME", 0)
async def test_logbook_stream_excluded_entities_inherits_filters_from_recorder(
hass, recorder_mock, hass_ws_client
recorder_mock, hass, hass_ws_client
):
"""Test subscribe/unsubscribe logbook stream inherts filters from recorder."""
now = dt_util.utcnow()
@ -1088,7 +1088,7 @@ async def test_logbook_stream_excluded_entities_inherits_filters_from_recorder(
@patch("homeassistant.components.logbook.websocket_api.EVENT_COALESCE_TIME", 0)
async def test_subscribe_unsubscribe_logbook_stream(
hass, recorder_mock, hass_ws_client
recorder_mock, hass, hass_ws_client
):
"""Test subscribe/unsubscribe logbook stream."""
now = dt_util.utcnow()
@ -1391,7 +1391,7 @@ async def test_subscribe_unsubscribe_logbook_stream(
@patch("homeassistant.components.logbook.websocket_api.EVENT_COALESCE_TIME", 0)
async def test_subscribe_unsubscribe_logbook_stream_entities(
hass, recorder_mock, hass_ws_client
recorder_mock, hass, hass_ws_client
):
"""Test subscribe/unsubscribe logbook stream with specific entities."""
now = dt_util.utcnow()
@ -1489,7 +1489,7 @@ async def test_subscribe_unsubscribe_logbook_stream_entities(
@patch("homeassistant.components.logbook.websocket_api.EVENT_COALESCE_TIME", 0)
async def test_subscribe_unsubscribe_logbook_stream_entities_with_end_time(
hass, recorder_mock, hass_ws_client
recorder_mock, hass, hass_ws_client
):
"""Test subscribe/unsubscribe logbook stream with specific entities and an end_time."""
now = dt_util.utcnow()
@ -1596,7 +1596,7 @@ async def test_subscribe_unsubscribe_logbook_stream_entities_with_end_time(
@patch("homeassistant.components.logbook.websocket_api.EVENT_COALESCE_TIME", 0)
async def test_subscribe_unsubscribe_logbook_stream_entities_past_only(
hass, recorder_mock, hass_ws_client
recorder_mock, hass, hass_ws_client
):
"""Test subscribe/unsubscribe logbook stream with specific entities in the past."""
now = dt_util.utcnow()
@ -1664,7 +1664,7 @@ async def test_subscribe_unsubscribe_logbook_stream_entities_past_only(
@patch("homeassistant.components.logbook.websocket_api.EVENT_COALESCE_TIME", 0)
async def test_subscribe_unsubscribe_logbook_stream_big_query(
hass, recorder_mock, hass_ws_client
recorder_mock, hass, hass_ws_client
):
"""Test subscribe/unsubscribe logbook stream and ask for a large time frame.
@ -1764,7 +1764,7 @@ async def test_subscribe_unsubscribe_logbook_stream_big_query(
@patch("homeassistant.components.logbook.websocket_api.EVENT_COALESCE_TIME", 0)
async def test_subscribe_unsubscribe_logbook_stream_device(
hass, recorder_mock, hass_ws_client
recorder_mock, hass, hass_ws_client
):
"""Test subscribe/unsubscribe logbook stream with a device."""
now = dt_util.utcnow()
@ -1856,7 +1856,7 @@ async def test_subscribe_unsubscribe_logbook_stream_device(
assert hass.bus.async_listeners() == init_listeners
async def test_event_stream_bad_start_time(hass, hass_ws_client, recorder_mock):
async def test_event_stream_bad_start_time(recorder_mock, hass, hass_ws_client):
"""Test event_stream bad start time."""
await async_setup_component(hass, "logbook", {})
await async_recorder_block_till_done(hass)
@ -1876,7 +1876,7 @@ async def test_event_stream_bad_start_time(hass, hass_ws_client, recorder_mock):
@patch("homeassistant.components.logbook.websocket_api.EVENT_COALESCE_TIME", 0)
async def test_logbook_stream_match_multiple_entities(
hass, recorder_mock, hass_ws_client
recorder_mock, hass, hass_ws_client
):
"""Test logbook stream with a described integration that uses multiple entities."""
now = dt_util.utcnow()
@ -1971,7 +1971,7 @@ async def test_logbook_stream_match_multiple_entities(
assert hass.bus.async_listeners() == init_listeners
async def test_event_stream_bad_end_time(hass, hass_ws_client, recorder_mock):
async def test_event_stream_bad_end_time(recorder_mock, hass, hass_ws_client):
"""Test event_stream bad end time."""
await async_setup_component(hass, "logbook", {})
await async_recorder_block_till_done(hass)
@ -2004,8 +2004,8 @@ async def test_event_stream_bad_end_time(hass, hass_ws_client, recorder_mock):
async def test_live_stream_with_one_second_commit_interval(
hass: HomeAssistant,
async_setup_recorder_instance: SetupRecorderInstanceT,
hass: HomeAssistant,
hass_ws_client,
):
"""Test the recorder with a 1s commit interval."""
@ -2095,7 +2095,7 @@ async def test_live_stream_with_one_second_commit_interval(
@patch("homeassistant.components.logbook.websocket_api.EVENT_COALESCE_TIME", 0)
async def test_subscribe_disconnected(hass, recorder_mock, hass_ws_client):
async def test_subscribe_disconnected(recorder_mock, hass, hass_ws_client):
"""Test subscribe/unsubscribe logbook stream gets disconnected."""
now = dt_util.utcnow()
await asyncio.gather(
@ -2150,7 +2150,7 @@ async def test_subscribe_disconnected(hass, recorder_mock, hass_ws_client):
@patch("homeassistant.components.logbook.websocket_api.EVENT_COALESCE_TIME", 0)
async def test_stream_consumer_stop_processing(hass, recorder_mock, hass_ws_client):
async def test_stream_consumer_stop_processing(recorder_mock, hass, hass_ws_client):
"""Test we unsubscribe if the stream consumer fails or is canceled."""
now = dt_util.utcnow()
await asyncio.gather(
@ -2203,7 +2203,7 @@ async def test_stream_consumer_stop_processing(hass, recorder_mock, hass_ws_clie
@patch("homeassistant.components.logbook.websocket_api.EVENT_COALESCE_TIME", 0)
async def test_recorder_is_far_behind(hass, recorder_mock, hass_ws_client, caplog):
async def test_recorder_is_far_behind(recorder_mock, hass, hass_ws_client, caplog):
"""Test we still start live streaming if the recorder is far behind."""
now = dt_util.utcnow()
await asyncio.gather(
@ -2279,7 +2279,7 @@ async def test_recorder_is_far_behind(hass, recorder_mock, hass_ws_client, caplo
@patch("homeassistant.components.logbook.websocket_api.EVENT_COALESCE_TIME", 0)
async def test_subscribe_all_entities_are_continuous(
hass, recorder_mock, hass_ws_client
recorder_mock, hass, hass_ws_client
):
"""Test subscribe/unsubscribe logbook stream with entities that are always filtered."""
now = dt_util.utcnow()
@ -2337,7 +2337,7 @@ async def test_subscribe_all_entities_are_continuous(
@patch("homeassistant.components.logbook.websocket_api.EVENT_COALESCE_TIME", 0)
async def test_subscribe_all_entities_have_uom_multiple(
hass, recorder_mock, hass_ws_client
recorder_mock, hass, hass_ws_client
):
"""Test logbook stream with specific request for multiple entities that are always filtered."""
now = dt_util.utcnow()
@ -2394,7 +2394,7 @@ async def test_subscribe_all_entities_have_uom_multiple(
@patch("homeassistant.components.logbook.websocket_api.EVENT_COALESCE_TIME", 0)
async def test_subscribe_entities_some_have_uom_multiple(
hass, recorder_mock, hass_ws_client
recorder_mock, hass, hass_ws_client
):
"""Test logbook stream with uom filtered entities and non-filtered entities."""
now = dt_util.utcnow()
@ -2499,7 +2499,7 @@ async def test_subscribe_entities_some_have_uom_multiple(
@patch("homeassistant.components.logbook.websocket_api.EVENT_COALESCE_TIME", 0)
async def test_logbook_stream_ignores_forced_updates(
hass, recorder_mock, hass_ws_client
recorder_mock, hass, hass_ws_client
):
"""Test logbook live stream ignores forced updates."""
now = dt_util.utcnow()
@ -2613,7 +2613,7 @@ async def test_logbook_stream_ignores_forced_updates(
@patch("homeassistant.components.logbook.websocket_api.EVENT_COALESCE_TIME", 0)
async def test_subscribe_all_entities_are_continuous_with_device(
hass, recorder_mock, hass_ws_client
recorder_mock, hass, hass_ws_client
):
"""Test subscribe/unsubscribe logbook stream with entities that are always filtered and a device."""
now = dt_util.utcnow()

View File

@ -22,7 +22,7 @@ from tests.common import async_fire_time_changed
from tests.components.recorder.common import async_wait_recording_done
async def test_exclude_attributes(hass, recorder_mock):
async def test_exclude_attributes(recorder_mock, hass):
"""Test media_player registered attributes to be excluded."""
await async_setup_component(
hass, media_player.DOMAIN, {media_player.DOMAIN: {"platform": "demo"}}

View File

@ -16,7 +16,7 @@ from tests.common import async_fire_time_changed
from tests.components.recorder.common import async_wait_recording_done
async def test_exclude_attributes(hass, recorder_mock):
async def test_exclude_attributes(recorder_mock, hass):
"""Test number registered attributes to be excluded."""
await async_setup_component(
hass, number.DOMAIN, {number.DOMAIN: {"platform": "demo"}}

View File

@ -144,7 +144,7 @@ async def test_state_problem_if_unavailable(hass):
assert state.attributes[plant.READING_MOISTURE] == STATE_UNAVAILABLE
async def test_load_from_db(hass, recorder_mock):
async def test_load_from_db(recorder_mock, hass):
"""Test bootstrapping the brightness history from the database.
This test can should only be executed if the loading of the history

View File

@ -10,7 +10,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
async def test_async_pre_backup(hass: HomeAssistant, recorder_mock) -> None:
async def test_async_pre_backup(recorder_mock, hass: HomeAssistant) -> None:
"""Test pre backup."""
with patch(
"homeassistant.components.recorder.core.Recorder.lock_database"
@ -20,7 +20,7 @@ async def test_async_pre_backup(hass: HomeAssistant, recorder_mock) -> None:
async def test_async_pre_backup_with_timeout(
hass: HomeAssistant, recorder_mock
recorder_mock, hass: HomeAssistant
) -> None:
"""Test pre backup with timeout."""
with patch(
@ -32,7 +32,7 @@ async def test_async_pre_backup_with_timeout(
async def test_async_pre_backup_with_migration(
hass: HomeAssistant, recorder_mock
recorder_mock, hass: HomeAssistant
) -> None:
"""Test pre backup with migration."""
with patch(
@ -42,7 +42,7 @@ async def test_async_pre_backup_with_migration(
await async_pre_backup(hass)
async def test_async_post_backup(hass: HomeAssistant, recorder_mock) -> None:
async def test_async_post_backup(recorder_mock, hass: HomeAssistant) -> None:
"""Test post backup."""
with patch(
"homeassistant.components.recorder.core.Recorder.unlock_database"
@ -51,7 +51,7 @@ async def test_async_post_backup(hass: HomeAssistant, recorder_mock) -> None:
assert unlock_mock.called
async def test_async_post_backup_failure(hass: HomeAssistant, recorder_mock) -> None:
async def test_async_post_backup_failure(recorder_mock, hass: HomeAssistant) -> None:
"""Test post backup failure."""
with patch(
"homeassistant.components.recorder.core.Recorder.unlock_database",

View File

@ -71,7 +71,7 @@ async def _async_get_states_and_events_with_filter(
return filtered_states_entity_ids, filtered_events_entity_ids
async def test_included_and_excluded_simple_case_no_domains(hass, recorder_mock):
async def test_included_and_excluded_simple_case_no_domains(recorder_mock, hass):
"""Test filters with included and excluded without domains."""
filter_accept = {"sensor.kitchen4", "switch.kitchen"}
filter_reject = {
@ -127,7 +127,7 @@ async def test_included_and_excluded_simple_case_no_domains(hass, recorder_mock)
assert not filtered_events_entity_ids.intersection(filter_reject)
async def test_included_and_excluded_simple_case_no_globs(hass, recorder_mock):
async def test_included_and_excluded_simple_case_no_globs(recorder_mock, hass):
"""Test filters with included and excluded without globs."""
filter_accept = {"switch.bla", "sensor.blu", "sensor.keep"}
filter_reject = {"sensor.bli"}
@ -168,7 +168,7 @@ async def test_included_and_excluded_simple_case_no_globs(hass, recorder_mock):
async def test_included_and_excluded_simple_case_without_underscores(
hass, recorder_mock
recorder_mock, hass
):
"""Test filters with included and excluded without underscores."""
filter_accept = {"light.any", "sensor.kitchen4", "switch.kitchen"}
@ -221,7 +221,7 @@ async def test_included_and_excluded_simple_case_without_underscores(
assert not filtered_events_entity_ids.intersection(filter_reject)
async def test_included_and_excluded_simple_case_with_underscores(hass, recorder_mock):
async def test_included_and_excluded_simple_case_with_underscores(recorder_mock, hass):
"""Test filters with included and excluded with underscores."""
filter_accept = {"light.any", "sensor.kitchen_4", "switch.kitchen"}
filter_reject = {"switch.other", "cover.any", "sensor.weather_5", "light.kitchen"}
@ -273,7 +273,7 @@ async def test_included_and_excluded_simple_case_with_underscores(hass, recorder
assert not filtered_events_entity_ids.intersection(filter_reject)
async def test_included_and_excluded_complex_case(hass, recorder_mock):
async def test_included_and_excluded_complex_case(recorder_mock, hass):
"""Test filters with included and excluded with a complex filter."""
filter_accept = {"light.any", "sensor.kitchen_4", "switch.kitchen"}
filter_reject = {
@ -330,7 +330,7 @@ async def test_included_and_excluded_complex_case(hass, recorder_mock):
assert not filtered_events_entity_ids.intersection(filter_reject)
async def test_included_entities_and_excluded_domain(hass, recorder_mock):
async def test_included_entities_and_excluded_domain(recorder_mock, hass):
"""Test filters with included entities and excluded domain."""
filter_accept = {
"media_player.test",
@ -376,7 +376,7 @@ async def test_included_entities_and_excluded_domain(hass, recorder_mock):
assert not filtered_events_entity_ids.intersection(filter_reject)
async def test_same_domain_included_excluded(hass, recorder_mock):
async def test_same_domain_included_excluded(recorder_mock, hass):
"""Test filters with the same domain included and excluded."""
filter_accept = {
"media_player.test",
@ -422,7 +422,7 @@ async def test_same_domain_included_excluded(hass, recorder_mock):
assert not filtered_events_entity_ids.intersection(filter_reject)
async def test_same_entity_included_excluded(hass, recorder_mock):
async def test_same_entity_included_excluded(recorder_mock, hass):
"""Test filters with the same entity included and excluded."""
filter_accept = {
"media_player.test",
@ -468,7 +468,7 @@ async def test_same_entity_included_excluded(hass, recorder_mock):
assert not filtered_events_entity_ids.intersection(filter_reject)
async def test_same_entity_included_excluded_include_domain_wins(hass, recorder_mock):
async def test_same_entity_included_excluded_include_domain_wins(recorder_mock, hass):
"""Test filters with domain and entities and the include domain wins."""
filter_accept = {
"media_player.test2",
@ -516,7 +516,7 @@ async def test_same_entity_included_excluded_include_domain_wins(hass, recorder_
assert not filtered_events_entity_ids.intersection(filter_reject)
async def test_specificly_included_entity_always_wins(hass, recorder_mock):
async def test_specificly_included_entity_always_wins(recorder_mock, hass):
"""Test specificlly included entity always wins."""
filter_accept = {
"media_player.test2",
@ -564,7 +564,7 @@ async def test_specificly_included_entity_always_wins(hass, recorder_mock):
assert not filtered_events_entity_ids.intersection(filter_reject)
async def test_specificly_included_entity_always_wins_over_glob(hass, recorder_mock):
async def test_specificly_included_entity_always_wins_over_glob(recorder_mock, hass):
"""Test specificlly included entity always wins over a glob."""
filter_accept = {
"sensor.apc900va_status",

View File

@ -650,8 +650,8 @@ def record_states(hass) -> tuple[datetime, datetime, dict[str, list[State]]]:
async def test_state_changes_during_period_query_during_migration_to_schema_25(
hass: ha.HomeAssistant,
async_setup_recorder_instance: SetupRecorderInstanceT,
hass: ha.HomeAssistant,
):
"""Test we can query data prior to schema 25 and during migration to schema 25."""
instance = await async_setup_recorder_instance(hass, {})
@ -700,8 +700,8 @@ async def test_state_changes_during_period_query_during_migration_to_schema_25(
async def test_get_states_query_during_migration_to_schema_25(
hass: ha.HomeAssistant,
async_setup_recorder_instance: SetupRecorderInstanceT,
hass: ha.HomeAssistant,
):
"""Test we can query data prior to schema 25 and during migration to schema 25."""
instance = await async_setup_recorder_instance(hass, {})
@ -746,8 +746,8 @@ async def test_get_states_query_during_migration_to_schema_25(
async def test_get_states_query_during_migration_to_schema_25_multiple_entities(
hass: ha.HomeAssistant,
async_setup_recorder_instance: SetupRecorderInstanceT,
hass: ha.HomeAssistant,
):
"""Test we can query data prior to schema 25 and during migration to schema 25."""
instance = await async_setup_recorder_instance(hass, {})
@ -795,8 +795,8 @@ async def test_get_states_query_during_migration_to_schema_25_multiple_entities(
async def test_get_full_significant_states_handles_empty_last_changed(
hass: ha.HomeAssistant,
async_setup_recorder_instance: SetupRecorderInstanceT,
hass: ha.HomeAssistant,
):
"""Test getting states when last_changed is null."""
await async_setup_recorder_instance(hass, {})

View File

@ -92,7 +92,7 @@ def _default_recorder(hass):
async def test_shutdown_before_startup_finishes(
hass: HomeAssistant, async_setup_recorder_instance: SetupRecorderInstanceT, tmp_path
async_setup_recorder_instance: SetupRecorderInstanceT, hass: HomeAssistant, tmp_path
):
"""Test shutdown before recorder starts is clean."""
@ -124,8 +124,8 @@ async def test_shutdown_before_startup_finishes(
async def test_canceled_before_startup_finishes(
hass: HomeAssistant,
async_setup_recorder_instance: SetupRecorderInstanceT,
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
):
"""Test recorder shuts down when its startup future is canceled out from under it."""
@ -145,7 +145,7 @@ async def test_canceled_before_startup_finishes(
)
async def test_shutdown_closes_connections(hass, recorder_mock):
async def test_shutdown_closes_connections(recorder_mock, hass):
"""Test shutdown closes connections."""
hass.state = CoreState.not_running
@ -171,7 +171,7 @@ async def test_shutdown_closes_connections(hass, recorder_mock):
async def test_state_gets_saved_when_set_before_start_event(
hass: HomeAssistant, async_setup_recorder_instance: SetupRecorderInstanceT
async_setup_recorder_instance: SetupRecorderInstanceT, hass: HomeAssistant
):
"""Test we can record an event when starting with not running."""
@ -197,7 +197,7 @@ async def test_state_gets_saved_when_set_before_start_event(
assert db_states[0].event_id is None
async def test_saving_state(hass: HomeAssistant, recorder_mock):
async def test_saving_state(recorder_mock, hass: HomeAssistant):
"""Test saving and restoring a state."""
entity_id = "test.recorder"
state = "restoring_from_db"
@ -220,7 +220,7 @@ async def test_saving_state(hass: HomeAssistant, recorder_mock):
async def test_saving_many_states(
hass: HomeAssistant, async_setup_recorder_instance: SetupRecorderInstanceT
async_setup_recorder_instance: SetupRecorderInstanceT, hass: HomeAssistant
):
"""Test we expire after many commits."""
instance = await async_setup_recorder_instance(
@ -248,7 +248,7 @@ async def test_saving_many_states(
async def test_saving_state_with_intermixed_time_changes(
hass: HomeAssistant, recorder_mock
recorder_mock, hass: HomeAssistant
):
"""Test saving states with intermixed time changes."""
entity_id = "test.recorder"
@ -348,7 +348,7 @@ def test_saving_state_with_sqlalchemy_exception(hass, hass_recorder, caplog):
async def test_force_shutdown_with_queue_of_writes_that_generate_exceptions(
hass, async_setup_recorder_instance, caplog
async_setup_recorder_instance, hass, caplog
):
"""Test forcing shutdown."""
instance = await async_setup_recorder_instance(hass)
@ -1370,8 +1370,8 @@ def test_entity_id_filter(hass_recorder):
async def test_database_lock_and_unlock(
hass: HomeAssistant,
async_setup_recorder_instance: SetupRecorderInstanceT,
hass: HomeAssistant,
tmp_path,
):
"""Test writing events during lock getting written after unlocking."""
@ -1412,8 +1412,8 @@ async def test_database_lock_and_unlock(
async def test_database_lock_and_overflow(
hass: HomeAssistant,
async_setup_recorder_instance: SetupRecorderInstanceT,
hass: HomeAssistant,
tmp_path,
):
"""Test writing events during lock leading to overflow the queue causes the database to unlock."""
@ -1450,7 +1450,7 @@ async def test_database_lock_and_overflow(
assert not instance.unlock_database()
async def test_database_lock_timeout(hass, recorder_mock):
async def test_database_lock_timeout(recorder_mock, hass):
"""Test locking database timeout when recorder stopped."""
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
@ -1473,7 +1473,7 @@ async def test_database_lock_timeout(hass, recorder_mock):
block_task.event.set()
async def test_database_lock_without_instance(hass, recorder_mock):
async def test_database_lock_without_instance(recorder_mock, hass):
"""Test database lock doesn't fail if instance is not initialized."""
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
@ -1494,8 +1494,8 @@ async def test_in_memory_database(hass, caplog):
async def test_database_connection_keep_alive(
hass: HomeAssistant,
async_setup_recorder_instance: SetupRecorderInstanceT,
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
):
"""Test we keep alive socket based dialects."""
@ -1514,8 +1514,8 @@ async def test_database_connection_keep_alive(
async def test_database_connection_keep_alive_disabled_on_sqlite(
hass: HomeAssistant,
async_setup_recorder_instance: SetupRecorderInstanceT,
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
):
"""Test we do not do keep alive for sqlite."""
@ -1590,7 +1590,7 @@ def test_deduplication_state_attributes_inside_commit_interval(hass_recorder, ca
assert first_attributes_id == last_attributes_id
async def test_async_block_till_done(hass, async_setup_recorder_instance):
async def test_async_block_till_done(async_setup_recorder_instance, hass):
"""Test we can block until recordering is done."""
instance = await async_setup_recorder_instance(hass)
await async_wait_recording_done(hass)

View File

@ -53,7 +53,7 @@ def mock_use_sqlite(request):
async def test_purge_old_states(
hass: HomeAssistant, async_setup_recorder_instance: SetupRecorderInstanceT
async_setup_recorder_instance: SetupRecorderInstanceT, hass: HomeAssistant
):
"""Test deleting old states."""
instance = await async_setup_recorder_instance(hass)
@ -135,7 +135,7 @@ async def test_purge_old_states(
async def test_purge_old_states_encouters_database_corruption(
hass: HomeAssistant, async_setup_recorder_instance: SetupRecorderInstanceT
async_setup_recorder_instance: SetupRecorderInstanceT, hass: HomeAssistant
):
"""Test database image image is malformed while deleting old states."""
await async_setup_recorder_instance(hass)
@ -165,8 +165,8 @@ async def test_purge_old_states_encouters_database_corruption(
async def test_purge_old_states_encounters_temporary_mysql_error(
hass: HomeAssistant,
async_setup_recorder_instance: SetupRecorderInstanceT,
hass: HomeAssistant,
caplog,
):
"""Test retry on specific mysql operational errors."""
@ -196,8 +196,8 @@ async def test_purge_old_states_encounters_temporary_mysql_error(
async def test_purge_old_states_encounters_operational_error(
hass: HomeAssistant,
async_setup_recorder_instance: SetupRecorderInstanceT,
hass: HomeAssistant,
caplog,
):
"""Test error on operational errors that are not mysql does not retry."""
@ -222,7 +222,7 @@ async def test_purge_old_states_encounters_operational_error(
async def test_purge_old_events(
hass: HomeAssistant, async_setup_recorder_instance: SetupRecorderInstanceT
async_setup_recorder_instance: SetupRecorderInstanceT, hass: HomeAssistant
):
"""Test deleting old events."""
instance = await async_setup_recorder_instance(hass)
@ -259,7 +259,7 @@ async def test_purge_old_events(
async def test_purge_old_recorder_runs(
hass: HomeAssistant, async_setup_recorder_instance: SetupRecorderInstanceT
async_setup_recorder_instance: SetupRecorderInstanceT, hass: HomeAssistant
):
"""Test deleting old recorder runs keeps current run."""
instance = await async_setup_recorder_instance(hass)
@ -295,7 +295,7 @@ async def test_purge_old_recorder_runs(
async def test_purge_old_statistics_runs(
hass: HomeAssistant, async_setup_recorder_instance: SetupRecorderInstanceT
async_setup_recorder_instance: SetupRecorderInstanceT, hass: HomeAssistant
):
"""Test deleting old statistics runs keeps the latest run."""
instance = await async_setup_recorder_instance(hass)
@ -320,8 +320,8 @@ async def test_purge_old_statistics_runs(
@pytest.mark.parametrize("use_sqlite", (True, False), indirect=True)
async def test_purge_method(
hass: HomeAssistant,
async_setup_recorder_instance: SetupRecorderInstanceT,
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
use_sqlite: bool,
):
@ -436,8 +436,8 @@ async def test_purge_method(
@pytest.mark.parametrize("use_sqlite", (True, False), indirect=True)
async def test_purge_edge_case(
hass: HomeAssistant,
async_setup_recorder_instance: SetupRecorderInstanceT,
hass: HomeAssistant,
use_sqlite: bool,
):
"""Test states and events are purged even if they occurred shortly before purge_before."""
@ -503,8 +503,8 @@ async def test_purge_edge_case(
async def test_purge_cutoff_date(
hass: HomeAssistant,
async_setup_recorder_instance: SetupRecorderInstanceT,
hass: HomeAssistant,
):
"""Test states and events are purged only if they occurred before "now() - keep_days"."""
@ -651,8 +651,8 @@ async def test_purge_cutoff_date(
@pytest.mark.parametrize("use_sqlite", (True, False), indirect=True)
async def test_purge_filtered_states(
hass: HomeAssistant,
async_setup_recorder_instance: SetupRecorderInstanceT,
hass: HomeAssistant,
use_sqlite: bool,
):
"""Test filtered states are purged."""
@ -837,8 +837,8 @@ async def test_purge_filtered_states(
@pytest.mark.parametrize("use_sqlite", (True, False), indirect=True)
async def test_purge_filtered_states_to_empty(
hass: HomeAssistant,
async_setup_recorder_instance: SetupRecorderInstanceT,
hass: HomeAssistant,
use_sqlite: bool,
):
"""Test filtered states are purged all the way to an empty db."""
@ -890,8 +890,8 @@ async def test_purge_filtered_states_to_empty(
@pytest.mark.parametrize("use_sqlite", (True, False), indirect=True)
async def test_purge_without_state_attributes_filtered_states_to_empty(
hass: HomeAssistant,
async_setup_recorder_instance: SetupRecorderInstanceT,
hass: HomeAssistant,
use_sqlite: bool,
):
"""Test filtered legacy states without state attributes are purged all the way to an empty db."""
@ -964,8 +964,8 @@ async def test_purge_without_state_attributes_filtered_states_to_empty(
async def test_purge_filtered_events(
hass: HomeAssistant,
async_setup_recorder_instance: SetupRecorderInstanceT,
hass: HomeAssistant,
):
"""Test filtered events are purged."""
config: ConfigType = {"exclude": {"event_types": ["EVENT_PURGE"]}}
@ -1052,8 +1052,8 @@ async def test_purge_filtered_events(
async def test_purge_filtered_events_state_changed(
hass: HomeAssistant,
async_setup_recorder_instance: SetupRecorderInstanceT,
hass: HomeAssistant,
):
"""Test filtered state_changed events are purged. This should also remove all states."""
config: ConfigType = {"exclude": {"event_types": [EVENT_STATE_CHANGED]}}
@ -1155,7 +1155,7 @@ async def test_purge_filtered_events_state_changed(
async def test_purge_entities(
hass: HomeAssistant, async_setup_recorder_instance: SetupRecorderInstanceT
async_setup_recorder_instance: SetupRecorderInstanceT, hass: HomeAssistant
):
"""Test purging of specific entities."""
await async_setup_recorder_instance(hass)
@ -1527,7 +1527,7 @@ def _add_state_and_state_changed_event(
async def test_purge_many_old_events(
hass: HomeAssistant, async_setup_recorder_instance: SetupRecorderInstanceT
async_setup_recorder_instance: SetupRecorderInstanceT, hass: HomeAssistant
):
"""Test deleting old events."""
instance = await async_setup_recorder_instance(hass)
@ -1580,7 +1580,7 @@ async def test_purge_many_old_events(
async def test_purge_can_mix_legacy_and_new_format(
hass: HomeAssistant, async_setup_recorder_instance: SetupRecorderInstanceT
async_setup_recorder_instance: SetupRecorderInstanceT, hass: HomeAssistant
):
"""Test purging with legacy a new events."""
instance = await async_setup_recorder_instance(hass)

View File

@ -8,7 +8,7 @@ from homeassistant.components.recorder.models import process_timestamp
from homeassistant.util import dt as dt_util
async def test_run_history(hass, recorder_mock):
async def test_run_history(recorder_mock, hass):
"""Test the run history gives the correct run."""
instance = recorder.get_instance(hass)
now = dt_util.utcnow()

View File

@ -448,9 +448,9 @@ def test_statistics_duplicated(hass_recorder, caplog):
),
)
async def test_import_statistics(
recorder_mock,
hass,
hass_ws_client,
recorder_mock,
caplog,
source,
statistic_id,

View File

@ -14,7 +14,7 @@ from .common import async_wait_recording_done
from tests.common import SetupRecorderInstanceT, get_system_health_info
async def test_recorder_system_health(hass, recorder_mock):
async def test_recorder_system_health(recorder_mock, hass):
"""Test recorder system health."""
assert await async_setup_component(hass, "system_health", {})
await async_wait_recording_done(hass)
@ -32,7 +32,7 @@ async def test_recorder_system_health(hass, recorder_mock):
@pytest.mark.parametrize(
"dialect_name", [SupportedDialect.MYSQL, SupportedDialect.POSTGRESQL]
)
async def test_recorder_system_health_alternate_dbms(hass, recorder_mock, dialect_name):
async def test_recorder_system_health_alternate_dbms(recorder_mock, hass, dialect_name):
"""Test recorder system health."""
assert await async_setup_component(hass, "system_health", {})
await async_wait_recording_done(hass)
@ -57,7 +57,7 @@ async def test_recorder_system_health_alternate_dbms(hass, recorder_mock, dialec
"dialect_name", [SupportedDialect.MYSQL, SupportedDialect.POSTGRESQL]
)
async def test_recorder_system_health_db_url_missing_host(
hass, recorder_mock, dialect_name
recorder_mock, hass, dialect_name
):
"""Test recorder system health with a db_url without a hostname."""
assert await async_setup_component(hass, "system_health", {})
@ -85,7 +85,7 @@ async def test_recorder_system_health_db_url_missing_host(
async def test_recorder_system_health_crashed_recorder_runs_table(
hass: HomeAssistant, async_setup_recorder_instance: SetupRecorderInstanceT
async_setup_recorder_instance: SetupRecorderInstanceT, hass: HomeAssistant
):
"""Test recorder system health with crashed recorder runs table."""
with patch("homeassistant.components.recorder.run_history.RunHistory.load_from_db"):

View File

@ -651,8 +651,8 @@ def test_periodic_db_cleanups(hass_recorder):
@patch("homeassistant.components.recorder.pool.check_loop")
async def test_write_lock_db(
skip_check_loop,
hass: HomeAssistant,
async_setup_recorder_instance: SetupRecorderInstanceT,
hass: HomeAssistant,
tmp_path,
):
"""Test database write lock."""

View File

@ -122,7 +122,7 @@ VOLUME_SENSOR_M3_ATTRIBUTES_TOTAL = {
}
async def test_statistics_during_period(hass, hass_ws_client, recorder_mock):
async def test_statistics_during_period(recorder_mock, hass, hass_ws_client):
"""Test statistics_during_period."""
now = dt_util.utcnow()
@ -200,9 +200,9 @@ async def test_statistics_during_period(hass, hass_ws_client, recorder_mock):
],
)
async def test_statistics_during_period_unit_conversion(
recorder_mock,
hass,
hass_ws_client,
recorder_mock,
attributes,
state,
value,
@ -293,9 +293,9 @@ async def test_statistics_during_period_unit_conversion(
],
)
async def test_sum_statistics_during_period_unit_conversion(
recorder_mock,
hass,
hass_ws_client,
recorder_mock,
attributes,
state,
value,
@ -386,7 +386,7 @@ async def test_sum_statistics_during_period_unit_conversion(
],
)
async def test_statistics_during_period_invalid_unit_conversion(
hass, hass_ws_client, recorder_mock, custom_units
recorder_mock, hass, hass_ws_client, custom_units
):
"""Test statistics_during_period."""
now = dt_util.utcnow()
@ -425,7 +425,7 @@ async def test_statistics_during_period_invalid_unit_conversion(
async def test_statistics_during_period_in_the_past(
hass, hass_ws_client, recorder_mock
recorder_mock, hass, hass_ws_client
):
"""Test statistics_during_period in the past."""
hass.config.set_time_zone("UTC")
@ -548,7 +548,7 @@ async def test_statistics_during_period_in_the_past(
async def test_statistics_during_period_bad_start_time(
hass, hass_ws_client, recorder_mock
recorder_mock, hass, hass_ws_client
):
"""Test statistics_during_period."""
client = await hass_ws_client()
@ -566,7 +566,7 @@ async def test_statistics_during_period_bad_start_time(
async def test_statistics_during_period_bad_end_time(
hass, hass_ws_client, recorder_mock
recorder_mock, hass, hass_ws_client
):
"""Test statistics_during_period."""
now = dt_util.utcnow()
@ -614,9 +614,9 @@ async def test_statistics_during_period_bad_end_time(
],
)
async def test_list_statistic_ids(
recorder_mock,
hass,
hass_ws_client,
recorder_mock,
units,
attributes,
display_unit,
@ -724,7 +724,7 @@ async def test_list_statistic_ids(
assert response["result"] == []
async def test_validate_statistics(hass, hass_ws_client, recorder_mock):
async def test_validate_statistics(recorder_mock, hass, hass_ws_client):
"""Test validate_statistics can be called."""
id = 1
@ -746,7 +746,7 @@ async def test_validate_statistics(hass, hass_ws_client, recorder_mock):
await assert_validation_result(client, {})
async def test_clear_statistics(hass, hass_ws_client, recorder_mock):
async def test_clear_statistics(recorder_mock, hass, hass_ws_client):
"""Test removing statistics."""
now = dt_util.utcnow()
@ -873,7 +873,7 @@ async def test_clear_statistics(hass, hass_ws_client, recorder_mock):
"new_unit, new_unit_class", [("dogs", None), (None, None), ("W", "power")]
)
async def test_update_statistics_metadata(
hass, hass_ws_client, recorder_mock, new_unit, new_unit_class
recorder_mock, hass, hass_ws_client, new_unit, new_unit_class
):
"""Test removing statistics."""
now = dt_util.utcnow()
@ -964,7 +964,7 @@ async def test_update_statistics_metadata(
}
async def test_change_statistics_unit(hass, hass_ws_client, recorder_mock):
async def test_change_statistics_unit(recorder_mock, hass, hass_ws_client):
"""Test change unit of recorded statistics."""
now = dt_util.utcnow()
@ -1083,7 +1083,7 @@ async def test_change_statistics_unit(hass, hass_ws_client, recorder_mock):
async def test_change_statistics_unit_errors(
hass, hass_ws_client, recorder_mock, caplog
recorder_mock, hass, hass_ws_client, caplog
):
"""Test change unit of recorded statistics."""
now = dt_util.utcnow()
@ -1200,7 +1200,7 @@ async def test_change_statistics_unit_errors(
await assert_statistics(expected_statistics)
async def test_recorder_info(hass, hass_ws_client, recorder_mock):
async def test_recorder_info(recorder_mock, hass, hass_ws_client):
"""Test getting recorder status."""
client = await hass_ws_client()
@ -1329,7 +1329,7 @@ async def test_backup_start_no_recorder(
async def test_backup_start_timeout(
hass, hass_ws_client, hass_supervisor_access_token, recorder_mock
recorder_mock, hass, hass_ws_client, hass_supervisor_access_token
):
"""Test getting backup start when recorder is not present."""
client = await hass_ws_client(hass, hass_supervisor_access_token)
@ -1348,7 +1348,7 @@ async def test_backup_start_timeout(
async def test_backup_end(
hass, hass_ws_client, hass_supervisor_access_token, recorder_mock
recorder_mock, hass, hass_ws_client, hass_supervisor_access_token
):
"""Test backup start."""
client = await hass_ws_client(hass, hass_supervisor_access_token)
@ -1366,7 +1366,7 @@ async def test_backup_end(
async def test_backup_end_without_start(
hass, hass_ws_client, hass_supervisor_access_token, recorder_mock
recorder_mock, hass, hass_ws_client, hass_supervisor_access_token
):
"""Test backup start."""
client = await hass_ws_client(hass, hass_supervisor_access_token)
@ -1400,7 +1400,7 @@ async def test_backup_end_without_start(
],
)
async def test_get_statistics_metadata(
hass, hass_ws_client, recorder_mock, units, attributes, unit, unit_class
recorder_mock, hass, hass_ws_client, units, attributes, unit, unit_class
):
"""Test get_statistics_metadata."""
now = dt_util.utcnow()
@ -1545,7 +1545,7 @@ async def test_get_statistics_metadata(
),
)
async def test_import_statistics(
hass, hass_ws_client, recorder_mock, caplog, source, statistic_id
recorder_mock, hass, hass_ws_client, caplog, source, statistic_id
):
"""Test importing statistics."""
client = await hass_ws_client()
@ -1772,7 +1772,7 @@ async def test_import_statistics(
),
)
async def test_adjust_sum_statistics_energy(
hass, hass_ws_client, recorder_mock, caplog, source, statistic_id
recorder_mock, hass, hass_ws_client, caplog, source, statistic_id
):
"""Test adjusting statistics."""
client = await hass_ws_client()
@ -1968,7 +1968,7 @@ async def test_adjust_sum_statistics_energy(
),
)
async def test_adjust_sum_statistics_gas(
hass, hass_ws_client, recorder_mock, caplog, source, statistic_id
recorder_mock, hass, hass_ws_client, caplog, source, statistic_id
):
"""Test adjusting statistics."""
client = await hass_ws_client()
@ -2168,9 +2168,9 @@ async def test_adjust_sum_statistics_gas(
),
)
async def test_adjust_sum_statistics_errors(
recorder_mock,
hass,
hass_ws_client,
recorder_mock,
caplog,
state_unit,
statistic_unit,

View File

@ -16,8 +16,8 @@ from tests.components.recorder.common import async_wait_recording_done
async def test_exclude_attributes(
hass: HomeAssistant,
recorder_mock: None,
hass: HomeAssistant,
enable_custom_integrations: None,
) -> None:
"""Test attributes to be excluded."""

View File

@ -27,7 +27,7 @@ def calls(hass):
return async_mock_service(hass, "test", "automation")
async def test_exclude_attributes(hass, recorder_mock, calls):
async def test_exclude_attributes(recorder_mock, hass, calls):
"""Test automation registered attributes to be excluded."""
await hass.async_block_till_done()
calls = []

View File

@ -16,7 +16,7 @@ from tests.common import async_fire_time_changed
from tests.components.recorder.common import async_wait_recording_done
async def test_exclude_attributes(hass, recorder_mock):
async def test_exclude_attributes(recorder_mock, hass):
"""Test select registered attributes to be excluded."""
await async_setup_component(
hass, select.DOMAIN, {select.DOMAIN: {"platform": "demo"}}

View File

@ -430,9 +430,9 @@ def test_compile_hourly_statistics_wrong_unit(hass_recorder, caplog, attributes)
],
)
async def test_compile_hourly_sum_statistics_amount(
recorder_mock,
hass,
hass_ws_client,
recorder_mock,
caplog,
units,
state_class,
@ -3328,7 +3328,7 @@ def record_states(hass, zero, entity_id, attributes, seq=None):
],
)
async def test_validate_unit_change_convertible(
hass, hass_ws_client, recorder_mock, units, attributes, unit, unit2, supported_unit
recorder_mock, hass, hass_ws_client, units, attributes, unit, unit2, supported_unit
):
"""Test validate_statistics.
@ -3443,7 +3443,7 @@ async def test_validate_unit_change_convertible(
],
)
async def test_validate_statistics_unit_ignore_device_class(
hass, hass_ws_client, recorder_mock, units, attributes
recorder_mock, hass, hass_ws_client, units, attributes
):
"""Test validate_statistics.
@ -3514,7 +3514,7 @@ async def test_validate_statistics_unit_ignore_device_class(
],
)
async def test_validate_statistics_unit_change_no_device_class(
hass, hass_ws_client, recorder_mock, units, attributes, unit, unit2, supported_unit
recorder_mock, hass, hass_ws_client, units, attributes, unit, unit2, supported_unit
):
"""Test validate_statistics.
@ -3629,7 +3629,7 @@ async def test_validate_statistics_unit_change_no_device_class(
],
)
async def test_validate_statistics_unsupported_state_class(
hass, hass_ws_client, recorder_mock, units, attributes, unit
recorder_mock, hass, hass_ws_client, units, attributes, unit
):
"""Test validate_statistics."""
id = 1
@ -3693,7 +3693,7 @@ async def test_validate_statistics_unsupported_state_class(
],
)
async def test_validate_statistics_sensor_no_longer_recorded(
hass, hass_ws_client, recorder_mock, units, attributes, unit
recorder_mock, hass, hass_ws_client, units, attributes, unit
):
"""Test validate_statistics."""
id = 1
@ -3754,7 +3754,7 @@ async def test_validate_statistics_sensor_no_longer_recorded(
],
)
async def test_validate_statistics_sensor_not_recorded(
hass, hass_ws_client, recorder_mock, units, attributes, unit
recorder_mock, hass, hass_ws_client, units, attributes, unit
):
"""Test validate_statistics."""
id = 1
@ -3812,7 +3812,7 @@ async def test_validate_statistics_sensor_not_recorded(
],
)
async def test_validate_statistics_sensor_removed(
hass, hass_ws_client, recorder_mock, units, attributes, unit
recorder_mock, hass, hass_ws_client, units, attributes, unit
):
"""Test validate_statistics."""
id = 1
@ -3871,7 +3871,7 @@ async def test_validate_statistics_sensor_removed(
],
)
async def test_validate_statistics_unit_change_no_conversion(
hass, recorder_mock, hass_ws_client, attributes, unit1, unit2
recorder_mock, hass, hass_ws_client, attributes, unit1, unit2
):
"""Test validate_statistics."""
id = 1
@ -3988,7 +3988,7 @@ async def test_validate_statistics_unit_change_no_conversion(
await assert_validation_result(client, expected)
async def test_validate_statistics_other_domain(hass, hass_ws_client, recorder_mock):
async def test_validate_statistics_other_domain(recorder_mock, hass, hass_ws_client):
"""Test sensor does not raise issues for statistics for other domains."""
id = 1

View File

@ -16,7 +16,7 @@ from tests.common import async_fire_time_changed
from tests.components.recorder.common import async_wait_recording_done
async def test_exclude_attributes(hass, recorder_mock):
async def test_exclude_attributes(recorder_mock, hass):
"""Test siren registered attributes to be excluded."""
await async_setup_component(
hass, siren.DOMAIN, {siren.DOMAIN: {"platform": "demo"}}

View File

@ -21,7 +21,7 @@ from . import (
from tests.common import MockConfigEntry
async def test_form(hass: HomeAssistant, recorder_mock) -> None:
async def test_form(recorder_mock, hass: HomeAssistant) -> None:
"""Test we get the form."""
result = await hass.config_entries.flow.async_init(
@ -53,7 +53,7 @@ async def test_form(hass: HomeAssistant, recorder_mock) -> None:
assert len(mock_setup_entry.mock_calls) == 1
async def test_import_flow_success(hass: HomeAssistant, recorder_mock) -> None:
async def test_import_flow_success(recorder_mock, hass: HomeAssistant) -> None:
"""Test a successful import of yaml."""
with patch(
@ -80,7 +80,7 @@ async def test_import_flow_success(hass: HomeAssistant, recorder_mock) -> None:
assert len(mock_setup_entry.mock_calls) == 1
async def test_import_flow_already_exist(hass: HomeAssistant, recorder_mock) -> None:
async def test_import_flow_already_exist(recorder_mock, hass: HomeAssistant) -> None:
"""Test import of yaml already exist."""
MockConfigEntry(
@ -103,7 +103,7 @@ async def test_import_flow_already_exist(hass: HomeAssistant, recorder_mock) ->
assert result3["reason"] == "already_configured"
async def test_flow_fails_db_url(hass: HomeAssistant, recorder_mock) -> None:
async def test_flow_fails_db_url(recorder_mock, hass: HomeAssistant) -> None:
"""Test config flow fails incorrect db url."""
result4 = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -124,7 +124,7 @@ async def test_flow_fails_db_url(hass: HomeAssistant, recorder_mock) -> None:
assert result4["errors"] == {"db_url": "db_url_invalid"}
async def test_flow_fails_invalid_query(hass: HomeAssistant, recorder_mock) -> None:
async def test_flow_fails_invalid_query(recorder_mock, hass: HomeAssistant) -> None:
"""Test config flow fails incorrect db url."""
result4 = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -170,7 +170,7 @@ async def test_flow_fails_invalid_query(hass: HomeAssistant, recorder_mock) -> N
}
async def test_options_flow(hass: HomeAssistant, recorder_mock) -> None:
async def test_options_flow(recorder_mock, hass: HomeAssistant) -> None:
"""Test options config flow."""
entry = MockConfigEntry(
domain=DOMAIN,
@ -219,7 +219,7 @@ async def test_options_flow(hass: HomeAssistant, recorder_mock) -> None:
async def test_options_flow_name_previously_removed(
hass: HomeAssistant, recorder_mock
recorder_mock, hass: HomeAssistant
) -> None:
"""Test options config flow where the name was missing."""
entry = MockConfigEntry(
@ -270,7 +270,7 @@ async def test_options_flow_name_previously_removed(
}
async def test_options_flow_fails_db_url(hass: HomeAssistant, recorder_mock) -> None:
async def test_options_flow_fails_db_url(recorder_mock, hass: HomeAssistant) -> None:
"""Test options flow fails incorrect db url."""
entry = MockConfigEntry(
domain=DOMAIN,
@ -313,7 +313,7 @@ async def test_options_flow_fails_db_url(hass: HomeAssistant, recorder_mock) ->
async def test_options_flow_fails_invalid_query(
hass: HomeAssistant, recorder_mock
recorder_mock, hass: HomeAssistant
) -> None:
"""Test options flow fails incorrect query and template."""
entry = MockConfigEntry(
@ -369,7 +369,7 @@ async def test_options_flow_fails_invalid_query(
}
async def test_options_flow_db_url_empty(hass: HomeAssistant, recorder_mock) -> None:
async def test_options_flow_db_url_empty(recorder_mock, hass: HomeAssistant) -> None:
"""Test options config flow with leaving db_url empty."""
entry = MockConfigEntry(
domain=DOMAIN,

View File

@ -1010,7 +1010,7 @@ async def test_invalid_state_characteristic(hass: HomeAssistant):
assert state is None
async def test_initialize_from_database(hass: HomeAssistant, recorder_mock):
async def test_initialize_from_database(recorder_mock, hass: HomeAssistant):
"""Test initializing the statistics from the recorder database."""
# enable and pre-fill the recorder
await hass.async_block_till_done()
@ -1049,7 +1049,7 @@ async def test_initialize_from_database(hass: HomeAssistant, recorder_mock):
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS
async def test_initialize_from_database_with_maxage(hass: HomeAssistant, recorder_mock):
async def test_initialize_from_database_with_maxage(recorder_mock, hass: HomeAssistant):
"""Test initializing the statistics from the database."""
now = dt_util.utcnow()
mock_data = {
@ -1109,7 +1109,7 @@ async def test_initialize_from_database_with_maxage(hass: HomeAssistant, recorde
) + timedelta(hours=1)
async def test_reload(hass: HomeAssistant, recorder_mock):
async def test_reload(recorder_mock, hass: HomeAssistant):
"""Verify we can reload statistics sensors."""
await async_setup_component(

View File

@ -26,7 +26,7 @@ from tests.common import async_fire_time_changed
from tests.components.recorder.common import async_wait_recording_done
async def test_exclude_attributes(hass, recorder_mock):
async def test_exclude_attributes(recorder_mock, hass):
"""Test sun attributes to be excluded."""
await async_setup_component(hass, DOMAIN, {})
await hass.async_block_till_done()

View File

@ -15,7 +15,7 @@ def tibber_setup_fixture():
yield
async def test_show_config_form(hass, recorder_mock):
async def test_show_config_form(recorder_mock, hass):
"""Test show configuration form."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -25,7 +25,7 @@ async def test_show_config_form(hass, recorder_mock):
assert result["step_id"] == "user"
async def test_create_entry(hass, recorder_mock):
async def test_create_entry(recorder_mock, hass):
"""Test create entry from user input."""
test_data = {
CONF_ACCESS_TOKEN: "valid",
@ -49,7 +49,7 @@ async def test_create_entry(hass, recorder_mock):
assert result["data"] == test_data
async def test_flow_entry_already_exists(hass, recorder_mock, config_entry):
async def test_flow_entry_already_exists(recorder_mock, hass, config_entry):
"""Test user input for config_entry that already exists."""
test_data = {
CONF_ACCESS_TOKEN: "valid",

View File

@ -8,7 +8,7 @@ from .test_common import mock_get_homes
from tests.components.diagnostics import get_diagnostics_for_config_entry
async def test_entry_diagnostics(hass, hass_client, recorder_mock, config_entry):
async def test_entry_diagnostics(recorder_mock, hass, hass_client, config_entry):
"""Test config entry diagnostics."""
with patch(
"tibber.Tibber.update_info",

View File

@ -10,7 +10,7 @@ from .test_common import CONSUMPTION_DATA_1, PRODUCTION_DATA_1, mock_get_homes
from tests.components.recorder.common import async_wait_recording_done
async def test_async_setup_entry(hass, recorder_mock):
async def test_async_setup_entry(recorder_mock, hass):
"""Test setup Tibber."""
tibber_connection = AsyncMock()
tibber_connection.name = "tibber"

View File

@ -21,7 +21,7 @@ from tests.components.recorder.common import async_wait_recording_done
async def test_exclude_attributes(
hass: HomeAssistant, recorder_mock, enable_custom_integrations: None
recorder_mock, hass: HomeAssistant, enable_custom_integrations: None
):
"""Test update attributes to be excluded."""
platform = getattr(hass.components, f"test.{DOMAIN}")

View File

@ -16,7 +16,7 @@ from tests.common import async_fire_time_changed
from tests.components.recorder.common import async_wait_recording_done
async def test_exclude_attributes(hass, recorder_mock):
async def test_exclude_attributes(recorder_mock, hass):
"""Test vacuum registered attributes to be excluded."""
await async_setup_component(
hass, vacuum.DOMAIN, {vacuum.DOMAIN: {"platform": "demo"}}

View File

@ -20,7 +20,7 @@ from tests.common import async_fire_time_changed
from tests.components.recorder.common import async_wait_recording_done
async def test_exclude_attributes(hass, recorder_mock):
async def test_exclude_attributes(recorder_mock, hass):
"""Test water_heater registered attributes to be excluded."""
await async_setup_component(
hass, water_heater.DOMAIN, {water_heater.DOMAIN: {"platform": "demo"}}

View File

@ -15,7 +15,7 @@ from tests.common import async_fire_time_changed
from tests.components.recorder.common import async_wait_recording_done
async def test_exclude_attributes(hass: HomeAssistant, recorder_mock) -> None:
async def test_exclude_attributes(recorder_mock, hass: HomeAssistant) -> None:
"""Test weather attributes to be excluded."""
await async_setup_component(hass, DOMAIN, {DOMAIN: {"platform": "demo"}})
hass.config.units = METRIC_SYSTEM

View File

@ -312,9 +312,17 @@ def aiohttp_client(
@pytest.fixture
def hass(loop, load_registries, hass_storage, request):
def hass_fixture_setup():
"""Fixture whichis truthy if the hass fixture has been setup."""
return []
@pytest.fixture
def hass(hass_fixture_setup, loop, load_registries, hass_storage, request):
"""Fixture to provide a test instance of Home Assistant."""
hass_fixture_setup.append(True)
orig_tz = dt_util.DEFAULT_TIME_ZONE
def exc_handle(loop, context):
@ -912,9 +920,10 @@ async def _async_init_recorder_component(hass, add_config=None):
@pytest.fixture
async def async_setup_recorder_instance(
enable_nightly_purge, enable_statistics
hass_fixture_setup, enable_nightly_purge, enable_statistics
) -> AsyncGenerator[SetupRecorderInstanceT, None]:
"""Yield callable to setup recorder instance."""
assert not hass_fixture_setup
nightly = recorder.Recorder.async_nightly_tasks if enable_nightly_purge else None
stats = recorder.Recorder.async_periodic_statistics if enable_statistics else None

View File

@ -9,7 +9,7 @@ from tests.common import SetupRecorderInstanceT
async def test_async_migration_in_progress(
hass: HomeAssistant, async_setup_recorder_instance: SetupRecorderInstanceT
async_setup_recorder_instance: SetupRecorderInstanceT, hass: HomeAssistant
):
"""Test async_migration_in_progress wraps the recorder."""
with patch(