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
|
### Let's continue
|
||||||
|
|
||||||
@ -125,6 +132,7 @@ cards:
|
|||||||
|
|
||||||
`button_card.yaml`
|
`button_card.yaml`
|
||||||
```yaml
|
```yaml
|
||||||
|
# lovelace_gen
|
||||||
{% if entity.startswith("light") %}
|
{% if entity.startswith("light") %}
|
||||||
type: light
|
type: light
|
||||||
{% else %}
|
{% else %}
|
||||||
@ -168,6 +176,7 @@ This can also be used for pictures.
|
|||||||
## Example
|
## Example
|
||||||
`ui_lovelace.yaml`
|
`ui_lovelace.yaml`
|
||||||
```yaml
|
```yaml
|
||||||
|
# lovelace_gen
|
||||||
resources:
|
resources:
|
||||||
# When you regenerate, the browser cache for this file will be invalidated
|
# When you regenerate, the browser cache for this file will be invalidated
|
||||||
- url: !file /local/card-mod.js
|
- url: !file /local/card-mod.js
|
||||||
@ -180,6 +189,7 @@ views:
|
|||||||
|
|
||||||
`lovelace/my_cool_view.yaml`
|
`lovelace/my_cool_view.yaml`
|
||||||
```yaml
|
```yaml
|
||||||
|
# lovelace_gen
|
||||||
{% set my_lights = ["light.bed_light", "light.kitchen_lights", "light.ceiling_lights"] %}
|
{% set my_lights = ["light.bed_light", "light.kitchen_lights", "light.ceiling_lights"] %}
|
||||||
title: My view
|
title: My view
|
||||||
cards:
|
cards:
|
||||||
@ -214,6 +224,7 @@ cards:
|
|||||||
|
|
||||||
`lovelace/floorplan.yaml`
|
`lovelace/floorplan.yaml`
|
||||||
```yaml
|
```yaml
|
||||||
|
# lovelace_gen
|
||||||
{% macro lamp(entity, x, y) -%}
|
{% macro lamp(entity, x, y) -%}
|
||||||
{% if lamps %}
|
{% if lamps %}
|
||||||
- type: state-icon
|
- type: state-icon
|
||||||
|
@ -3,6 +3,7 @@ import logging
|
|||||||
import json
|
import json
|
||||||
import io
|
import io
|
||||||
import time
|
import time
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
import jinja2
|
import jinja2
|
||||||
|
|
||||||
@ -15,9 +16,18 @@ jinja = jinja2.Environment(loader=jinja2.FileSystemLoader("/"))
|
|||||||
|
|
||||||
def load_yaml(fname, args={}):
|
def load_yaml(fname, args={}):
|
||||||
try:
|
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 = io.StringIO(jinja.get_template(fname).render(args))
|
||||||
stream.name = fname
|
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:
|
except loader.yaml.YAMLError as exc:
|
||||||
_LOGGER.error(str(exc))
|
_LOGGER.error(str(exc))
|
||||||
raise HomeAssistantError(exc)
|
raise HomeAssistantError(exc)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user