Commit graph

34 commits

Author SHA1 Message Date
Erik Montnemery
5987266e56
Refactor template entity to allow reuse ()
* Refactor template entity to allow reuse

* Fix schema and default name

* Add tests

* Update requirements

* Improve test

* Tweak TemplateSensor initializer

* Drop attributes and availability from TemplateEntity

* Use rest sensor for proof of concept

* Revert changes in SNMP sensor

* Don't set _attr_should_poll in mixin class

* Update requirements
2022-06-08 15:55:49 +02:00
Erik Montnemery
dba2f5ab1c
Support this variable in template alarm actions () 2022-05-13 12:17:40 +02:00
Erik Montnemery
eba125b093
Ensure 'this' variable is always defined for template entities () 2022-05-03 07:43:44 -07:00
akloeckner
d20a620590
Make this variable available in template entities ()
* 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
epenet
47d6f75c17
Enable basic type checking in template ()
* Fix binary_sensor

* Adjust button

* Adjust fan

* Adjust select

* Adjust template_entity

* Adjust trigger_entity

* Adjust weather

* Adjust init

* Adjust number

* Adjust None check
2022-02-10 10:59:54 +01:00
Erik Montnemery
e9a9b119c4
Teach TemplateEntity unique_id () 2022-01-24 23:16:31 +01:00
Erik Montnemery
5622e45980
Render icon and picture templates at setup () 2022-01-24 16:40:50 +01:00
Erik Montnemery
321f54494e
Teach TemplateEntity entity name ()
* Teach TemplateEntity entity name

* Remove default name from number and select config schemas

* Re-add default name to number and select config schemas

* Set name to None if name template fails to render

* Update template button
2022-01-24 15:44:05 +01:00
Erik Montnemery
0e28fbbe83
Minor refactor of template vacuum () 2021-12-16 20:53:19 +01:00
Erik Montnemery
bb3a3bbc1b
Minor refactor of template number () 2021-12-16 16:22:17 +01:00
Erik Montnemery
a67a4873dc
Minor refactor of template cover () 2021-12-02 10:26:10 -08:00
Erik Montnemery
e20127d9ff
Minor refactor of template binary sensor ()
* Minor refactor of template binary sensor

* pylint

* Tweak
2021-11-10 07:58:22 +01:00
Erik Montnemery
bed4096430
Allow specifying a super template for async_track_template_result () 2021-10-27 16:07:17 +02:00
Marc Mueller
d51487f82a
Import Callable from collections.abc (3) () 2021-09-29 16:19:06 +02:00
Franck Nijhof
ee452d415d
Add SensorEntityDescription class () 2021-07-26 22:00:43 +02:00
Paulus Schoutsen
cc00617cd5
Allow defining state class for template sensors () 2021-06-23 14:37:04 -07:00
Michael
9eecd90afc
Add constructor return type in integrations T-Z () 2021-05-20 17:00:19 +02:00
Paulus Schoutsen
2d5edeb1ef
Set hass when adding template attribute () 2021-04-11 22:49:09 -07:00
Marc Mueller
b67b9b94f9
Update typing 13 () 2021-03-18 14:43:52 +01:00
Erik Montnemery
1fc8e32d86
Update integrations t-z to override extra_state_attributes() () 2021-03-11 20:16:26 +01:00
tkdrob
2c3a2bd35e
Clean up template () 2021-02-14 12:16:30 +01:00
J. Nick Koston
deedd41d62
Prevent template loop detection from triggering when all templates are self referencing () 2020-10-01 22:11:11 +02:00
J. Nick Koston
f837da6fe3
Defer template tracking setup until template entity start () 2020-09-22 09:28:02 -05:00
J. Nick Koston
aaa8083d49
Change template loop detection strategy to allow self-referencing updates when there are multiple templates () 2020-09-12 14:20:21 +02:00
J. Nick Koston
fd8a4182d9
Detect self-referencing loops in template entities and log a warning () 2020-09-10 20:50:11 +02:00
J. Nick Koston
a77e09b2c2
Make async_track_template_result track multiple templates ()
* Make async_track_template_result track multiple templates

Combine template entity updates to only write ha
state once per template group update

* Make async_track_template_result use dataclasses for input/output

* black versions

* naming
2020-08-31 19:07:40 -05:00
J. Nick Koston
6b7a7939d2
Include the first seen context data in the logbook api ()
* Include the context_entity_id in the logbook api

context_entity_id is the first entity seen during
a time period that includes the context

* update test

* more of them

* include friendly name

* pylint wants a ternary

* Refactor

* performance

* fix homekit context

* Fix self describing events

* Fix external_events
2020-08-24 12:44:40 -05:00
J. Nick Koston
83b9c6188d
Make template entities reloadable ()
* Make template entities reloadable

* Address review items
2020-08-21 18:31:48 -05:00
J. Nick Koston
796d74886e
Simplify template integration entities () 2020-08-21 14:33:53 +02:00
J. Nick Koston
5a8013b58c
Convert template binary_sensor to use async_track_template_result ()
Co-Authored-By: Penny Wood <Swamp-Ig@users.noreply.github.com>

Co-authored-by: Penny Wood <Swamp-Ig@users.noreply.github.com>
2020-08-20 09:07:58 -05:00
J. Nick Koston
f3d077c1e1
Convert template fan to use async_track_template_result ()
* Convert template lock to use async_track_template_result

* Convert template switch to use async_track_template_result

* Convert template fan to use async_track_template_result
2020-08-20 08:53:45 -05:00
J. Nick Koston
264e340b9e
Convert template switch to use async_track_template_result () 2020-08-20 08:51:27 -05:00
J. Nick Koston
d7f54ce98f
Convert template lock to use async_track_template_result () 2020-08-20 08:32:52 -05:00
J. Nick Koston
1381b279f0
Update template sensor to use async_track_template_result ()
* Add template entity

* Update template tracking to work for template sensors

* add test for whitespace

* Update homeassistant/helpers/config_validation.py

* revert

* fix

* reduce

* fix _refresh missing decorator

* defer until start

* do not throw errors during startup

* defer tracking until start event

Co-authored-by: Swamp-Ig <github@ninjateaparty.com>
2020-08-20 08:06:41 -05:00