From 6ef60aa979d7682c9431ef531d807f50d7af5fd8 Mon Sep 17 00:00:00 2001 From: Andrew Thigpen Date: Fri, 15 May 2015 19:59:43 -0500 Subject: [PATCH 1/4] Add include YAML tag. Allows including other files in the main configuration.yaml file. With this functionality, passwords or other sensitive information can be stored in a separate file from the main configuration. --- homeassistant/config.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/homeassistant/config.py b/homeassistant/config.py index b4f70cd1952..fa151325e31 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -103,6 +103,18 @@ def load_yaml_config_file(config_path): """ Parse a YAML configuration file. """ import yaml + def yaml_include(loader, node): + """ + Loads another YAML file and embeds it using the !include tag. + + Example: + device_tracker: !include device_tracker.yaml + """ + fname = os.path.join(os.path.dirname(config_path), node.value) + return load_yaml_config_file(fname) + + yaml.add_constructor('!include', yaml_include) + try: with open(config_path) as conf_file: # If configuration file is empty YAML returns None From f3f2240e4a0a9ab45116ab229b8d9819496ecddf Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 15 May 2015 23:26:22 -0700 Subject: [PATCH 2/4] Remove usage of deprecated hass.local_api in __main__ --- homeassistant/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/__main__.py b/homeassistant/__main__.py index 83a8c499718..316529ce74e 100644 --- a/homeassistant/__main__.py +++ b/homeassistant/__main__.py @@ -141,9 +141,9 @@ def main(): def open_browser(event): """ Open the webinterface in a browser. """ - if hass.local_api is not None: + if hass.config.api is not None: import webbrowser - webbrowser.open(hass.local_api.base_url) + webbrowser.open(hass.config.api.base_url) hass.bus.listen_once(EVENT_HOMEASSISTANT_START, open_browser) From e0d697d0bc71e24ca0c589540ba2e66a34d6efa9 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 15 May 2015 23:28:11 -0700 Subject: [PATCH 3/4] Default to UTC if invalid timezone specified --- homeassistant/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/homeassistant/__init__.py b/homeassistant/__init__.py index 132482d4bfa..09069924e6b 100644 --- a/homeassistant/__init__.py +++ b/homeassistant/__init__.py @@ -961,12 +961,14 @@ class Config(object): def as_dict(self): """ Converts config to a dictionary. """ + time_zone = self.time_zone or date_util.UTC + return { 'latitude': self.latitude, 'longitude': self.longitude, 'temperature_unit': self.temperature_unit, 'location_name': self.location_name, - 'time_zone': self.time_zone.zone, + 'time_zone': time_zone.zone, 'components': self.components, } From fc560d179eafcf8c75f7a033fbaff2f568e62788 Mon Sep 17 00:00:00 2001 From: Andrew Thigpen Date: Sat, 16 May 2015 11:27:34 -0500 Subject: [PATCH 4/4] Fix issues with YAML include tag. Calling load_yaml_config_file(config_path) causes issues when trying to load from multiple files in a directory since config_path is modified in the closure. This also separates the parse code block into its own function so that there is no restriction that the object be a dictionary for included files. This means that scalars, lists, etc. can also be stored in separate files -- for example, the scene component expects a list. --- homeassistant/config.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/homeassistant/config.py b/homeassistant/config.py index fa151325e31..b24c224f543 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -103,6 +103,19 @@ def load_yaml_config_file(config_path): """ Parse a YAML configuration file. """ import yaml + def parse(fname): + """ Actually parse the file. """ + try: + with open(fname) as conf_file: + # If configuration file is empty YAML returns None + # We convert that to an empty dict + conf_dict = yaml.load(conf_file) or {} + except yaml.YAMLError: + _LOGGER.exception('Error reading YAML configuration file %s', + fname) + raise HomeAssistantError() + return conf_dict + def yaml_include(loader, node): """ Loads another YAML file and embeds it using the !include tag. @@ -110,20 +123,12 @@ def load_yaml_config_file(config_path): Example: device_tracker: !include device_tracker.yaml """ - fname = os.path.join(os.path.dirname(config_path), node.value) - return load_yaml_config_file(fname) + fname = os.path.join(os.path.dirname(loader.name), node.value) + return parse(fname) yaml.add_constructor('!include', yaml_include) - try: - with open(config_path) as conf_file: - # If configuration file is empty YAML returns None - # We convert that to an empty dict - conf_dict = yaml.load(conf_file) or {} - - except yaml.YAMLError: - _LOGGER.exception('Error reading YAML configuration file') - raise HomeAssistantError() + conf_dict = parse(config_path) if not isinstance(conf_dict, dict): _LOGGER.error(