Commit Graph
55 Commits
Author SHA1 Message Date
RoboMagusandGitHub c54b65fdf0 Add 'last_reset' for 'total' state_class template sensor (#100806)
* Add last_reset to trigger based template sensors

* Add last_reset to state based template sensors

* CI check fixes

* Add pytests

* Add test cases for last_reset datetime parsing

* Add test for static last_reset value

* Fix ruff-format
2024-01-25 11:12:03 +01:00
J. Nick KostonandGitHub c399cab427 Small speed up to checking core state (#107845) 2024-01-18 08:41:32 -10:00
J. Nick KostonandGitHub 4b7a313ece Use identity checks for CoreState (#107846)
Some of the checks used ==, and some used is. Switch
everything to is as its faster
2024-01-12 10:21:26 +01:00
Erik MontnemeryandGitHub 42046a3ce2 Fix TriggerEntity.async_added_to_hass (#100119) 2023-09-11 14:33:43 +02:00
7b1c0c2df2 Extend template entities with a script section (#96175)
* Extend template entities with a script section

This allows making a trigger entity that triggers a few times a day,
and allows collecting data from a service resopnse which can be
fed into a template entity.

The current alternatives are to publish and subscribe to events or to
store data in input entities.

* Make variables set in actions accessible to templates

* Format code

---------

Co-authored-by: Erik <erik@montnemery.com>
2023-09-02 16:19:45 -07:00
Erik MontnemeryandGitHub 8c04e4c7a3 Add explicit test of template config entry setup (#99345) 2023-08-30 19:56:34 +02:00
Erik MontnemeryandGitHub 63c538b024 Add config flow for template sensor (#98970)
* Add config flow for template sensor

* Tweak error reporting

* Improve validation

* Fix test

* Rename translation strings

* Improve validation

* Fix sensor async_setup_entry

* Avoid duplicating sensor device class translations

* Avoid duplicating sensor device class translations

* Add config flow tests

* Include all units from DEVICE_CLASS_UNITS in unit_of_measurement select

* Address review comments
2023-08-30 16:22:52 +02:00
epenetandGitHub 9762b684c2 Adjust entity registry access in tests (3) (#88964) 2023-03-01 16:04:40 +01:00
epenetandGitHub 88cfbf6a34 Add type hints to integration tests (part 22) (#88234) 2023-02-16 14:08:03 +01:00
Franck NijhofandGitHub d3ed8de232 Update Ruff to v0.0.247 (#88210)
* Update Ruff to v0.0.247

* Fix new found violations
2023-02-15 16:46:03 -05:00
Franck NijhofandGitHub ed79265843 Enable Ruff PT006 (#88165)
* Enable Ruff PT006

* Adjust existing cases

* Fix tests

* Remove unneeded parentheses
2023-02-15 14:09:50 +01:00
epenetandGitHub 278050a73f Add type hints to integration tests (t-z) (#87707) 2023-02-08 19:10:53 +01:00
epenetandGitHub 1a8933d59d Adjust invalid test values in template (#86008) 2023-01-16 14:42:47 +01:00
Franck NijhofandGitHub 2e92fefc0a Fix uom/device class mismatches in tests (#84372) 2022-12-21 22:47:59 +01:00
akloecknerandGitHub aa314a0901 Add this variable to trigger-based templates (#72437)
add this variables to trigger-based templates

follow-up for https://github.com/home-assistant/core/issues/70359
2022-06-27 08:59:29 +02:00
Erik MontnemeryandGitHub eba125b093 Ensure 'this' variable is always defined for template entities (#70911) 2022-05-03 07:43:44 -07:00
Erik MontnemeryandGitHub 9bec649323 Restore state of trigger-based template sensor (#69344) 2022-04-21 09:32:18 -07:00
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
Franck NijhofandGitHub d645e80ccd Clean up async_update_entity helper usage (#68641) 2022-03-25 15:22:58 -07:00
cf4033b1bc Simplify time zone setting in tests (#68330)
* Simplify timezone setting in tests

* Fix typo

* Adjust caldav tests

* Adjust input_datetime tests

* Adjust time_date tests

* Adjust tod tests

* Adjust helper tests

* Adjust recorder tests

* Adjust risco tests

* Adjust aemet tests

* Adjust flux tests

* Adjust forecast_solar tests

* Revert unnecessary change in forecast_solar test

* Adjust climacell tests

* Adjust google tests

* Adjust sensor tests

* Adjust sonarr tests

* Adjust template tests

* Adjust zodiac tests

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2022-03-20 10:25:15 +01:00
1ed490ce62 Fix date/datetime support for templates (#61088)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2021-12-09 11:43:48 +01:00
Erik MontnemeryandGitHub c1d671b817 Fix template sensor when name template doesn't render (#58088) 2021-10-20 14:53:06 -07:00
a4d9019ffc Refactor persistent notification to no longer route all data via a service (#57157)
* Convert persistent notification tests to async

* Create/dismiss persistent notifications in exposed functions, not service calls

* Fix notify persistent_notification

* Remove setting up persistent_notification

* Drop more setups

* Empty methods

* Undeprecate sync methods because too big task

* Fix setup clearing notifications

* Fix a bunch of tests

* Fix more tests

* Uno mas

* Test persistent notification events

* Clean up stale comment

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 12:58:00 +02:00
jan iversenandGitHub 6348bf70ac Add caplog setup fixture. (#55714) 2021-09-04 07:09:55 -07:00
jan iversenandGitHub 7aa454231f Update template/test_sensor.py to use pytest (#55288) 2021-09-03 22:56:12 -07:00
Paulus SchoutsenandGitHub 0c2772e0be Fix template sensor availability (#55635) 2021-09-03 09:02:45 +02:00
Paulus SchoutsenandGitHub cc00617cd5 Allow defining state class for template sensors (#52130) 2021-06-23 14:37:04 -07:00
Paulus SchoutsenandGitHub dcee78b747 Template sensor/binary sensors without trigger now respect section unique id (#49613) 2021-04-24 07:14:31 -07:00
Paulus SchoutsenandGitHub 65126cec3e Allow top level non-trigger template entities (#48976) 2021-04-12 17:15:50 -07:00
Paulus SchoutsenandGitHub e882460933 Support modern config for the trigger based template entity (#48635) 2021-04-02 16:57:16 -07:00
Paulus SchoutsenandGitHub 212d9aa748 Fix trigger template entities without a unique ID (#48631) 2021-04-02 10:24:38 -07:00
022f56f54d Allow specifying template entities based on triggers (#48169)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-03-29 09:57:51 -07:00
Erik MontnemeryandGitHub ed31cc363b Wait for registries to load at startup (#46265)
* Wait for registries to load at startup

* Don't decorate new functions with @bind_hass

* Fix typing errors in zwave_js

* Load registries in async_test_home_assistant

* Tweak

* Typo

* Tweak

* Explicitly silence mypy errors

* Fix tests

* Fix more tests

* Fix test

* Improve docstring

* Wait for registries to load
2021-02-11 17:36:19 +01:00
Franck NijhofandGitHub 65cf2fcb6f Drop asynctest (#44746) 2021-01-01 22:31:56 +01:00
J. Nick KostonandGitHub 935c2df7cb Add a test for template entities that reuse the template (#42404) 2020-10-26 16:08:57 +01:00
ee914366a8 Add native Python types support to templates (#41227)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2020-10-07 00:05:52 +02:00
sycx2andGitHub e813d3ebf9 Improve template test sensor (#41199) 2020-10-05 14:52:31 +02:00
J. Nick KostonandGitHub deedd41d62 Prevent template loop detection from triggering when all templates are self referencing (#41013) 2020-10-01 22:11:11 +02:00
J. Nick KostonandGitHub b45215f1d2 Implement template rate_limit directive (#40667) 2020-10-01 21:39:44 +02:00
J. Nick KostonandGitHub aaa8083d49 Change template loop detection strategy to allow self-referencing updates when there are multiple templates (#39943) 2020-09-12 14:20:21 +02:00
J. Nick KostonandGitHub fd8a4182d9 Detect self-referencing loops in template entities and log a warning (#39897) 2020-09-10 20:50:11 +02:00
Franck NijhofandGitHub 1c2ebdf307 Upgrade black to 20.8b1 (#39287) 2020-08-27 13:56:20 +02:00
J. Nick KostonandGitHub 20398cc0a6 Subscribe to state change events only if the template has entities (#39188) 2020-08-26 00:20:04 +02:00
J. Nick KostonandGitHub 83b9c6188d Make template entities reloadable (#39075)
* Make template entities reloadable

* Address review items
2020-08-21 18:31:48 -05:00
1381b279f0 Update template sensor to use async_track_template_result (#38940)
* 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
5de21375c0 Make sure groups are initialized before template sensors (#37766)
* Make sure groups are initialized before template sensors

This way users may use the `expand` function in templates to expand
groups and have HA listen for changes to group members.

Fixes #35872

* Patch async_setup_platform instead of async_setup

* Cleanup

* Use an event to avoid sleep

* Update tests/components/template/test_sensor.py

Co-authored-by: J. Nick Koston <nick@koston.org>

Co-authored-by: J. Nick Koston <nick@koston.org>
2020-08-08 21:34:14 -05:00
Michaël ArnautsandGitHub f09a9abc1c Add optional unique_id attribute to the template platforms (#38011)
* Add unique_id to template platforms

* Update test_binary_sensor.py

* Update test_binary_sensor.py
2020-08-01 12:45:55 -10:00
J. Nick KostonandGitHub 44fefb3216 Improve handling of template platforms when entity extraction fails (#37831)
Most of the the template platforms would check for
extract_entities failing to extract entities and avoid
setting up a state change listner for MATCH_ALL after
extract_entities had warned that it could not extract
the entities and updates would need to be done manually.
This protection has been extended to all template platforms.

Alter the behavior of extract_entities to return the
successfully extracted entities if one or more templates
fail extraction instead of returning MATCH_ALL
2020-07-14 22:34:35 -07:00
276f3afb00 Do async_setup_platform in background (#36244)
Co-authored-by: J. Nick Koston <nick@koston.org>
2020-05-31 22:18:30 -07:00
Bas NijholtandFranck Nijhof 415176e350 Sort imports according to PEP8 for template (#29655) 2019-12-08 21:05:08 +01:00