Allow redefining node anchors

This commit is contained in:
Thomas Lovén 2019-11-15 22:27:14 +01:00
parent 1878c92c91
commit 5870a3f4b2
2 changed files with 28 additions and 0 deletions

View File

@ -250,6 +250,9 @@ elements:
![lovelace_gen](https://user-images.githubusercontent.com/1299821/62565373-ecd4ac80-b886-11e9-9dcb-c41b43027b2b.png)
## Hidden bonus
With lovelace_gen installed, you'll be able to redefine node anchors in the same file. A feature in the YAML specification, but an error in the engine Home Assistant normally uses...
# FAQ
### How can I do global variables?

View File

@ -65,3 +65,28 @@ loader.yaml.SafeLoader.add_constructor("!file", _uncache_file)
async def async_setup(hass, config):
llgen_config.update(config.get("lovelace_gen"));
return True
# Allow redefinition of node anchors
import yaml
def compose_node(self, parent, index):
if self.check_event(yaml.events.AliasEvent):
event = self.get_event()
anchor = event.anchor
if anchor not in self.anchors:
raise yaml.composer.ComposerError(None, None, "found undefined alias %r"
% anchor, event.start_mark)
return self.anchors[anchor]
event = self.peek_event()
anchor = event.anchor
self.descend_resolver(parent, index)
if self.check_event(yaml.events.ScalarEvent):
node = self.compose_scalar_node(anchor)
elif self.check_event(yaml.events.SequenceStartEvent):
node = self.compose_sequence_node(anchor)
elif self.check_event(yaml.events.MappingStartEvent):
node = self.compose_mapping_node(anchor)
self.ascend_resolver()
return node
yaml.composer.Composer.compose_node = compose_node