Commit Graph

468 Commits (5890a7d38c3a7c5a74a455a47ad352b640928a2c)

Author SHA1 Message Date
J. Nick Koston 25510fc13c
Limit executor imports to a single thread (#111898)
* Limit executor imports to a single thread

* test for import executor

* test for import executor

* test for import executor

* fixes

* better fix
2024-02-29 21:02:13 -05:00
J. Nick Koston b9718fe2e9
Avoid tracking tasks that finish right away (#111690) 2024-02-27 19:09:34 -10:00
J. Nick Koston c4d719a7cf
Use eager_start for background service call tasks (#111620) 2024-02-27 12:06:32 -10:00
J. Nick Koston 67e356904b
Add support for eager tasks (#111425)
* Add support for eager tasks

python 3.12 supports eager tasks

reading:
https://docs.python.org/3/library/asyncio-task.html#eager-task-factory
https://github.com/python/cpython/issues/97696

There are lots of places were we are unlikely to suspend, but we might
suspend so creating a task makes sense

* reduce

* revert entity

* revert

* coverage

* coverage

* coverage

* coverage

* fix test
2024-02-26 11:36:46 -05:00
Franck Nijhof 1c55ba0cb2
Use covariant for fire event data type (#110843) 2024-02-18 13:21:55 +01:00
J. Nick Koston b5afdf34f4
Improve ability to debug one time listeners blocking the event loop (#110064) 2024-02-09 08:44:14 +01:00
J. Nick Koston f73431ac06
Switch utc_to_timestamp to .timestamp() where possible (#109729)
* Switch utc_to_timestamp to .timestamp()

.timestamp() is faster now in newer cpython

```
from homeassistant.util.dt import utc_to_timestamp, utcnow
import timeit
now = utcnow()
print(timeit.timeit('utc_to_timestamp(now)',globals={"now":now,"utc_to_timestamp":utc_to_timestamp}))
print(timeit.timeit('now.timestamp()',globals={"now":now}))
```

utc_to_timestamp = 0.18721245788037777
timestamp = 0.11421508435159922

* compat

* revert

* revert

* revert

* revert

* revert
2024-02-05 23:04:52 +01:00
Marc Mueller cd0ee98dba
Use builtin TimeoutError [core + helpers] (#109684) 2024-02-05 12:09:54 +01:00
J. Nick Koston 7e3001f843
Remove default values from calls to async_fire (#109613)
There were a few places were we passing unnecessary default values. Since
this code tends to get copied, remove them
2024-02-04 14:49:42 -05:00
J. Nick Koston e35c7fde89
Avoid many string lowers in the state machine (#109607) 2024-02-04 17:35:35 +01:00
J. Nick Koston 7c86ab14c3
Refactor service enumeration methods to better match existing use cases (#108671) 2024-01-22 14:21:17 -10:00
J. Nick Koston a3f9fc45e3
Refactor async_listen_once to remove nonlocal (#108627) 2024-01-21 22:52:47 -05:00
J. Nick Koston 52b5d2e370
Avoid json encoder default fallback when serializing config (#108360)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-01-19 19:22:17 -10:00
J. Nick Koston c399cab427
Small speed up to checking core state (#107845) 2024-01-18 08:41:32 -10:00
J. Nick Koston 60ab360fe7
Avoid bytes to string to bytes conversion in websocket api (#108139) 2024-01-16 21:37:34 +01:00
J. Nick Koston 3d595fff13
Avoid duplicate timestamp conversions for websocket api and recorder (#108144)
* Avoid duplicate timestamp conversions for websocket api and recorder

We convert the time from datetime to timestamps one per
open websocket connection and the recorder for every
state update. Only do the conversion once since its
~30% of the cost of building the state diff

* more

* two more

* two more in live history
2024-01-16 14:05:01 +01:00
J. Nick Koston 1cdfb06d77
Add cached_property to State.name (#108011) 2024-01-14 11:50:40 +01:00
J. Nick Koston 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
J. Nick Koston d04e2d56da
Add support for JSON fragments (#107213) 2024-01-07 17:36:31 -10:00
J. Nick Koston 44018a4183
Use faster identity checks for SupportsResponse Enum (#107351) 2024-01-06 10:12:31 +01:00
Erik Montnemery c805ea7b4f
Include deprecated constants in wildcard imports (#107114) 2024-01-05 11:46:45 +01:00
Erik Montnemery 9eefd95e91
Deduplicate handling of duplicated constants (#107074)
* Deduplicate handling of duplicated constants

* Use DeprecatedConstant + DeprecatedConstantEnum

* Fixup

* Remove test cases with unnamed tuples
2024-01-04 13:25:09 +01:00
J. Nick Koston 1cbacd13aa
Use identity checks for HassJobType (#106860) 2024-01-02 12:33:02 +01:00
J. Nick Koston 9e3869ae1c
Avoid recreating ReadOnly dicts when attributes do not change (#106687) 2023-12-29 17:10:40 -10:00
Erik Montnemery a4e9a053c7
Fix missing await when running shutdown jobs (#106632) 2023-12-29 10:04:16 +01:00
Richard Kroegel bd4177edc8
Add supports_response to ServiceRegistry.register() (#106164)
Co-authored-by: rikroe <rikroe@users.noreply.github.com>
2023-12-27 13:01:20 +01:00
Robert Resch fbcb31b103
Deprecate deprecated unit of measurement constants (#106455) 2023-12-27 09:04:25 +01:00
Robert Resch b08268da31
Deprecate deprecated core constants (#106456) 2023-12-27 08:42:57 +01:00
Tudor Sandu 636e38f4b3
Trigger Home Assistant shutdown automations right before the stop event instead of during it (#91165)
Co-authored-by: Erik <erik@montnemery.com>
2023-12-05 11:24:41 -10:00
J. Nick Koston 1522118453
Remove aiohttp cancel on disconnect workaround (#104175) 2023-11-29 11:20:36 -07:00
Jan Bouwhuis 487ff8cd7f
Rename ex to exc as name for exceptions (#104479) 2023-11-25 08:30:18 +01:00
J. Nick Koston cc31d77205
Use ulid_now instead of ulid_at_timestamp if no timestamp is passed (#104226)
* Use ulid_now instead of ulid_at_timestamp if no timestamp is passed

ulid_now is slightly faster than ulid_at_timestamp

* tweak usage
2023-11-19 22:27:24 -05:00
tronikos 9af5e838c6
Add type annotation for service functions with response (#102813)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2023-11-09 12:31:12 +01:00
J. Nick Koston dca72c598e
Small speed up to async_listen (#103307)
Avoid constructing an inner function each time we call async_listen
and use a partial which holds a reference to the function body with new
args instead of making another full function
2023-11-03 20:58:03 +01:00
Kevin Stillhammer 06c9719cd6
Support multiple responses for service calls (#96370)
* add supports_response to platform entity services

* support multiple entities in entity_service_call

* support legacy response format for service calls

* revert changes to script/shell_command

* add back test for multiple responses for legacy service

* remove SupportsResponse.ONLY_LEGACY

* Apply suggestion

Co-authored-by: Allen Porter <allen.porter@gmail.com>

* test for entity_id remove None

* revert Apply suggestion

* return EntityServiceResponse from _handle_entity_call

* Use asyncio.gather

* EntityServiceResponse not Optional

* styling

---------

Co-authored-by: Allen Porter <allen.porter@gmail.com>
2023-11-02 18:37:35 -07:00
J. Nick Koston b3743937de
Avoid looking up the callable type for HassJob when we already know it (#102962)
* Avoid looking up the callable type for HassJob when we already know it

When we connect the frontend we call async_listen with run_immediately MANY
times when we already know the job type (it will always be a callback). This
reduces the latency to get the frontend going

* missing coverage
2023-10-30 12:45:22 +01:00
J. Nick Koston 009dc91b97
Fix inner callback decorators with partials (#102873) 2023-10-28 08:38:42 -05:00
Erik Montnemery 97cc05d0b4
Make it possible to restart core in safe mode (#102606) 2023-10-24 14:47:58 +02:00
Erik Montnemery c481fdb7d0
Rename safe mode to recovery mode (#102580) 2023-10-23 20:33:08 +02:00
Jan Bouwhuis 31bd500222
Make get_channel available as generic helper (#101721)
* Make get_channel available as generic helper

* Follow up comment
2023-10-10 14:02:32 +02:00
Erik Montnemery fbcc5318c5
Move attributes to be excluded from recording to entity classes (#100239)
Co-authored-by: J. Nick Koston <nick@koston.org>
2023-09-20 18:09:12 +02:00
J. Nick Koston 547f32818c
Make core States use cached_property (#100312)
Need to validate this is worth removing __slots__
2023-09-13 20:33:25 -04:00
Erik Montnemery 6057fe5926
Replace StateMachine._domain_index with a UserDict (#100270)
* Replace StateMachine._domain_index with a UserDict

* Access the UserDict's backing dict directly

* Optimize
2023-09-13 18:05:17 +02:00
J. Nick Koston ad4619c038
Speed up serializing event messages (#100017) 2023-09-10 08:25:13 -05:00
Marc Mueller 5d54660802
Fix asyncio.wait typing (#99726) 2023-09-06 16:53:41 +02:00
Erik Montnemery 7643820e59
Add loader.async_get_loaded_integration (#99440)
* Add loader.async_get_loaded_integration

* Decorate async_get_loaded_integration with @callback
2023-09-04 14:12:33 +02:00
Erik Montnemery 7c595ee2da
Validate state in template helper preview (#99455)
* Validate state in template helper preview

* Deduplicate state validation
2023-09-04 14:10:43 +02:00
J. Nick Koston 186e796e25
Speed up fetching states by domain (#99467) 2023-09-03 09:30:39 -05:00
J. Nick Koston 1ab2e900f9
Improve lingering timer checks (#99472) 2023-09-02 12:43:27 -05:00
Ville Skyttä 6399d74c15
Remove unnnecessary pylint configs from core (#98704) 2023-08-22 23:12:12 +02:00