def __init__(self, hass, limited=False, strict=False):
    'Initialise template environment.'
    if (not strict):
        undefined = LoggingUndefined
    else:
        undefined = jinja2.StrictUndefined
    super().__init__(undefined=undefined)
    self.hass = hass
    self.template_cache = weakref.WeakValueDictionary()
    self.filters['round'] = forgiving_round
    self.filters['multiply'] = multiply
    self.filters['log'] = logarithm
    self.filters['sin'] = sine
    self.filters['cos'] = cosine
    self.filters['tan'] = tangent
    self.filters['asin'] = arc_sine
    self.filters['acos'] = arc_cosine
    self.filters['atan'] = arc_tangent
    self.filters['atan2'] = arc_tangent2
    self.filters['sqrt'] = square_root
    self.filters['as_timestamp'] = forgiving_as_timestamp
    self.filters['as_local'] = dt_util.as_local
    self.filters['timestamp_custom'] = timestamp_custom
    self.filters['timestamp_local'] = timestamp_local
    self.filters['timestamp_utc'] = timestamp_utc
    self.filters['to_json'] = to_json
    self.filters['from_json'] = from_json
    self.filters['is_defined'] = fail_when_undefined
    self.filters['max'] = max
    self.filters['min'] = min
    self.filters['random'] = random_every_time
    self.filters['base64_encode'] = base64_encode
    self.filters['base64_decode'] = base64_decode
    self.filters['ordinal'] = ordinal
    self.filters['regex_match'] = regex_match
    self.filters['regex_replace'] = regex_replace
    self.filters['regex_search'] = regex_search
    self.filters['regex_findall_index'] = regex_findall_index
    self.filters['bitwise_and'] = bitwise_and
    self.filters['bitwise_or'] = bitwise_or
    self.filters['ord'] = ord
    self.globals['log'] = logarithm
    self.globals['sin'] = sine
    self.globals['cos'] = cosine
    self.globals['tan'] = tangent
    self.globals['sqrt'] = square_root
    self.globals['pi'] = math.pi
    self.globals['tau'] = (math.pi * 2)
    self.globals['e'] = math.e
    self.globals['asin'] = arc_sine
    self.globals['acos'] = arc_cosine
    self.globals['atan'] = arc_tangent
    self.globals['atan2'] = arc_tangent2
    self.globals['float'] = forgiving_float
    self.globals['as_local'] = dt_util.as_local
    self.globals['as_timestamp'] = forgiving_as_timestamp
    self.globals['relative_time'] = relative_time
    self.globals['timedelta'] = timedelta
    self.globals['strptime'] = strptime
    self.globals['urlencode'] = urlencode
    self.globals['max'] = max
    self.globals['min'] = min
    if (hass is None):
        return

    def hassfunction(func):
        'Wrap function that depend on hass.'

        @wraps(func)
        def wrapper(*args, **kwargs):
            return func(hass, *args[1:], **kwargs)
        return contextfunction(wrapper)
    self.globals['device_entities'] = hassfunction(device_entities)
    self.filters['device_entities'] = contextfilter(self.globals['device_entities'])
    if limited:

        def unsupported(name):

            def warn_unsupported(*args, **kwargs):
                raise TemplateError(f"Use of '{name}' is not supported in limited templates")
            return warn_unsupported
        hass_globals = ['closest', 'distance', 'expand', 'is_state', 'is_state_attr', 'state_attr', 'states', 'utcnow', 'now']
        hass_filters = ['closest', 'expand']
        for glob in hass_globals:
            self.globals[glob] = unsupported(glob)
        for filt in hass_filters:
            self.filters[filt] = unsupported(filt)
        return
    self.globals['expand'] = hassfunction(expand)
    self.filters['expand'] = contextfilter(self.globals['expand'])
    self.globals['closest'] = hassfunction(closest)
    self.filters['closest'] = contextfilter(hassfunction(closest_filter))
    self.globals['distance'] = hassfunction(distance)
    self.globals['is_state'] = hassfunction(is_state)
    self.globals['is_state_attr'] = hassfunction(is_state_attr)
    self.globals['state_attr'] = hassfunction(state_attr)
    self.globals['states'] = AllStates(hass)
    self.globals['utcnow'] = hassfunction(utcnow)
    self.globals['now'] = hassfunction(now)
