thomasloven / hass-lovelace_gen

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

Incompatible with 2022.7? #39

Open IDmedia opened 1 year ago

IDmedia commented 1 year ago

Tried upgrading HA to 2022.7 and I'm getting "Unknown error" without any errors in the console or logs. Can't get the UI to show until I comment out my lovelace_gen include. Anyone else having this issue?

Example from my UI-lovelace.yaml file causing the error:

      - !include
        - lovelace/xiaomi_vacuum.yaml
        - vacuum: vacuum.rockrobo_2nd_floor
          camera: camera.rockrobo_2nd_floor_map
          zones: input_select.rockrobo_2nd_floor_zones
          title: Second Floor Vacuum
chriscolden commented 1 year ago

I'm having the issue and commenting out some of my includes makes it work, but i cannot for the life of me see why those are causing it to fail. Doesn't seem to be anything in the breaking changes of 2022.7 that would apply to me.

IDmedia commented 1 year ago

The only thing I can see is that Home Assistant changed to Python 3.10 and that the jinja2 package has been updated and the integration doesn't pin the version: https://github.com/pallets/jinja/releases

Can't yet see why it should break though.

robertklep commented 1 year ago

I think it has to do with "Our YAML & JSON tooling improved, using faster libraries and methods".

Other than with lovelace_gen I also had some issues with emoji's in template strings.

But it's a strange issue: my YAML files using lovelace_gen are working fine when included in my "desktop" dashboard, yet the exact same files are throwing an error when included in my "phone" dashboard.

chriscolden commented 1 year ago

Bit more digging, i found this in my log file.

File "/usr/local/lib/python3.10/site-packages/jinja2/loaders.py", line 195, in get_source
    pieces = split_template_path(template)
  File "/usr/local/lib/python3.10/site-packages/jinja2/loaders.py", line 36, in split_template_path
    raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: /config/lovelace/dashboards/../views/office.yaml

Path is correct, if i remove # lovelace_gen and change to a standard card include in that file (ie no jinja2) it picks up the file in that location.

edit

Some more oddities.

icon: mdi:home-assistant
title: Room
cards:
  - !include
    - ../cards/heating.yaml
    - entity: office

This works with multi level attributes but no # lovelace_gen at the top of the file. Something very weird is going on. add # lovelace_gen at the top and it breaks.

chriscolden commented 1 year ago

So dug into the changes in the core yaml loader which this imports and it seems references to SafeLineLoader have been replaced with LoaderType

I've not tested yet, but I'm guessing these two lines.

loader.SafeLineLoader.add_constructor("!include", _include_yaml)
loader.SafeLineLoader.add_constructor("!file", _uncache_file)

Need to change.

chriscolden commented 1 year ago

So just pored over the jinja2 loader.py file and found that split_template_path will throw a template not found if the path has a .. in it. I was doing this to keep cards, dashboards and views seperate. Soon as moved them all into the same directory its started working. Not saying the lovelace_gen doesn't need some work to follow the improvements made in the latest release as it does look like it does to me, but will leave that up to @thomasloven

IDmedia commented 1 year ago

@chriscolden Does it mean it then works for you on the latest version of HA? I'm still struggling to get it to work at all after upgrading

chriscolden commented 1 year ago

yeah im working again it would seem. i had a directory structure of config/lovelace/cards config/lovelace/dashboards config/lovelace/views

which means i had to ../ out the directory to get to my next inlcude.

Just moved to config/lovelace/dashboards config/lovelace/dashboards/views config/lovelace/dashboards/views/cards

then replaced ../ with ./

and it seems to have sprung into life.

chriscolden commented 1 year ago

@IDmedia do you see this in your logs when you load a dashboard?

jinja2.exceptions.TemplateNotFound: /config/lovelace/dashboards/../views/office.yaml

IDmedia commented 1 year ago

No, I'm not using '..' in the path. No visible errors in the logs or console except the "unknown error" message when trying to view the dashboard.

chriscolden commented 1 year ago

you will have to post some examples. maybe create a new dashboard for testing, or at least comment out most of it and post whats not working for you.

IDmedia commented 1 year ago

you will have to post some examples. maybe create a new dashboard for testing, or at least comment out most of it and post whats not working for you.

The example is in the initial post (same goes for the path). Once I comment the lovelace_gen yaml out everything works so I know it's causing the issue. Something changed in the latest version of HA, just not sure what yet.

chriscolden commented 1 year ago

So what's in the lovelace/xiaomi_vacuum.yaml file? just standard yaml?

chriscolden commented 1 year ago

Did you see this about that file.

Important: For some reason, which I can't seem to nail down, things stop working if you add # lovelace_gen to ui-lovelace.yaml. Adding it to any file included from ui-lovelace.yaml works, though.

