Skip to content

Instantly share code, notes, and snippets.

@AlexxIT
Last active March 5, 2020 14:50
Show Gist options
  • Save AlexxIT/c0f3dff945ee2f9154e99864a14d8174 to your computer and use it in GitHub Desktop.
Save AlexxIT/c0f3dff945ee2f9154e99864a14d8174 to your computer and use it in GitHub Desktop.
Extend Home Assistant jinja2 Templates
# положи меня /config/custom_components/__init__.py
# но лучше не страдай х..нёй и поставь Node-RED
import urllib.parse
from homeassistant.helpers import template
_TemplateEnvironment = template.TemplateEnvironment
def unquote(value):
""" {{ '%20тест%5Bжанр%5D'|unquote }} """
return urllib.parse.unquote(value)
def monkey(*args):
env = _TemplateEnvironment(*args)
env.filters['unquote'] = unquote
return env
template.TemplateEnvironment = monkey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment