mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 19:57:07 +00:00
Small speed up to checking core state (#107845)
This commit is contained in:
parent
32b0bf6b4e
commit
c399cab427
@ -393,16 +393,23 @@ class HomeAssistant:
|
|||||||
self._stop_future: concurrent.futures.Future[None] | None = None
|
self._stop_future: concurrent.futures.Future[None] | None = None
|
||||||
self._shutdown_jobs: list[HassJobWithArgs] = []
|
self._shutdown_jobs: list[HassJobWithArgs] = []
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def is_running(self) -> bool:
|
def is_running(self) -> bool:
|
||||||
"""Return if Home Assistant is running."""
|
"""Return if Home Assistant is running."""
|
||||||
return self.state in (CoreState.starting, CoreState.running)
|
return self.state in (CoreState.starting, CoreState.running)
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def is_stopping(self) -> bool:
|
def is_stopping(self) -> bool:
|
||||||
"""Return if Home Assistant is stopping."""
|
"""Return if Home Assistant is stopping."""
|
||||||
return self.state in (CoreState.stopping, CoreState.final_write)
|
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:
|
def start(self) -> int:
|
||||||
"""Start Home Assistant.
|
"""Start Home Assistant.
|
||||||
|
|
||||||
@ -451,7 +458,7 @@ class HomeAssistant:
|
|||||||
_LOGGER.info("Starting Home Assistant")
|
_LOGGER.info("Starting Home Assistant")
|
||||||
setattr(self.loop, "_thread_ident", threading.get_ident())
|
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_CORE_CONFIG_UPDATE)
|
||||||
self.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
self.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||||
|
|
||||||
@ -483,7 +490,7 @@ class HomeAssistant:
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
self.state = CoreState.running
|
self.set_state(CoreState.running)
|
||||||
self.bus.async_fire(EVENT_CORE_CONFIG_UPDATE)
|
self.bus.async_fire(EVENT_CORE_CONFIG_UPDATE)
|
||||||
self.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
|
self.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
|
||||||
|
|
||||||
@ -894,7 +901,7 @@ class HomeAssistant:
|
|||||||
|
|
||||||
self.exit_code = exit_code
|
self.exit_code = exit_code
|
||||||
|
|
||||||
self.state = CoreState.stopping
|
self.set_state(CoreState.stopping)
|
||||||
self.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
self.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||||
try:
|
try:
|
||||||
async with self.timeout.async_timeout(STOP_STAGE_SHUTDOWN_TIMEOUT):
|
async with self.timeout.async_timeout(STOP_STAGE_SHUTDOWN_TIMEOUT):
|
||||||
@ -907,7 +914,7 @@ class HomeAssistant:
|
|||||||
self._async_log_running_tasks("stop integrations")
|
self._async_log_running_tasks("stop integrations")
|
||||||
|
|
||||||
# Stage 3 - Final write
|
# Stage 3 - Final write
|
||||||
self.state = CoreState.final_write
|
self.set_state(CoreState.final_write)
|
||||||
self.bus.async_fire(EVENT_HOMEASSISTANT_FINAL_WRITE)
|
self.bus.async_fire(EVENT_HOMEASSISTANT_FINAL_WRITE)
|
||||||
try:
|
try:
|
||||||
async with self.timeout.async_timeout(FINAL_WRITE_STAGE_SHUTDOWN_TIMEOUT):
|
async with self.timeout.async_timeout(FINAL_WRITE_STAGE_SHUTDOWN_TIMEOUT):
|
||||||
@ -920,7 +927,7 @@ class HomeAssistant:
|
|||||||
self._async_log_running_tasks("final write")
|
self._async_log_running_tasks("final write")
|
||||||
|
|
||||||
# Stage 4 - Close
|
# Stage 4 - Close
|
||||||
self.state = CoreState.not_running
|
self.set_state(CoreState.not_running)
|
||||||
self.bus.async_fire(EVENT_HOMEASSISTANT_CLOSE)
|
self.bus.async_fire(EVENT_HOMEASSISTANT_CLOSE)
|
||||||
|
|
||||||
# Make a copy of running_tasks since a task can finish
|
# Make a copy of running_tasks since a task can finish
|
||||||
@ -971,7 +978,7 @@ class HomeAssistant:
|
|||||||
)
|
)
|
||||||
self._async_log_running_tasks("close")
|
self._async_log_running_tasks("close")
|
||||||
|
|
||||||
self.state = CoreState.stopped
|
self.set_state(CoreState.stopped)
|
||||||
|
|
||||||
if self._stopped is not None:
|
if self._stopped is not None:
|
||||||
self._stopped.set()
|
self._stopped.set()
|
||||||
|
@ -285,7 +285,7 @@ async def async_test_home_assistant(event_loop, load_registries=True):
|
|||||||
)
|
)
|
||||||
hass.data[bootstrap.DATA_REGISTRIES_LOADED] = None
|
hass.data[bootstrap.DATA_REGISTRIES_LOADED] = None
|
||||||
|
|
||||||
hass.state = CoreState.running
|
hass.set_state(CoreState.running)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def clear_instance(event):
|
def clear_instance(event):
|
||||||
|
@ -735,9 +735,12 @@ async def test_proactive_mode_filter_states(
|
|||||||
"off",
|
"off",
|
||||||
{"friendly_name": "Test Contact Sensor", "device_class": "door"},
|
{"friendly_name": "Test Contact Sensor", "device_class": "door"},
|
||||||
)
|
)
|
||||||
with patch.object(hass, "state", core.CoreState.stopping):
|
|
||||||
await hass.async_block_till_done()
|
current_state = hass.state
|
||||||
await hass.async_block_till_done()
|
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
|
assert len(aioclient_mock.mock_calls) == 0
|
||||||
|
|
||||||
# unsupported entity should not report
|
# unsupported entity should not report
|
||||||
|
@ -340,7 +340,7 @@ async def test_restored_state(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Home assistant is not running yet
|
# Home assistant is not running yet
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
mock_restore_cache_with_extra_data(
|
mock_restore_cache_with_extra_data(
|
||||||
hass,
|
hass,
|
||||||
[
|
[
|
||||||
|
@ -1202,7 +1202,7 @@ async def test_initial_value_off(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
async def test_initial_value_on(hass: HomeAssistant) -> None:
|
async def test_initial_value_on(hass: HomeAssistant) -> None:
|
||||||
"""Test initial value on."""
|
"""Test initial value on."""
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
calls = async_mock_service(hass, "test", "automation")
|
calls = async_mock_service(hass, "test", "automation")
|
||||||
|
|
||||||
assert await async_setup_component(
|
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:
|
async def test_initial_value_off_but_restore_on(hass: HomeAssistant) -> None:
|
||||||
"""Test initial value off and restored state is turned on."""
|
"""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")
|
calls = async_mock_service(hass, "test", "automation")
|
||||||
mock_restore_cache(hass, (State("automation.hello", STATE_ON),))
|
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:
|
async def test_automation_not_trigger_on_bootstrap(hass: HomeAssistant) -> None:
|
||||||
"""Test if automation is not trigger on bootstrap."""
|
"""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")
|
calls = async_mock_service(hass, "test", "automation")
|
||||||
|
|
||||||
assert await async_setup_component(
|
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)
|
await asyncio.wait_for(script_done_event.wait(), 10)
|
||||||
|
|
||||||
# Trigger 1st stage script shutdown
|
# Trigger 1st stage script shutdown
|
||||||
hass.state = CoreState.stopping
|
hass.set_state(CoreState.stopping)
|
||||||
hass.bus.async_fire("homeassistant_stop")
|
hass.bus.async_fire("homeassistant_stop")
|
||||||
await asyncio.wait_for(stop_scripts_at_shutdown_called.wait(), 10)
|
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)
|
await asyncio.wait_for(service_called.wait(), 1)
|
||||||
|
|
||||||
# Trigger 1st stage script shutdown
|
# Trigger 1st stage script shutdown
|
||||||
hass.state = CoreState.stopping
|
hass.set_state(CoreState.stopping)
|
||||||
hass.bus.async_fire("homeassistant_stop")
|
hass.bus.async_fire("homeassistant_stop")
|
||||||
await asyncio.wait_for(stop_scripts_at_shutdown_called.wait(), 1)
|
await asyncio.wait_for(stop_scripts_at_shutdown_called.wait(), 1)
|
||||||
|
|
||||||
|
@ -439,7 +439,7 @@ async def test_no_polling_after_stop_event(
|
|||||||
|
|
||||||
assert needs_poll_calls == 1
|
assert needs_poll_calls == 1
|
||||||
|
|
||||||
hass.state = CoreState.stopping
|
hass.set_state(CoreState.stopping)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert needs_poll_calls == 1
|
assert needs_poll_calls == 1
|
||||||
|
|
||||||
|
@ -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[0] == call({"testdata": 0}, False)
|
||||||
assert async_handle_update.mock_calls[1] == call({"testdata": 1})
|
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()
|
await hass.async_block_till_done()
|
||||||
assert needs_poll_calls == 1
|
assert needs_poll_calls == 1
|
||||||
|
|
||||||
|
@ -553,7 +553,7 @@ async def test_no_updates_once_stopping(
|
|||||||
inject_bluetooth_service_info(hass, GENERIC_BLUETOOTH_SERVICE_INFO)
|
inject_bluetooth_service_info(hass, GENERIC_BLUETOOTH_SERVICE_INFO)
|
||||||
assert len(all_events) == 1
|
assert len(all_events) == 1
|
||||||
|
|
||||||
hass.state = CoreState.stopping
|
hass.set_state(CoreState.stopping)
|
||||||
|
|
||||||
# We should stop processing events once hass is stopping
|
# We should stop processing events once hass is stopping
|
||||||
inject_bluetooth_service_info(hass, GENERIC_BLUETOOTH_SERVICE_INFO_2)
|
inject_bluetooth_service_info(hass, GENERIC_BLUETOOTH_SERVICE_INFO_2)
|
||||||
|
@ -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
|
assert hass.states.get("fan.name_1").state == STATE_UNAVAILABLE
|
||||||
|
|
||||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||||
hass.state = CoreState.stopping
|
hass.set_state(CoreState.stopping)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
with patch_bond_device_state(return_value={"power": 1, "speed": 1}):
|
with patch_bond_device_state(return_value={"power": 1, "speed": 1}):
|
||||||
|
@ -120,7 +120,7 @@ async def test_unload_config_entry(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
async def test_delay_load_during_startup(hass: HomeAssistant) -> None:
|
async def test_delay_load_during_startup(hass: HomeAssistant) -> None:
|
||||||
"""Test delayed loading of a config entry during startup."""
|
"""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 = MockConfigEntry(domain=DOMAIN, data={CONF_HOST: HOST, CONF_PORT: PORT})
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
@ -551,7 +551,7 @@ async def test_alexa_config_migrate_expose_entity_prefs(
|
|||||||
alexa_settings_version: int,
|
alexa_settings_version: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test migrating Alexa entity config."""
|
"""Test migrating Alexa entity config."""
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
|
|
||||||
assert await async_setup_component(hass, "homeassistant", {})
|
assert await async_setup_component(hass, "homeassistant", {})
|
||||||
hass.states.async_set("light.state_only", "on")
|
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,
|
entity_registry: er.EntityRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test migrating Alexa entity config from v2 to v3 when no entity is exposed."""
|
"""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", {})
|
assert await async_setup_component(hass, "homeassistant", {})
|
||||||
hass.states.async_set("light.state_only", "on")
|
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,
|
entity_registry: er.EntityRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test migrating Alexa entity config from v2 to v3 when an entity is exposed."""
|
"""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", {})
|
assert await async_setup_component(hass, "homeassistant", {})
|
||||||
hass.states.async_set("light.state_only", "on")
|
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,
|
entity_registry: er.EntityRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test migrating Alexa entity config."""
|
"""Test migrating Alexa entity config."""
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
|
|
||||||
assert await async_setup_component(hass, "homeassistant", {})
|
assert await async_setup_component(hass, "homeassistant", {})
|
||||||
entity_default = entity_registry.async_get_or_create(
|
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,
|
entity_registry: er.EntityRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test migrating Alexa entity config."""
|
"""Test migrating Alexa entity config."""
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
|
|
||||||
assert await async_setup_component(hass, "homeassistant", {})
|
assert await async_setup_component(hass, "homeassistant", {})
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ async def test_google_entity_registry_sync(
|
|||||||
assert len(mock_sync.mock_calls) == 3
|
assert len(mock_sync.mock_calls) == 3
|
||||||
|
|
||||||
# When hass is not started yet we wait till started
|
# When hass is not started yet we wait till started
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
hass.bus.async_fire(
|
hass.bus.async_fire(
|
||||||
er.EVENT_ENTITY_REGISTRY_UPDATED,
|
er.EVENT_ENTITY_REGISTRY_UPDATED,
|
||||||
{"action": "create", "entity_id": entry.entity_id},
|
{"action": "create", "entity_id": entry.entity_id},
|
||||||
@ -338,7 +338,7 @@ async def test_sync_google_on_home_assistant_start(
|
|||||||
config = CloudGoogleConfig(
|
config = CloudGoogleConfig(
|
||||||
hass, GACTIONS_SCHEMA({}), "mock-user-id", cloud_prefs, hass.data["cloud"]
|
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:
|
with patch.object(config, "async_sync_entities_all") as mock_sync:
|
||||||
await config.async_initialize()
|
await config.async_initialize()
|
||||||
await config.async_connect_agent_user("mock-user-id")
|
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,
|
google_settings_version: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test migrating Google entity config."""
|
"""Test migrating Google entity config."""
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
|
|
||||||
assert await async_setup_component(hass, "homeassistant", {})
|
assert await async_setup_component(hass, "homeassistant", {})
|
||||||
hass.states.async_set("light.state_only", "on")
|
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,
|
entity_registry: er.EntityRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test migrating Google entity config from v2 to v3 when no entity is exposed."""
|
"""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", {})
|
assert await async_setup_component(hass, "homeassistant", {})
|
||||||
hass.states.async_set("light.state_only", "on")
|
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,
|
entity_registry: er.EntityRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test migrating Google entity config from v2 to v3 when an entity is exposed."""
|
"""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", {})
|
assert await async_setup_component(hass, "homeassistant", {})
|
||||||
hass.states.async_set("light.state_only", "on")
|
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,
|
entity_registry: er.EntityRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test migrating Google entity config."""
|
"""Test migrating Google entity config."""
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
|
|
||||||
assert await async_setup_component(hass, "homeassistant", {})
|
assert await async_setup_component(hass, "homeassistant", {})
|
||||||
entity_default = entity_registry.async_get_or_create(
|
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,
|
entity_registry: er.EntityRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test migrating Google entity config."""
|
"""Test migrating Google entity config."""
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
|
|
||||||
assert await async_setup_component(hass, "homeassistant", {})
|
assert await async_setup_component(hass, "homeassistant", {})
|
||||||
|
|
||||||
|
@ -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("counter.test1", "11"), State("counter.test2", "-22"))
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
|
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
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(
|
await async_setup_component(
|
||||||
hass, DOMAIN, {DOMAIN: {"test1": {}, "test2": {CONF_INITIAL: 10}, "test3": {}}}
|
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:
|
async def test_no_initial_state_and_no_restore_state(hass: HomeAssistant) -> None:
|
||||||
"""Ensure that entity is create without initial and restore feature."""
|
"""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}}})
|
await async_setup_component(hass, DOMAIN, {DOMAIN: {"test1": {CONF_STEP: 5}}})
|
||||||
|
|
||||||
|
@ -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:
|
async def test_initialize_start(hass: HomeAssistant) -> None:
|
||||||
"""Test we initialize when HA starts."""
|
"""Test we initialize when HA starts."""
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
device_sun_light_trigger.DOMAIN,
|
device_sun_light_trigger.DOMAIN,
|
||||||
|
@ -64,11 +64,12 @@ async def test_delayed_speedtest_during_startup(
|
|||||||
)
|
)
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
with patch(
|
original_state = hass.state
|
||||||
"homeassistant.components.fastdotcom.coordinator.fast_com"
|
hass.set_state(CoreState.starting)
|
||||||
), patch.object(hass, "state", CoreState.starting):
|
with patch("homeassistant.components.fastdotcom.coordinator.fast_com"):
|
||||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
hass.set_state(original_state)
|
||||||
|
|
||||||
assert config_entry.state == config_entries.ConfigEntryState.LOADED
|
assert config_entry.state == config_entries.ConfigEntryState.LOADED
|
||||||
state = hass.states.get("sensor.fast_com_download")
|
state = hass.states.get("sensor.fast_com_download")
|
||||||
|
@ -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(
|
await async_setup_component(
|
||||||
hass,
|
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(
|
await async_setup_component(
|
||||||
hass,
|
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(
|
await async_setup_component(
|
||||||
hass,
|
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(
|
await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -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(
|
await async_setup_component(
|
||||||
hass,
|
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(
|
await async_setup_component(
|
||||||
hass,
|
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(
|
assert await async_setup_component(
|
||||||
hass, input_boolean.DOMAIN, {"input_boolean": {"test": None}}
|
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()
|
await hass.async_block_till_done()
|
||||||
assert hass.states.get(heater_switch) is None
|
assert hass.states.get(heater_switch) is None
|
||||||
|
@ -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:
|
async def test_setup_before_started(hass: HomeAssistant) -> None:
|
||||||
"""Test we can setup before starting."""
|
"""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)
|
assert await async_setup_component(hass, DOMAIN, CONFIG_MISSING_FAN)
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -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.one", "armed_away")
|
||||||
hass.states.async_set("alarm_control_panel.two", "armed_home")
|
hass.states.async_set("alarm_control_panel.two", "armed_home")
|
||||||
hass.states.async_set("alarm_control_panel.three", "armed_away")
|
hass.states.async_set("alarm_control_panel.three", "armed_away")
|
||||||
hass.state = CoreState.stopped
|
hass.set_state(CoreState.stopped)
|
||||||
|
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
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.one", "docked")
|
||||||
hass.states.async_set("vacuum.two", "off")
|
hass.states.async_set("vacuum.two", "off")
|
||||||
hass.states.async_set("vacuum.three", "off")
|
hass.states.async_set("vacuum.three", "off")
|
||||||
hass.state = CoreState.stopped
|
hass.set_state(CoreState.stopped)
|
||||||
|
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
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.two", "off")
|
||||||
hass.states.async_set("switch.three", "on")
|
hass.states.async_set("switch.three", "on")
|
||||||
|
|
||||||
hass.state = CoreState.stopped
|
hass.set_state(CoreState.stopped)
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
"group",
|
"group",
|
||||||
@ -1409,7 +1409,7 @@ async def test_group_that_references_a_group_of_lights(hass: HomeAssistant) -> N
|
|||||||
"light.living_front_ri",
|
"light.living_front_ri",
|
||||||
"light.living_back_lef",
|
"light.living_back_lef",
|
||||||
]
|
]
|
||||||
hass.state = CoreState.stopped
|
hass.set_state(CoreState.stopped)
|
||||||
|
|
||||||
for entity_id in entity_ids:
|
for entity_id in entity_ids:
|
||||||
hass.states.async_set(entity_id, "off")
|
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_front_ri",
|
||||||
"cover.living_back_lef",
|
"cover.living_back_lef",
|
||||||
]
|
]
|
||||||
hass.state = CoreState.stopped
|
hass.set_state(CoreState.stopped)
|
||||||
|
|
||||||
for entity_id in entity_ids:
|
for entity_id in entity_ids:
|
||||||
hass.states.async_set(entity_id, "closed")
|
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_front_ri",
|
||||||
"cover.living_back_lef",
|
"cover.living_back_lef",
|
||||||
]
|
]
|
||||||
hass.state = CoreState.stopped
|
hass.set_state(CoreState.stopped)
|
||||||
|
|
||||||
for entity_id in entity_ids:
|
for entity_id in entity_ids:
|
||||||
hass.states.async_set(entity_id, "closed")
|
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_front_ri",
|
||||||
"device_tracker.living_back_lef",
|
"device_tracker.living_back_lef",
|
||||||
]
|
]
|
||||||
hass.state = CoreState.stopped
|
hass.set_state(CoreState.stopped)
|
||||||
|
|
||||||
for entity_id in group_1_entity_ids:
|
for entity_id in group_1_entity_ids:
|
||||||
hass.states.async_set(entity_id, "closed")
|
hass.states.async_set(entity_id, "closed")
|
||||||
|
@ -58,7 +58,7 @@ def hassio_stubs(hassio_env, hass, hass_client, aioclient_mock):
|
|||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.hassio.HassIO.refresh_updates",
|
"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", {}))
|
hass.loop.run_until_complete(async_setup_component(hass, "hassio", {}))
|
||||||
|
|
||||||
return hass_api.call_args[0][1]
|
return hass_api.call_args[0][1]
|
||||||
|
@ -486,7 +486,7 @@ async def test_route_not_found(
|
|||||||
async def test_restore_state(hass: HomeAssistant) -> None:
|
async def test_restore_state(hass: HomeAssistant) -> None:
|
||||||
"""Test sensor restore state."""
|
"""Test sensor restore state."""
|
||||||
# Home assistant is not running yet
|
# 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"
|
last_reset = "2022-11-29T00:00:00.000000+00:00"
|
||||||
mock_restore_cache_with_extra_data(
|
mock_restore_cache_with_extra_data(
|
||||||
hass,
|
hass,
|
||||||
|
@ -31,7 +31,7 @@ async def test_if_fires_on_hass_start(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test the firing when Home Assistant starts."""
|
"""Test the firing when Home Assistant starts."""
|
||||||
calls = async_mock_service(hass, "test", "automation")
|
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 await async_setup_component(hass, automation.DOMAIN, hass_config)
|
||||||
assert automation.is_on(hass, "automation.hello")
|
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:
|
async def test_if_fires_on_hass_shutdown(hass: HomeAssistant) -> None:
|
||||||
"""Test the firing when Home Assistant shuts down."""
|
"""Test the firing when Home Assistant shuts down."""
|
||||||
calls = async_mock_service(hass, "test", "automation")
|
calls = async_mock_service(hass, "test", "automation")
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
|
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -610,7 +610,7 @@ async def test_windowcovering_basic_restore(
|
|||||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test setting up an entity from state in the event registry."""
|
"""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(
|
entity_registry.async_get_or_create(
|
||||||
"cover",
|
"cover",
|
||||||
@ -648,7 +648,7 @@ async def test_windowcovering_restore(
|
|||||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test setting up an entity from state in the event entity_registry."""
|
"""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(
|
entity_registry.async_get_or_create(
|
||||||
"cover",
|
"cover",
|
||||||
|
@ -557,7 +557,7 @@ async def test_fan_restore(
|
|||||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test setting up an entity from state in the event registry."""
|
"""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(
|
entity_registry.async_get_or_create(
|
||||||
"fan",
|
"fan",
|
||||||
|
@ -580,7 +580,7 @@ async def test_light_restore(
|
|||||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test setting up an entity from state in the event registry."""
|
"""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(
|
entity_registry.async_get_or_create(
|
||||||
"light", "hue", "1234", suggested_object_id="simple"
|
"light", "hue", "1234", suggested_object_id="simple"
|
||||||
|
@ -432,7 +432,7 @@ async def test_tv_restore(
|
|||||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test setting up an entity from state in the event registry."""
|
"""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(
|
entity_registry.async_get_or_create(
|
||||||
"media_player",
|
"media_player",
|
||||||
|
@ -545,7 +545,7 @@ async def test_sensor_restore(
|
|||||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test setting up an entity from state in the event registry."""
|
"""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(
|
entity_registry.async_get_or_create(
|
||||||
"sensor",
|
"sensor",
|
||||||
|
@ -971,7 +971,7 @@ async def test_thermostat_restore(
|
|||||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test setting up an entity from state in the event registry."""
|
"""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(
|
entity_registry.async_get_or_create(
|
||||||
"climate", "generic", "1234", suggested_object_id="simple"
|
"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
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test setting up an entity from state in the event registry."""
|
"""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(
|
entity_registry.async_get_or_create(
|
||||||
"water_heater", "generic", "1234", suggested_object_id="simple"
|
"water_heater", "generic", "1234", suggested_object_id="simple"
|
||||||
|
@ -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")
|
mock_component(hass, "recorder")
|
||||||
|
|
||||||
await async_setup_component(hass, DOMAIN, {DOMAIN: {"b1": None, "b2": None}})
|
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("input_boolean.b1", "on"), State("input_boolean.b2", "off"))
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
|
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -96,7 +96,7 @@ async def test_restore_state(hass: HomeAssistant) -> None:
|
|||||||
(State("input_button.b1", "2021-01-01T23:59:59+00:00"),),
|
(State("input_button.b1", "2021-01-01T23:59:59+00:00"),),
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
mock_component(hass, "recorder")
|
mock_component(hass, "recorder")
|
||||||
|
|
||||||
await async_setup_component(hass, DOMAIN, {DOMAIN: {"b1": None, "b2": None}})
|
await async_setup_component(hass, DOMAIN, {DOMAIN: {"b1": None, "b2": None}})
|
||||||
|
@ -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)
|
initial = datetime.datetime(2017, 1, 1, 23, 42)
|
||||||
default = datetime.datetime.combine(datetime.date.today(), DEFAULT_TIME)
|
default = datetime.datetime.combine(datetime.date.today(), DEFAULT_TIME)
|
||||||
|
@ -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("input_number.b1", "70"), State("input_number.b2", "200"))
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
|
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
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("input_number.b1", "="), State("input_number.b2", "200"))
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
|
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
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("input_number.b1", "70"), State("input_number.b2", "200"))
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
|
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
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:
|
async def test_no_initial_state_and_no_restore_state(hass: HomeAssistant) -> None:
|
||||||
"""Ensure that entity is create without initial and restore feature."""
|
"""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}}})
|
await async_setup_component(hass, DOMAIN, {DOMAIN: {"b1": {"min": 0, "max": 100}}})
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ async def test_restore_state(hass: HomeAssistant) -> None:
|
|||||||
(State("input_text.b1", "test"), State("input_text.b2", "testing too long")),
|
(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(
|
assert await async_setup_component(
|
||||||
hass, DOMAIN, {DOMAIN: {"b1": None, "b2": {"min": 0, "max": 10}}}
|
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")),
|
(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(
|
await async_setup_component(
|
||||||
hass,
|
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:
|
async def test_no_initial_state_and_no_restore_state(hass: HomeAssistant) -> None:
|
||||||
"""Ensure that entity is create without initial and restore feature."""
|
"""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}}})
|
await async_setup_component(hass, DOMAIN, {DOMAIN: {"b1": {"min": 0, "max": 100}}})
|
||||||
|
|
||||||
|
@ -1221,7 +1221,7 @@ async def test_restore_state(hass: HomeAssistant, expected_state) -> None:
|
|||||||
"""Ensure state is restored on startup."""
|
"""Ensure state is restored on startup."""
|
||||||
mock_restore_cache(hass, (State("alarm_control_panel.test", expected_state),))
|
mock_restore_cache(hass, (State("alarm_control_panel.test", expected_state),))
|
||||||
|
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
mock_component(hass, "recorder")
|
mock_component(hass, "recorder")
|
||||||
|
|
||||||
assert await async_setup_component(
|
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(entity_id, expected_state, attributes, last_updated=time),)
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
mock_component(hass, "recorder")
|
mock_component(hass, "recorder")
|
||||||
|
|
||||||
assert await async_setup_component(
|
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),),
|
(State(entity_id, STATE_ALARM_TRIGGERED, attributes, last_updated=time),),
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
mock_component(hass, "recorder")
|
mock_component(hass, "recorder")
|
||||||
|
|
||||||
assert await async_setup_component(
|
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),),
|
(State(entity_id, STATE_ALARM_TRIGGERED, attributes, last_updated=time),),
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
mock_component(hass, "recorder")
|
mock_component(hass, "recorder")
|
||||||
|
|
||||||
assert await async_setup_component(
|
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),),
|
(State(entity_id, STATE_ALARM_TRIGGERED, attributes, last_updated=time),),
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
mock_component(hass, "recorder")
|
mock_component(hass, "recorder")
|
||||||
|
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
|
@ -2452,7 +2452,7 @@ async def test_delayed_birth_message(
|
|||||||
"""Test sending birth message does not happen until Home Assistant starts."""
|
"""Test sending birth message does not happen until Home Assistant starts."""
|
||||||
mqtt_mock = await mqtt_mock_entry()
|
mqtt_mock = await mqtt_mock_entry()
|
||||||
|
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
birth = asyncio.Event()
|
birth = asyncio.Event()
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -315,7 +315,7 @@ async def test_default_entity_and_device_name(
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
events = async_capture_events(hass, ir.EVENT_REPAIRS_ISSUE_REGISTRY_UPDATED)
|
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()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
entry = MockConfigEntry(domain=mqtt.DOMAIN, data={mqtt.CONF_BROKER: "mock-broker"})
|
entry = MockConfigEntry(domain=mqtt.DOMAIN, data={mqtt.CONF_BROKER: "mock-broker"})
|
||||||
|
@ -140,7 +140,7 @@ async def test_waiting_for_client_not_loaded(
|
|||||||
mqtt_client_mock: MqttMockPahoClient,
|
mqtt_client_mock: MqttMockPahoClient,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test waiting for client while mqtt entry is not yet loaded."""
|
"""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()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
@ -199,7 +199,7 @@ async def test_waiting_for_client_entry_fails(
|
|||||||
mqtt_client_mock: MqttMockPahoClient,
|
mqtt_client_mock: MqttMockPahoClient,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test waiting for client where mqtt entry is failing."""
|
"""Test waiting for client where mqtt entry is failing."""
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
@ -227,7 +227,7 @@ async def test_waiting_for_client_setup_fails(
|
|||||||
mqtt_client_mock: MqttMockPahoClient,
|
mqtt_client_mock: MqttMockPahoClient,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test waiting for client where mqtt entry is failing during setup."""
|
"""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()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
@ -254,7 +254,7 @@ async def test_waiting_for_client_timeout(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test waiting for client with timeout."""
|
"""Test waiting for client with timeout."""
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
@ -273,7 +273,7 @@ async def test_waiting_for_client_with_disabled_entry(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test waiting for client with timeout."""
|
"""Test waiting for client with timeout."""
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
|
@ -58,7 +58,7 @@ async def test_setup_and_stop_waits_for_ha(
|
|||||||
e_id = "fake.entity"
|
e_id = "fake.entity"
|
||||||
|
|
||||||
# HA is not running
|
# HA is not running
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
|
|
||||||
assert await add_statestream(hass, base_topic="pub")
|
assert await add_statestream(hass, base_topic="pub")
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -310,7 +310,7 @@ async def test_setup_component_with_delay(
|
|||||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test setup of the netatmo component with delayed startup."""
|
"""Test setup of the netatmo component with delayed startup."""
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"pyatmo.AbstractAsyncAuth.async_addwebhook", side_effect=AsyncMock()
|
"pyatmo.AbstractAsyncAuth.async_addwebhook", side_effect=AsyncMock()
|
||||||
|
@ -195,7 +195,7 @@ async def test_options_flow(hass: HomeAssistant, mock_get_source_ip) -> None:
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
config_entry.add_to_hass(hass)
|
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)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -99,7 +99,7 @@ async def test_valid_invalid_user_ids(
|
|||||||
|
|
||||||
async def test_setup_tracker(hass: HomeAssistant, hass_admin_user: MockUser) -> None:
|
async def test_setup_tracker(hass: HomeAssistant, hass_admin_user: MockUser) -> None:
|
||||||
"""Test set up person with one device tracker."""
|
"""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
|
user_id = hass_admin_user.id
|
||||||
config = {
|
config = {
|
||||||
DOMAIN: {
|
DOMAIN: {
|
||||||
@ -159,7 +159,7 @@ async def test_setup_two_trackers(
|
|||||||
hass: HomeAssistant, hass_admin_user: MockUser
|
hass: HomeAssistant, hass_admin_user: MockUser
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test set up person with two device trackers."""
|
"""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
|
user_id = hass_admin_user.id
|
||||||
config = {
|
config = {
|
||||||
DOMAIN: {
|
DOMAIN: {
|
||||||
@ -247,7 +247,7 @@ async def test_ignore_unavailable_states(
|
|||||||
hass: HomeAssistant, hass_admin_user: MockUser
|
hass: HomeAssistant, hass_admin_user: MockUser
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test set up person with two device trackers, one unavailable."""
|
"""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
|
user_id = hass_admin_user.id
|
||||||
config = {
|
config = {
|
||||||
DOMAIN: {
|
DOMAIN: {
|
||||||
@ -302,7 +302,7 @@ async def test_restore_home_state(
|
|||||||
}
|
}
|
||||||
state = State("person.tracked_person", "home", attrs)
|
state = State("person.tracked_person", "home", attrs)
|
||||||
mock_restore_cache(hass, (state,))
|
mock_restore_cache(hass, (state,))
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
mock_component(hass, "recorder")
|
mock_component(hass, "recorder")
|
||||||
config = {
|
config = {
|
||||||
DOMAIN: {
|
DOMAIN: {
|
||||||
|
@ -137,7 +137,7 @@ async def test_shutdown_before_startup_finishes(
|
|||||||
recorder.CONF_DB_URL: recorder_db_url,
|
recorder.CONF_DB_URL: recorder_db_url,
|
||||||
recorder.CONF_COMMIT_INTERVAL: 1,
|
recorder.CONF_COMMIT_INTERVAL: 1,
|
||||||
}
|
}
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
|
|
||||||
recorder_helper.async_initialize_recorder(hass)
|
recorder_helper.async_initialize_recorder(hass)
|
||||||
hass.create_task(async_setup_recorder_instance(hass, config))
|
hass.create_task(async_setup_recorder_instance(hass, config))
|
||||||
@ -168,7 +168,7 @@ async def test_canceled_before_startup_finishes(
|
|||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test recorder shuts down when its startup future is canceled out from under it."""
|
"""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)
|
recorder_helper.async_initialize_recorder(hass)
|
||||||
hass.create_task(async_setup_recorder_instance(hass))
|
hass.create_task(async_setup_recorder_instance(hass))
|
||||||
await recorder_helper.async_wait_recorder(hass)
|
await recorder_helper.async_wait_recorder(hass)
|
||||||
@ -192,7 +192,7 @@ async def test_shutdown_closes_connections(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test shutdown closes connections."""
|
"""Test shutdown closes connections."""
|
||||||
|
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
|
|
||||||
instance = get_instance(hass)
|
instance = get_instance(hass)
|
||||||
await instance.async_db_ready
|
await instance.async_db_ready
|
||||||
@ -219,7 +219,7 @@ async def test_state_gets_saved_when_set_before_start_event(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test we can record an event when starting with not running."""
|
"""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)
|
recorder_helper.async_initialize_recorder(hass)
|
||||||
hass.create_task(async_setup_recorder_instance(hass))
|
hass.create_task(async_setup_recorder_instance(hass))
|
||||||
|
@ -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(f"{DOMAIN}.test", STATE_ON), State(f"{DOMAIN}.test2", STATE_ON))
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
|
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
_, _, _, _ = await mock_rflink(hass, CONFIG, DOMAIN, monkeypatch)
|
_, _, _, _ = await mock_rflink(hass, CONFIG, DOMAIN, monkeypatch)
|
||||||
|
@ -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(f"{DOMAIN}.c1", STATE_OPEN), State(f"{DOMAIN}.c2", STATE_CLOSED))
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
|
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
_, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
|
_, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
|
||||||
|
@ -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
|
# setup mocking rflink module
|
||||||
_, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
|
_, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
|
||||||
|
@ -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(f"{DOMAIN}.s1", STATE_ON), State(f"{DOMAIN}.s2", STATE_OFF))
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
|
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
_, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
|
_, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
|
||||||
|
@ -1152,7 +1152,7 @@ async def test_script_restore_last_triggered(hass: HomeAssistant) -> None:
|
|||||||
State("script.last_triggered", STATE_OFF, {"last_triggered": time}),
|
State("script.last_triggered", STATE_OFF, {"last_triggered": time}),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
|
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
@ -1373,7 +1373,7 @@ async def test_recursive_script_turn_on(
|
|||||||
await asyncio.wait_for(service_called.wait(), 1)
|
await asyncio.wait_for(service_called.wait(), 1)
|
||||||
|
|
||||||
# Trigger 1st stage script shutdown
|
# Trigger 1st stage script shutdown
|
||||||
hass.state = CoreState.stopping
|
hass.set_state(CoreState.stopping)
|
||||||
hass.bus.async_fire("homeassistant_stop")
|
hass.bus.async_fire("homeassistant_stop")
|
||||||
await asyncio.wait_for(stop_scripts_at_shutdown_called.wait(), 1)
|
await asyncio.wait_for(stop_scripts_at_shutdown_called.wait(), 1)
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ def test_compile_missing_statistics(
|
|||||||
start_time = three_days_ago + timedelta(days=3)
|
start_time = three_days_ago + timedelta(days=3)
|
||||||
freezer.move_to(three_days_ago)
|
freezer.move_to(three_days_ago)
|
||||||
hass: HomeAssistant = get_test_home_assistant()
|
hass: HomeAssistant = get_test_home_assistant()
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
recorder_helper.async_initialize_recorder(hass)
|
recorder_helper.async_initialize_recorder(hass)
|
||||||
setup_component(hass, "sensor", {})
|
setup_component(hass, "sensor", {})
|
||||||
setup_component(hass, "recorder", {"recorder": config})
|
setup_component(hass, "recorder", {"recorder": config})
|
||||||
@ -90,7 +90,7 @@ def test_compile_missing_statistics(
|
|||||||
hass.stop()
|
hass.stop()
|
||||||
freezer.move_to(start_time)
|
freezer.move_to(start_time)
|
||||||
hass: HomeAssistant = get_test_home_assistant()
|
hass: HomeAssistant = get_test_home_assistant()
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
recorder_helper.async_initialize_recorder(hass)
|
recorder_helper.async_initialize_recorder(hass)
|
||||||
setup_component(hass, "sensor", {})
|
setup_component(hass, "sensor", {})
|
||||||
hass.states.set("sensor.test1", "0", POWER_SENSOR_ATTRIBUTES)
|
hass.states.set("sensor.test1", "0", POWER_SENSOR_ATTRIBUTES)
|
||||||
|
@ -764,7 +764,7 @@ async def test_no_update_template_match_all(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test that we do not update sensors that match on all."""
|
"""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(
|
await setup.async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -507,7 +507,7 @@ async def test_no_template_match_all(
|
|||||||
"""Test that we allow static templates."""
|
"""Test that we allow static templates."""
|
||||||
hass.states.async_set("sensor.test_sensor", "startup")
|
hass.states.async_set("sensor.test_sensor", "startup")
|
||||||
|
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
|
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
@ -752,7 +752,7 @@ async def test_this_variable_early_hass_not_running(
|
|||||||
"""
|
"""
|
||||||
entity_id = "sensor.none_false"
|
entity_id = "sensor.none_false"
|
||||||
|
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
|
|
||||||
# Setup template
|
# Setup template
|
||||||
with assert_setup_component(count, domain):
|
with assert_setup_component(count, domain):
|
||||||
|
@ -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")
|
mock_component(hass, "recorder")
|
||||||
|
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
|
@ -147,7 +147,7 @@ async def test_config_options(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
async def test_methods_and_events(hass: HomeAssistant) -> None:
|
async def test_methods_and_events(hass: HomeAssistant) -> None:
|
||||||
"""Test methods and events."""
|
"""Test methods and events."""
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
|
|
||||||
await async_setup_component(hass, DOMAIN, {DOMAIN: {"test1": {CONF_DURATION: 10}}})
|
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:
|
async def test_wait_till_timer_expires(hass: HomeAssistant) -> None:
|
||||||
"""Test for a timer to end."""
|
"""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}}})
|
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:
|
async def test_no_initial_state_and_no_restore_state(hass: HomeAssistant) -> None:
|
||||||
"""Ensure that entity is create without initial and restore feature."""
|
"""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}}})
|
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:
|
async def test_timer_restarted_event(hass: HomeAssistant) -> None:
|
||||||
"""Ensure restarted event is called after starting a paused or running timer."""
|
"""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}}})
|
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:
|
async def test_state_changed_when_timer_restarted(hass: HomeAssistant) -> None:
|
||||||
"""Ensure timer's state changes when it restarted."""
|
"""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}}})
|
await async_setup_component(hass, DOMAIN, {DOMAIN: {"test1": {CONF_DURATION: 10}}})
|
||||||
|
|
||||||
|
@ -426,7 +426,7 @@ async def test_restore_traces(
|
|||||||
hass: HomeAssistant, hass_storage: dict[str, Any], hass_ws_client, domain
|
hass: HomeAssistant, hass_storage: dict[str, Any], hass_ws_client, domain
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test restored traces."""
|
"""Test restored traces."""
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
id = 1
|
id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
@ -598,7 +598,7 @@ async def test_restore_traces_overflow(
|
|||||||
num_restored_moon_traces,
|
num_restored_moon_traces,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test restored traces are evicted first."""
|
"""Test restored traces are evicted first."""
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
id = 1
|
id = 1
|
||||||
|
|
||||||
trace_uuids = []
|
trace_uuids = []
|
||||||
@ -679,7 +679,7 @@ async def test_restore_traces_late_overflow(
|
|||||||
restored_run_id,
|
restored_run_id,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test restored traces are evicted first."""
|
"""Test restored traces are evicted first."""
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
id = 1
|
id = 1
|
||||||
|
|
||||||
trace_uuids = []
|
trace_uuids = []
|
||||||
|
@ -534,7 +534,7 @@ async def test_restore_state(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test utility sensor restore state."""
|
"""Test utility sensor restore state."""
|
||||||
# Home assistant is not runnit yet
|
# 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"
|
last_reset = "2020-12-21T00:00:00.013073+00:00"
|
||||||
|
|
||||||
@ -865,7 +865,7 @@ async def test_delta_values(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test utility meter "delta_values" mode."""
|
"""Test utility meter "delta_values" mode."""
|
||||||
# Home assistant is not runnit yet
|
# Home assistant is not runnit yet
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
|
|
||||||
now = dt_util.utcnow()
|
now = dt_util.utcnow()
|
||||||
with freeze_time(now):
|
with freeze_time(now):
|
||||||
@ -974,7 +974,7 @@ async def test_non_periodically_resetting(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test utility meter "non periodically resetting" mode."""
|
"""Test utility meter "non periodically resetting" mode."""
|
||||||
# Home assistant is not runnit yet
|
# Home assistant is not runnit yet
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
|
|
||||||
now = dt_util.utcnow()
|
now = dt_util.utcnow()
|
||||||
with freeze_time(now):
|
with freeze_time(now):
|
||||||
|
@ -49,7 +49,7 @@ async def test_dryer_sensor_values(
|
|||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the sensor value callbacks."""
|
"""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)
|
thetimestamp: datetime = datetime(2022, 11, 29, 00, 00, 00, 00, UTC)
|
||||||
mock_restore_cache_with_extra_data(
|
mock_restore_cache_with_extra_data(
|
||||||
hass,
|
hass,
|
||||||
@ -113,7 +113,7 @@ async def test_washer_sensor_values(
|
|||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the sensor value callbacks."""
|
"""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)
|
thetimestamp: datetime = datetime(2022, 11, 29, 00, 00, 00, 00, UTC)
|
||||||
mock_restore_cache_with_extra_data(
|
mock_restore_cache_with_extra_data(
|
||||||
hass,
|
hass,
|
||||||
@ -280,7 +280,7 @@ async def test_restore_state(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test sensor restore state."""
|
"""Test sensor restore state."""
|
||||||
# Home assistant is not running yet
|
# 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)
|
thetimestamp: datetime = datetime(2022, 11, 29, 00, 00, 00, 00, UTC)
|
||||||
mock_restore_cache_with_extra_data(
|
mock_restore_cache_with_extra_data(
|
||||||
hass,
|
hass,
|
||||||
@ -333,7 +333,7 @@ async def test_callback(
|
|||||||
mock_sensor1_api: MagicMock,
|
mock_sensor1_api: MagicMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test callback timestamp callback function."""
|
"""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)
|
thetimestamp: datetime = datetime(2022, 11, 29, 00, 00, 00, 00, UTC)
|
||||||
mock_restore_cache_with_extra_data(
|
mock_restore_cache_with_extra_data(
|
||||||
hass,
|
hass,
|
||||||
|
@ -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)
|
zha_device = await zha_device_restored(zigpy_shade_device)
|
||||||
entity_id = find_entity_id(Platform.COVER, zha_device, hass)
|
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)
|
zha_device = await zha_device_restored(zigpy_cover_device)
|
||||||
entity_id = find_entity_id(Platform.COVER, zha_device, hass)
|
entity_id = find_entity_id(Platform.COVER, zha_device, hass)
|
||||||
|
@ -279,7 +279,7 @@ async def test_shutdown_on_ha_stop(
|
|||||||
zha_data.gateway, "shutdown", wraps=zha_data.gateway.shutdown
|
zha_data.gateway, "shutdown", wraps=zha_data.gateway.shutdown
|
||||||
) as mock_shutdown:
|
) as mock_shutdown:
|
||||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||||
hass.state = CoreState.stopping
|
hass.set_state(CoreState.stopping)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(mock_shutdown.mock_calls) == 1
|
assert len(mock_shutdown.mock_calls) == 1
|
||||||
|
@ -327,14 +327,14 @@ async def test_update_entity_ha_not_running(
|
|||||||
assert len(client.async_send_command.call_args_list) == 1
|
assert len(client.async_send_command.call_args_list) == 1
|
||||||
|
|
||||||
# Update should be delayed by a day because HA is not running
|
# 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))
|
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(minutes=5))
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(client.async_send_command.call_args_list) == 1
|
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))
|
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(minutes=5, days=1))
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -1408,7 +1408,7 @@ async def test_cleanup_device_registry_removes_expired_orphaned_devices(
|
|||||||
|
|
||||||
async def test_cleanup_startup(hass: HomeAssistant) -> None:
|
async def test_cleanup_startup(hass: HomeAssistant) -> None:
|
||||||
"""Test we run a cleanup on startup."""
|
"""Test we run a cleanup on startup."""
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.helpers.device_registry.Debouncer.async_call"
|
"homeassistant.helpers.device_registry.Debouncer.async_call"
|
||||||
|
@ -38,7 +38,7 @@ async def test_async_create_flow_deferred_until_started(
|
|||||||
hass: HomeAssistant, mock_flow_init
|
hass: HomeAssistant, mock_flow_init
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test flows are deferred until started."""
|
"""Test flows are deferred until started."""
|
||||||
hass.state = CoreState.stopped
|
hass.set_state(CoreState.stopped)
|
||||||
discovery_flow.async_create_flow(
|
discovery_flow.async_create_flow(
|
||||||
hass,
|
hass,
|
||||||
"hue",
|
"hue",
|
||||||
@ -79,7 +79,7 @@ async def test_async_create_flow_checks_existing_flows_before_startup(
|
|||||||
hass: HomeAssistant, mock_flow_init
|
hass: HomeAssistant, mock_flow_init
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test existing flows prevent an identical ones from being created before startup."""
|
"""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):
|
for _ in range(2):
|
||||||
discovery_flow.async_create_flow(
|
discovery_flow.async_create_flow(
|
||||||
hass,
|
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."""
|
"""Test we no longer create flows when hass is stopping."""
|
||||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
hass.state = CoreState.stopping
|
hass.set_state(CoreState.stopping)
|
||||||
mock_flow_init.reset_mock()
|
mock_flow_init.reset_mock()
|
||||||
discovery_flow.async_create_flow(
|
discovery_flow.async_create_flow(
|
||||||
hass,
|
hass,
|
||||||
|
@ -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:
|
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."""
|
"""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)
|
async_setup_entry = Mock(side_effect=PlatformNotReady)
|
||||||
initial_listeners = hass.bus.async_listeners()[EVENT_HOMEASSISTANT_STARTED]
|
initial_listeners = hass.bus.async_listeners()[EVENT_HOMEASSISTANT_STARTED]
|
||||||
|
|
||||||
|
@ -870,7 +870,7 @@ async def test_restore_states(
|
|||||||
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test restoring states."""
|
"""Test restoring states."""
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
|
|
||||||
entity_registry.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
"light",
|
"light",
|
||||||
@ -936,7 +936,7 @@ async def test_async_get_device_class_lookup(
|
|||||||
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test registry device class lookup."""
|
"""Test registry device class lookup."""
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
|
|
||||||
entity_registry.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
"binary_sensor",
|
"binary_sensor",
|
||||||
|
@ -210,7 +210,7 @@ async def test_save_persistent_states(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
async def test_hass_starting(hass: HomeAssistant) -> None:
|
async def test_hass_starting(hass: HomeAssistant) -> None:
|
||||||
"""Test that we cache data."""
|
"""Test that we cache data."""
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
|
|
||||||
now = dt_util.utcnow()
|
now = dt_util.utcnow()
|
||||||
stored_states = [
|
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])
|
await data.store.async_save([state.as_dict() for state in stored_states])
|
||||||
|
|
||||||
# Emulate a fresh load
|
# Emulate a fresh load
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
hass.data.pop(DATA_RESTORE_STATE)
|
hass.data.pop(DATA_RESTORE_STATE)
|
||||||
await async_load(hass)
|
await async_load(hass)
|
||||||
data = async_get(hass)
|
data = async_get(hass)
|
||||||
|
@ -4340,7 +4340,7 @@ async def test_shutdown_after(
|
|||||||
script_obj = script.Script(hass, sequence, "test script", "test_domain")
|
script_obj = script.Script(hass, sequence, "test script", "test_domain")
|
||||||
delay_started_flag = async_watch_for_action(script_obj, delay_alias)
|
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")
|
hass.bus.async_fire("homeassistant_stop")
|
||||||
await hass.async_block_till_done()
|
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")
|
script_obj = script.Script(hass, sequence, "test script", "test_domain")
|
||||||
|
|
||||||
# Trigger 1st stage script shutdown
|
# Trigger 1st stage script shutdown
|
||||||
hass.state = CoreState.stopping
|
hass.set_state(CoreState.stopping)
|
||||||
hass.bus.async_fire("homeassistant_stop")
|
hass.bus.async_fire("homeassistant_stop")
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
# Trigger 2nd stage script shutdown
|
# Trigger 2nd stage script shutdown
|
||||||
|
@ -21,7 +21,7 @@ async def test_at_start_when_running_awaitable(hass: HomeAssistant) -> None:
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
|
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
assert hass.is_running
|
assert hass.is_running
|
||||||
|
|
||||||
start.async_at_start(hass, cb_at_start)
|
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)()
|
start.async_at_start(hass, cb_at_start)()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
|
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
assert hass.is_running
|
assert hass.is_running
|
||||||
|
|
||||||
start.async_at_start(hass, cb_at_start)()
|
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:
|
async def test_at_start_when_starting_awaitable(hass: HomeAssistant) -> None:
|
||||||
"""Test at start when yet to start."""
|
"""Test at start when yet to start."""
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
assert not hass.is_running
|
assert not hass.is_running
|
||||||
|
|
||||||
calls = []
|
calls = []
|
||||||
@ -81,7 +81,7 @@ async def test_at_start_when_starting_callback(
|
|||||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test at start when yet to start."""
|
"""Test at start when yet to start."""
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
assert not hass.is_running
|
assert not hass.is_running
|
||||||
|
|
||||||
calls = []
|
calls = []
|
||||||
@ -130,7 +130,7 @@ async def test_cancelling_at_start_when_running(
|
|||||||
|
|
||||||
async def test_cancelling_at_start_when_starting(hass: HomeAssistant) -> None:
|
async def test_cancelling_at_start_when_starting(hass: HomeAssistant) -> None:
|
||||||
"""Test cancelling at start when yet to start."""
|
"""Test cancelling at start when yet to start."""
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
assert not hass.is_running
|
assert not hass.is_running
|
||||||
|
|
||||||
calls = []
|
calls = []
|
||||||
@ -164,7 +164,7 @@ async def test_at_started_when_running_awaitable(hass: HomeAssistant) -> None:
|
|||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
|
|
||||||
# Test the job is not run if state is CoreState.starting
|
# 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)
|
start.async_at_started(hass, cb_at_start)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -188,7 +188,7 @@ async def test_at_started_when_running_callback(
|
|||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
|
|
||||||
# Test the job is not run if state is CoreState.starting
|
# 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)()
|
start.async_at_started(hass, cb_at_start)()
|
||||||
assert len(calls) == 1
|
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:
|
async def test_at_started_when_starting_awaitable(hass: HomeAssistant) -> None:
|
||||||
"""Test at started when yet to start."""
|
"""Test at started when yet to start."""
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
|
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
@ -225,7 +225,7 @@ async def test_at_started_when_starting_callback(
|
|||||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test at started when yet to start."""
|
"""Test at started when yet to start."""
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
|
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
@ -277,7 +277,7 @@ async def test_cancelling_at_started_when_running(
|
|||||||
|
|
||||||
async def test_cancelling_at_started_when_starting(hass: HomeAssistant) -> None:
|
async def test_cancelling_at_started_when_starting(hass: HomeAssistant) -> None:
|
||||||
"""Test cancelling at start when yet to start."""
|
"""Test cancelling at start when yet to start."""
|
||||||
hass.state = CoreState.not_running
|
hass.set_state(CoreState.not_running)
|
||||||
assert not hass.is_running
|
assert not hass.is_running
|
||||||
|
|
||||||
calls = []
|
calls = []
|
||||||
|
@ -140,7 +140,7 @@ async def test_saving_on_final_write(
|
|||||||
assert store.key not in hass_storage
|
assert store.key not in hass_storage
|
||||||
|
|
||||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||||
hass.state = CoreState.stopping
|
hass.set_state(CoreState.stopping)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
|
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)
|
store = storage.Store(hass, MOCK_VERSION, MOCK_KEY)
|
||||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
hass.state = CoreState.stopping
|
hass.set_state(CoreState.stopping)
|
||||||
|
|
||||||
store.async_delay_save(lambda: MOCK_DATA, 1)
|
store.async_delay_save(lambda: MOCK_DATA, 1)
|
||||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=2))
|
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
|
assert store.key not in hass_storage
|
||||||
|
|
||||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||||
hass.state = CoreState.stopping
|
hass.set_state(CoreState.stopping)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert store.key not in hass_storage
|
assert store.key not in hass_storage
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ async def test_not_saving_while_stopping(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test saves don't write when stopping Home Assistant."""
|
"""Test saves don't write when stopping Home Assistant."""
|
||||||
store = storage.Store(hass, MOCK_VERSION, MOCK_KEY)
|
store = storage.Store(hass, MOCK_VERSION, MOCK_KEY)
|
||||||
hass.state = CoreState.stopping
|
hass.set_state(CoreState.stopping)
|
||||||
await store.async_save(MOCK_DATA)
|
await store.async_save(MOCK_DATA)
|
||||||
assert store.key not in hass_storage
|
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
|
assert read_only_store.key not in hass_storage
|
||||||
|
|
||||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||||
hass.state = CoreState.stopping
|
hass.set_state(CoreState.stopping)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
|
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
|
||||||
|
@ -506,7 +506,7 @@ async def test_stop_refresh_on_ha_stop(
|
|||||||
|
|
||||||
# Fire Home Assistant stop event
|
# Fire Home Assistant stop event
|
||||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||||
hass.state = CoreState.stopping
|
hass.set_state(CoreState.stopping)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
# Make sure no update with subscriber after stop event
|
# Make sure no update with subscriber after stop event
|
||||||
|
@ -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:
|
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."""
|
"""Test if we unload an entry that is in retry mode before started."""
|
||||||
entry = MockConfigEntry(domain="test")
|
entry = MockConfigEntry(domain="test")
|
||||||
hass.state = CoreState.starting
|
hass.set_state(CoreState.starting)
|
||||||
initial_listeners = hass.bus.async_listeners()[EVENT_HOMEASSISTANT_STARTED]
|
initial_listeners = hass.bus.async_listeners()[EVENT_HOMEASSISTANT_STARTED]
|
||||||
|
|
||||||
mock_setup_entry = AsyncMock(side_effect=ConfigEntryNotReady)
|
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 entry.state is config_entries.ConfigEntryState.SETUP_RETRY
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
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))
|
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(minutes=5))
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user