Skip to content

lib.config: allow attributes to be recursively applied to struct items#763

Merged
Morg42 merged 5 commits intosmarthomeNG:developfrom
Morg42:struct-attr
Feb 24, 2026
Merged

lib.config: allow attributes to be recursively applied to struct items#763
Morg42 merged 5 commits intosmarthomeNG:developfrom
Morg42:struct-attr

Conversation

@Morg42
Copy link
Copy Markdown
Member

@Morg42 Morg42 commented Feb 17, 2026

closes #723

You can insert item structs into items:

item1:
    struct: foo

or

item1:
    struct:
    - foo

If you want to recursively add attributes (e.g. enforce_updates: true or database: init or visu_acl: ro...) to all items imported from a struct, you would have to explicitly and manually define every item.

With this PR, you can do this as follows:

item1:
    struct:
    - foo:
       - enforce_updates: true

Note that:

  1. even for one struct, you need to notate a list with dashes,
  2. after the struct name, you have to add a colon : to make this a dict in yaml. Omitting the colon will prevent shng from being able to parse the yaml file.

You can add multiple struct (in the usual list format), and you can add multiple attributes (also in list format as shown). And of course you can add different attributes each time you include the same dict...

i_fn:
    struct: 
    -   my.attr.sf:
        - value: 'abc'
    -   my.attr.sn:
        - value: 2

i_f:
    struct:
    -   my.attr.sf:
        - value: 'xyz'

i_n:
    struct:
    -   my.attr.sn:
        - value: '1'

Adding nested dict structs is possible, but might lead to unforeseen consequences, as nested attributes introduce subitems to all items...

i_n:
    struct:
    -   my.attr.sn:
        - subitem:
               value: '1'

would add item subitem with value 1 (and implicit type foo) to every item in the struct...

@Morg42 Morg42 self-assigned this Feb 17, 2026
@Morg42 Morg42 requested review from bmxp and onkelandy February 17, 2026 15:37
@Morg42 Morg42 merged commit 5c8abf2 into smarthomeNG:develop Feb 24, 2026
4 checks passed
@Morg42 Morg42 deleted the struct-attr branch February 24, 2026 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant