593 Commits

Author SHA1 Message Date
2c13c70e12 Update ruff to 0.12.0 (#147106) 2025-06-19 20:39:09 +02:00
4cd3527761 Enable B009 (#144192) 2025-05-21 16:37:51 +01:00
34d17ca458 Move state length validation to StateMachine APIs (#143681)
* Move state length validation to StateMachine async_set method

We call validate_state to make sure we do not allow any states
into the state machine that have a length>255 so we do not break
the recorder. Since async_set_internal already requires callers
to pre-validate the state, we can move the check to async_set
instead of at State object creation time to avoid needing to
check it twice in the hot path (entity write state)

* move check in async_set_internal so it only happens on state change

* no need to check if same_state
2025-04-25 21:15:15 -04:00
03950f270a Remove lower call in async_reserve (#143682)
async_reserve is only called from the the entity_platform helper
which already ensures the entity_id is validated and in lower
case.
a783b6a0ab/homeassistant/helpers/entity_platform.py (L936)
2025-04-25 21:12:55 -04:00
199a274c80 Remove deprecated hass.helpers (#143514) 2025-04-23 17:24:25 +02:00
f22eca3d9e Remove deprecated hass.components (#141947) 2025-04-23 14:04:36 +02:00
93162f6b65 Mark Event and HassJob with @final (#142055) 2025-04-02 14:04:48 +02:00
0d511c697c Improve performance of as_compressed_state (#141800)
We have to build all of these at startup.

Its a lot faster to compare floats instead
of datetime objects. Since we already have to
fetch last_changed_timestamp, use it to compare
with last_updated_timestamp since we already know
we will have last_updated_timestamp
2025-03-30 22:20:24 +02:00
40eb8b91cc Adjust to recommended propcache.api import paths (#136150) 2025-01-21 10:58:22 +01:00
ef8b8fbbaa Enable RUF023 (#135830) 2025-01-17 12:28:27 +01:00
60bdc13c94 Drop Python 3.12 support (#135589) 2025-01-14 16:23:15 +01:00
5df7092f41 Improve formatting in core files (#135256)
* Adjust core files formatting

* Adjust translations script
2025-01-10 09:08:37 +01:00
899fb091fc Simplify access to hass in service calls (#133062) 2024-12-13 09:31:21 +01:00
be81fd86d3 Remvove deprecated core constants (#131803) 2024-11-28 11:06:04 +01:00
c7485b94d5 Use breaks_in_ha_version in report_usage (#131137)
* Use breaks_in_ha_version in report_usage

* Revert behavior change
2024-11-23 18:58:24 +01:00
a3b0909e3f Add new frame helper to better distinguish custom and core integrations (#130025)
* Add new frame helper to clarify options available

* Adjust

* Improve

* Use report_usage in core

* Add tests

* Use is/is not

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

* Use enum.auto()

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2024-11-07 18:23:35 +01:00
1c6ad2fa66 Allow importing homeassistant.core.Config until 2025.11 (#129537) 2024-10-30 22:56:59 +01:00
4b56701152 Move core config class to core_config.py (#129163) 2024-10-26 07:00:31 +02:00
3512cb9599 Use webrtc-models package (#129032) 2024-10-25 10:18:55 +02:00
3e62c6ae2f Move core config functionality to its own module (#129065)
* Move core config functionality to its own module

* Adjust test
2024-10-24 13:34:51 +02:00
487593af38 Allow configuring WebRTC stun and turn servers (#128984)
* Allow configuring WebRTC stun and turn servers

* Add tests

* Remove class WebRTCCoreConfiguration
2024-10-23 14:41:45 +02:00
db494de809 Restore __slots__ to core objects (#127441) 2024-10-03 22:23:47 +02:00
0f29fd3e10 Switch to using fast cached_property implementation in propcache (#127339) 2024-10-03 13:11:02 -05:00
6c01e4b99c Use BaseEventLoop._thread_id instead of a custom attribute (#124054)
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-08-17 10:59:39 +02:00
b15ea58851 Relocate code to get scheduled TimerHandles (#123546) 2024-08-12 09:15:33 +02:00
d1264655a0 Fix some typos in core.py (#121189) 2024-07-04 13:04:52 +02:00
48172b0426 Small speed up to writing entity state (#121043) 2024-07-03 12:16:41 -05:00
852bb19223 Cleanup db_schema from_event constructors (#120803) 2024-06-29 07:49:16 -05:00
3895252965 Fix docstring for EventStateEventData (#120662) 2024-06-27 08:00:14 -05:00
a165064e9d Improve typing of state event helpers (#120639) 2024-06-27 06:08:19 -05:00
d589eaf440 Simplify EVENT_STATE_REPORTED (#120508) 2024-06-26 11:23:26 +02:00
b4eee166aa Add voluptuous type aliases (#120399) 2024-06-25 11:58:27 +02:00
7e61ec96e7 Make the radius of the home zone configurable (#119385) 2024-06-15 13:22:01 +02:00
904b89df80 Allow importing typing helper in core files (#119377)
* Allow importing typing helper in core files

* Really fix the circular import

* Update test
2024-06-11 13:48:12 +02:00
f9205cd88d Avoid additional timestamp conversion to set state (#118885)
Avoid addtional timestamp conversion to set state

Since we already have the timestamp, we can pass it on to the State
object and avoid the additional timestamp conversion which can be as
much as 30% of the state write runtime.

Since datetime objects are limited to microsecond precision, we need
to adjust some tests to account for the additional precision that we
will now be able to get in the database
2024-06-05 23:43:34 -04:00
475c20d529 Always do thread safety check when writing state (#118886)
* Always do thread safety check when writing state

Refactor the 3 most common places where the thread safety check
for the event loop to be inline to make the check fast enough
that we can keep it long term. While code review catches most
of the thread safety issues in core, some of them still make
it through, and new ones keep getting added. Its not possible
to catch them all with manual code review, so its worth the
tiny overhead to check each time.

Previously the check was limited to custom components
because they were the most common source of thread
safety issues.

* Always do thread safety check when writing state

Refactor the 3 most common places where the thread safety check
for the event loop to be inline to make the check fast enough
that we can keep it long term. While code review catches most
of the thread safety issues in core, some of them still make
it through, and new ones keep getting added. Its not possible
to catch them all with manual code review, so its worth the
tiny overhead to check each time.

Previously the check was limited to custom components
because they were the most common source of thread
safety issues.

* async_fire is more common than expected with ccs

* fix mock

* fix hass mocking
2024-06-05 23:41:55 -04:00
76aa504e36 Fix last_reported_timestamp not being updated when last_reported is changed (#118341)
* Reduce number of calls to last_reported_timestamp

When a state is created, last_update is always the same
as last_reported, and we only update it later if it changes
so we can pre-set the cached property to avoid it being
run when the recorder accesses it later.

* fix cache not being overridden

* coverage
2024-05-28 19:03:19 -10:00
33ff84469a Align max expected entities constant between modules (#118102) 2024-05-27 14:06:16 -10:00
25f199c39c Improve performance of verify_event_loop_thread (#118198) 2024-05-26 17:39:15 -10:00
87fc27eeae Teach Context about deepcopy (#118206)
Teach context about deepcopy
2024-05-26 23:14:02 -04:00
56431ef750 Pre-set the HassJob job_type cached_property if its known (#118199) 2024-05-26 16:13:48 -10:00
c368ffffd5 Add async_get_hass_or_none (#118164) 2024-05-26 13:38:46 +02:00
e663d4f602 Refactor state_reported listener setup to avoid merge in async_fire_internal (#117953)
* Refactor state_reported listener setup to avoid merge in async_fire_internal

Instead of merging the listeners in async_fire_internal, setup the listener for
state_changed at the same time so async_fire_internal can avoid having to copy
another list

* Refactor state_reported listener setup to avoid merge in async_fire_internal

Instead of merging the listeners in async_fire_internal, setup the listener for
state_changed at the same time so async_fire_internal can avoid having to copy
another list

* tweak

* tweak

* tweak

* tweak

* tweak
2024-05-22 23:14:50 -04:00
e12d23bd48 Speed up async_get_loaded_integrations (#117851)
* Speed up async_get_loaded_integrations

Use a setcomp and difference to find the components to split
to avoid the loop. A setcomp is inlined in python3.12 so its
much faster

* Speed up async_get_loaded_integrations

Use a setcomp and difference to find the components to split
to avoid the loop. A setcomp is inlined in python3.12 so its
much faster

* simplify

* fix compat

* bootstrap

* fix tests
2024-05-21 09:08:49 -04:00
e8fc4e0f19 Small speed up to adding event bus listeners (#117849) 2024-05-21 13:52:44 +02:00
7998f874c0 Use PEP 695 for function annotations with scoping (#117787) 2024-05-20 12:43:39 +02:00
f50973c76c Use PEP 695 misc (#117788) 2024-05-20 12:01:49 +02:00
5a609c34bb Fix blocking I/O in the event loop when loading timezones (#117721) 2024-05-20 11:06:03 +02:00
0293315b23 Use PEP 695 for covariant class annotations (#117780) 2024-05-20 10:55:44 +02:00
4cf0a3f154 Use PEP 695 for function annotations (3) (#117660) 2024-05-18 11:43:32 +02:00