diff --git a/homeassistant/config.py b/homeassistant/config.py index 629001b972f..3b2dd1ce740 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -13,14 +13,11 @@ from homeassistant.const import ( CONF_TIME_ZONE) import homeassistant.util.location as loc_util - _LOGGER = logging.getLogger(__name__) - YAML_CONFIG_FILE = 'configuration.yaml' -CONF_CONFIG_FILE = 'home-assistant.conf' -DEFAULT_CONFIG = [ +DEFAULT_CONFIG = ( # Tuples (attribute, default, auto detect property, description) (CONF_NAME, 'Home', None, 'Name of the location where Home Assistant is ' 'running'), @@ -30,9 +27,9 @@ DEFAULT_CONFIG = [ (CONF_TEMPERATURE_UNIT, 'C', None, 'C for Celcius, F for Fahrenheit'), (CONF_TIME_ZONE, 'UTC', 'time_zone', 'Pick yours from here: http://en.wiki' 'pedia.org/wiki/List_of_tz_database_time_zones'), -] -DEFAULT_COMPONENTS = [ - 'discovery', 'frontend', 'conversation', 'history', 'logbook', 'sun'] +) +DEFAULT_COMPONENTS = ( + 'discovery', 'frontend', 'conversation', 'history', 'logbook', 'sun') 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): """ Looks in given directory for supported config files. """ - for filename in (YAML_CONFIG_FILE, CONF_CONFIG_FILE): - config_path = os.path.join(config_dir, filename) + config_path = os.path.join(config_dir, YAML_CONFIG_FILE) - if os.path.isfile(config_path): - return config_path - - return None + return config_path if os.path.isfile(config_path) else None def load_config_file(config_path): """ Loads given config file. """ - config_ext = os.path.splitext(config_path)[1] - - if config_ext == '.yaml': - return load_yaml_config_file(config_path) - - elif config_ext == '.conf': - return load_conf_config_file(config_path) + return 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() 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 diff --git a/tests/test_config.py b/tests/test_config.py index 368f660eeb7..235549f6cef 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -20,7 +20,6 @@ from common import get_test_config_dir CONFIG_DIR = get_test_config_dir() 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): @@ -51,9 +50,8 @@ class TestConfig(unittest.TestCase): def tearDown(self): # pylint: disable=invalid-name """ Clean up. """ - for path in (YAML_PATH, CONF_PATH): - if os.path.isfile(path): - os.remove(path) + if os.path.isfile(YAML_PATH): + os.remove(YAML_PATH) def test_create_default_config(self): """ Test creationg of default config. """ @@ -69,21 +67,6 @@ class TestConfig(unittest.TestCase): 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): """ Test that calling ensure_config_exists creates a new config file if none exists. """ @@ -135,20 +118,6 @@ class TestConfig(unittest.TestCase): self.assertEqual({'hello': 'world'}, 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): """ Test that detect location sets the correct config keys. """ with mock.patch('homeassistant.util.location.detect_location_info',