Fix config imports (#27669)

* Fix config imports

* Remove old migration

* Remove migrate tests
pull/27734/head
Paulus Schoutsen 2019-10-15 16:15:26 -07:00 committed by GitHub
parent c700085490
commit 93f9afcd21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 90 deletions

View File

@ -5,12 +5,11 @@ import uuid
from homeassistant.components.automation import DOMAIN, PLATFORM_SCHEMA
from homeassistant.components.automation.config import async_validate_config_item
from homeassistant.const import CONF_ID, SERVICE_RELOAD
from homeassistant.config import AUTOMATION_CONFIG_PATH
import homeassistant.helpers.config_validation as cv
from . import EditIdBasedConfigView
CONFIG_PATH = "automations.yaml"
async def async_setup(hass):
"""Set up the Automation config API."""
@ -23,7 +22,7 @@ async def async_setup(hass):
EditAutomationConfigView(
DOMAIN,
"config",
CONFIG_PATH,
AUTOMATION_CONFIG_PATH,
cv.string,
PLATFORM_SCHEMA,
post_write_hook=hook,

View File

@ -1,12 +1,11 @@
"""Provide configuration end points for Groups."""
from homeassistant.components.group import DOMAIN, GROUP_SCHEMA
from homeassistant.const import SERVICE_RELOAD
from homeassistant.config import GROUP_CONFIG_PATH
import homeassistant.helpers.config_validation as cv
from . import EditKeyBasedConfigView
CONFIG_PATH = "groups.yaml"
async def async_setup(hass):
"""Set up the Group config API."""
@ -17,7 +16,12 @@ async def async_setup(hass):
hass.http.register_view(
EditKeyBasedConfigView(
"group", "config", CONFIG_PATH, cv.slug, GROUP_SCHEMA, post_write_hook=hook
"group",
"config",
GROUP_CONFIG_PATH,
cv.slug,
GROUP_SCHEMA,
post_write_hook=hook,
)
)
return True

View File

@ -1,12 +1,11 @@
"""Provide configuration end points for scripts."""
from homeassistant.components.script import DOMAIN, SCRIPT_ENTRY_SCHEMA
from homeassistant.const import SERVICE_RELOAD
from homeassistant.config import SCRIPT_CONFIG_PATH
import homeassistant.helpers.config_validation as cv
from . import EditKeyBasedConfigView
CONFIG_PATH = "scripts.yaml"
async def async_setup(hass):
"""Set up the script config API."""
@ -19,7 +18,7 @@ async def async_setup(hass):
EditKeyBasedConfigView(
"script",
"config",
CONFIG_PATH,
SCRIPT_CONFIG_PATH,
cv.slug,
SCRIPT_ENTRY_SCHEMA,
post_write_hook=hook,

View File

@ -66,9 +66,11 @@ VERSION_FILE = ".HA_VERSION"
CONFIG_DIR_NAME = ".homeassistant"
DATA_CUSTOMIZE = "hass_customize"
FILE_MIGRATION = (("ios.conf", ".ios.conf"),)
GROUP_CONFIG_PATH = "groups.yaml"
AUTOMATION_CONFIG_PATH = "automations.yaml"
SCRIPT_CONFIG_PATH = "scripts.yaml"
DEFAULT_CONFIG = """
DEFAULT_CONFIG = f"""
# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
@ -80,9 +82,9 @@ default_config:
tts:
- platform: google_translate
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
group: !include {GROUP_CONFIG_PATH}
automation: !include {AUTOMATION_CONFIG_PATH}
script: !include {SCRIPT_CONFIG_PATH}
"""
DEFAULT_SECRETS = """
# Use this file to store secrets like usernames and passwords.
@ -253,12 +255,6 @@ async def async_create_default_config(
def _write_default_config(config_dir: str) -> Optional[str]:
"""Write the default config."""
from homeassistant.components.config.group import CONFIG_PATH as GROUP_CONFIG_PATH
from homeassistant.components.config.automation import (
CONFIG_PATH as AUTOMATION_CONFIG_PATH,
)
from homeassistant.components.config.script import CONFIG_PATH as SCRIPT_CONFIG_PATH
config_path = os.path.join(config_dir, YAML_CONFIG_FILE)
secret_path = os.path.join(config_dir, SECRET_YAML)
version_path = os.path.join(config_dir, VERSION_FILE)
@ -407,12 +403,6 @@ def process_ha_config_upgrade(hass: HomeAssistant) -> None:
with open(version_path, "wt") as outp:
outp.write(__version__)
_LOGGER.debug("Migrating old system configuration files to new locations")
for oldf, newf in FILE_MIGRATION:
if os.path.isfile(hass.config.path(oldf)):
_LOGGER.info("Migrating %s to %s", oldf, newf)
os.rename(hass.config.path(oldf), hass.config.path(newf))
@callback
def async_log_exception(

View File

@ -33,11 +33,6 @@ from homeassistant.const import (
from homeassistant.util import dt as dt_util
from homeassistant.util.yaml import SECRET_YAML
from homeassistant.helpers.entity import Entity
from homeassistant.components.config.group import CONFIG_PATH as GROUP_CONFIG_PATH
from homeassistant.components.config.automation import (
CONFIG_PATH as AUTOMATIONS_CONFIG_PATH,
)
from homeassistant.components.config.script import CONFIG_PATH as SCRIPTS_CONFIG_PATH
import homeassistant.helpers.check_config as check_config
from tests.common import get_test_config_dir, patch_yaml_files
@ -46,9 +41,9 @@ CONFIG_DIR = get_test_config_dir()
YAML_PATH = os.path.join(CONFIG_DIR, config_util.YAML_CONFIG_FILE)
SECRET_PATH = os.path.join(CONFIG_DIR, SECRET_YAML)
VERSION_PATH = os.path.join(CONFIG_DIR, config_util.VERSION_FILE)
GROUP_PATH = os.path.join(CONFIG_DIR, GROUP_CONFIG_PATH)
AUTOMATIONS_PATH = os.path.join(CONFIG_DIR, AUTOMATIONS_CONFIG_PATH)
SCRIPTS_PATH = os.path.join(CONFIG_DIR, SCRIPTS_CONFIG_PATH)
GROUP_PATH = os.path.join(CONFIG_DIR, config_util.GROUP_CONFIG_PATH)
AUTOMATIONS_PATH = os.path.join(CONFIG_DIR, config_util.AUTOMATION_CONFIG_PATH)
SCRIPTS_PATH = os.path.join(CONFIG_DIR, config_util.SCRIPT_CONFIG_PATH)
ORIG_TIMEZONE = dt_util.DEFAULT_TIME_ZONE
@ -345,62 +340,6 @@ def test_config_upgrade_no_file(hass):
assert opened_file.write.call_args == mock.call(__version__)
@mock.patch("homeassistant.config.shutil")
@mock.patch("homeassistant.config.os")
@mock.patch("homeassistant.config.find_config_file", mock.Mock())
def test_migrate_file_on_upgrade(mock_os, mock_shutil, hass):
"""Test migrate of config files on upgrade."""
ha_version = "0.7.0"
mock_os.path.isdir = mock.Mock(return_value=True)
mock_open = mock.mock_open()
def _mock_isfile(filename):
return True
with mock.patch("homeassistant.config.open", mock_open, create=True), mock.patch(
"homeassistant.config.os.path.isfile", _mock_isfile
):
opened_file = mock_open.return_value
# pylint: disable=no-member
opened_file.readline.return_value = ha_version
hass.config.path = mock.Mock()
config_util.process_ha_config_upgrade(hass)
assert mock_os.rename.call_count == 1
@mock.patch("homeassistant.config.shutil")
@mock.patch("homeassistant.config.os")
@mock.patch("homeassistant.config.find_config_file", mock.Mock())
def test_migrate_no_file_on_upgrade(mock_os, mock_shutil, hass):
"""Test not migrating config files on upgrade."""
ha_version = "0.7.0"
mock_os.path.isdir = mock.Mock(return_value=True)
mock_open = mock.mock_open()
def _mock_isfile(filename):
return False
with mock.patch("homeassistant.config.open", mock_open, create=True), mock.patch(
"homeassistant.config.os.path.isfile", _mock_isfile
):
opened_file = mock_open.return_value
# pylint: disable=no-member
opened_file.readline.return_value = ha_version
hass.config.path = mock.Mock()
config_util.process_ha_config_upgrade(hass)
assert mock_os.rename.call_count == 0
async def test_loading_configuration_from_storage(hass, hass_storage):
"""Test loading core config onto hass object."""
hass_storage["core.config"] = {