Make it possible to restart core in safe mode (#102606)

This commit is contained in:
Erik Montnemery
2023-10-24 14:47:58 +02:00
committed by GitHub
parent 46322a0f59
commit 97cc05d0b4
14 changed files with 170 additions and 11 deletions

View File

@@ -11,6 +11,7 @@ from homeassistant import config
import homeassistant.components as comps
from homeassistant.components.homeassistant import (
ATTR_ENTRY_ID,
ATTR_SAFE_MODE,
SERVICE_CHECK_CONFIG,
SERVICE_HOMEASSISTANT_RESTART,
SERVICE_HOMEASSISTANT_STOP,
@@ -536,22 +537,32 @@ async def test_raises_when_config_is_invalid(
assert mock_async_check_ha_config_file.called
async def test_restart_homeassistant(hass: HomeAssistant) -> None:
@pytest.mark.parametrize(
("service_data", "safe_mode_enabled"),
[({}, False), ({ATTR_SAFE_MODE: False}, False), ({ATTR_SAFE_MODE: True}, True)],
)
async def test_restart_homeassistant(
hass: HomeAssistant, service_data: dict, safe_mode_enabled: bool
) -> None:
"""Test we can restart when there is no configuration error."""
await async_setup_component(hass, "homeassistant", {})
with patch(
"homeassistant.config.async_check_ha_config_file", return_value=None
) as mock_check, patch(
"homeassistant.config.async_enable_safe_mode"
) as mock_safe_mode, patch(
"homeassistant.core.HomeAssistant.async_stop", return_value=None
) as mock_restart:
await hass.services.async_call(
"homeassistant",
SERVICE_HOMEASSISTANT_RESTART,
service_data,
blocking=True,
)
assert mock_check.called
await hass.async_block_till_done()
assert mock_restart.called
assert mock_safe_mode.called == safe_mode_enabled
async def test_stop_homeassistant(hass: HomeAssistant) -> None: