def from_config_file(config_path, hass=None, verbose=False, daemon=False, skip_pip=True, log_rotate_days=None): """ Reads the configuration file and tries to start all the required functionality. Will add functionality to 'hass' parameter if given, instantiates a new Home Assistant object if 'hass' is not given. """ if hass is None: hass = core.HomeAssistant() # Set config dir to directory holding config file config_dir = os.path.abspath(os.path.dirname(config_path)) hass.config.config_dir = config_dir mount_local_lib_path(config_dir) enable_logging(hass, verbose, daemon, log_rotate_days) config_dict = config_util.load_config_file(config_path) return from_config_dict(config_dict, hass, enable_log=False, skip_pip=skip_pip)
def test_load_config_loads_yaml_config(self): """ Test correct YAML config loading. """ with open(YAML_PATH, 'w') as f: f.write('hello: world') self.assertEqual({'hello': 'world'}, config_util.load_config_file(YAML_PATH))
def from_config_file(config_path, hass=None): """ Reads the configuration file and tries to start all the required functionality. Will add functionality to 'hass' parameter if given, instantiates a new Home Assistant object if 'hass' is not given. """ if hass is None: hass = homeassistant.HomeAssistant() # Set config dir to directory holding config file hass.config.config_dir = os.path.abspath(os.path.dirname(config_path)) config_dict = config_util.load_config_file(config_path) return from_config_dict(config_dict, hass)
def from_config_file(config_path, hass=None): """ Reads the configuration file and tries to start all the required functionality. Will add functionality to 'hass' parameter if given, instantiates a new Home Assistant object if 'hass' is not given. """ if hass is None: hass = core.HomeAssistant() # Set config dir to directory holding config file hass.config.config_dir = os.path.abspath(os.path.dirname(config_path)) config_dict = config_util.load_config_file(config_path) return from_config_dict(config_dict, hass)
def test_create_default_config_detect_location(self, mock_print): """ Test that detect location sets the correct config keys. """ config_util.ensure_config_exists(CONFIG_DIR) config = config_util.load_config_file(YAML_PATH) self.assertIn(DOMAIN, config) ha_conf = config[DOMAIN] expected_values = { CONF_LATITUDE: 2.0, CONF_LONGITUDE: 1.0, CONF_TEMPERATURE_UNIT: 'F', CONF_NAME: 'Home', CONF_TIME_ZONE: 'America/Los_Angeles' } self.assertEqual(expected_values, ha_conf) self.assertTrue(mock_print.called)
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", mock_detect_location_info): config_util.ensure_config_exists(CONFIG_DIR) config = config_util.load_config_file(YAML_PATH) self.assertIn(DOMAIN, config) ha_conf = config[DOMAIN] expected_values = { CONF_LATITUDE: 2.0, CONF_LONGITUDE: 1.0, CONF_TEMPERATURE_UNIT: "F", CONF_NAME: "Home", CONF_TIME_ZONE: "America/Los_Angeles", } self.assertEqual(expected_values, ha_conf)
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_load_config_loads_yaml_config(self): """ Test correct YAML config loading. """ with open(YAML_PATH, "w") as f: f.write("hello: world") self.assertEqual({"hello": "world"}, config_util.load_config_file(YAML_PATH))