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:
Paulus Schoutsen authored and GitHub committed 2020-01-14 13:03:02 -08:00
1 parent c4673ddee1
commit 5fdc60e067
35 files changed
+480 -430

No files matched your search

+18 -1
View File
@@ -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