Add Safe Mode (#30723)
* Store last working HTTP settings * Add safe mode * Fix tests * Add cloud to safe mode * Update logging text * Fix camera tests leaving files behind * Make emulated_hue tests not leave files behind * Make logbook tests not leave files behind * Make tts tests not leave files behind * Make image_processing tests not leave files behind * Make manual_mqtt tests not leave files behind
This commit is contained in:
1 parent
c4673ddee1
commit
5fdc60e067
35 files changed
+480
-430
No files matched your search
@@ -13,7 +13,7 @@ from yarl import URL
|
||||
|
||||
from homeassistant.components import websocket_api
|
||||
from homeassistant.components.http.view import HomeAssistantView
|
||||
from homeassistant.config import find_config_file, load_yaml_config_file
|
||||
from homeassistant.config import async_hass_config_yaml
|
||||
from homeassistant.const import CONF_NAME, EVENT_THEMES_UPDATED
|
||||
from homeassistant.core import callback
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
@@ -362,11 +362,10 @@ def _async_setup_themes(hass, themes):
|
||||
else:
|
||||
_LOGGER.warning("Theme %s is not defined.", name)
|
||||
|
||||
@callback
|
||||
def reload_themes(_):
|
||||
async def reload_themes(_):
|
||||
"""Reload themes."""
|
||||
path = find_config_file(hass.config.config_dir)
|
||||
new_themes = load_yaml_config_file(path)[DOMAIN].get(CONF_THEMES, {})
|
||||
config = await async_hass_config_yaml(hass)
|
||||
new_themes = config[DOMAIN].get(CONF_THEMES, {})
|
||||
hass.data[DATA_THEMES] = new_themes
|
||||
if hass.data[DATA_DEFAULT_THEME] not in new_themes:
|
||||
hass.data[DATA_DEFAULT_THEME] = DEFAULT_THEME
|
||||
|
||||
@@ -3,7 +3,7 @@ from ipaddress import ip_network
|
||||
import logging
|
||||
import os
|
||||
import ssl
|
||||
from typing import Optional
|
||||
from typing import Optional, cast
|
||||
|
||||
from aiohttp import web
|
||||
from aiohttp.web_exceptions import HTTPMovedPermanently
|
||||
@@ -14,7 +14,10 @@ from homeassistant.const import (
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
SERVER_PORT,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import storage
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.loader import bind_hass
|
||||
import homeassistant.util as hass_util
|
||||
from homeassistant.util import ssl as ssl_util
|
||||
|
||||
@@ -56,6 +59,9 @@ NO_LOGIN_ATTEMPT_THRESHOLD = -1
|
||||
|
||||
MAX_CLIENT_SIZE: int = 1024 ** 2 * 16
|
||||
|
||||
STORAGE_KEY = DOMAIN
|
||||
STORAGE_VERSION = 1
|
||||
|
||||
|
||||
HTTP_SCHEMA = vol.Schema(
|
||||
{
|
||||
@@ -85,6 +91,13 @@ HTTP_SCHEMA = vol.Schema(
|
||||
CONFIG_SCHEMA = vol.Schema({DOMAIN: HTTP_SCHEMA}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
||||
@bind_hass
|
||||
async def async_get_last_config(hass: HomeAssistant) -> Optional[dict]:
|
||||
"""Return the last known working config."""
|
||||
store = storage.Store(hass, STORAGE_VERSION, STORAGE_KEY)
|
||||
return cast(Optional[dict], await store.async_load())
|
||||
|
||||
|
||||
class ApiConfig:
|
||||
"""Configuration settings for API server."""
|
||||
|
||||
@@ -151,6 +164,10 @@ async def async_setup(hass, config):
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, stop_server)
|
||||
await server.start()
|
||||
|
||||
# If we are set up successful, we store the HTTP settings for safe mode.
|
||||
store = storage.Store(hass, STORAGE_VERSION, STORAGE_KEY)
|
||||
await store.async_save(conf)
|
||||
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, start_server)
|
||||
|
||||
hass.http = server
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
"""The Safe Mode integration."""
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
DOMAIN = "safe_mode"
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: dict):
|
||||
"""Set up the Safe Mode component."""
|
||||
persistent_notification.async_create(
|
||||
hass,
|
||||
"Home Assistant is running in safe mode. Check [the error log](/developer-tools/logs) to see what went wrong.",
|
||||
"Safe Mode",
|
||||
)
|
||||
return True
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"domain": "safe_mode",
|
||||
"name": "Safe Mode",
|
||||
"config_flow": false,
|
||||
"documentation": "https://www.home-assistant.io/integrations/safe_mode",
|
||||
"requirements": [],
|
||||
"ssdp": [],
|
||||
"zeroconf": [],
|
||||
"homekit": {},
|
||||
"dependencies": ["frontend", "config", "persistent_notification", "cloud"],
|
||||
"codeowners": ["@home-assistant/core"]
|
||||
}
|
||||
Reference in new issue
Block a user