thomasloven / hass-lovelace_gen

🔹 Improve the lovelace yaml parser for Home Assistant
MIT License
209 stars 22 forks source link

[Feature Request] Split lovelace_gen based UI YAML file #48

Open theone11 opened 1 year ago

theone11 commented 1 year ago

I would like to request a feature for "simple" splitting of lovelace_gen based UI YAML file.

I think it will also solve, or give possible solution for https://github.com/thomasloven/hass-lovelace_gen/issues/32

I have a ~2100 lines UI YAML file very heavily relying on lovelace_gen that includes Variable, Macros, loops, etc... (If not for lovelace_gen the code will be ~7500 lines) https://github.com/theone11/HomeAssistantConfig/blob/master/lovelace_new_data.yaml

I want to split the YAML file into multiple YAML files but not in the "regular" HomeAssistant !include way - I don't think it is possible in my case (I have tried many ways) - And if there is a way it may need for me to repeat some of the variables and macros in each of the files.

I want to split the YAML files by cutting the files wherever I want and that lovelace_gen will concatenate the files before processing them (the cut files will keep the original identation required by YAML) - See simple example below.

The files to concatenate (include) can be listed just after the # lovelace_gen command so lovelace_gen "knows" to concatenate all files before proceeding with the processing of the code:

# lovelace_gen_include <filename.yaml>

or

# lovelace_gen_include_dir <folder_name>

For example if I have a single file:

UI.yaml

# lovelace_gen

{% set ... %}
{% set ... %}

{% macro ... -%}
{%- endmacro %}

{% macro ... -%}
{%- endmacro %}

title: Home
views:
  - badges: []
    icon: 'mdi:home-outline'
    panel: true
    path: floorplan
    title: FloorPlan
    cards:
      - type: picture-elements
        image: /local/images/floorplan/background_t.png
        elements:
          - type: image
            entity: cover.cover1
            ...
          - type: image
            entity: cover.cover2
            ...
          - type: image
            entity: cover.cover3
            ...
          - type: image
            entity: light.light1
            ...
          - type: image
            entity: light.light2
            ...
          - type: image
            entity: light.light3
            ...

I would like it to be able to split it up like so:

UI.yaml

# lovelace_gen
# lovelace_gen_include UI_1.yaml
# lovelace_gen_include UI_2.yaml
# lovelace_gen_include UI_3.yaml

{% set ... %}
{% set ... %}

{% macro ... -%}
{%- endmacro %}

{% macro ... -%}
{%- endmacro %}

UI_1.yaml

title: Home
views:
  - badges: []
    icon: 'mdi:home-outline'
    panel: true
    path: floorplan
    title: FloorPlan
    cards:
      - type: picture-elements
        image: /local/images/floorplan/background_t.png
        elements:

UI_2.yaml

          - type: image
            entity: cover.cover1
            ...
          - type:image
            entity: cover.cover2
            ...
          - type: image
            entity: cover.cover3
            ...

UI_3.yaml

          - type: image
            entity: light.light1
            ...
          - type: image
            entity: light.light2
            ...
          - type: image
            entity: light.light3
            ...