mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Allign error handling for restart for hassio with core (#50114)
* Allign error handling for restart for hassio with core * Reuse HASS_DOMAIN * Address comments
This commit is contained in:
parent
93572bfe02
commit
65cf138360
@ -9,7 +9,10 @@ from typing import Any
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.auth.const import GROUP_ID_ADMIN
|
from homeassistant.auth.const import GROUP_ID_ADMIN
|
||||||
from homeassistant.components.homeassistant import SERVICE_CHECK_CONFIG
|
from homeassistant.components.homeassistant import (
|
||||||
|
SERVICE_CHECK_CONFIG,
|
||||||
|
SHUTDOWN_SERVICES,
|
||||||
|
)
|
||||||
import homeassistant.config as conf_util
|
import homeassistant.config as conf_util
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -21,7 +24,7 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import DOMAIN as HASS_DOMAIN, Config, HomeAssistant, callback
|
from homeassistant.core import DOMAIN as HASS_DOMAIN, Config, HomeAssistant, callback
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
import homeassistant.helpers.config_validation as cv
|
from homeassistant.helpers import config_validation as cv, recorder
|
||||||
from homeassistant.helpers.device_registry import DeviceRegistry, async_get_registry
|
from homeassistant.helpers.device_registry import DeviceRegistry, async_get_registry
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
from homeassistant.loader import bind_hass
|
from homeassistant.loader import bind_hass
|
||||||
@ -469,23 +472,40 @@ async def async_setup(hass: HomeAssistant, config: Config) -> bool: # noqa: C90
|
|||||||
|
|
||||||
async def async_handle_core_service(call):
|
async def async_handle_core_service(call):
|
||||||
"""Service handler for handling core services."""
|
"""Service handler for handling core services."""
|
||||||
|
if (
|
||||||
|
call.service in SHUTDOWN_SERVICES
|
||||||
|
and await 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:
|
if call.service == SERVICE_HOMEASSISTANT_STOP:
|
||||||
await hassio.stop_homeassistant()
|
await hassio.stop_homeassistant()
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
errors = await conf_util.async_check_ha_config_file(hass)
|
||||||
errors = await conf_util.async_check_ha_config_file(hass)
|
|
||||||
except HomeAssistantError:
|
|
||||||
return
|
|
||||||
|
|
||||||
if errors:
|
if errors:
|
||||||
_LOGGER.error(errors)
|
_LOGGER.error(
|
||||||
|
"The system cannot %s because the configuration is not valid: %s",
|
||||||
|
call.service,
|
||||||
|
errors,
|
||||||
|
)
|
||||||
hass.components.persistent_notification.async_create(
|
hass.components.persistent_notification.async_create(
|
||||||
"Config error. See [the logs](/config/logs) for details.",
|
"Config error. See [the logs](/config/logs) for details.",
|
||||||
"Config validating",
|
"Config validating",
|
||||||
f"{HASS_DOMAIN}.check_config",
|
f"{HASS_DOMAIN}.check_config",
|
||||||
)
|
)
|
||||||
return
|
raise HomeAssistantError(
|
||||||
|
f"The system cannot {call.service} "
|
||||||
|
f"because the configuration is not valid: {errors}"
|
||||||
|
)
|
||||||
|
|
||||||
if call.service == SERVICE_HOMEASSISTANT_RESTART:
|
if call.service == SERVICE_HOMEASSISTANT_RESTART:
|
||||||
await hassio.restart_homeassistant()
|
await hassio.restart_homeassistant()
|
||||||
|
@ -133,11 +133,12 @@ async def async_setup(hass: ha.HomeAssistant, config: dict) -> bool: # noqa: C9
|
|||||||
and await recorder.async_migration_in_progress(hass)
|
and await recorder.async_migration_in_progress(hass)
|
||||||
):
|
):
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"The system cannot %s while a database upgrade in progress",
|
"The system cannot %s while a database upgrade is in progress",
|
||||||
call.service,
|
call.service,
|
||||||
)
|
)
|
||||||
raise HomeAssistantError(
|
raise HomeAssistantError(
|
||||||
f"The system cannot {call.service} while a database upgrade in progress."
|
f"The system cannot {call.service} "
|
||||||
|
"while a database upgrade is in progress."
|
||||||
)
|
)
|
||||||
|
|
||||||
if call.service == SERVICE_HOMEASSISTANT_STOP:
|
if call.service == SERVICE_HOMEASSISTANT_STOP:
|
||||||
@ -158,7 +159,8 @@ async def async_setup(hass: ha.HomeAssistant, config: dict) -> bool: # noqa: C9
|
|||||||
f"{ha.DOMAIN}.check_config",
|
f"{ha.DOMAIN}.check_config",
|
||||||
)
|
)
|
||||||
raise HomeAssistantError(
|
raise HomeAssistantError(
|
||||||
f"The system cannot {call.service} because the configuration is not valid: {errors}"
|
f"The system cannot {call.service} "
|
||||||
|
f"because the configuration is not valid: {errors}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if call.service == SERVICE_HOMEASSISTANT_RESTART:
|
if call.service == SERVICE_HOMEASSISTANT_RESTART:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user