From c399cab42756fdca4522227fc6e5da8976d6f1fd Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 18 Jan 2024 08:41:32 -1000 Subject: [PATCH] Small speed up to checking core state (#107845) --- homeassistant/core.py | 23 ++++++++++++------- tests/common.py | 2 +- tests/components/alexa/test_state_report.py | 9 +++++--- tests/components/august/test_sensor.py | 2 +- tests/components/automation/test_init.py | 10 ++++---- .../test_active_update_coordinator.py | 2 +- .../bluetooth/test_active_update_processor.py | 2 +- .../test_passive_update_processor.py | 2 +- tests/components/bond/test_entity.py | 2 +- tests/components/cert_expiry/test_init.py | 2 +- tests/components/cloud/test_alexa_config.py | 10 ++++---- tests/components/cloud/test_google_config.py | 14 +++++------ tests/components/counter/test_init.py | 6 ++--- .../device_sun_light_trigger/test_init.py | 2 +- tests/components/fastdotcom/test_init.py | 7 +++--- .../generic_hygrostat/test_humidifier.py | 8 +++---- .../generic_thermostat/test_climate.py | 8 +++---- tests/components/group/test_fan.py | 2 +- tests/components/group/test_init.py | 14 +++++------ tests/components/hassio/conftest.py | 2 +- .../here_travel_time/test_sensor.py | 2 +- .../triggers/test_homeassistant.py | 4 ++-- tests/components/homekit/test_type_covers.py | 4 ++-- tests/components/homekit/test_type_fans.py | 2 +- tests/components/homekit/test_type_lights.py | 2 +- .../homekit/test_type_media_players.py | 2 +- tests/components/homekit/test_type_sensors.py | 2 +- .../homekit/test_type_thermostats.py | 4 ++-- tests/components/input_boolean/test_init.py | 4 ++-- tests/components/input_button/test_init.py | 2 +- tests/components/input_datetime/test_init.py | 2 +- tests/components/input_number/test_init.py | 8 +++---- tests/components/input_text/test_init.py | 6 ++--- .../manual/test_alarm_control_panel.py | 10 ++++---- tests/components/mqtt/test_init.py | 2 +- tests/components/mqtt/test_mixins.py | 2 +- tests/components/mqtt/test_util.py | 10 ++++---- .../components/mqtt_statestream/test_init.py | 2 +- tests/components/netatmo/test_init.py | 2 +- .../nmap_tracker/test_config_flow.py | 2 +- tests/components/person/test_init.py | 8 +++---- tests/components/recorder/test_init.py | 8 +++---- tests/components/rflink/test_binary_sensor.py | 2 +- tests/components/rflink/test_cover.py | 2 +- tests/components/rflink/test_light.py | 2 +- tests/components/rflink/test_switch.py | 2 +- tests/components/script/test_init.py | 4 ++-- .../sensor/test_recorder_missing_stats.py | 4 ++-- .../components/template/test_binary_sensor.py | 2 +- tests/components/template/test_sensor.py | 4 ++-- tests/components/template/test_switch.py | 2 +- tests/components/timer/test_init.py | 10 ++++---- tests/components/trace/test_websocket_api.py | 6 ++--- tests/components/utility_meter/test_sensor.py | 6 ++--- tests/components/whirlpool/test_sensor.py | 8 +++---- tests/components/zha/test_cover.py | 4 ++-- tests/components/zha/test_init.py | 2 +- tests/components/zwave_js/test_update.py | 4 ++-- tests/helpers/test_device_registry.py | 2 +- tests/helpers/test_discovery_flow.py | 6 ++--- tests/helpers/test_entity_platform.py | 2 +- tests/helpers/test_entity_registry.py | 4 ++-- tests/helpers/test_restore_state.py | 4 ++-- tests/helpers/test_script.py | 4 ++-- tests/helpers/test_start.py | 20 ++++++++-------- tests/helpers/test_storage.py | 10 ++++---- tests/helpers/test_update_coordinator.py | 2 +- tests/test_config_entries.py | 4 ++-- 68 files changed, 176 insertions(+), 165 deletions(-) diff --git a/homeassistant/core.py b/homeassistant/core.py index 9c9ca335602..bef89118de9 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -393,16 +393,23 @@ class HomeAssistant: self._stop_future: concurrent.futures.Future[None] | None = None self._shutdown_jobs: list[HassJobWithArgs] = [] - @property + @cached_property def is_running(self) -> bool: """Return if Home Assistant is running.""" return self.state in (CoreState.starting, CoreState.running) - @property + @cached_property def is_stopping(self) -> bool: """Return if Home Assistant is stopping.""" return self.state in (CoreState.stopping, CoreState.final_write) + def set_state(self, state: CoreState) -> None: + """Set the current state.""" + self.state = state + for prop in ("is_running", "is_stopping"): + with suppress(AttributeError): + delattr(self, prop) + def start(self) -> int: """Start Home Assistant. @@ -451,7 +458,7 @@ class HomeAssistant: _LOGGER.info("Starting Home Assistant") setattr(self.loop, "_thread_ident", threading.get_ident()) - self.state = CoreState.starting + self.set_state(CoreState.starting) self.bus.async_fire(EVENT_CORE_CONFIG_UPDATE) self.bus.async_fire(EVENT_HOMEASSISTANT_START) @@ -483,7 +490,7 @@ class HomeAssistant: ) return - self.state = CoreState.running + self.set_state(CoreState.running) self.bus.async_fire(EVENT_CORE_CONFIG_UPDATE) self.bus.async_fire(EVENT_HOMEASSISTANT_STARTED) @@ -894,7 +901,7 @@ class HomeAssistant: self.exit_code = exit_code - self.state = CoreState.stopping + self.set_state(CoreState.stopping) self.bus.async_fire(EVENT_HOMEASSISTANT_STOP) try: async with self.timeout.async_timeout(STOP_STAGE_SHUTDOWN_TIMEOUT): @@ -907,7 +914,7 @@ class HomeAssistant: self._async_log_running_tasks("stop integrations") # Stage 3 - Final write - self.state = CoreState.final_write + self.set_state(CoreState.final_write) self.bus.async_fire(EVENT_HOMEASSISTANT_FINAL_WRITE) try: async with self.timeout.async_timeout(FINAL_WRITE_STAGE_SHUTDOWN_TIMEOUT): @@ -920,7 +927,7 @@ class HomeAssistant: self._async_log_running_tasks("final write") # Stage 4 - Close - self.state = CoreState.not_running + self.set_state(CoreState.not_running) self.bus.async_fire(EVENT_HOMEASSISTANT_CLOSE) # Make a copy of running_tasks since a task can finish @@ -971,7 +978,7 @@ class HomeAssistant: ) self._async_log_running_tasks("close") - self.state = CoreState.stopped + self.set_state(CoreState.stopped) if self._stopped is not None: self._stopped.set() diff --git a/tests/common.py b/tests/common.py index 8b5a16c7104..1b40904d5e2 100644 --- a/tests/common.py +++ b/tests/common.py @@ -285,7 +285,7 @@ async def async_test_home_assistant(event_loop, load_registries=True): ) hass.data[bootstrap.DATA_REGISTRIES_LOADED] = None - hass.state = CoreState.running + hass.set_state(CoreState.running) @callback def clear_instance(event): diff --git a/tests/components/alexa/test_state_report.py b/tests/components/alexa/test_state_report.py index c17593e0e2a..08d198145df 100644 --- a/tests/components/alexa/test_state_report.py +++ b/tests/components/alexa/test_state_report.py @@ -735,9 +735,12 @@ async def test_proactive_mode_filter_states( "off", {"friendly_name": "Test Contact Sensor", "device_class": "door"}, ) - with patch.object(hass, "state", core.CoreState.stopping): - await hass.async_block_till_done() - await hass.async_block_till_done() + + current_state = hass.state + hass.set_state(core.CoreState.stopping) + await hass.async_block_till_done() + await hass.async_block_till_done() + hass.set_state(current_state) assert len(aioclient_mock.mock_calls) == 0 # unsupported entity should not report diff --git a/tests/components/august/test_sensor.py b/tests/components/august/test_sensor.py index f2ea0066345..10b7eb86235 100644 --- a/tests/components/august/test_sensor.py +++ b/tests/components/august/test_sensor.py @@ -340,7 +340,7 @@ async def test_restored_state( ) # Home assistant is not running yet - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) mock_restore_cache_with_extra_data( hass, [ diff --git a/tests/components/automation/test_init.py b/tests/components/automation/test_init.py index 6bb1b89259a..3a8c12f735a 100644 --- a/tests/components/automation/test_init.py +++ b/tests/components/automation/test_init.py @@ -1202,7 +1202,7 @@ async def test_initial_value_off(hass: HomeAssistant) -> None: async def test_initial_value_on(hass: HomeAssistant) -> None: """Test initial value on.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) calls = async_mock_service(hass, "test", "automation") assert await async_setup_component( @@ -1231,7 +1231,7 @@ async def test_initial_value_on(hass: HomeAssistant) -> None: async def test_initial_value_off_but_restore_on(hass: HomeAssistant) -> None: """Test initial value off and restored state is turned on.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) calls = async_mock_service(hass, "test", "automation") mock_restore_cache(hass, (State("automation.hello", STATE_ON),)) @@ -1328,7 +1328,7 @@ async def test_automation_is_on_if_no_initial_state_or_restore( async def test_automation_not_trigger_on_bootstrap(hass: HomeAssistant) -> None: """Test if automation is not trigger on bootstrap.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) calls = async_mock_service(hass, "test", "automation") assert await async_setup_component( @@ -2460,7 +2460,7 @@ async def test_recursive_automation_starting_script( await asyncio.wait_for(script_done_event.wait(), 10) # Trigger 1st stage script shutdown - hass.state = CoreState.stopping + hass.set_state(CoreState.stopping) hass.bus.async_fire("homeassistant_stop") await asyncio.wait_for(stop_scripts_at_shutdown_called.wait(), 10) @@ -2521,7 +2521,7 @@ async def test_recursive_automation( await asyncio.wait_for(service_called.wait(), 1) # Trigger 1st stage script shutdown - hass.state = CoreState.stopping + hass.set_state(CoreState.stopping) hass.bus.async_fire("homeassistant_stop") await asyncio.wait_for(stop_scripts_at_shutdown_called.wait(), 1) diff --git a/tests/components/bluetooth/test_active_update_coordinator.py b/tests/components/bluetooth/test_active_update_coordinator.py index 2686138d724..83fee1456cd 100644 --- a/tests/components/bluetooth/test_active_update_coordinator.py +++ b/tests/components/bluetooth/test_active_update_coordinator.py @@ -439,7 +439,7 @@ async def test_no_polling_after_stop_event( assert needs_poll_calls == 1 - hass.state = CoreState.stopping + hass.set_state(CoreState.stopping) await hass.async_block_till_done() assert needs_poll_calls == 1 diff --git a/tests/components/bluetooth/test_active_update_processor.py b/tests/components/bluetooth/test_active_update_processor.py index fba86223a2d..00562a20daf 100644 --- a/tests/components/bluetooth/test_active_update_processor.py +++ b/tests/components/bluetooth/test_active_update_processor.py @@ -436,7 +436,7 @@ async def test_no_polling_after_stop_event( assert async_handle_update.mock_calls[0] == call({"testdata": 0}, False) assert async_handle_update.mock_calls[1] == call({"testdata": 1}) - hass.state = CoreState.stopping + hass.set_state(CoreState.stopping) await hass.async_block_till_done() assert needs_poll_calls == 1 diff --git a/tests/components/bluetooth/test_passive_update_processor.py b/tests/components/bluetooth/test_passive_update_processor.py index 345c4b62b7e..5c7c4e39083 100644 --- a/tests/components/bluetooth/test_passive_update_processor.py +++ b/tests/components/bluetooth/test_passive_update_processor.py @@ -553,7 +553,7 @@ async def test_no_updates_once_stopping( inject_bluetooth_service_info(hass, GENERIC_BLUETOOTH_SERVICE_INFO) assert len(all_events) == 1 - hass.state = CoreState.stopping + hass.set_state(CoreState.stopping) # We should stop processing events once hass is stopping inject_bluetooth_service_info(hass, GENERIC_BLUETOOTH_SERVICE_INFO_2) diff --git a/tests/components/bond/test_entity.py b/tests/components/bond/test_entity.py index 100a133ae4d..d61b4e06560 100644 --- a/tests/components/bond/test_entity.py +++ b/tests/components/bond/test_entity.py @@ -206,7 +206,7 @@ async def test_polling_stops_at_the_stop_event(hass: HomeAssistant) -> None: assert hass.states.get("fan.name_1").state == STATE_UNAVAILABLE hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP) - hass.state = CoreState.stopping + hass.set_state(CoreState.stopping) await hass.async_block_till_done() with patch_bond_device_state(return_value={"power": 1, "speed": 1}): diff --git a/tests/components/cert_expiry/test_init.py b/tests/components/cert_expiry/test_init.py index 00f8a34fb0c..0e0ff1444eb 100644 --- a/tests/components/cert_expiry/test_init.py +++ b/tests/components/cert_expiry/test_init.py @@ -120,7 +120,7 @@ async def test_unload_config_entry(hass: HomeAssistant) -> None: async def test_delay_load_during_startup(hass: HomeAssistant) -> None: """Test delayed loading of a config entry during startup.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) entry = MockConfigEntry(domain=DOMAIN, data={CONF_HOST: HOST, CONF_PORT: PORT}) entry.add_to_hass(hass) diff --git a/tests/components/cloud/test_alexa_config.py b/tests/components/cloud/test_alexa_config.py index 2be2a8eb2bb..0ebc385b516 100644 --- a/tests/components/cloud/test_alexa_config.py +++ b/tests/components/cloud/test_alexa_config.py @@ -551,7 +551,7 @@ async def test_alexa_config_migrate_expose_entity_prefs( alexa_settings_version: int, ) -> None: """Test migrating Alexa entity config.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) assert await async_setup_component(hass, "homeassistant", {}) hass.states.async_set("light.state_only", "on") @@ -649,7 +649,7 @@ async def test_alexa_config_migrate_expose_entity_prefs_v2_no_exposed( entity_registry: er.EntityRegistry, ) -> None: """Test migrating Alexa entity config from v2 to v3 when no entity is exposed.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) assert await async_setup_component(hass, "homeassistant", {}) hass.states.async_set("light.state_only", "on") @@ -696,7 +696,7 @@ async def test_alexa_config_migrate_expose_entity_prefs_v2_exposed( entity_registry: er.EntityRegistry, ) -> None: """Test migrating Alexa entity config from v2 to v3 when an entity is exposed.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) assert await async_setup_component(hass, "homeassistant", {}) hass.states.async_set("light.state_only", "on") @@ -744,7 +744,7 @@ async def test_alexa_config_migrate_expose_entity_prefs_default_none( entity_registry: er.EntityRegistry, ) -> None: """Test migrating Alexa entity config.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) assert await async_setup_component(hass, "homeassistant", {}) entity_default = entity_registry.async_get_or_create( @@ -782,7 +782,7 @@ async def test_alexa_config_migrate_expose_entity_prefs_default( entity_registry: er.EntityRegistry, ) -> None: """Test migrating Alexa entity config.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) assert await async_setup_component(hass, "homeassistant", {}) diff --git a/tests/components/cloud/test_google_config.py b/tests/components/cloud/test_google_config.py index 39bf60570f2..bedc6b459c5 100644 --- a/tests/components/cloud/test_google_config.py +++ b/tests/components/cloud/test_google_config.py @@ -236,7 +236,7 @@ async def test_google_entity_registry_sync( assert len(mock_sync.mock_calls) == 3 # When hass is not started yet we wait till started - hass.state = CoreState.starting + hass.set_state(CoreState.starting) hass.bus.async_fire( er.EVENT_ENTITY_REGISTRY_UPDATED, {"action": "create", "entity_id": entry.entity_id}, @@ -338,7 +338,7 @@ async def test_sync_google_on_home_assistant_start( config = CloudGoogleConfig( hass, GACTIONS_SCHEMA({}), "mock-user-id", cloud_prefs, hass.data["cloud"] ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) with patch.object(config, "async_sync_entities_all") as mock_sync: await config.async_initialize() await config.async_connect_agent_user("mock-user-id") @@ -498,7 +498,7 @@ async def test_google_config_migrate_expose_entity_prefs( google_settings_version: int, ) -> None: """Test migrating Google entity config.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) assert await async_setup_component(hass, "homeassistant", {}) hass.states.async_set("light.state_only", "on") @@ -611,7 +611,7 @@ async def test_google_config_migrate_expose_entity_prefs_v2_no_exposed( entity_registry: er.EntityRegistry, ) -> None: """Test migrating Google entity config from v2 to v3 when no entity is exposed.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) assert await async_setup_component(hass, "homeassistant", {}) hass.states.async_set("light.state_only", "on") @@ -658,7 +658,7 @@ async def test_google_config_migrate_expose_entity_prefs_v2_exposed( entity_registry: er.EntityRegistry, ) -> None: """Test migrating Google entity config from v2 to v3 when an entity is exposed.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) assert await async_setup_component(hass, "homeassistant", {}) hass.states.async_set("light.state_only", "on") @@ -705,7 +705,7 @@ async def test_google_config_migrate_expose_entity_prefs_default_none( entity_registry: er.EntityRegistry, ) -> None: """Test migrating Google entity config.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) assert await async_setup_component(hass, "homeassistant", {}) entity_default = entity_registry.async_get_or_create( @@ -742,7 +742,7 @@ async def test_google_config_migrate_expose_entity_prefs_default( entity_registry: er.EntityRegistry, ) -> None: """Test migrating Google entity config.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) assert await async_setup_component(hass, "homeassistant", {}) diff --git a/tests/components/counter/test_init.py b/tests/components/counter/test_init.py index 53bec13d567..a52c083d10f 100644 --- a/tests/components/counter/test_init.py +++ b/tests/components/counter/test_init.py @@ -282,7 +282,7 @@ async def test_initial_state_overrules_restore_state(hass: HomeAssistant) -> Non hass, (State("counter.test1", "11"), State("counter.test2", "-22")) ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await async_setup_component( hass, @@ -315,7 +315,7 @@ async def test_restore_state_overrules_initial_state(hass: HomeAssistant) -> Non ), ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await async_setup_component( hass, DOMAIN, {DOMAIN: {"test1": {}, "test2": {CONF_INITIAL: 10}, "test3": {}}} @@ -332,7 +332,7 @@ async def test_restore_state_overrules_initial_state(hass: HomeAssistant) -> Non async def test_no_initial_state_and_no_restore_state(hass: HomeAssistant) -> None: """Ensure that entity is create without initial and restore feature.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await async_setup_component(hass, DOMAIN, {DOMAIN: {"test1": {CONF_STEP: 5}}}) diff --git a/tests/components/device_sun_light_trigger/test_init.py b/tests/components/device_sun_light_trigger/test_init.py index ada1c03a923..3831d247ed4 100644 --- a/tests/components/device_sun_light_trigger/test_init.py +++ b/tests/components/device_sun_light_trigger/test_init.py @@ -238,7 +238,7 @@ async def test_lights_turn_on_when_coming_home_after_sun_set_person( async def test_initialize_start(hass: HomeAssistant) -> None: """Test we initialize when HA starts.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) assert await async_setup_component( hass, device_sun_light_trigger.DOMAIN, diff --git a/tests/components/fastdotcom/test_init.py b/tests/components/fastdotcom/test_init.py index dc61acb620e..547d574b25a 100644 --- a/tests/components/fastdotcom/test_init.py +++ b/tests/components/fastdotcom/test_init.py @@ -64,11 +64,12 @@ async def test_delayed_speedtest_during_startup( ) config_entry.add_to_hass(hass) - with patch( - "homeassistant.components.fastdotcom.coordinator.fast_com" - ), patch.object(hass, "state", CoreState.starting): + original_state = hass.state + hass.set_state(CoreState.starting) + with patch("homeassistant.components.fastdotcom.coordinator.fast_com"): await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() + hass.set_state(original_state) assert config_entry.state == config_entries.ConfigEntryState.LOADED state = hass.states.get("sensor.fast_com_download") diff --git a/tests/components/generic_hygrostat/test_humidifier.py b/tests/components/generic_hygrostat/test_humidifier.py index 9c0fa7ddaef..d68e5ca78e0 100644 --- a/tests/components/generic_hygrostat/test_humidifier.py +++ b/tests/components/generic_hygrostat/test_humidifier.py @@ -1376,7 +1376,7 @@ async def test_restore_state(hass: HomeAssistant) -> None: ), ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await async_setup_component( hass, @@ -1414,7 +1414,7 @@ async def test_restore_state_target_humidity(hass: HomeAssistant) -> None: ), ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await async_setup_component( hass, @@ -1457,7 +1457,7 @@ async def test_restore_state_and_return_to_normal(hass: HomeAssistant) -> None: ), ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await async_setup_component( hass, @@ -1512,7 +1512,7 @@ async def test_no_restore_state(hass: HomeAssistant) -> None: ), ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await async_setup_component( hass, diff --git a/tests/components/generic_thermostat/test_climate.py b/tests/components/generic_thermostat/test_climate.py index 9196de8b096..e0b6e5c9987 100644 --- a/tests/components/generic_thermostat/test_climate.py +++ b/tests/components/generic_thermostat/test_climate.py @@ -1317,7 +1317,7 @@ async def test_restore_state(hass: HomeAssistant, hvac_mode) -> None: ), ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await async_setup_component( hass, @@ -1355,7 +1355,7 @@ async def test_no_restore_state(hass: HomeAssistant) -> None: ), ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await async_setup_component( hass, @@ -1432,7 +1432,7 @@ async def test_restore_will_turn_off_(hass: HomeAssistant) -> None: ), ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) assert await async_setup_component( hass, input_boolean.DOMAIN, {"input_boolean": {"test": None}} @@ -1480,7 +1480,7 @@ async def test_restore_will_turn_off_when_loaded_second(hass: HomeAssistant) -> ), ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await hass.async_block_till_done() assert hass.states.get(heater_switch) is None diff --git a/tests/components/group/test_fan.py b/tests/components/group/test_fan.py index 2a1baef6798..ecc21ab0cd2 100644 --- a/tests/components/group/test_fan.py +++ b/tests/components/group/test_fan.py @@ -386,7 +386,7 @@ async def test_state_missing_entity_id(hass: HomeAssistant, setup_comp) -> None: async def test_setup_before_started(hass: HomeAssistant) -> None: """Test we can setup before starting.""" - hass.state = CoreState.stopped + hass.set_state(CoreState.stopped) assert await async_setup_component(hass, DOMAIN, CONFIG_MISSING_FAN) await hass.async_block_till_done() diff --git a/tests/components/group/test_init.py b/tests/components/group/test_init.py index 5c48385c91e..cb5143d5a12 100644 --- a/tests/components/group/test_init.py +++ b/tests/components/group/test_init.py @@ -1139,7 +1139,7 @@ async def test_group_alarm(hass: HomeAssistant) -> None: hass.states.async_set("alarm_control_panel.one", "armed_away") hass.states.async_set("alarm_control_panel.two", "armed_home") hass.states.async_set("alarm_control_panel.three", "armed_away") - hass.state = CoreState.stopped + hass.set_state(CoreState.stopped) assert await async_setup_component( hass, @@ -1187,7 +1187,7 @@ async def test_group_vacuum_off(hass: HomeAssistant) -> None: hass.states.async_set("vacuum.one", "docked") hass.states.async_set("vacuum.two", "off") hass.states.async_set("vacuum.three", "off") - hass.state = CoreState.stopped + hass.set_state(CoreState.stopped) assert await async_setup_component( hass, @@ -1280,7 +1280,7 @@ async def test_switch_removed(hass: HomeAssistant) -> None: hass.states.async_set("switch.two", "off") hass.states.async_set("switch.three", "on") - hass.state = CoreState.stopped + hass.set_state(CoreState.stopped) assert await async_setup_component( hass, "group", @@ -1409,7 +1409,7 @@ async def test_group_that_references_a_group_of_lights(hass: HomeAssistant) -> N "light.living_front_ri", "light.living_back_lef", ] - hass.state = CoreState.stopped + hass.set_state(CoreState.stopped) for entity_id in entity_ids: hass.states.async_set(entity_id, "off") @@ -1443,7 +1443,7 @@ async def test_group_that_references_a_group_of_covers(hass: HomeAssistant) -> N "cover.living_front_ri", "cover.living_back_lef", ] - hass.state = CoreState.stopped + hass.set_state(CoreState.stopped) for entity_id in entity_ids: hass.states.async_set(entity_id, "closed") @@ -1479,7 +1479,7 @@ async def test_group_that_references_two_groups_of_covers(hass: HomeAssistant) - "cover.living_front_ri", "cover.living_back_lef", ] - hass.state = CoreState.stopped + hass.set_state(CoreState.stopped) for entity_id in entity_ids: hass.states.async_set(entity_id, "closed") @@ -1523,7 +1523,7 @@ async def test_group_that_references_two_types_of_groups(hass: HomeAssistant) -> "device_tracker.living_front_ri", "device_tracker.living_back_lef", ] - hass.state = CoreState.stopped + hass.set_state(CoreState.stopped) for entity_id in group_1_entity_ids: hass.states.async_set(entity_id, "closed") diff --git a/tests/components/hassio/conftest.py b/tests/components/hassio/conftest.py index 0cce33f6dfd..e54fdcafd1d 100644 --- a/tests/components/hassio/conftest.py +++ b/tests/components/hassio/conftest.py @@ -58,7 +58,7 @@ def hassio_stubs(hassio_env, hass, hass_client, aioclient_mock): ), patch( "homeassistant.components.hassio.HassIO.refresh_updates", ): - hass.state = CoreState.starting + hass.set_state(CoreState.starting) hass.loop.run_until_complete(async_setup_component(hass, "hassio", {})) return hass_api.call_args[0][1] diff --git a/tests/components/here_travel_time/test_sensor.py b/tests/components/here_travel_time/test_sensor.py index 28228788cf5..21580c48f33 100644 --- a/tests/components/here_travel_time/test_sensor.py +++ b/tests/components/here_travel_time/test_sensor.py @@ -486,7 +486,7 @@ async def test_route_not_found( async def test_restore_state(hass: HomeAssistant) -> None: """Test sensor restore state.""" # Home assistant is not running yet - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) last_reset = "2022-11-29T00:00:00.000000+00:00" mock_restore_cache_with_extra_data( hass, diff --git a/tests/components/homeassistant/triggers/test_homeassistant.py b/tests/components/homeassistant/triggers/test_homeassistant.py index 6ac8291ee55..9a202bc99a1 100644 --- a/tests/components/homeassistant/triggers/test_homeassistant.py +++ b/tests/components/homeassistant/triggers/test_homeassistant.py @@ -31,7 +31,7 @@ async def test_if_fires_on_hass_start( ) -> None: """Test the firing when Home Assistant starts.""" calls = async_mock_service(hass, "test", "automation") - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) assert await async_setup_component(hass, automation.DOMAIN, hass_config) assert automation.is_on(hass, "automation.hello") @@ -54,7 +54,7 @@ async def test_if_fires_on_hass_start( async def test_if_fires_on_hass_shutdown(hass: HomeAssistant) -> None: """Test the firing when Home Assistant shuts down.""" calls = async_mock_service(hass, "test", "automation") - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) assert await async_setup_component( hass, diff --git a/tests/components/homekit/test_type_covers.py b/tests/components/homekit/test_type_covers.py index 989e4dd01d3..bc43ebaf42f 100644 --- a/tests/components/homekit/test_type_covers.py +++ b/tests/components/homekit/test_type_covers.py @@ -610,7 +610,7 @@ async def test_windowcovering_basic_restore( hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events ) -> None: """Test setting up an entity from state in the event registry.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) entity_registry.async_get_or_create( "cover", @@ -648,7 +648,7 @@ async def test_windowcovering_restore( hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events ) -> None: """Test setting up an entity from state in the event entity_registry.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) entity_registry.async_get_or_create( "cover", diff --git a/tests/components/homekit/test_type_fans.py b/tests/components/homekit/test_type_fans.py index 118e67a43b1..edaa277576e 100644 --- a/tests/components/homekit/test_type_fans.py +++ b/tests/components/homekit/test_type_fans.py @@ -557,7 +557,7 @@ async def test_fan_restore( hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events ) -> None: """Test setting up an entity from state in the event registry.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) entity_registry.async_get_or_create( "fan", diff --git a/tests/components/homekit/test_type_lights.py b/tests/components/homekit/test_type_lights.py index 7568e7a4844..80555750640 100644 --- a/tests/components/homekit/test_type_lights.py +++ b/tests/components/homekit/test_type_lights.py @@ -580,7 +580,7 @@ async def test_light_restore( hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events ) -> None: """Test setting up an entity from state in the event registry.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) entity_registry.async_get_or_create( "light", "hue", "1234", suggested_object_id="simple" diff --git a/tests/components/homekit/test_type_media_players.py b/tests/components/homekit/test_type_media_players.py index 1954d6bf8ca..8089db833e8 100644 --- a/tests/components/homekit/test_type_media_players.py +++ b/tests/components/homekit/test_type_media_players.py @@ -432,7 +432,7 @@ async def test_tv_restore( hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events ) -> None: """Test setting up an entity from state in the event registry.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) entity_registry.async_get_or_create( "media_player", diff --git a/tests/components/homekit/test_type_sensors.py b/tests/components/homekit/test_type_sensors.py index 23e53eef94d..fae963c81f5 100644 --- a/tests/components/homekit/test_type_sensors.py +++ b/tests/components/homekit/test_type_sensors.py @@ -545,7 +545,7 @@ async def test_sensor_restore( hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events ) -> None: """Test setting up an entity from state in the event registry.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) entity_registry.async_get_or_create( "sensor", diff --git a/tests/components/homekit/test_type_thermostats.py b/tests/components/homekit/test_type_thermostats.py index 0bea0144506..3f5d939bb82 100644 --- a/tests/components/homekit/test_type_thermostats.py +++ b/tests/components/homekit/test_type_thermostats.py @@ -971,7 +971,7 @@ async def test_thermostat_restore( hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events ) -> None: """Test setting up an entity from state in the event registry.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) entity_registry.async_get_or_create( "climate", "generic", "1234", suggested_object_id="simple" @@ -1801,7 +1801,7 @@ async def test_water_heater_restore( hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events ) -> None: """Test setting up an entity from state in the event registry.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) entity_registry.async_get_or_create( "water_heater", "generic", "1234", suggested_object_id="simple" diff --git a/tests/components/input_boolean/test_init.py b/tests/components/input_boolean/test_init.py index 4caf914ca19..65d7fb93d19 100644 --- a/tests/components/input_boolean/test_init.py +++ b/tests/components/input_boolean/test_init.py @@ -133,7 +133,7 @@ async def test_restore_state(hass: HomeAssistant) -> None: ), ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) mock_component(hass, "recorder") await async_setup_component(hass, DOMAIN, {DOMAIN: {"b1": None, "b2": None}}) @@ -153,7 +153,7 @@ async def test_initial_state_overrules_restore_state(hass: HomeAssistant) -> Non hass, (State("input_boolean.b1", "on"), State("input_boolean.b2", "off")) ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await async_setup_component( hass, diff --git a/tests/components/input_button/test_init.py b/tests/components/input_button/test_init.py index 9233668c113..2f9b677e134 100644 --- a/tests/components/input_button/test_init.py +++ b/tests/components/input_button/test_init.py @@ -96,7 +96,7 @@ async def test_restore_state(hass: HomeAssistant) -> None: (State("input_button.b1", "2021-01-01T23:59:59+00:00"),), ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) mock_component(hass, "recorder") await async_setup_component(hass, DOMAIN, {DOMAIN: {"b1": None, "b2": None}}) diff --git a/tests/components/input_datetime/test_init.py b/tests/components/input_datetime/test_init.py index a0b80ac420c..0a3f9b3ed6c 100644 --- a/tests/components/input_datetime/test_init.py +++ b/tests/components/input_datetime/test_init.py @@ -325,7 +325,7 @@ async def test_restore_state(hass: HomeAssistant) -> None: ), ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) initial = datetime.datetime(2017, 1, 1, 23, 42) default = datetime.datetime.combine(datetime.date.today(), DEFAULT_TIME) diff --git a/tests/components/input_number/test_init.py b/tests/components/input_number/test_init.py index 1334ba4aebd..305ff74b6bf 100644 --- a/tests/components/input_number/test_init.py +++ b/tests/components/input_number/test_init.py @@ -238,7 +238,7 @@ async def test_restore_state(hass: HomeAssistant) -> None: hass, (State("input_number.b1", "70"), State("input_number.b2", "200")) ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await async_setup_component( hass, @@ -261,7 +261,7 @@ async def test_restore_invalid_state(hass: HomeAssistant) -> None: hass, (State("input_number.b1", "="), State("input_number.b2", "200")) ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await async_setup_component( hass, @@ -284,7 +284,7 @@ async def test_initial_state_overrules_restore_state(hass: HomeAssistant) -> Non hass, (State("input_number.b1", "70"), State("input_number.b2", "200")) ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await async_setup_component( hass, @@ -308,7 +308,7 @@ async def test_initial_state_overrules_restore_state(hass: HomeAssistant) -> Non async def test_no_initial_state_and_no_restore_state(hass: HomeAssistant) -> None: """Ensure that entity is create without initial and restore feature.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await async_setup_component(hass, DOMAIN, {DOMAIN: {"b1": {"min": 0, "max": 100}}}) diff --git a/tests/components/input_text/test_init.py b/tests/components/input_text/test_init.py index 23d1c3307e5..c057407a644 100644 --- a/tests/components/input_text/test_init.py +++ b/tests/components/input_text/test_init.py @@ -165,7 +165,7 @@ async def test_restore_state(hass: HomeAssistant) -> None: (State("input_text.b1", "test"), State("input_text.b2", "testing too long")), ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) assert await async_setup_component( hass, DOMAIN, {DOMAIN: {"b1": None, "b2": {"min": 0, "max": 10}}} @@ -187,7 +187,7 @@ async def test_initial_state_overrules_restore_state(hass: HomeAssistant) -> Non (State("input_text.b1", "testing"), State("input_text.b2", "testing too long")), ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await async_setup_component( hass, @@ -211,7 +211,7 @@ async def test_initial_state_overrules_restore_state(hass: HomeAssistant) -> Non async def test_no_initial_state_and_no_restore_state(hass: HomeAssistant) -> None: """Ensure that entity is create without initial and restore feature.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await async_setup_component(hass, DOMAIN, {DOMAIN: {"b1": {"min": 0, "max": 100}}}) diff --git a/tests/components/manual/test_alarm_control_panel.py b/tests/components/manual/test_alarm_control_panel.py index 9ca8ac9e2ba..14e28b0999d 100644 --- a/tests/components/manual/test_alarm_control_panel.py +++ b/tests/components/manual/test_alarm_control_panel.py @@ -1221,7 +1221,7 @@ async def test_restore_state(hass: HomeAssistant, expected_state) -> None: """Ensure state is restored on startup.""" mock_restore_cache(hass, (State("alarm_control_panel.test", expected_state),)) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) mock_component(hass, "recorder") assert await async_setup_component( @@ -1266,7 +1266,7 @@ async def test_restore_state_arming(hass: HomeAssistant, expected_state) -> None hass, (State(entity_id, expected_state, attributes, last_updated=time),) ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) mock_component(hass, "recorder") assert await async_setup_component( @@ -1323,7 +1323,7 @@ async def test_restore_state_pending(hass: HomeAssistant, previous_state) -> Non (State(entity_id, STATE_ALARM_TRIGGERED, attributes, last_updated=time),), ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) mock_component(hass, "recorder") assert await async_setup_component( @@ -1388,7 +1388,7 @@ async def test_restore_state_triggered(hass: HomeAssistant, previous_state) -> N (State(entity_id, STATE_ALARM_TRIGGERED, attributes, last_updated=time),), ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) mock_component(hass, "recorder") assert await async_setup_component( @@ -1434,7 +1434,7 @@ async def test_restore_state_triggered_long_ago(hass: HomeAssistant) -> None: (State(entity_id, STATE_ALARM_TRIGGERED, attributes, last_updated=time),), ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) mock_component(hass, "recorder") assert await async_setup_component( diff --git a/tests/components/mqtt/test_init.py b/tests/components/mqtt/test_init.py index 5bd41da057c..bfbf4e8670c 100644 --- a/tests/components/mqtt/test_init.py +++ b/tests/components/mqtt/test_init.py @@ -2452,7 +2452,7 @@ async def test_delayed_birth_message( """Test sending birth message does not happen until Home Assistant starts.""" mqtt_mock = await mqtt_mock_entry() - hass.state = CoreState.starting + hass.set_state(CoreState.starting) birth = asyncio.Event() await hass.async_block_till_done() diff --git a/tests/components/mqtt/test_mixins.py b/tests/components/mqtt/test_mixins.py index 3c25d419cfe..751521645a9 100644 --- a/tests/components/mqtt/test_mixins.py +++ b/tests/components/mqtt/test_mixins.py @@ -315,7 +315,7 @@ async def test_default_entity_and_device_name( """ events = async_capture_events(hass, ir.EVENT_REPAIRS_ISSUE_REGISTRY_UPDATED) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await hass.async_block_till_done() entry = MockConfigEntry(domain=mqtt.DOMAIN, data={mqtt.CONF_BROKER: "mock-broker"}) diff --git a/tests/components/mqtt/test_util.py b/tests/components/mqtt/test_util.py index d1f265770b8..14153b44d87 100644 --- a/tests/components/mqtt/test_util.py +++ b/tests/components/mqtt/test_util.py @@ -140,7 +140,7 @@ async def test_waiting_for_client_not_loaded( mqtt_client_mock: MqttMockPahoClient, ) -> None: """Test waiting for client while mqtt entry is not yet loaded.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await hass.async_block_till_done() entry = MockConfigEntry( @@ -199,7 +199,7 @@ async def test_waiting_for_client_entry_fails( mqtt_client_mock: MqttMockPahoClient, ) -> None: """Test waiting for client where mqtt entry is failing.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await hass.async_block_till_done() entry = MockConfigEntry( @@ -227,7 +227,7 @@ async def test_waiting_for_client_setup_fails( mqtt_client_mock: MqttMockPahoClient, ) -> None: """Test waiting for client where mqtt entry is failing during setup.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await hass.async_block_till_done() entry = MockConfigEntry( @@ -254,7 +254,7 @@ async def test_waiting_for_client_timeout( hass: HomeAssistant, ) -> None: """Test waiting for client with timeout.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await hass.async_block_till_done() entry = MockConfigEntry( @@ -273,7 +273,7 @@ async def test_waiting_for_client_with_disabled_entry( hass: HomeAssistant, ) -> None: """Test waiting for client with timeout.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await hass.async_block_till_done() entry = MockConfigEntry( diff --git a/tests/components/mqtt_statestream/test_init.py b/tests/components/mqtt_statestream/test_init.py index cd228183c9e..c7bb9d4fcfa 100644 --- a/tests/components/mqtt_statestream/test_init.py +++ b/tests/components/mqtt_statestream/test_init.py @@ -58,7 +58,7 @@ async def test_setup_and_stop_waits_for_ha( e_id = "fake.entity" # HA is not running - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) assert await add_statestream(hass, base_topic="pub") await hass.async_block_till_done() diff --git a/tests/components/netatmo/test_init.py b/tests/components/netatmo/test_init.py index 9aee3170027..3e0231579a8 100644 --- a/tests/components/netatmo/test_init.py +++ b/tests/components/netatmo/test_init.py @@ -310,7 +310,7 @@ async def test_setup_component_with_delay( hass: HomeAssistant, config_entry: MockConfigEntry ) -> None: """Test setup of the netatmo component with delayed startup.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) with patch( "pyatmo.AbstractAsyncAuth.async_addwebhook", side_effect=AsyncMock() diff --git a/tests/components/nmap_tracker/test_config_flow.py b/tests/components/nmap_tracker/test_config_flow.py index 96393a5139d..95c944449de 100644 --- a/tests/components/nmap_tracker/test_config_flow.py +++ b/tests/components/nmap_tracker/test_config_flow.py @@ -195,7 +195,7 @@ async def test_options_flow(hass: HomeAssistant, mock_get_source_ip) -> None: }, ) config_entry.add_to_hass(hass) - hass.state = CoreState.stopped + hass.set_state(CoreState.stopped) assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() diff --git a/tests/components/person/test_init.py b/tests/components/person/test_init.py index 71491ee3caf..a9f91801883 100644 --- a/tests/components/person/test_init.py +++ b/tests/components/person/test_init.py @@ -99,7 +99,7 @@ async def test_valid_invalid_user_ids( async def test_setup_tracker(hass: HomeAssistant, hass_admin_user: MockUser) -> None: """Test set up person with one device tracker.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) user_id = hass_admin_user.id config = { DOMAIN: { @@ -159,7 +159,7 @@ async def test_setup_two_trackers( hass: HomeAssistant, hass_admin_user: MockUser ) -> None: """Test set up person with two device trackers.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) user_id = hass_admin_user.id config = { DOMAIN: { @@ -247,7 +247,7 @@ async def test_ignore_unavailable_states( hass: HomeAssistant, hass_admin_user: MockUser ) -> None: """Test set up person with two device trackers, one unavailable.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) user_id = hass_admin_user.id config = { DOMAIN: { @@ -302,7 +302,7 @@ async def test_restore_home_state( } state = State("person.tracked_person", "home", attrs) mock_restore_cache(hass, (state,)) - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) mock_component(hass, "recorder") config = { DOMAIN: { diff --git a/tests/components/recorder/test_init.py b/tests/components/recorder/test_init.py index a9a12d72c41..f8aa219fdb4 100644 --- a/tests/components/recorder/test_init.py +++ b/tests/components/recorder/test_init.py @@ -137,7 +137,7 @@ async def test_shutdown_before_startup_finishes( recorder.CONF_DB_URL: recorder_db_url, recorder.CONF_COMMIT_INTERVAL: 1, } - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) recorder_helper.async_initialize_recorder(hass) hass.create_task(async_setup_recorder_instance(hass, config)) @@ -168,7 +168,7 @@ async def test_canceled_before_startup_finishes( caplog: pytest.LogCaptureFixture, ) -> None: """Test recorder shuts down when its startup future is canceled out from under it.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) recorder_helper.async_initialize_recorder(hass) hass.create_task(async_setup_recorder_instance(hass)) await recorder_helper.async_wait_recorder(hass) @@ -192,7 +192,7 @@ async def test_shutdown_closes_connections( ) -> None: """Test shutdown closes connections.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) instance = get_instance(hass) await instance.async_db_ready @@ -219,7 +219,7 @@ async def test_state_gets_saved_when_set_before_start_event( ) -> None: """Test we can record an event when starting with not running.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) recorder_helper.async_initialize_recorder(hass) hass.create_task(async_setup_recorder_instance(hass)) diff --git a/tests/components/rflink/test_binary_sensor.py b/tests/components/rflink/test_binary_sensor.py index 7c1ee331d48..416bd4f71b4 100644 --- a/tests/components/rflink/test_binary_sensor.py +++ b/tests/components/rflink/test_binary_sensor.py @@ -193,7 +193,7 @@ async def test_restore_state(hass: HomeAssistant, monkeypatch) -> None: hass, (State(f"{DOMAIN}.test", STATE_ON), State(f"{DOMAIN}.test2", STATE_ON)) ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) # setup mocking rflink module _, _, _, _ = await mock_rflink(hass, CONFIG, DOMAIN, monkeypatch) diff --git a/tests/components/rflink/test_cover.py b/tests/components/rflink/test_cover.py index 2f1ff42cc9a..71b3d2067d0 100644 --- a/tests/components/rflink/test_cover.py +++ b/tests/components/rflink/test_cover.py @@ -349,7 +349,7 @@ async def test_restore_state(hass: HomeAssistant, monkeypatch) -> None: hass, (State(f"{DOMAIN}.c1", STATE_OPEN), State(f"{DOMAIN}.c2", STATE_CLOSED)) ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) # setup mocking rflink module _, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch) diff --git a/tests/components/rflink/test_light.py b/tests/components/rflink/test_light.py index 34b918cd3ed..75d2566f336 100644 --- a/tests/components/rflink/test_light.py +++ b/tests/components/rflink/test_light.py @@ -575,7 +575,7 @@ async def test_restore_state(hass: HomeAssistant, monkeypatch) -> None: ), ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) # setup mocking rflink module _, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch) diff --git a/tests/components/rflink/test_switch.py b/tests/components/rflink/test_switch.py index 07e34c7ebfe..35646d0fd22 100644 --- a/tests/components/rflink/test_switch.py +++ b/tests/components/rflink/test_switch.py @@ -263,7 +263,7 @@ async def test_restore_state(hass: HomeAssistant, monkeypatch) -> None: hass, (State(f"{DOMAIN}.s1", STATE_ON), State(f"{DOMAIN}.s2", STATE_OFF)) ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) # setup mocking rflink module _, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch) diff --git a/tests/components/script/test_init.py b/tests/components/script/test_init.py index 83abd37137e..5f8e04d527a 100644 --- a/tests/components/script/test_init.py +++ b/tests/components/script/test_init.py @@ -1152,7 +1152,7 @@ async def test_script_restore_last_triggered(hass: HomeAssistant) -> None: State("script.last_triggered", STATE_OFF, {"last_triggered": time}), ), ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) assert await async_setup_component( hass, @@ -1373,7 +1373,7 @@ async def test_recursive_script_turn_on( await asyncio.wait_for(service_called.wait(), 1) # Trigger 1st stage script shutdown - hass.state = CoreState.stopping + hass.set_state(CoreState.stopping) hass.bus.async_fire("homeassistant_stop") await asyncio.wait_for(stop_scripts_at_shutdown_called.wait(), 1) diff --git a/tests/components/sensor/test_recorder_missing_stats.py b/tests/components/sensor/test_recorder_missing_stats.py index f6f6445a0fb..b67a353932a 100644 --- a/tests/components/sensor/test_recorder_missing_stats.py +++ b/tests/components/sensor/test_recorder_missing_stats.py @@ -52,7 +52,7 @@ def test_compile_missing_statistics( start_time = three_days_ago + timedelta(days=3) freezer.move_to(three_days_ago) hass: HomeAssistant = get_test_home_assistant() - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) recorder_helper.async_initialize_recorder(hass) setup_component(hass, "sensor", {}) setup_component(hass, "recorder", {"recorder": config}) @@ -90,7 +90,7 @@ def test_compile_missing_statistics( hass.stop() freezer.move_to(start_time) hass: HomeAssistant = get_test_home_assistant() - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) recorder_helper.async_initialize_recorder(hass) setup_component(hass, "sensor", {}) hass.states.set("sensor.test1", "0", POWER_SENSOR_ATTRIBUTES) diff --git a/tests/components/template/test_binary_sensor.py b/tests/components/template/test_binary_sensor.py index 01c0f005716..708571ce913 100644 --- a/tests/components/template/test_binary_sensor.py +++ b/tests/components/template/test_binary_sensor.py @@ -764,7 +764,7 @@ async def test_no_update_template_match_all( ) -> None: """Test that we do not update sensors that match on all.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) await setup.async_setup_component( hass, diff --git a/tests/components/template/test_sensor.py b/tests/components/template/test_sensor.py index 8aef5947d56..d25f638cfdb 100644 --- a/tests/components/template/test_sensor.py +++ b/tests/components/template/test_sensor.py @@ -507,7 +507,7 @@ async def test_no_template_match_all( """Test that we allow static templates.""" hass.states.async_set("sensor.test_sensor", "startup") - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) await async_setup_component( hass, @@ -752,7 +752,7 @@ async def test_this_variable_early_hass_not_running( """ entity_id = "sensor.none_false" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) # Setup template with assert_setup_component(count, domain): diff --git a/tests/components/template/test_switch.py b/tests/components/template/test_switch.py index db09fe6e676..1e979fc9926 100644 --- a/tests/components/template/test_switch.py +++ b/tests/components/template/test_switch.py @@ -525,7 +525,7 @@ async def test_restore_state(hass: HomeAssistant) -> None: ), ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) mock_component(hass, "recorder") await async_setup_component( diff --git a/tests/components/timer/test_init.py b/tests/components/timer/test_init.py index 6b6929e88ec..92baa013f14 100644 --- a/tests/components/timer/test_init.py +++ b/tests/components/timer/test_init.py @@ -147,7 +147,7 @@ async def test_config_options(hass: HomeAssistant) -> None: async def test_methods_and_events(hass: HomeAssistant) -> None: """Test methods and events.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await async_setup_component(hass, DOMAIN, {DOMAIN: {"test1": {CONF_DURATION: 10}}}) @@ -393,7 +393,7 @@ async def test_start_service(hass: HomeAssistant) -> None: async def test_wait_till_timer_expires(hass: HomeAssistant) -> None: """Test for a timer to end.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await async_setup_component(hass, DOMAIN, {DOMAIN: {"test1": {CONF_DURATION: 20}}}) @@ -460,7 +460,7 @@ async def test_wait_till_timer_expires(hass: HomeAssistant) -> None: async def test_no_initial_state_and_no_restore_state(hass: HomeAssistant) -> None: """Ensure that entity is create without initial and restore feature.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await async_setup_component(hass, DOMAIN, {DOMAIN: {"test1": {CONF_DURATION: 10}}}) @@ -569,7 +569,7 @@ async def test_config_reload( async def test_timer_restarted_event(hass: HomeAssistant) -> None: """Ensure restarted event is called after starting a paused or running timer.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await async_setup_component(hass, DOMAIN, {DOMAIN: {"test1": {CONF_DURATION: 10}}}) @@ -636,7 +636,7 @@ async def test_timer_restarted_event(hass: HomeAssistant) -> None: async def test_state_changed_when_timer_restarted(hass: HomeAssistant) -> None: """Ensure timer's state changes when it restarted.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) await async_setup_component(hass, DOMAIN, {DOMAIN: {"test1": {CONF_DURATION: 10}}}) diff --git a/tests/components/trace/test_websocket_api.py b/tests/components/trace/test_websocket_api.py index 1197719328b..511667a7462 100644 --- a/tests/components/trace/test_websocket_api.py +++ b/tests/components/trace/test_websocket_api.py @@ -426,7 +426,7 @@ async def test_restore_traces( hass: HomeAssistant, hass_storage: dict[str, Any], hass_ws_client, domain ) -> None: """Test restored traces.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) id = 1 def next_id(): @@ -598,7 +598,7 @@ async def test_restore_traces_overflow( num_restored_moon_traces, ) -> None: """Test restored traces are evicted first.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) id = 1 trace_uuids = [] @@ -679,7 +679,7 @@ async def test_restore_traces_late_overflow( restored_run_id, ) -> None: """Test restored traces are evicted first.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) id = 1 trace_uuids = [] diff --git a/tests/components/utility_meter/test_sensor.py b/tests/components/utility_meter/test_sensor.py index d77c2db356a..37127363614 100644 --- a/tests/components/utility_meter/test_sensor.py +++ b/tests/components/utility_meter/test_sensor.py @@ -534,7 +534,7 @@ async def test_restore_state( ) -> None: """Test utility sensor restore state.""" # Home assistant is not runnit yet - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) last_reset = "2020-12-21T00:00:00.013073+00:00" @@ -865,7 +865,7 @@ async def test_delta_values( ) -> None: """Test utility meter "delta_values" mode.""" # Home assistant is not runnit yet - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) now = dt_util.utcnow() with freeze_time(now): @@ -974,7 +974,7 @@ async def test_non_periodically_resetting( ) -> None: """Test utility meter "non periodically resetting" mode.""" # Home assistant is not runnit yet - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) now = dt_util.utcnow() with freeze_time(now): diff --git a/tests/components/whirlpool/test_sensor.py b/tests/components/whirlpool/test_sensor.py index 3155d588e14..20d0c436134 100644 --- a/tests/components/whirlpool/test_sensor.py +++ b/tests/components/whirlpool/test_sensor.py @@ -49,7 +49,7 @@ async def test_dryer_sensor_values( entity_registry: er.EntityRegistry, ) -> None: """Test the sensor value callbacks.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) thetimestamp: datetime = datetime(2022, 11, 29, 00, 00, 00, 00, UTC) mock_restore_cache_with_extra_data( hass, @@ -113,7 +113,7 @@ async def test_washer_sensor_values( entity_registry: er.EntityRegistry, ) -> None: """Test the sensor value callbacks.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) thetimestamp: datetime = datetime(2022, 11, 29, 00, 00, 00, 00, UTC) mock_restore_cache_with_extra_data( hass, @@ -280,7 +280,7 @@ async def test_restore_state( ) -> None: """Test sensor restore state.""" # Home assistant is not running yet - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) thetimestamp: datetime = datetime(2022, 11, 29, 00, 00, 00, 00, UTC) mock_restore_cache_with_extra_data( hass, @@ -333,7 +333,7 @@ async def test_callback( mock_sensor1_api: MagicMock, ) -> None: """Test callback timestamp callback function.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) thetimestamp: datetime = datetime(2022, 11, 29, 00, 00, 00, 00, UTC) mock_restore_cache_with_extra_data( hass, diff --git a/tests/components/zha/test_cover.py b/tests/components/zha/test_cover.py index 0adb7583d31..5a1f2a862ac 100644 --- a/tests/components/zha/test_cover.py +++ b/tests/components/zha/test_cover.py @@ -685,7 +685,7 @@ async def test_shade_restore_state( ), ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) zha_device = await zha_device_restored(zigpy_shade_device) entity_id = find_entity_id(Platform.COVER, zha_device, hass) @@ -711,7 +711,7 @@ async def test_cover_restore_state( ), ) - hass.state = CoreState.starting + hass.set_state(CoreState.starting) zha_device = await zha_device_restored(zigpy_cover_device) entity_id = find_entity_id(Platform.COVER, zha_device, hass) diff --git a/tests/components/zha/test_init.py b/tests/components/zha/test_init.py index c2e9469c239..9c9ffbb3ba1 100644 --- a/tests/components/zha/test_init.py +++ b/tests/components/zha/test_init.py @@ -279,7 +279,7 @@ async def test_shutdown_on_ha_stop( zha_data.gateway, "shutdown", wraps=zha_data.gateway.shutdown ) as mock_shutdown: hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP) - hass.state = CoreState.stopping + hass.set_state(CoreState.stopping) await hass.async_block_till_done() assert len(mock_shutdown.mock_calls) == 1 diff --git a/tests/components/zwave_js/test_update.py b/tests/components/zwave_js/test_update.py index 9e17f25c708..ed42363ca41 100644 --- a/tests/components/zwave_js/test_update.py +++ b/tests/components/zwave_js/test_update.py @@ -327,14 +327,14 @@ async def test_update_entity_ha_not_running( assert len(client.async_send_command.call_args_list) == 1 # Update should be delayed by a day because HA is not running - hass.state = CoreState.starting + hass.set_state(CoreState.starting) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(minutes=5)) await hass.async_block_till_done() assert len(client.async_send_command.call_args_list) == 1 - hass.state = CoreState.running + hass.set_state(CoreState.running) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(minutes=5, days=1)) await hass.async_block_till_done() diff --git a/tests/helpers/test_device_registry.py b/tests/helpers/test_device_registry.py index 240afa2cbab..c82a7493fe1 100644 --- a/tests/helpers/test_device_registry.py +++ b/tests/helpers/test_device_registry.py @@ -1408,7 +1408,7 @@ async def test_cleanup_device_registry_removes_expired_orphaned_devices( async def test_cleanup_startup(hass: HomeAssistant) -> None: """Test we run a cleanup on startup.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) with patch( "homeassistant.helpers.device_registry.Debouncer.async_call" diff --git a/tests/helpers/test_discovery_flow.py b/tests/helpers/test_discovery_flow.py index 9f1d8dfcbc9..0b3386f8e04 100644 --- a/tests/helpers/test_discovery_flow.py +++ b/tests/helpers/test_discovery_flow.py @@ -38,7 +38,7 @@ async def test_async_create_flow_deferred_until_started( hass: HomeAssistant, mock_flow_init ) -> None: """Test flows are deferred until started.""" - hass.state = CoreState.stopped + hass.set_state(CoreState.stopped) discovery_flow.async_create_flow( hass, "hue", @@ -79,7 +79,7 @@ async def test_async_create_flow_checks_existing_flows_before_startup( hass: HomeAssistant, mock_flow_init ) -> None: """Test existing flows prevent an identical ones from being created before startup.""" - hass.state = CoreState.stopped + hass.set_state(CoreState.stopped) for _ in range(2): discovery_flow.async_create_flow( hass, @@ -104,7 +104,7 @@ async def test_async_create_flow_does_nothing_after_stop( """Test we no longer create flows when hass is stopping.""" hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED) await hass.async_block_till_done() - hass.state = CoreState.stopping + hass.set_state(CoreState.stopping) mock_flow_init.reset_mock() discovery_flow.async_create_flow( hass, diff --git a/tests/helpers/test_entity_platform.py b/tests/helpers/test_entity_platform.py index dfaec4577aa..01558c426c7 100644 --- a/tests/helpers/test_entity_platform.py +++ b/tests/helpers/test_entity_platform.py @@ -937,7 +937,7 @@ async def test_reset_cancels_retry_setup(hass: HomeAssistant) -> None: async def test_reset_cancels_retry_setup_when_not_started(hass: HomeAssistant) -> None: """Test that resetting a platform will cancel scheduled a setup retry when not yet started.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) async_setup_entry = Mock(side_effect=PlatformNotReady) initial_listeners = hass.bus.async_listeners()[EVENT_HOMEASSISTANT_STARTED] diff --git a/tests/helpers/test_entity_registry.py b/tests/helpers/test_entity_registry.py index d01d7746253..1c13da1192f 100644 --- a/tests/helpers/test_entity_registry.py +++ b/tests/helpers/test_entity_registry.py @@ -870,7 +870,7 @@ async def test_restore_states( hass: HomeAssistant, entity_registry: er.EntityRegistry ) -> None: """Test restoring states.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) entity_registry.async_get_or_create( "light", @@ -936,7 +936,7 @@ async def test_async_get_device_class_lookup( hass: HomeAssistant, entity_registry: er.EntityRegistry ) -> None: """Test registry device class lookup.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) entity_registry.async_get_or_create( "binary_sensor", diff --git a/tests/helpers/test_restore_state.py b/tests/helpers/test_restore_state.py index 79298ed1611..2a01439ccbd 100644 --- a/tests/helpers/test_restore_state.py +++ b/tests/helpers/test_restore_state.py @@ -210,7 +210,7 @@ async def test_save_persistent_states(hass: HomeAssistant) -> None: async def test_hass_starting(hass: HomeAssistant) -> None: """Test that we cache data.""" - hass.state = CoreState.starting + hass.set_state(CoreState.starting) now = dt_util.utcnow() stored_states = [ @@ -224,7 +224,7 @@ async def test_hass_starting(hass: HomeAssistant) -> None: await data.store.async_save([state.as_dict() for state in stored_states]) # Emulate a fresh load - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) hass.data.pop(DATA_RESTORE_STATE) await async_load(hass) data = async_get(hass) diff --git a/tests/helpers/test_script.py b/tests/helpers/test_script.py index 1ea602f7cda..a4361d28e74 100644 --- a/tests/helpers/test_script.py +++ b/tests/helpers/test_script.py @@ -4340,7 +4340,7 @@ async def test_shutdown_after( script_obj = script.Script(hass, sequence, "test script", "test_domain") delay_started_flag = async_watch_for_action(script_obj, delay_alias) - hass.state = CoreState.stopping + hass.set_state(CoreState.stopping) hass.bus.async_fire("homeassistant_stop") await hass.async_block_till_done() @@ -4379,7 +4379,7 @@ async def test_start_script_after_shutdown( script_obj = script.Script(hass, sequence, "test script", "test_domain") # Trigger 1st stage script shutdown - hass.state = CoreState.stopping + hass.set_state(CoreState.stopping) hass.bus.async_fire("homeassistant_stop") await hass.async_block_till_done() # Trigger 2nd stage script shutdown diff --git a/tests/helpers/test_start.py b/tests/helpers/test_start.py index f5204a2ec64..d203b336f27 100644 --- a/tests/helpers/test_start.py +++ b/tests/helpers/test_start.py @@ -21,7 +21,7 @@ async def test_at_start_when_running_awaitable(hass: HomeAssistant) -> None: await hass.async_block_till_done() assert len(calls) == 1 - hass.state = CoreState.starting + hass.set_state(CoreState.starting) assert hass.is_running start.async_at_start(hass, cb_at_start) @@ -46,7 +46,7 @@ async def test_at_start_when_running_callback( start.async_at_start(hass, cb_at_start)() assert len(calls) == 1 - hass.state = CoreState.starting + hass.set_state(CoreState.starting) assert hass.is_running start.async_at_start(hass, cb_at_start)() @@ -59,7 +59,7 @@ async def test_at_start_when_running_callback( async def test_at_start_when_starting_awaitable(hass: HomeAssistant) -> None: """Test at start when yet to start.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) assert not hass.is_running calls = [] @@ -81,7 +81,7 @@ async def test_at_start_when_starting_callback( hass: HomeAssistant, caplog: pytest.LogCaptureFixture ) -> None: """Test at start when yet to start.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) assert not hass.is_running calls = [] @@ -130,7 +130,7 @@ async def test_cancelling_at_start_when_running( async def test_cancelling_at_start_when_starting(hass: HomeAssistant) -> None: """Test cancelling at start when yet to start.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) assert not hass.is_running calls = [] @@ -164,7 +164,7 @@ async def test_at_started_when_running_awaitable(hass: HomeAssistant) -> None: assert len(calls) == 1 # Test the job is not run if state is CoreState.starting - hass.state = CoreState.starting + hass.set_state(CoreState.starting) start.async_at_started(hass, cb_at_start) await hass.async_block_till_done() @@ -188,7 +188,7 @@ async def test_at_started_when_running_callback( assert len(calls) == 1 # Test the job is not run if state is CoreState.starting - hass.state = CoreState.starting + hass.set_state(CoreState.starting) start.async_at_started(hass, cb_at_start)() assert len(calls) == 1 @@ -200,7 +200,7 @@ async def test_at_started_when_running_callback( async def test_at_started_when_starting_awaitable(hass: HomeAssistant) -> None: """Test at started when yet to start.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) calls = [] @@ -225,7 +225,7 @@ async def test_at_started_when_starting_callback( hass: HomeAssistant, caplog: pytest.LogCaptureFixture ) -> None: """Test at started when yet to start.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) calls = [] @@ -277,7 +277,7 @@ async def test_cancelling_at_started_when_running( async def test_cancelling_at_started_when_starting(hass: HomeAssistant) -> None: """Test cancelling at start when yet to start.""" - hass.state = CoreState.not_running + hass.set_state(CoreState.not_running) assert not hass.is_running calls = [] diff --git a/tests/helpers/test_storage.py b/tests/helpers/test_storage.py index 85aa4d2de0e..4506d827096 100644 --- a/tests/helpers/test_storage.py +++ b/tests/helpers/test_storage.py @@ -140,7 +140,7 @@ async def test_saving_on_final_write( assert store.key not in hass_storage hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP) - hass.state = CoreState.stopping + hass.set_state(CoreState.stopping) await hass.async_block_till_done() async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10)) @@ -164,7 +164,7 @@ async def test_not_delayed_saving_while_stopping( store = storage.Store(hass, MOCK_VERSION, MOCK_KEY) hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP) await hass.async_block_till_done() - hass.state = CoreState.stopping + hass.set_state(CoreState.stopping) store.async_delay_save(lambda: MOCK_DATA, 1) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=2)) @@ -181,7 +181,7 @@ async def test_not_delayed_saving_after_stopping( assert store.key not in hass_storage hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP) - hass.state = CoreState.stopping + hass.set_state(CoreState.stopping) await hass.async_block_till_done() assert store.key not in hass_storage @@ -195,7 +195,7 @@ async def test_not_saving_while_stopping( ) -> None: """Test saves don't write when stopping Home Assistant.""" store = storage.Store(hass, MOCK_VERSION, MOCK_KEY) - hass.state = CoreState.stopping + hass.set_state(CoreState.stopping) await store.async_save(MOCK_DATA) assert store.key not in hass_storage @@ -723,7 +723,7 @@ async def test_read_only_store( assert read_only_store.key not in hass_storage hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP) - hass.state = CoreState.stopping + hass.set_state(CoreState.stopping) await hass.async_block_till_done() async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10)) diff --git a/tests/helpers/test_update_coordinator.py b/tests/helpers/test_update_coordinator.py index 182ed6c3cb4..6497382ab9a 100644 --- a/tests/helpers/test_update_coordinator.py +++ b/tests/helpers/test_update_coordinator.py @@ -506,7 +506,7 @@ async def test_stop_refresh_on_ha_stop( # Fire Home Assistant stop event hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP) - hass.state = CoreState.stopping + hass.set_state(CoreState.stopping) await hass.async_block_till_done() # Make sure no update with subscriber after stop event diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index fd74a2e6286..2a56e34b981 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -1084,7 +1084,7 @@ async def test_setup_retrying_during_unload(hass: HomeAssistant) -> None: async def test_setup_retrying_during_unload_before_started(hass: HomeAssistant) -> None: """Test if we unload an entry that is in retry mode before started.""" entry = MockConfigEntry(domain="test") - hass.state = CoreState.starting + hass.set_state(CoreState.starting) initial_listeners = hass.bus.async_listeners()[EVENT_HOMEASSISTANT_STARTED] mock_setup_entry = AsyncMock(side_effect=ConfigEntryNotReady) @@ -1121,7 +1121,7 @@ async def test_setup_does_not_retry_during_shutdown(hass: HomeAssistant) -> None assert entry.state is config_entries.ConfigEntryState.SETUP_RETRY assert len(mock_setup_entry.mock_calls) == 1 - hass.state = CoreState.stopping + hass.set_state(CoreState.stopping) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(minutes=5)) await hass.async_block_till_done()