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

More bug fixes, improvements, and features #159

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

PaulSD
Copy link

@PaulSD PaulSD commented Feb 22, 2025

Primary changes:

  • Use strict mode in eval() to keep the global javascript variable namespace clean.
  • Allow ${} syntax in variables
  • Allow disabling template parsing per value using a $! prefix
  • Add support for "static" variables that are evaluated once when the card is loaded, rather than on every update
  • Add support for templates that return Promises / use asynchronous functions. (Based on Allow async evaluation in special mode #149, with some changes/improvements.)

After this is merged, my opinion is that the dev branch is good enough to be merged into master.
However, of course, feel free to leave this in dev for now and do another beta release if you aren't comfortable with merging into master yet.

Closes #149.

Specifically, support ${} in variables, multiple templates in variables,
and nested templates in data structures.
These will be evaluated only on the first update/render, and will be
preserved without re-evaluation for subsequent updates.

These may be used to manage the performance impact of expensive
operations, by eliminating unnecessary re-evaluations.
@ildar170975
Copy link
Collaborator

Seems to be very massive work.
Separate thanks for "Upload Artifacts".
Will test.

Meanwhile, some FRs (could be implemented separately if possible):

  1. Is it possible to add a config variable (stands for a config of a card) as available in templates?
  2. Is it possible to make this scenario
variables:
  xxx: !secret my_super_secret

supported?

@PaulSD
Copy link
Author

PaulSD commented Feb 23, 2025

Is it possible to add a config variable (stands for a config of a card) as available in templates?

You mean you want the full original config of CTC (before evaluation of templates) available as a variable? Yeah, I can probably do that. Do you have an example of how you might use that, so I can make sure I implement this in a way that supports what you are trying to do?

!secret my_super_secret

Unfortunately this one isn't easy. !secret is processed by the YAML parser on the HA server, and I think it is only processed when parsing configuration.yaml (not when parsing any other YAML) ... If it isn't already being processed by HA before handing the config off to CTC, then I think the only way to handle this would be to modify HA itself to do that. (There is nothing CTC can do using the current HA APIs to handle that.)

@ildar170975
Copy link
Collaborator

You mean you want the full original config of CTC (before evaluation of templates) available as a variable? Yeah, I can probably do that. Do you have an example of how you might use that, so I can make sure I implement this in a way that supports what you are trying to do?

Thanks in advance! I decided to create a separate FR (#160) to avoid cluttering of this PR.

!secret is processed by the YAML parser on the HA server, and I think it is only processed when parsing configuration.yaml (not when parsing any other YAML)

Sad... We can use secrets in lovelace yaml like:

type: history-graph
hours_to_show: !secret xxxxxx

so I thought may be it could be possible to use them inside variables.

Thanks again!
Will keep testing these changes.

@PaulSD PaulSD force-pushed the master branch 2 times, most recently from 7a4af80 to 5111820 Compare February 24, 2025 04:09
Co-authored-by: Paul Donohue <git@PaulSD.com>
Co-authored-by: Mike A. <git@mikealmel.ooo>
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.

2 participants