Initialise template environment.
def __init__(self, hass, limited=False, strict=False):
    
    if (not strict):
        undefined = LoggingUndefined
    else:
        undefined = jinja2.StrictUndefined
    super().__init__(undefined=undefined)
    self.hass = hass
    self.template_cache = weakref.WeakValueDictionary()
    self.filters['round'] = forgiving_round
    self.filters['multiply'] = multiply
    self.filters['log'] = logarithm
    self.filters['sin'] = sine
    self.filters['cos'] = cosine
    self.filters['tan'] = tangent
    self.filters['asin'] = arc_sine
    self.filters['acos'] = arc_cosine
    self.filters['atan'] = arc_tangent
    self.filters['atan2'] = arc_tangent2
    self.filters['sqrt'] = square_root
    self.filters['as_timestamp'] = forgiving_as_timestamp
    self.filters['as_local'] = dt_util.as_local
    self.filters['timestamp_custom'] = timestamp_custom
    self.filters['timestamp_local'] = timestamp_local
    self.filters['timestamp_utc'] = timestamp_utc
    self.filters['to_json'] = to_json
    self.filters['from_json'] = from_json
    self.filters['is_defined'] = fail_when_undefined
    self.filters['max'] = max
    self.filters['min'] = min
    self.filters['random'] = random_every_time
    self.filters['base64_encode'] = base64_encode
    self.filters['base64_decode'] = base64_decode
    self.filters['ordinal'] = ordinal
    self.filters['regex_match'] = regex_match
    self.filters['regex_replace'] = regex_replace
    self.filters['regex_search'] = regex_search
    self.filters['regex_findall_index'] = regex_findall_index
    self.filters['bitwise_and'] = bitwise_and
    self.filters['bitwise_or'] = bitwise_or
    self.filters['ord'] = ord
    self.globals['log'] = logarithm
    self.globals['sin'] = sine
    self.globals['cos'] = cosine
    self.globals['tan'] = tangent
    self.globals['sqrt'] = square_root
    self.globals['pi'] = math.pi
    self.globals['tau'] = (math.pi * 2)
    self.globals['e'] = math.e
    self.globals['asin'] = arc_sine
    self.globals['acos'] = arc_cosine
    self.globals['atan'] = arc_tangent
    self.globals['atan2'] = arc_tangent2
    self.globals['float'] = forgiving_float
    self.globals['as_local'] = dt_util.as_local
    self.globals['as_timestamp'] = forgiving_as_timestamp
    self.globals['relative_time'] = relative_time
    self.globals['timedelta'] = timedelta
    self.globals['strptime'] = strptime
    self.globals['urlencode'] = urlencode
    self.globals['max'] = max
    self.globals['min'] = min
    if (hass is None):
        return

    def hassfunction(func):
        'Wrap function that depend on hass.'

        @wraps(func)
        def wrapper(*args, **kwargs):
            return func(hass, *args[1:], **kwargs)
        return contextfunction(wrapper)
    self.globals['device_entities'] = hassfunction(device_entities)
    self.filters['device_entities'] = contextfilter(self.globals['device_entities'])
    if limited:

        def unsupported(name):

            def warn_unsupported(*args, **kwargs):
                raise TemplateError(f"Use of '{name}' is not supported in limited templates")
            return warn_unsupported
        hass_globals = ['closest', 'distance', 'expand', 'is_state', 'is_state_attr', 'state_attr', 'states', 'utcnow', 'now']
        hass_filters = ['closest', 'expand']
        for glob in hass_globals:
            self.globals[glob] = unsupported(glob)
        for filt in hass_filters:
            self.filters[filt] = unsupported(filt)
        return
    self.globals['expand'] = hassfunction(expand)
    self.filters['expand'] = contextfilter(self.globals['expand'])
    self.globals['closest'] = hassfunction(closest)
    self.filters['closest'] = contextfilter(hassfunction(closest_filter))
    self.globals['distance'] = hassfunction(distance)
    self.globals['is_state'] = hassfunction(is_state)
    self.globals['is_state_attr'] = hassfunction(is_state_attr)
    self.globals['state_attr'] = hassfunction(state_attr)
    self.globals['states'] = AllStates(hass)
    self.globals['utcnow'] = hassfunction(utcnow)
    self.globals['now'] = hassfunction(now)