Commit Graph
149 Commits
Author SHA1 Message Date
Erik MontnemeryandGitHub d860b35f41 Fix flaky test test_async_parallel_updates_with_zero_on_sync_update (#143810) 2025-04-28 09:27:26 +02:00
J. Nick KostonandGitHub 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
Erik MontnemeryandGitHub dc8e1773f1 Remove unused defaults from entity_registry.RegistryEntry (#143655) 2025-04-25 12:41:58 +02:00
J. Nick KostonandGitHub cb0523660d Improve error logging when state is too long (#143636) 2025-04-24 18:37:32 -10:00
Erik MontnemeryandGitHub 428cc1a951 Update signature of platforms' async_setup_entry in tests (#138271) 2025-02-11 13:17:39 +01:00
Ville SkyttäandGitHub 40eb8b91cc Adjust to recommended propcache.api import paths (#136150) 2025-01-21 10:58:22 +01:00
Franck NijhofandGitHub 00c052bb22 Revert "Remove deprecated supported features warning in ..." (multiple) (#134933) 2025-01-07 00:08:02 +01:00
epenetandGitHub f2500e5a32 Remove deprecated supported features warning in MediaPlayer (#132365) 2024-12-09 23:03:55 +01:00
Erik MontnemeryandGitHub 0d447c9d50 Improve entity cached attributes (#128876) 2024-10-21 10:29:01 +02:00
J. Nick KostonandGitHub 0f29fd3e10 Switch to using fast cached_property implementation in propcache (#127339) 2024-10-03 13:11:02 -05:00
epenetandGitHub 56b4a7f291 Add missing hass type in tests/helpers (#124039) 2024-08-16 17:09:12 +02:00
Marc MuellerandGitHub a6068dcdf2 Update import locations in tests (#122216) 2024-07-20 11:16:04 +02:00
epenetandGitHub 648ef94888 Improve type hints in core helper tests (#120096) 2024-06-21 15:43:27 +02:00
epenetandGitHub 9f41133bbc Add missing argument type to core tests (#119667) 2024-06-14 08:42:01 +02:00
epenetandGitHub 38a6e666a7 Add missing return type to some test functions (#119665) 2024-06-14 08:26:45 +02:00
epenetandGitHub 7d631c28a6 Ignore attribute-defined-outside-init pylint warnings in tests (#119470) 2024-06-12 12:22:31 +02:00
J. Nick KostonandGitHub 62b1bde0e8 Only entity verify state writable once after success unless hass is missing (#118896) 2024-06-06 11:46:44 -05:00
J. Nick KostonandGitHub 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
J. Nick KostonandGitHub 79b4889812 Always do thread safety checks when writing state for custom components (#116044) 2024-04-24 10:05:52 +02:00
J. Nick KostonandGitHub 53a179088f Add debug mode to catch unsafe thread operations using core helpers (#115390)
* adjust

* adjust

* fixes

* one more

* test

* debug

* move to config

* cover

* Update homeassistant/core.py

* set debug from RuntimeConfig

* reduce

* fix message

* raise

* Update homeassistant/core.py

* Update homeassistant/core.py

* no flood check for raise

* cover
2024-04-24 03:36:05 +02:00
SidandGitHub 895f73d8e4 Enable Ruff A001 (#115654) 2024-04-21 23:25:27 +02:00
Alberto MontesandGitHub c94b0a82ca Make release channel a hardcoded enum rather than a free form string (#115595)
* Make release channel a hardcoded enum rather than a free form string

* Update enum comparison to remove equality and us identity comparison

* Fix comparison condition to match the previous implementation

* Update tests to use Enum instead of string
2024-04-20 20:01:49 +02:00
Marc MuellerandGitHub 816ce116bf Remove unnecessary functools.cached_property backport (#114239) 2024-04-04 11:24:26 +02:00
6bb4e7d62c Bump ruff to 0.3.4 (#112690)
Co-authored-by: Sid <[email protected]>
Co-authored-by: Marc Mueller <[email protected]>
Co-authored-by: J. Nick Koston <[email protected]>
2024-03-26 00:02:16 +01:00
00ec7f11f0 Enable Ruff rule PT007 (#113764)
Co-authored-by: Franck Nijhof <[email protected]>
2024-03-19 09:01:07 +01:00
Joost LekkerkerkerandGitHub 05172d8e4d Improve loops and lists (#113269)
* Enable PERF

* Enable PERF rule

* Enable PERF rule

* Don't enable flag yet
2024-03-14 10:22:20 +01:00
J. Nick KostonandGitHub b7d9f26cee Cache the job type for entity service calls (#112793) 2024-03-08 22:49:08 -10:00
Marc MuellerandGitHub a6b842f818 Add empty line after module docstring (2) [other] (#112738) 2024-03-08 19:16:38 +01:00
d9addc45f9 Avoid scheduling a task to add each entity when not using update_before_add (#110951)
Co-authored-by: Paulus Schoutsen <[email protected]>
2024-02-23 10:49:26 -10:00
J. Nick KostonandGitHub 9c145b5faa Fix race in removing entities from the registry (#110978) 2024-02-20 20:48:31 -06:00
J. Nick KostonandGitHub 454c62b5b4 Avoid total_seconds conversion every state write when context is set (#107617) 2024-01-13 21:04:32 -05:00
Erik MontnemeryandGitHub 9859306718 Prevent overriding cached attribute as property (#107657)
* Prevent overriding cached attribute as property

* Remove debug
2024-01-09 19:16:45 +01:00
eb01998395 Add support for placeholders in entity name translations (#104453)
* add placeholder support to entity name translation

* add negativ tests

* make property also available via description

* fix doc string in translation_placeholders()

* fix detection of placeholder

* validate placeholders for localized strings

* add test

* Cache translation_placeholders property

* Make translation_placeholders uncondotionally return dict

* Fall back to unsubstituted name in case of mismatch

* Only replace failing translations with English

* Update snapshots

* Blow up on non stable releases

* Fix test

* Update entity.py

---------

Co-authored-by: Erik <[email protected]>
Co-authored-by: Joost Lekkerkerker <[email protected]>
2024-01-03 17:34:47 +01:00
Erik MontnemeryandGitHub 599271fdc0 Don't use entity_id in __repr__ of not added entity (#106861) 2024-01-02 11:35:16 +01:00
Erik MontnemeryandGitHub c1f1b5c50b Ensure it's safe to call Entity.__repr__ on non added entity (#106032) 2023-12-31 18:54:34 +01:00
Erik MontnemeryandGitHub 56a58f9285 Improve tests of inheriting entity descriptions (#106647) 2023-12-29 13:22:52 +01:00
J. Nick KostonandGitHub a46fe94216 Add helper to report deprecated entity supported features magic numbers (#106602) 2023-12-28 12:24:36 -10:00
Erik MontnemeryandGitHub 3a744d374b Add support for caching entity properties (#100601) 2023-12-22 09:02:55 -10:00
Erik MontnemeryandGitHub 0534b0dee4 Improve entity tests (#106175) 2023-12-21 15:32:25 +01:00
Erik MontnemeryandGitHub 9020dbb093 Remove context_recent_time property from entity base class (#105652) 2023-12-14 08:33:31 +01:00
Erik MontnemeryandGitHub dd5a48996a Keep capabilities up to date in the entity registry (#101748)
* Keep capabilities up to date in the entity registry

* Warn if entities update their capabilities very often

* Fix updating of device class

* Stop tracking capability updates once flooding is logged

* Only sync registry if state changed

* Improve test

* Revert "Only sync registry if state changed"

This reverts commit 1c52571596c06444df234d4b088242b494b630f2.

* Avoid calculating device class twice

* Address review comments

* Revert using dataclass

* Fix unintended revert

* Add helper method
2023-12-13 17:27:26 +01:00
Erik MontnemeryandGitHub 22c3847c0e Allow inheriting FrozenOrThawed with custom init (#105624) 2023-12-13 10:13:34 +01:00
Erik MontnemeryandGitHub 5bd0833f49 Improve FrozenOrThawed (#105541) 2023-12-12 21:19:41 +01:00
Erik MontnemeryandGitHub dd338799d4 Make it possible to inherit EntityDescription in frozen and mutable dataclasses (#105211) 2023-12-11 20:00:55 +01:00
Erik MontnemeryandGitHub 01b3e0c49e Remove useless code from entity helper tests (#103854) 2023-11-12 18:55:34 +01:00
Erik MontnemeryandGitHub d913508607 Allow removing an entity more than once (#102904) 2023-11-08 12:50:40 +01:00
Jan-Philipp BeneckeandGitHub ae1117bc74 Fix failing entity reuse test (#103342)
* Fix failing entity reuse test

* One more test
2023-11-03 23:19:37 +01:00
Erik MontnemeryandGitHub 0ea0a1ed06 Prevent accidentally reusing an entity object (#102911)
* Prevent accidentally reusing an entity object

* Fix group reload service

* Revert "Fix group reload service"

* Improve test

* Add tests aserting entity can't be reused
2023-11-03 21:01:38 +01:00
J. Nick KostonandGitHub e5ebdf7ad4 Remove implict name check from Entity base class (#101905) 2023-10-15 23:40:43 +02:00
Nicolas van de WalleandGitHub 1b11062b27 Improved debugging for "Failed to set state" (#101657) 2023-10-08 19:40:42 +02:00