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

Added new filters for templates #18125

Merged
merged 3 commits into from
Dec 1, 2018
Merged

Added new filters for templates #18125

merged 3 commits into from
Dec 1, 2018

Conversation

skalavala
Copy link
Contributor

@skalavala skalavala commented Nov 2, 2018

Description:

Added base64 encode, base64 decode and ordinal filters for templates.

Related issue (if applicable): fixes #

Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#<home-assistant.io PR number goes here>

Example entry for configuration.yaml (if applicable):

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

Added base64_encode, base64_decode and ordinal filters.
added test cases for base64_encode, base64_decode and ordinal filters.
@skalavala skalavala requested a review from a team as a code owner November 2, 2018 17:14
@ghost ghost added the in progress label Nov 2, 2018
@skalavala skalavala changed the title Added new filters for Jinja Added new filters for templates Nov 2, 2018
@balloob
Copy link
Member

balloob commented Nov 3, 2018

use case?

@skalavala
Copy link
Contributor Author

use case?

The ordinal filter is used to display properly formatted text in the UI, as well as for TTS. I can now announce that it is "65th birthday" instead of instead of "65 years old".

The base64_encode and decode are used for the curl command that expects header variables in base64 encoded format. Without this, there is no way to pass base64 encoded variables using templates. 😄

@balloob
Copy link
Member

balloob commented Nov 5, 2018

We don't have a curl command?

@skalavala
Copy link
Contributor Author

We don't have a curl command?

We don't have curl command. We have shell_command and rest_command that people normally use.

@balloob
Copy link
Member

balloob commented Nov 6, 2018

I don't find that a good reason to add base64 to our templating engine. People can have their shell command call a script that does the encoding? I'm a bit scared of turning our template engine into a data preparation tool for all possible CLIs out there.

@pvizeli
Copy link
Member

pvizeli commented Nov 6, 2018

Base64 could be fine, because it's hard to do this with shell scripts and make rest_command more powerful but the other one for 65th is strange.

@skalavala
Copy link
Contributor Author

Base64 could be fine, because it's hard to do this with shell scripts and make rest_command more powerful but the other one for 65th is strange.

I added the ordinal filter only because we get number of people in the forum asking for it for their tts or for display in the UI. We can remove that if we don't want it support that.

However, addition of base64 en/decoding would be very useful and currently there is no clean way of implementing that effectively when using the services like rest_command or shell_command.

Copy link
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be merged when docs added

@pvizeli pvizeli merged commit c23792d into home-assistant:dev Dec 1, 2018
@ghost ghost removed the in progress label Dec 1, 2018
@balloob balloob mentioned this pull request Dec 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants