From 495ebd6aab8cb2bdd151a35eec5d23c1c4c28db9 Mon Sep 17 00:00:00 2001 From: Jimmy Hedman Date: Tue, 10 Apr 2018 09:37:26 +0200 Subject: [PATCH] Added !include constructor. - This adds !include as a constructor which lets you use: wifi: !include wifisecrets.yaml --- esphomeyaml/yaml_util.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/esphomeyaml/yaml_util.py b/esphomeyaml/yaml_util.py index 5acd53999f..48e538f939 100644 --- a/esphomeyaml/yaml_util.py +++ b/esphomeyaml/yaml_util.py @@ -97,8 +97,16 @@ def _add_reference(obj, loader, node): return obj +def _include(self, node): + """Include file""" + filename = self.construct_scalar(node) + with open(filename, 'r') as f: + return yaml.load(f, yaml.SafeLoader) + + yaml.SafeLoader.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, _ordered_dict) yaml.SafeLoader.add_constructor(yaml.resolver.BaseResolver.DEFAULT_SEQUENCE_TAG, _construct_seq) +yaml.SafeLoader.add_constructor('!include', _include) # From: https://gist.github.com/miracle2k/3184458