Commit Graph

126 Commits

Author SHA1 Message Date
J. Nick Koston
0380116ef6 Improve logging of _TrackPointUTCTime objects (#116711) 2024-05-04 17:35:44 -05:00
J. Nick Koston
d48bd9b016 Deprecate async_track_state_change in favor of async_track_state_change_event (#115558) 2024-04-18 10:45:14 -05:00
Marc Mueller
0f03079065 Update import for EventStateChangedData [i-z] (#114900) 2024-04-04 11:48:29 -10:00
J. Nick Koston
b574220247 Refactor rate limit helper to track time in seconds (#113898)
* 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
Marc Mueller
b026b5d589 Replace EventType with Event [helpers] (#112743) 2024-03-08 19:41:50 +01:00
J. Nick Koston
a7b4cd3512 Pass job type to event listeners when creating entities (#112551) 2024-03-06 16:10:07 -10:00
Marc Mueller
cd0ee98dba Use builtin TimeoutError [core + helpers] (#109684) 2024-02-05 12:09:54 +01:00
Jan-Philipp Benecke
d1aa690c24 Migrate non-component tests to use freezegun/freezer (#105142) 2023-12-07 22:58:09 +01:00
Erik Montnemery
1654ef7759 Make WS command render_template not give up if initial render raises (#99808) 2023-09-08 21:02:06 +02:00
Erik Montnemery
9dac6a2948 Use loop.time in DataUpdateCoordinator (#98937) 2023-08-28 10:16:34 -05:00
Marc Mueller
a9ade1f84d Use asyncio.timeout [core] (#98447) 2023-08-15 08:36:05 -05:00
Marc Mueller
f39a35c4ef Fix jinja2 DeprecationWarnings (#97728) 2023-08-04 11:25:08 +02:00
Marc Mueller
995c29e052 Cleanup EventType typing (#97136) 2023-07-24 13:18:38 +02:00
Marc Mueller
4161f53bea Improve async_track_state_change_filtered callback typing (#97134) 2023-07-24 12:42:29 +02:00
Marc Mueller
582499a260 Improve async_track_template_result callback typing (#97135) 2023-07-24 12:42:17 +02:00
Marc Mueller
797a9c1ead Improve async_track_state_added/removed_domain callback typing (#97126) 2023-07-24 09:11:41 +02:00
Marc Mueller
2618bfc073 Use EventType for state changed [core] (#97115) 2023-07-23 18:10:03 -05:00
J. Nick Koston
0a9c4f15c4 Add event helper to dispatch device registry updates by device_id (#93602)
* Add event helper to dispatch device registry updates by device_id

* Update homeassistant/helpers/event.py

* dry

* dry

* reduce

* reduce

* reorder

* reduce

* cleanup stack depth

* dry

* fix double lookup

* remove unused

* collapse
2023-05-27 20:04:09 -04:00
J. Nick Koston
56cc6633f5 Use fast path for track_time_change that fires every second (#91432)
We were missing a check for `*` and were only checking
`None`. Automations use `*`, python code uses `None`.
2023-04-14 21:02:54 -04:00
epenet
c01b1eb013 Adjust async_track_time_interval name argument (#90838)
Adjust async_track_time_interval naming
2023-04-05 10:58:02 -04:00
J. Nick Koston
f4c341253b Avoid sorting domain/all states in templates (#90608) 2023-03-31 11:27:55 -10:00
J. Nick Koston
02ef7d445d Allow passing an optional name to async_track_time_interval (#90244)
* Allow passing an optional name to async_track_time_interval

This is the same idea as passing a name to asyncio.create_task which
makes it easier to track down bugs

* more

* short

* still cannot find it

* add a few more

* test
2023-03-25 10:11:14 -04:00
epenet
79c9447770 Fix lingering timer in event helper tests (#89819)
Fix lingering timer in event tests
2023-03-16 23:01:23 -04:00
epenet
69aa3a75c5 Fix lingering timer in event sun tests (#89808) 2023-03-16 18:32:34 +01:00
epenet
46a5aa71ec Add type hints to helper tests (#89784) 2023-03-16 11:10:56 +01:00
J. Nick Koston
cefba7c638 Avoid falling back to listening for all states when a template render raises an exception (#89392)
When a template render raised an exception we would start listening for
all states until the template did not raise an exception anymore. This
was not needed since the entity that is causing the exception was
already in the tracker.

Re-rendering on all state changes can be extremely expensive and can
bring an instance into a sluggish or unresponsive state when updating
from a much older version that did not raise ValueError when a default
was missing.
2023-03-08 15:50:34 -05:00
epenet
5f25b71df7 Add type hints to core tests (#88478) 2023-02-20 11:42:56 +01:00
epenet
c98b4e3204 Add typing to tests with single hass argument (2) (#87675)
* Add typing to tests with single hass argument (2)

* a few more
2023-02-08 08:51:43 +01:00
krahabb
899342d391 Refactor async_call_later to improve performance and reduce conversion loss (#87117)
Co-authored-by: J. Nick Koston <nick@koston.org>
2023-02-05 12:04:38 -06:00
epenet
30bf0634fe Add per-file-ignore to pylint (#86289) 2023-01-22 17:26:24 +01:00
Franck Nijhof
dd266b7119 Remove elevation warning from sun (#80239) 2022-10-14 15:23:44 +02:00
Franck Nijhof
8f4caf4141 Clean up accessing event helpers via hass (#72011) 2022-05-17 19:36:29 +02:00
Erik Montnemery
4885331509 Fail template functions when no default specified (#71687) 2022-05-13 09:46:49 -07:00
J. Nick Koston
30fdfc454f Avoid lowercasing entities after template ratelimit recovery (#71415) 2022-05-09 12:48:38 +02:00
J. Nick Koston
fe6a4bfb1d Remove EVENT_TIME_CHANGED and EVENT_TIMER_OUT_OF_SYNC (#69643)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2022-04-09 09:05:54 -10:00
Erik Montnemery
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
Tobias Sauerwein
8b38fa58aa Bump pytest to 7.0.0 (#65981) 2022-02-08 10:03:27 +01:00
Erik Montnemery
39d6aba3bc Improve startup of unavailable template entities (#59827) 2021-11-22 09:20:38 -08:00
Erik Montnemery
acf58111c6 Correct initial update of async_track_template_result (#59705) 2021-11-15 13:00:46 +01:00
Erik Montnemery
30f7bc0f18 Use freezegun in DST tests (#58939) 2021-11-02 18:11:39 +01:00
J. Nick Koston
1cd9be7538 Fix recursive limit in find_next_time_expression_time (#58914)
* Fix recursive limit in find_next_time_expression_time

* Add test case

* Update test_event.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2021-11-02 00:11:17 +01:00
Otto Winter
a9c0f89c09 Fix find_next_time_expression_time (#58894)
* Better tests

* Fix find_next_time_expression_time

* Add tests for Nov 7th 2021, Chicago transtion

* Update event tests

* Update test_event.py

* small performance improvement

Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2021-11-01 17:45:13 +01:00
Erik Montnemery
bed4096430 Allow specifying a super template for async_track_template_result (#58477) 2021-10-27 16:07:17 +02:00
Eduard van Valkenburg
779ef3c8e1 Add timedelta option for async_call_later (#50164) 2021-06-12 13:14:35 +02:00
J. Nick Koston
bf2d40adfe Migrate from pytz to python-dateutil (#49643)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2021-05-07 22:46:26 -07:00
FMKaiba
09eb74fd9d Upgrade Astral to 2.2 (#48573) 2021-04-02 00:29:08 +02:00
Franck Nijhof
65cf2fcb6f Drop asynctest (#44746) 2021-01-01 22:31:56 +01:00
J. Nick Koston
2ef25e7414 Fix script wait templates with now/utcnow (#44717) 2021-01-01 13:03:34 +01:00
Anders Melchiorsen
650c57db5b Fix async_track_utc_time_change firing too early (#42176) 2020-11-05 16:34:56 +01:00
J. Nick Koston
8eb89cdb46 Fix flapping event template test (#42614) 2020-10-30 00:05:55 +01:00