Commit Graph

437 Commits (b94c9c8f6dd5dcfbe151d1b786476c9ffd1941c5)

Author SHA1 Message Date
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
Erik Montnemery 31f5932fe4
Log events with no listeners (#98540)
* Log events with no listeners

* Unconditionally create the Event object

* Reformat code
2023-08-16 20:14:49 +02:00
Erik Montnemery 91faa53843
Don't allow hass.config.config_dir to be None (#98442) 2023-08-16 13:00:14 +02:00
Marc Mueller a9ade1f84d
Use asyncio.timeout [core] (#98447) 2023-08-15 08:36:05 -05:00
Franck Nijhof 868a5f377f
Ruff: isort don't split imports based on trailing comma (#98162) 2023-08-10 14:27:03 +02:00
Franck Nijhof 30058297cf
Migrate backported StrEnum to built-in StrEnum (#97101) 2023-07-23 23:19:24 +02:00
Marc Mueller 77f38e33e5
Import names from typing instead of typing_extensions [3.11] (#97065) 2023-07-22 17:03:44 -05:00
J. Nick Koston 99def97ed9
Add cancel messages to core task cancelation (#96972) 2023-07-20 18:03:36 -05:00
J. Nick Koston 08af42b00e
Fix mixed case service schema registration (#96448) 2023-07-12 14:39:51 -10:00
Jan Bouwhuis 18ee9f4725
Refactor async_get_hass to rely on threading.local instead of a ContextVar (#96005)
* Test for async_get_hass

* Add Fix
2023-07-07 14:52:38 -04:00
J. Nick Koston dc5ee71d7a
Add slots to core EventBus (#95856) 2023-07-05 11:47:24 -05:00
J. Nick Koston ea57f78392
Add slots to the service registry (#95857) 2023-07-05 15:59:36 +02:00
J. Nick Koston b2e708834f
Add slots to the StateMachine class (#95849) 2023-07-05 14:00:37 +02:00
J. Nick Koston 91f334ca59
Small cleanups to service calls (#95873) 2023-07-05 09:25:38 +02:00
J. Nick Koston 0ff3836083
Use a normal tuple for the EventBus jobs (#95731) 2023-07-02 16:35:57 -05:00
Allen Porter 528c206094
Add script specific error messages for `response_variable` (#95188) 2023-06-24 21:34:57 -07:00
J. Nick Koston 5059cee53f
Reduce overhead to fire events (#95163) 2023-06-24 14:39:13 -05:00
Allen Porter 30e8f806c1
Improve service response data APIs (#94819)
* Improve service response data APIs

Make the API naming more consistent, and require registration that a
service supports response data so that we can better integrate with
the UI and avoid user confusion with better error messages.

* Improve test coverage

* Add an enum for registering response values

* Assign enum values

* Convert SupportsResponse to StrEnum

* Update service call test docstrings

* Add tiny missing full stop in comment

---------

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
2023-06-20 06:24:31 -07:00
Allen Porter 84c66b3cad
Add support for services to return data (#94401)
* Add support for service calls with resopnse data.

Update the service calls to allow returning responses with data,
with an initial use case supporting basic service calls usable
within script.

* Revert enttiy platform/component changes

* Remove unnecessary comma diff

* Revert additional unnecessary changes

* Simplify service call

* Simplify and fix typing and revert whitespace

* Clarify typing intent

* Revert more entity service calls

* Revert additional entity service changes

* Set blocking=True for group notify service call

* Revert unnecessary changes

* Reverting more whitespace changes

* Revert more service changes

* Add test coverage for None return case

* Add parameter to service calls indicating return values were requested

* Update tests/test_core.py

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>

* Add additional service call tests

* Update test comment

---------

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2023-06-16 12:43:35 -04:00
Allen Porter 12129e9d21
Update service call return values and error handling (#94657)
* Update return signature of service calls

* Add timeout error handling in websocket api for service calls

* Update recorder tests to remove assertion on service call

* Remove timeout behavior and update callers that depend on it today

* Fix tests

* Add missing else

* await coro directly

* Fix more tests

* Update the intent task to use wait instead of timeout

* Remove script service call limits and limit constants

* Update tests that depend on service call limits

* Use wait instead of wait_for and add test

* Update homeassistant/helpers/intent.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

---------

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2023-06-16 07:01:40 -07:00
J. Nick Koston c721cbd10c
Collapse valid state check when creating a state (#93655)
Inline valid state check when creating a state

This was added in #9696 and only used in one place so
it does not need to be another function
2023-05-27 19:53:08 -04:00
J. Nick Koston e09e4f14d6
Speed up setting state (#93472) 2023-05-25 07:34:07 -05:00
J. Nick Koston 780f9bcdc0
Fix shutdown being delayed for cancelling tasks (#93287) 2023-05-21 14:17:34 +02:00
J. Nick Koston 32481065a8
Increase size of valid entity id cache (#93125) 2023-05-17 13:06:52 +02:00
J. Nick Koston bf16f6b104
Remove as_compressed_state cache (#93169)
* Remove as_compressed_state cache

All calls to as_compressed_state are now covered by a higher level
JSON cache so there is no need to store these in memory anymore

* Remove as_compressed_state cache

All calls to as_compressed_state are now covered by a higher level
JSON cache so there is no need to store these in memory anymore
2023-05-16 12:39:16 -05:00
J. Nick Koston 99265a983a
Speed up reconnects by caching state serialize (#93050) 2023-05-16 02:33:12 -05:00
J. Nick Koston 24284fe379
Speed up validating domains in templates (#92975)
This path gets called quite a bit since most templates
access the state via states.DOMAIN...
2023-05-12 14:57:51 +02:00
J. Nick Koston 07d1a16efd
Add as_dict cache to Context and Event (#92162) 2023-04-28 21:15:39 +02:00
J. Nick Koston 237faf62ac
Add a name to the background service call tasks (#91252) 2023-04-11 19:23:25 -10:00
epenet 9705607db4
Fix lingering timer in cloud (#90822)
* Fix lingering timer in cloud

* Rename variable

* Improve

* Improve again

* Adjust

* Adjust

* Add property to HassJob instead

* Adjust

* Rename

* Adjust

* Adjust

* Make it read-only

* Add specific test
2023-04-07 11:38:17 +02:00
J. Nick Koston 5eb0c35a97
Add names to common helper tasks (#90803) 2023-04-05 08:41:15 +02:00
J. Nick Koston 4c21caa917
Fix filesize doing blocking I/O in the event loop (#90479)
Fix filesize doing I/O in the event loop
2023-03-29 17:26:28 -04:00