1
0
mirror of https://github.com/home-assistant/core.git synced 2025-10-09 19:59:30 +00:00
Commit Graph

60 Commits

Author SHA1 Message Date
Joost Lekkerkerker
6bb4e7d62c Bump ruff to 0.3.4 ()
Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-03-26 00:02:16 +01:00
J. Nick Koston
b574220247 Refactor rate limit helper to track time in seconds ()
* Refactor rate limit helper to track time in seconds

Currently we created datetime and timedelta objects to enforce the
rate limit. When the rate limit was being hit hard, this got expensive.

We now use floats everywhere instead as they are much cheaper which
is important when we are running up against a rate limit, which is
by definition a hot path

The rate limit helper is currently only used for templates and
we do not have any code in the code base that directly passes
in a rate limit so the impact to custom components is expected
to be negligible if any

* misesd two
2024-03-20 19:49:37 -04:00
J. Nick Koston
6b5518b2bf Fix template sensor test relying on event bus debug logging () 2024-03-19 10:44:04 -10:00
Erik Montnemery
d0352ed91d Fix missing context when running script from template entity ()
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-03-16 12:37:24 -10:00
Marc Mueller
87165c0d6e Add empty line after module docstring [tests t-z] () 2024-03-08 14:44:56 +01:00
RoboMagus
c54b65fdf0 Add 'last_reset' for 'total' state_class template sensor ()
* 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 Koston
c399cab427 Small speed up to checking core state () 2024-01-18 08:41:32 -10:00
J. Nick Koston
4b7a313ece Use identity checks for CoreState ()
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 Montnemery
42046a3ce2 Fix TriggerEntity.async_added_to_hass () 2023-09-11 14:33:43 +02:00
Allen Porter
7b1c0c2df2 Extend template entities with a script section ()
* 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 Montnemery
8c04e4c7a3 Add explicit test of template config entry setup () 2023-08-30 19:56:34 +02:00
Erik Montnemery
63c538b024 Add config flow for template sensor ()
* 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
epenet
9762b684c2 Adjust entity registry access in tests (3) () 2023-03-01 16:04:40 +01:00
epenet
88cfbf6a34 Add type hints to integration tests (part 22) () 2023-02-16 14:08:03 +01:00
Franck Nijhof
d3ed8de232 Update Ruff to v0.0.247 ()
* Update Ruff to v0.0.247

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

* Adjust existing cases

* Fix tests

* Remove unneeded parentheses
2023-02-15 14:09:50 +01:00
epenet
278050a73f Add type hints to integration tests (t-z) () 2023-02-08 19:10:53 +01:00
epenet
1a8933d59d Adjust invalid test values in template () 2023-01-16 14:42:47 +01:00
Franck Nijhof
2e92fefc0a Fix uom/device class mismatches in tests () 2022-12-21 22:47:59 +01:00
akloeckner
aa314a0901 Add this variable to trigger-based templates ()
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 Montnemery
eba125b093 Ensure 'this' variable is always defined for template entities () 2022-05-03 07:43:44 -07:00
Erik Montnemery
9bec649323 Restore state of trigger-based template sensor () 2022-04-21 09:32:18 -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
Franck Nijhof
d645e80ccd Clean up async_update_entity helper usage () 2022-03-25 15:22:58 -07:00
Erik Montnemery
cf4033b1bc Simplify time zone setting in tests ()
* 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
Franck Nijhof
1ed490ce62 Fix date/datetime support for templates ()
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2021-12-09 11:43:48 +01:00
Erik Montnemery
c1d671b817 Fix template sensor when name template doesn't render () 2021-10-20 14:53:06 -07:00
Paulus Schoutsen
a4d9019ffc Refactor persistent notification to no longer route all data via a service ()
* 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 iversen
6348bf70ac Add caplog setup fixture. () 2021-09-04 07:09:55 -07:00
jan iversen
7aa454231f Update template/test_sensor.py to use pytest () 2021-09-03 22:56:12 -07:00
Paulus Schoutsen
0c2772e0be Fix template sensor availability () 2021-09-03 09:02:45 +02:00
Paulus Schoutsen
cc00617cd5 Allow defining state class for template sensors () 2021-06-23 14:37:04 -07:00
Paulus Schoutsen
dcee78b747 Template sensor/binary sensors without trigger now respect section unique id () 2021-04-24 07:14:31 -07:00
Paulus Schoutsen
65126cec3e Allow top level non-trigger template entities () 2021-04-12 17:15:50 -07:00
Paulus Schoutsen
e882460933 Support modern config for the trigger based template entity () 2021-04-02 16:57:16 -07:00
Paulus Schoutsen
212d9aa748 Fix trigger template entities without a unique ID () 2021-04-02 10:24:38 -07:00
Paulus Schoutsen
022f56f54d Allow specifying template entities based on triggers ()
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-03-29 09:57:51 -07:00
Erik Montnemery
ed31cc363b Wait for registries to load at startup ()
* 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 Nijhof
65cf2fcb6f Drop asynctest () 2021-01-01 22:31:56 +01:00
J. Nick Koston
935c2df7cb Add a test for template entities that reuse the template () 2020-10-26 16:08:57 +01:00
Franck Nijhof
ee914366a8 Add native Python types support to templates ()
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2020-10-07 00:05:52 +02:00
sycx2
e813d3ebf9 Improve template test sensor () 2020-10-05 14:52:31 +02: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
b45215f1d2 Implement template rate_limit directive () 2020-10-01 21:39:44 +02: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
Franck Nijhof
1c2ebdf307 Upgrade black to 20.8b1 () 2020-08-27 13:56:20 +02:00
J. Nick Koston
20398cc0a6 Subscribe to state change events only if the template has entities () 2020-08-26 00:20:04 +02: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
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