thomasloven / hass-lovelace_gen

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

Beta kills lovelace gen #56

Closed Petro31 closed 11 months ago

Petro31 commented 11 months ago

Latest HA kills lovelace gen

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 26, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/lovelace/websocket.py", line 38, in send_with_error_handling
    result = await func(hass, connection, msg, config)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/lovelace/websocket.py", line 90, in websocket_lovelace_config
    return await config.async_load(msg["force"])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/lovelace/dashboard.py", line 185, in async_load
    is_updated, config = await self.hass.async_add_executor_job(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/lovelace/dashboard.py", line 204, in _load_config
    config = load_yaml(self.path, Secrets(Path(self.hass.config.config_dir)))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/yaml/loader.py", line 155, in load_yaml
    return parse_yaml(conf_file, secrets)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/yaml/loader.py", line 168, in parse_yaml
    return _parse_yaml(FastSafeLoader, content, secrets)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/yaml/loader.py", line 198, in _parse_yaml
    yaml.load(content, Loader=lambda stream: loader(stream, secrets))  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/yaml/__init__.py", line 81, in load
    return loader.get_single_data()
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/yaml/constructor.py", line 51, in get_single_data
    return self.construct_document(node)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/yaml/constructor.py", line 55, in construct_document
    data = self.construct_object(node)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/yaml/constructor.py", line 100, in construct_object
    data = constructor(self, node)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/yaml/loader.py", line 330, in _handle_mapping_tag
    nodes = loader.construct_pairs(node)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/yaml/constructor.py", line 155, in construct_pairs
    value = self.construct_object(value_node, deep=deep)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/yaml/constructor.py", line 100, in construct_object
    data = constructor(self, node)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/yaml/loader.py", line 249, in _include_yaml
    return _add_reference(load_yaml(fname, loader.secrets), loader, node)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/lovelace_gen/__init__.py", line 34, in load_yaml
    return loader.yaml.load(stream, Loader=lambda _stream: loader.SafeLineLoader(_stream, secrets)) or OrderedDict()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/yaml/__init__.py", line 79, in load
    loader = Loader(stream)
             ^^^^^^^^^^^^^^
  File "/config/custom_components/lovelace_gen/__init__.py", line 34, in <lambda>
    return loader.yaml.load(stream, Loader=lambda _stream: loader.SafeLineLoader(_stream, secrets)) or OrderedDict()
                                                           ^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'homeassistant.util.yaml.loader' has no attribute 'SafeLineLoader'

Seems like an issue w/ the upstream library. I'll look into it later, just documenting atm.

Petro31 commented 11 months ago

The yaml loaders were renamed in this commit

https://github.com/home-assistant/core/commit/e49f6b41eeb1009fe00376e1358c85739312a302

Looks like a quick bandaide would be to change all references to SafeLoader to FastSafeLoader. I'll give it a try when I get home today.

Oh and 'SafeLineLoader->PythonSafeLoader`

Petro31 commented 11 months ago

There's a new error w/ beta2 which breaks this again. I won't have time to look at it until next week, which will be after the release.

tbrasser commented 11 months ago

This seems to work for me :) #58

thomasloven commented 11 months ago

The fix by @tbrasser has been released!