twrecked / hass-virtual

Virtual Components for Home Assistant
GNU General Public License v3.0
167 stars 28 forks source link

Cover: adding several devices causes an error if yaml-anchor is used #128

Open ildar170975 opened 3 months ago

ildar170975 commented 3 months ago

Consider this code:

version: 1
devices:
  Test Cover:
    - platform: cover
      initial_value: 'closed'
      open_close_duration: 5
      open_close_tick: 1

  Test Cover abc:
    - platform: cover
      initial_value: 'closed'
      open_close_duration: 5
      open_close_tick: 1

Trying to add these covers: изображение

Seems that 2 covers are created properly: изображение

And no errors/warnings in Log.

Then consider this code:

version: 1
devices:
  Test Cover: &ref_settings
    - platform: cover
      initial_value: 'closed'
      open_close_duration: 5
      open_close_tick: 1

  Test Cover abc: *ref_settings

which is supposed to produce same result. But it gives an error: изображение

No covers are created.

There is an error in Log: 2024-08-23 19:36:40.903 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry imported - virtual for virtual Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 604, in async_setup result = await component.async_setup_entry(hass, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/virtual/init.py", line 149, in async_setup_entry await vcfg.async_load() File "/config/custom_components/virtual/cfg.py", line 306, in async_load platform = entity.pop(CONF_PLATFORM) ^^^^^^^^^^^^^^^^^^^^^^^^^ KeyError: 'platform'

ildar170975 commented 3 months ago

Mysteriously this variant works:

version: 1
devices:
  Test Cover:
    - <<: &ref_settings
        platform: cover
        initial_value: 'closed'
        open_close_duration: 5
        open_close_tick: 1

  Test Cover abc:
    - *ref_settings

and this - does NOT:

version: 1
devices:
  Test Cover:
    - <<: &ref_settings
        platform: cover
        initial_value: 'closed'
        open_close_duration: 5
        open_close_tick: 1

  Test Cover abc:
    - *ref_settings
  Test Cover xyz:
    - *ref_settings

The glitch could be related somehow to an omitted "name" option - this code works (creates 3 covers):

version: 1
devices:
  Test Cover:
    - <<: &ref_settings
        platform: cover
        initial_value: 'closed'
        open_close_duration: 5
        open_close_tick: 1
      name: testing_cover

  Test Cover abc:
    - <<: *ref_settings
      name: testing_cover_abc
  Test Cover xyz:
    - <<: *ref_settings
      name: testing_cover_xyz