mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Remove support for old home-assistant.conf file
This commit is contained in:
parent
d2b5f429fe
commit
aa20b94927
@ -13,14 +13,11 @@ from homeassistant.const import (
|
|||||||
CONF_TIME_ZONE)
|
CONF_TIME_ZONE)
|
||||||
import homeassistant.util.location as loc_util
|
import homeassistant.util.location as loc_util
|
||||||
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
YAML_CONFIG_FILE = 'configuration.yaml'
|
YAML_CONFIG_FILE = 'configuration.yaml'
|
||||||
CONF_CONFIG_FILE = 'home-assistant.conf'
|
|
||||||
|
|
||||||
DEFAULT_CONFIG = [
|
DEFAULT_CONFIG = (
|
||||||
# Tuples (attribute, default, auto detect property, description)
|
# Tuples (attribute, default, auto detect property, description)
|
||||||
(CONF_NAME, 'Home', None, 'Name of the location where Home Assistant is '
|
(CONF_NAME, 'Home', None, 'Name of the location where Home Assistant is '
|
||||||
'running'),
|
'running'),
|
||||||
@ -30,9 +27,9 @@ DEFAULT_CONFIG = [
|
|||||||
(CONF_TEMPERATURE_UNIT, 'C', None, 'C for Celcius, F for Fahrenheit'),
|
(CONF_TEMPERATURE_UNIT, 'C', None, 'C for Celcius, F for Fahrenheit'),
|
||||||
(CONF_TIME_ZONE, 'UTC', 'time_zone', 'Pick yours from here: http://en.wiki'
|
(CONF_TIME_ZONE, 'UTC', 'time_zone', 'Pick yours from here: http://en.wiki'
|
||||||
'pedia.org/wiki/List_of_tz_database_time_zones'),
|
'pedia.org/wiki/List_of_tz_database_time_zones'),
|
||||||
]
|
)
|
||||||
DEFAULT_COMPONENTS = [
|
DEFAULT_COMPONENTS = (
|
||||||
'discovery', 'frontend', 'conversation', 'history', 'logbook', 'sun']
|
'discovery', 'frontend', 'conversation', 'history', 'logbook', 'sun')
|
||||||
|
|
||||||
|
|
||||||
def ensure_config_exists(config_dir, detect_location=True):
|
def ensure_config_exists(config_dir, detect_location=True):
|
||||||
@ -95,24 +92,14 @@ def create_default_config(config_dir, detect_location=True):
|
|||||||
|
|
||||||
def find_config_file(config_dir):
|
def find_config_file(config_dir):
|
||||||
""" Looks in given directory for supported config files. """
|
""" Looks in given directory for supported config files. """
|
||||||
for filename in (YAML_CONFIG_FILE, CONF_CONFIG_FILE):
|
config_path = os.path.join(config_dir, YAML_CONFIG_FILE)
|
||||||
config_path = os.path.join(config_dir, filename)
|
|
||||||
|
|
||||||
if os.path.isfile(config_path):
|
return config_path if os.path.isfile(config_path) else None
|
||||||
return config_path
|
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def load_config_file(config_path):
|
def load_config_file(config_path):
|
||||||
""" Loads given config file. """
|
""" Loads given config file. """
|
||||||
config_ext = os.path.splitext(config_path)[1]
|
return load_yaml_config_file(config_path)
|
||||||
|
|
||||||
if config_ext == '.yaml':
|
|
||||||
return load_yaml_config_file(config_path)
|
|
||||||
|
|
||||||
elif config_ext == '.conf':
|
|
||||||
return load_conf_config_file(config_path)
|
|
||||||
|
|
||||||
|
|
||||||
def load_yaml_config_file(config_path):
|
def load_yaml_config_file(config_path):
|
||||||
@ -152,21 +139,3 @@ def load_yaml_config_file(config_path):
|
|||||||
raise HomeAssistantError()
|
raise HomeAssistantError()
|
||||||
|
|
||||||
return conf_dict
|
return conf_dict
|
||||||
|
|
||||||
|
|
||||||
def load_conf_config_file(config_path):
|
|
||||||
""" Parse the old style conf configuration. """
|
|
||||||
import configparser
|
|
||||||
|
|
||||||
config_dict = {}
|
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
|
||||||
config.read(config_path)
|
|
||||||
|
|
||||||
for section in config.sections():
|
|
||||||
config_dict[section] = {}
|
|
||||||
|
|
||||||
for key, val in config.items(section):
|
|
||||||
config_dict[section][key] = val
|
|
||||||
|
|
||||||
return config_dict
|
|
||||||
|
@ -20,7 +20,6 @@ from common import get_test_config_dir
|
|||||||
|
|
||||||
CONFIG_DIR = get_test_config_dir()
|
CONFIG_DIR = get_test_config_dir()
|
||||||
YAML_PATH = os.path.join(CONFIG_DIR, config_util.YAML_CONFIG_FILE)
|
YAML_PATH = os.path.join(CONFIG_DIR, config_util.YAML_CONFIG_FILE)
|
||||||
CONF_PATH = os.path.join(CONFIG_DIR, config_util.CONF_CONFIG_FILE)
|
|
||||||
|
|
||||||
|
|
||||||
def create_file(path):
|
def create_file(path):
|
||||||
@ -51,9 +50,8 @@ class TestConfig(unittest.TestCase):
|
|||||||
|
|
||||||
def tearDown(self): # pylint: disable=invalid-name
|
def tearDown(self): # pylint: disable=invalid-name
|
||||||
""" Clean up. """
|
""" Clean up. """
|
||||||
for path in (YAML_PATH, CONF_PATH):
|
if os.path.isfile(YAML_PATH):
|
||||||
if os.path.isfile(path):
|
os.remove(YAML_PATH)
|
||||||
os.remove(path)
|
|
||||||
|
|
||||||
def test_create_default_config(self):
|
def test_create_default_config(self):
|
||||||
""" Test creationg of default config. """
|
""" Test creationg of default config. """
|
||||||
@ -69,21 +67,6 @@ class TestConfig(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(YAML_PATH, config_util.find_config_file(CONFIG_DIR))
|
self.assertEqual(YAML_PATH, config_util.find_config_file(CONFIG_DIR))
|
||||||
|
|
||||||
def test_find_config_file_conf(self):
|
|
||||||
""" Test if it finds the old CONF config file. """
|
|
||||||
|
|
||||||
create_file(CONF_PATH)
|
|
||||||
|
|
||||||
self.assertEqual(CONF_PATH, config_util.find_config_file(CONFIG_DIR))
|
|
||||||
|
|
||||||
def test_find_config_file_prefers_yaml_over_conf(self):
|
|
||||||
""" Test if find config prefers YAML over CONF if both exist. """
|
|
||||||
|
|
||||||
create_file(YAML_PATH)
|
|
||||||
create_file(CONF_PATH)
|
|
||||||
|
|
||||||
self.assertEqual(YAML_PATH, config_util.find_config_file(CONFIG_DIR))
|
|
||||||
|
|
||||||
def test_ensure_config_exists_creates_config(self):
|
def test_ensure_config_exists_creates_config(self):
|
||||||
""" Test that calling ensure_config_exists creates a new config file if
|
""" Test that calling ensure_config_exists creates a new config file if
|
||||||
none exists. """
|
none exists. """
|
||||||
@ -135,20 +118,6 @@ class TestConfig(unittest.TestCase):
|
|||||||
self.assertEqual({'hello': 'world'},
|
self.assertEqual({'hello': 'world'},
|
||||||
config_util.load_config_file(YAML_PATH))
|
config_util.load_config_file(YAML_PATH))
|
||||||
|
|
||||||
def test_load_config_loads_conf_config(self):
|
|
||||||
""" Test correct YAML config loading. """
|
|
||||||
create_file(CONF_PATH)
|
|
||||||
|
|
||||||
self.assertEqual({}, config_util.load_config_file(CONF_PATH))
|
|
||||||
|
|
||||||
def test_conf_config_file(self):
|
|
||||||
""" Test correct CONF config loading. """
|
|
||||||
with open(CONF_PATH, 'w') as f:
|
|
||||||
f.write('[ha]\ntime_zone=America/Los_Angeles')
|
|
||||||
|
|
||||||
self.assertEqual({'ha': {'time_zone': 'America/Los_Angeles'}},
|
|
||||||
config_util.load_conf_config_file(CONF_PATH))
|
|
||||||
|
|
||||||
def test_create_default_config_detect_location(self):
|
def test_create_default_config_detect_location(self):
|
||||||
""" Test that detect location sets the correct config keys. """
|
""" Test that detect location sets the correct config keys. """
|
||||||
with mock.patch('homeassistant.util.location.detect_location_info',
|
with mock.patch('homeassistant.util.location.detect_location_info',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user