'Bind a template to a specific hass instance.'

def _ensure_compiled(self):

    if (self._compiled is not None):
        return
    self.ensure_valid()
    assert (self.hass is not None), 'hass    variable    not    set    on    template'
    location_methods = LocationMethods(self.hass)
    global_vars = ENV.make_globals({'closest': location_methods.closest, 'distance': location_methods.distance, 'is_state': self.hass.states.is_state, 'is_state_attr': self.hass.states.is_state_attr, 'states': AllStates(self.hass)})
    self._compiled = jinja2.Template.from_code(ENV, self._compiled_code, global_vars, None)
    return self._compiled
