• 0 Posts
  • 99 Comments
Joined 1 year ago
cake
Cake day: July 16th, 2023

help-circle
  • I looked at all the comments after I posted this and saw your full code. The suggestion I put there isn’t as nice as default(omit), but still probably much better than trying to go with this conditional route, which will probably increase code instead of reducing it. I think that should solve your problem. I didn’t really think about building the entire data payload on the fly until seeing your post, but it makes sense as a solution.


  • Ok, I think I got you. With your current setup, you’re not going to get the proper data structure, as it’s going to return all your key/value pairs as one big string. What you need to do here is create your empty dictionary, then add the key/value pairs, based on your logic, then return the resulting dictionary at the end.

    Something like this…

    kodi_control:
    sequence:
    - service: kodi.call_method
      target:
        entity_id: '{{ kodi_entity }}'
      data: >-
        {% set my_dict = {} %}
        {% set x=my_dict.__setitem__("method", {{ kodi_method }}) %}
        {% if kodi_playerid is defined %}
          {% set x=my_dict.__setitem__("playerid", {{ kodi_playerid }}) %}
        {% endif %}
        {% if kodi_action is defined %}
          {% set x=my_dict.__setitem__("action", {{ kodi_action }}) %}
        {% endif %}
        {% if kodi_value is defined %}
          {% set x=my_dict.__setitem__("value", {{ kodi_value }}) %}
        {% endif %}
        {% if kodi_window is defined %}
          {% set x=my_dict.__setitem__("window", {{ kodi_window }}) %}
        {% endif %}
        {% if kodi_parameters is defined %}
          {% set x=my_dict.__setitem__("parameters", {{ [ kodi_parameters ] }}) %}
        {% endif %}
        {{ my_dict }}
    


  • You can see if jinja filters work. Ansible has a bunch, but I’m not sure if it’s an Ansible thing or some of it is native to jinja. I know Ansible defines a lot of custom ones.

    Assuming it works, for what you’re doing it could be simplified to…

    script:
      sequence:
        target:
          entity_id: "{{ entity }}"
          data: "{{ variable | default(omit) }}"
    

    This basically says for data, use {{ variable }}, unless it doesn’t exist, in which case omit data. Omit could also be replaced with some another variable or static string (quoted) to use that as a default if {{ variable }} doesn’t exist.

    I tried quickly looking on the Home Assistant site to see if this would work and didn’t see anything, but if it’s anything like Ansible, the documentation leaves a lot of room for finding stuff through experience and leaning on other resources. I’d say try it and see what happens. That’s probably the fastest way to know if it will work.

    Depending on what data does here, you might be able to just add an else condition to set it to a blank string. That works better in some cases than others. I’m not sure if there is an “official” way to do this, but {{- '' -}} seems to work for me. I usually add those extra minus signs on everything when using jinja to avoid issues with extra spaces (those trim white space). If you don’t want to go the empty string route, or it doesn’t play well, you might be able to try NONE as well, as mentioned here.


  • I haven’t used Home Assistant, but have done a lot of Ansible with yaml and jinja2, which looks similar enough that I assume that’s what’s going on here.

    If so, the if statement can’t go anywhere, and should be part of the value of the data key.

    So it would be more like…

    script:
      sequence:
        target:
          entity_id: "{{ entity }}"
          data: >-
            {% if variable is defined %}
              {{ variable }}
            {% endif %}
    

    The >- is to define a block and trim white space. More info on that here if you care https://yaml-multiline.info/

    The indentation and spacing also matters a lot.



  • I don’t think Tim approves things the same way Jobs did.

    Apple does say this on the product page:

    The FineWoven material may show wear over time. Interaction with MagSafe accessories will leave slight imprints. If you are concerned about this, we suggest you use an iPhone 15 Pro Silicone Case or Clear Case.

    It doesn’t excuse the cutouts being bad, but they know it’s going to wear. The thing they kind do ignored is that people think old worn leather looks good, while old worn fabric generally looks bad.


  • I think the last sentence of the first paragraph was the real problem. I didn’t have that in there when I first wrote it, but then was confused on why someone would be in an Apple community who had no knowledge of the biggest Apple news over the last couple years. That could have been phrased better or excluded. I do still think someone with no knowledge of Apple Silicon doesn’t have enough context to say much on the topic. I did still provide the answer, as well. It wasn’t like my post was nothing but blind insults, which something I’ve seen from other users here.

    The fediverse seems to be blossoming quite well, despite your feelings about me.






  • Respecting the NDA becomes difficult when you’re doing the exact same job at a new company. A lot of what they know, and the reason they are being hired, is all stuff the NDA would cover. A person can’t realistically bring any ideas to the table without being influenced by their past.

    This article is about Apple Silicon, which is still pretty new (only 2-3 years old), has the whole industry re-thinking the use of off the shelf silicon, and has done amazingly well for Apple. Apple Silicon is the biggest innovation from Apple since the iPhone. I’m not sure what you’re talking about.