Commit Graph
137 Commits
Author SHA1 Message Date
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 <27780930+autinerd@users.noreply.github.com>
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-03-26 00:02:16 +01:00
00ec7f11f0 Enable Ruff rule PT007 (#113764)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
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 <balloob@gmail.com>
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 <erik@montnemery.com>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
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
Erik MontnemeryandGitHub 20188181f7 Fix spelling in sensor test (#101520) 2023-10-06 11:51:08 +02:00
Erik MontnemeryandGitHub 17779c5f0c Add loader.async_suggest_report_issue and loader.async_get_issue_tracker (#101336)
* Add loader.async_suggest_report_issue and loader.async_get_issue_tracker

* Update tests

* Add tests

* Address review comments

* Address review comments
2023-10-04 13:40:33 +02:00
Erik MontnemeryandGitHub d1afcd773f Revert "Cache entity properties that are never expected to change in the base class" (#100422)
Revert "Cache entity properties that are never expected to change in the base class (#95315)"

This reverts commit 042776ebb8.
2023-09-15 11:25:24 +02:00
J. Nick KostonandGitHub 042776ebb8 Cache entity properties that are never expected to change in the base class (#95315) 2023-09-14 17:48:48 -05:00
Erik MontnemeryandGitHub bbcbb2e322 Improve Entity._suggest_report_issue (#100204) 2023-09-12 21:07:32 +02:00
Erik MontnemeryandGitHub 51576b7214 Improve typing of entity.entity_sources (#99407)
* Improve typing of entity.entity_sources

* Calculate entity info source when generating WS response

* Adjust typing

* Update tests
2023-09-12 20:41:26 +02:00
709ce7e0af Set state of entity with invalid state to unknown (#99452)
* Set state of entity with invalid state to unknown

* Add test

* Apply suggestions from code review

Co-authored-by: Robert Resch <robert@resch.dev>

* Update test_entity.py

---------

Co-authored-by: Robert Resch <robert@resch.dev>
2023-09-04 14:09:51 +02:00
Erik MontnemeryandGitHub c7b4d4f361 Adjust helpers tests which create devices (#98214) 2023-08-10 19:28:16 +02:00
Erik MontnemeryandGitHub 614f3c6a15 Move device info validation to device registry (#96465)
* Move device info validation to device registry

* Don't move DeviceInfo

* Fix type annotation

* Don't block adding device for unknown config entry

* Fix test

* Remove use of locals()

* Improve error message
2023-07-14 08:55:17 -04:00
Jan BouwhuisandGitHub b9c7e7c15e Fix not including device_name in friendly name if it is None (#95485)
* Omit device_name in friendly name if it is None

* Fix test
2023-07-06 11:14:09 -04:00
J. Nick KostonandGitHub 9051750add Cache entity translation lookups and keys (#95180) 2023-06-25 08:50:48 -05:00
e2f5a707ce Fix use_device_name in case device device class translations are used (#95010)
Co-authored-by: Erik <erik@montnemery.com>
2023-06-22 11:30:19 +02:00