Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow async evaluation in special mode #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

malmeloo
Copy link

Adds async configuration value which allows using await (and other async constructs) in templates. Hidden behind a config option because the change is not backwards-compatible; see README changes for documentation.

Useful if you want to e.g. make a websocket request, example:

type: custom:config-template-card
entities:
  - ${vars.sonos_id.entity_id}
variables:
  sonos_id: states["media_player.keuken"]
  base_card:
    camera_view: auto
    type: picture-glance
    entities: []
    aspect_ratio: "1:1"
  getFavorites: |
    async () => {
      const favs = await this.hass.callWS({
        "type": "media_player/browse_media",
        "entity_id": vars.sonos_id.entity_id,
        "media_content_id": "object.item.audioItem.audioBroadcast",
        "media_content_type": "favorites_folder"
      })

      return favs.children.filter(
        (fav) => fav.can_play
      );
    }
  getCard: |
    (fav) => {
      return Object.assign({}, vars.base_card, {
        title: fav.title,
        image: fav.thumbnail
      })
    }
async: true
card:
  type: grid
  cards: ${return (await getFavorites()).map(getCard))

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