Coder Social home page Coder Social logo

Comments (8)

balloob avatar balloob commented on July 25, 2024

Note that I wouldn't want people to return objects. It's mainly for lists.

from architecture.

maddox avatar maddox commented on July 25, 2024

Note that I wouldn't want people to return objects. It's mainly for lists.

Good luck communicating that and setting the right expectations :/

Are there any other cases this can solve other than lists? If not, why not name the wrapper something super specific like list() and interpret it like that? That could set better expectations.

Is simple string matching out of the question? Just checking to see if an array format is returned, and then parsing it into a list?

from architecture.

OttoWinter avatar OttoWinter commented on July 25, 2024

Are there any other cases this can solve other than lists?

I would say having templated attributes (useful for things like lights, universal media_player, ...) could also be done this way - if it's a thing Home Assistant wants to add support for.

from architecture.

balloob avatar balloob commented on July 25, 2024

Both lists and objects can already be created. See this example: home-assistant/core#12469

Maybe adding this is not needed.

from architecture.

OttoWinter avatar OttoWinter commented on July 25, 2024

Oh, that's right - good catch! We should say that it only works when the cv.template_complex is used:

https://github.com/home-assistant/home-assistant/blob/e4ef6b91d6552bb6f1d49b579f94a161944ce1a4/homeassistant/helpers/config_validation.py#L349-L360

Next, I want to point out that this doesn't always look super clean. I mean it's not a problem, but worth pointing out: Suppose we have a variable rgb_color = '255,0,255' in a script. In order to pass it into light.turn_on, we'd have to write:

service: light.turn_on
data_template:
  entity_id: ...
  rgb_color:
    - "{{ rgb_color.split(',')[0]|int }}"
    - "{{ rgb_color.split(',')[1]|int }}"
    - "{{ rgb_color.split(',')[2]|int }}"

whereas {{ json(rgb_color.split(',') | map('int') | list) }} would be a bit nicer. Again, purely cosmetical and not really a problem.

from architecture.

balloob avatar balloob commented on July 25, 2024

It would be json({{rgb_color.split(',') | map('int') | list}}) as json is not an official function but something bolted on top of the template renderer. Still looks horrible.

I've posted an example with a script with data_template to the forums and let's leave it at that for now.

from architecture.

maddox avatar maddox commented on July 25, 2024

Is it in the docs somewhere?

from architecture.

balloob avatar balloob commented on July 25, 2024

Don't think so. PR welcome 😉

from architecture.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.