core/tests/components/template
akloeckner d20a620590
Make `this` variable available in template entities (#65201)
* feat: make this variable available in template entities

This makes the variable `this` available in template entities.
It will simplify the use of self-referencing template entities.
Because, without this, we have to repeat the entity id every time.
If we can solve this without explicitly spelling the entity id,
code can be re-used much better.

As a side-effect, this will allow to use `variables`-like patterns,
where attributes can be used as variables to calculate subsequent attributes or state.

Example:
```yaml
template:
  sensor:
    - name: test
      state: "{{ this.attributes.test }}"
      # not: "{{ state_attr('sensor.test', 'test' }}"
      attributes:
        test: "{{ now() }}"
```

* expose entity_id instead of this

* add test

* Refactor to expose this variable

* Tweak repr dunder

Co-authored-by: Erik <erik@montnemery.com>
2022-04-20 15:30:17 +02:00
..
fixtures Prettify yaml (tests) (#68891) 2022-03-30 11:26:08 +02:00
__init__.py
conftest.py
test_alarm_control_panel.py Raise if referenced entity does not support service (#68394) 2022-03-20 16:01:58 -07:00
test_binary_sensor.py Restore attributes of template binary sensor (#69350) 2022-04-05 22:58:12 -07:00
test_button.py
test_cover.py
test_fan.py
test_init.py
test_light.py
test_lock.py
test_number.py
test_select.py
test_sensor.py Make `this` variable available in template entities (#65201) 2022-04-20 15:30:17 +02:00
test_switch.py
test_template_entity.py
test_trigger.py
test_vacuum.py Clean up async_update_entity helper usage (#68641) 2022-03-25 15:22:58 -07:00
test_weather.py