chriscolden commented 1 year ago

I'm not using lovelace_gen in that file. mines still on storage mode, and i include a separate dashboards which use lovelace_gen. thats the only think i can glean here.

hahagana4b commented 1 year ago

Anyone was able to sort it out? It still not working for me in the new 2022.7 version

chriscolden commented 1 year ago

It's working for me now so you will need to post your config.

Idan37S commented 1 year ago

Mine isn't working as well, This is my config:

configuration.yaml -

lovelace:
  mode: storage
  dashboards:
    lovelace-floorplan-desktop:
      mode: yaml
      title: FloorPlan Desktop
      icon: mdi:floor-plan
      show_in_sidebar: true
      filename: lovelace_floorplan_desktop.yaml

lovelace_floorplan_desktop.yaml -

title: FloorPlan Desktop
views:
  - !include 
    - lovelace_floorplan_data.yaml
    - floorplan_type: desktop

lovelace_floorplan_data.yaml - i'm using {% raw %} and {% endraw %} in some parts. other then that nothing special

chriscolden commented 1 year ago

Sounds stupid, but try adding ./lovelace_floorplan_data.yaml

Idan37S commented 1 year ago

Didn't work unfortunately.

If I remove both the includes only then it works (rendering an empty page)

chriscolden commented 1 year ago

Can you post your lovelace_floorplan_data.yaml view.

Edit: lovelace_floorplan_desktop.yaml does that have a # lovelace_gen at the top?

Idan37S commented 1 year ago

Yes it has "# lovelace_gen" on top, and so does the lovelace_floorplan_data.yaml file

Idan37S commented 1 year ago

This is the lovelace_floorplan_data.yaml file, A bit long but pretty well structured I think: https://pastebin.com/ShcN5VcJ

chriscolden commented 1 year ago

so i just dumped your pastebin into a view and included it in mine. it doesn't render properly but i did get this.

image

Idan37S commented 1 year ago

That's interesting, seems like if you had the entities\images it would work, i just get an "unknown error". Can you please share the "view" code you used and the configuration code regarding the lovelace_gen?

chriscolden commented 1 year ago

Sure. I've just had to pop out so will do that later today.

Idan37S commented 1 year ago

Thanks @chriscolden, I really appreciate it.

chriscolden commented 1 year ago

Hey, sorry ran out of time yesterday. I've included all the way down to one of my most complex cards but haven't included all the cards the view includes. Nothing is out there. I dont use macros but everything else is pretty much the same as what you have.

https://pastebin.com/qazQXaZe

Idan37S commented 1 year ago

Thanks a lot @chriscolden! I will try to debug it and check the differences

Idan37S commented 1 year ago

I find out that it's the variables that causing it to not work for some reason.

Doesn't work:

views:
  - !include 
    - lovelace_floorplan_data.yaml
    - floorplan_type: mobile

Works:

views:
  - !include lovelace_floorplan_data.yaml

Anyone knows why or how to solve it?

Rudinskas commented 1 year ago

I cannot make work the yaml with includes function. I want to make optimization of ui-lovelace.yaml, but for me, the folder structure, does not work. Logs do not tell me what is wrong.

My configuration.yaml has:

    lovelace-irrigation:
      mode: yaml
      title: test
      show_in_sidebar: true
      filename: test.yaml 

In the left menu, I see the button name "Test", but when I click on it it shows only yaml cards that are in it, but not what is included. My code of test.yaml:

# lovelace_gen
title: Test
views:
  - ! includes lovelace\test.yaml 

lovelace\test.yaml has code:

title: My view
cards:        
  - entities:
      - entity: automation.gate_auto_open_when_i_arrive_to_home
      - entity: cover.main_gate
      - entity: sensor.main_gate_status
    show_header_toggle: false
    title: Main gate
    type: entities

Can somebody help to debug this issue?

Thank you in advance!

chriscolden commented 1 year ago

You have a space after your ! And an s on the end. It should be.

!include lovelace\test.yaml

Rudinskas commented 1 year ago

You have a space after your ! And an s on the end. It should be.

!include lovelace\test.yaml

Thank you! It works! I had the wrong guide.

rohankapoorcom commented 1 year ago

I just put up a PR that should fix this in #42. It undoes the performance improvement (using the C Loader for YAML) from Home Assistant 2022.7, but that seems to be an acceptable trade off.

nnhhuu commented 1 year ago

I just put up a PR that should fix this in #42. It undoes the performance improvement (using the C Loader for YAML) from Home Assistant 2022.7, but that seems to be an acceptable trade off.

Thank you, this solved my problem!!!! now i'm runing 2022.10 without a problem..