async def test_async_migration_in_progress( hass: HomeAssistant, async_setup_recorder_instance: SetupRecorderInstanceT ): """Test async_migration_in_progress wraps the recorder.""" with patch( "homeassistant.components.recorder.util.async_migration_in_progress", return_value=False, ): assert recorder.async_migration_in_progress(hass) is False # The recorder is not loaded with patch( "homeassistant.components.recorder.util.async_migration_in_progress", return_value=True, ): assert recorder.async_migration_in_progress(hass) is False await async_setup_recorder_instance(hass) # The recorder is now loaded with patch( "homeassistant.components.recorder.util.async_migration_in_progress", return_value=True, ): assert recorder.async_migration_in_progress(hass) is True
async def async_handle_core_service(call: ha.ServiceCall) -> None: """Service handler for handling core services.""" if call.service in SHUTDOWN_SERVICES and recorder.async_migration_in_progress( hass): _LOGGER.error( "The system cannot %s while a database upgrade is in progress", call.service, ) raise HomeAssistantError( f"The system cannot {call.service} " "while a database upgrade is in progress.") if call.service == SERVICE_HOMEASSISTANT_STOP: asyncio.create_task(hass.async_stop()) return errors = await conf_util.async_check_ha_config_file(hass) if errors: _LOGGER.error( "The system cannot %s because the configuration is not valid: %s", call.service, errors, ) hass.components.persistent_notification.async_create( "Config error. See [the logs](/config/logs) for details.", "Config validating", f"{ha.DOMAIN}.check_config", ) raise HomeAssistantError( f"The system cannot {call.service} " f"because the configuration is not valid: {errors}") if call.service == SERVICE_HOMEASSISTANT_RESTART: asyncio.create_task(hass.async_stop(RESTART_EXIT_CODE))
async def test_async_migration_in_progress(hass): """Test async_migration_in_progress wraps the recorder.""" with patch( "homeassistant.components.recorder.util.async_migration_in_progress", return_value=False, ): assert recorder.async_migration_in_progress(hass) is False # The recorder is not loaded with patch( "homeassistant.components.recorder.util.async_migration_in_progress", return_value=True, ): assert recorder.async_migration_in_progress(hass) is False await async_init_recorder_component(hass) # The recorder is now loaded with patch( "homeassistant.components.recorder.util.async_migration_in_progress", return_value=True, ): assert recorder.async_migration_in_progress(hass) is True