Stop lovelace_gen from breaking all the yaml which is not in lovelace...
This commit is contained in:
parent
878a96c3b9
commit
483172d83c
11
README.md
11
README.md
@ -28,6 +28,13 @@ To rerender the frontend, use the Refresh option from the three-dots-menu in Lov
|
||||
|
||||

|
||||
|
||||
### Second of all
|
||||
|
||||
Any yaml file that is to be processed with `lovelace_gen` *MUST* have the following as its first line:
|
||||
|
||||
```yaml
|
||||
# lovelace_gen
|
||||
```
|
||||
|
||||
### Let's continue
|
||||
|
||||
@ -125,6 +132,7 @@ cards:
|
||||
|
||||
`button_card.yaml`
|
||||
```yaml
|
||||
# lovelace_gen
|
||||
{% if entity.startswith("light") %}
|
||||
type: light
|
||||
{% else %}
|
||||
@ -168,6 +176,7 @@ This can also be used for pictures.
|
||||
## Example
|
||||
`ui_lovelace.yaml`
|
||||
```yaml
|
||||
# lovelace_gen
|
||||
resources:
|
||||
# When you regenerate, the browser cache for this file will be invalidated
|
||||
- url: !file /local/card-mod.js
|
||||
@ -180,6 +189,7 @@ views:
|
||||
|
||||
`lovelace/my_cool_view.yaml`
|
||||
```yaml
|
||||
# lovelace_gen
|
||||
{% set my_lights = ["light.bed_light", "light.kitchen_lights", "light.ceiling_lights"] %}
|
||||
title: My view
|
||||
cards:
|
||||
@ -214,6 +224,7 @@ cards:
|
||||
|
||||
`lovelace/floorplan.yaml`
|
||||
```yaml
|
||||
# lovelace_gen
|
||||
{% macro lamp(entity, x, y) -%}
|
||||
{% if lamps %}
|
||||
- type: state-icon
|
||||
|
@ -3,6 +3,7 @@ import logging
|
||||
import json
|
||||
import io
|
||||
import time
|
||||
from collections import OrderedDict
|
||||
|
||||
import jinja2
|
||||
|
||||
@ -15,9 +16,18 @@ jinja = jinja2.Environment(loader=jinja2.FileSystemLoader("/"))
|
||||
|
||||
def load_yaml(fname, args={}):
|
||||
try:
|
||||
ll_gen = False
|
||||
with open(fname, encoding="utf-8") as f:
|
||||
if f.readline().lower().startswith("# lovelace_gen"):
|
||||
ll_gen = True
|
||||
|
||||
if ll_gen:
|
||||
stream = io.StringIO(jinja.get_template(fname).render(args))
|
||||
stream.name = fname
|
||||
return loader.yaml.load(stream, Loader=loader.SafeLineLoader) or {}
|
||||
return loader.yaml.load(stream, Loader=loader.SafeLineLoader) or OrderedDict()
|
||||
else:
|
||||
with open(fname, encoding="utf-8") as config_file:
|
||||
return loader.yaml.load(config_file, Loader=loader.SafeLineLoader) or OrderedDict()
|
||||
except loader.yaml.YAMLError as exc:
|
||||
_LOGGER.error(str(exc))
|
||||
raise HomeAssistantError(exc)
|
||||
|
Loading…
x
Reference in New Issue
Block a user