347 Commits

Author SHA1 Message Date
J. Nick Koston
e71f6c5948
Small speedup to processing entity customize (#121271) 2024-07-05 08:57:08 +02:00
J. Nick Koston
cdb2ec4231
Small speed up to entity state calculation (#121273) 2024-07-05 08:56:20 +02:00
J. Nick Koston
48172b0426
Small speed up to writing entity state (#121043) 2024-07-03 12:16:41 -05:00
J. Nick Koston
5ae13c2ae2
Make use_device_name a cached_property in the base entity class (#119758)
There is a small risk that _attr_name or entity_description
would not be set before state was first written, but that
would likely be a bug.
2024-06-18 21:52:36 -04:00
J. Nick Koston
62b1bde0e8
Only entity verify state writable once after success unless hass is missing (#118896) 2024-06-06 11:46:44 -05:00
J. Nick Koston
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 Koston
ade0f94a20
Remove duplicate getattr call in entity wrap_attr (#118558) 2024-05-31 11:11:46 -04:00
J. Nick Koston
e0264c8604
Replace pop calls with del where the result is discarded in entity (#118340) 2024-05-28 15:26:53 -10:00
Marc Mueller
900b6211ef
Use PEP 695 for function annotations (2) (#117659) 2024-05-18 11:44:39 +02:00
Sid
2cc916db6d
Replace pylint broad-except with Ruff BLE001 (#116250) 2024-05-07 14:00:27 +02:00
J. Nick Koston
2401580b6f
Make a copy of capability_attributes instead of making a new dict (#116477) 2024-04-30 17:54:33 -05:00
J. Nick Koston
164403de20
Add thread safety checks to async_create_task (#116339)
* Add thread safety checks to async_create_task

Calling async_create_task from a thread almost always results in an
fast crash. Since most internals are using async_create_background_task
or other task APIs, and this is the one integrations seem to get wrong
the most, add a thread safety check here

* Add thread safety checks to async_create_task

Calling async_create_task from a thread almost always results in an
fast crash. Since most internals are using async_create_background_task
or other task APIs, and this is the one integrations seem to get wrong
the most, add a thread safety check here

* missed one

* Update homeassistant/core.py

* fix mocks

* one more internal

* more places where internal can be used

* more places where internal can be used

* more places where internal can be used

* internal one more place since this is high volume and was already eager_start
2024-04-28 18:29:00 -04:00
J. Nick Koston
ab2ea6100c
Speed up singleton decorator so it can be used more places (#116292) 2024-04-28 12:11:08 -05:00
J. Nick Koston
cbcfd71f3d
Reduce number of time calls needed to write state (#116297) 2024-04-27 13:17:31 -05:00
J. Nick Koston
f295172d07
Add a fast path for _stringify_state when state is already a str (#116295) 2024-04-27 10:48:17 -05:00
J. Nick Koston
eea66921bb
Avoid update call in entity state write if there is no customize data (#116296) 2024-04-27 10:48:05 -05:00
Sid
e662e3b65c
Bump ruff to 0.4.2 (#116201)
* Bump ruff to 0.4.2

* review comments
2024-04-26 08:48:32 +02:00
J. Nick Koston
df12789e08
Remove duplicate async_write_ha_state thread safety check (#116086) 2024-04-24 12:46:16 +02:00
J. Nick Koston
79b4889812
Always do thread safety checks when writing state for custom components (#116044) 2024-04-24 10:05:52 +02:00
J. Nick Koston
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
Alberto Montes
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
J. Nick Koston
dbc5109fd8
Avoid update calls in state writes when attributes are empty (#115624) 2024-04-15 17:42:18 +02:00
Marc Mueller
d8c8d1a297
Use dict instead of MutableMapping [extra_state_attributes] (#115319) 2024-04-09 15:06:11 -10:00
J. Nick Koston
a0936902c2
Use identity checks for EntityPlatformState enum (#115067) 2024-04-07 02:31:23 +02:00
J. Nick Koston
aeaed83578
Start async_schedule_update_ha_state task eagerly (#114704) 2024-04-05 08:14:21 -10:00
Marc Mueller
816ce116bf
Remove unnecessary functools.cached_property backport (#114239) 2024-04-04 11:24:26 +02:00
J. Nick Koston
2b9f22f11e
Make creation of capabilities_updated_at deque in Entity lazy (#114711)
Most entities will never update their capabilities so we should
avoid creating the deque as its a large chunk of the entity
creation time
2024-04-03 13:53:17 +02:00
Paul Chanvin
b2cab70cc0
Fix argument name in async_update_ha_state warning message (#113969)
Fixed warning message using async_update_ha_state
2024-03-22 02:26:11 +01:00
Sid
82a60fe8ad
Enable Ruff RSE (#113695) 2024-03-18 00:40:38 +01:00
J. Nick Koston
6666f6a8a5
Simplify clearing _attr cached_property in entities (#113136) 2024-03-13 12:04:27 +01:00
J. Nick Koston
fb163278a4
Simplify entity _attr cached_property getter implementation (#113195) 2024-03-13 11:59:36 +01:00
J. Nick Koston
b7d9f26cee
Cache the job type for entity service calls (#112793) 2024-03-08 22:49:08 -10:00
J. Nick Koston
6a7c255b93
Improve entity translation typing (#112788)
* Improve entity translation typing

* Improve entity translation typing
2024-03-08 22:30:13 -05:00
Marc Mueller
cef20506dc
Replace EventType with Event [missing] (#112753) 2024-03-08 21:56:42 +01:00
Marc Mueller
b026b5d589
Replace EventType with Event [helpers] (#112743) 2024-03-08 19:41:50 +01:00
Marc Mueller
19ab3d6daf
Add empty line after module docstring [helpers + other] (#112707) 2024-03-08 10:36:11 -05:00
J. Nick Koston
a7b4cd3512
Pass job type to event listeners when creating entities (#112551) 2024-03-06 16:10:07 -10:00
J. Nick Koston
ce0fb1e716
Fully fix race in removing entities (#111499)
Full fix race in removing entities

Followup to #110978 now that we can start the task
eagerly it completely closes the race window
2024-02-26 23:55:15 -05:00
J. Nick Koston
1a02330bd9
Avoid creating tasks to remove entities (#110967) 2024-02-20 21:32:36 -06:00
J. Nick Koston
9c145b5faa
Fix race in removing entities from the registry (#110978) 2024-02-20 20:48:31 -06:00
J. Nick Koston
454c62b5b4
Avoid total_seconds conversion every state write when context is set (#107617) 2024-01-13 21:04:32 -05:00
Erik Montnemery
9859306718
Prevent overriding cached attribute as property (#107657)
* Prevent overriding cached attribute as property

* Remove debug
2024-01-09 19:16:45 +01:00
Petru Paler
4a2958baeb
Fix entity property cache creation arguments (#107221) 2024-01-05 09:18:25 +01:00
Michael
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 Montnemery
599271fdc0
Don't use entity_id in __repr__ of not added entity (#106861) 2024-01-02 11:35:16 +01:00
Erik Montnemery
c1f1b5c50b
Ensure it's safe to call Entity.__repr__ on non added entity (#106032) 2023-12-31 18:54:34 +01:00
J. Nick Koston
a46fe94216
Add helper to report deprecated entity supported features magic numbers (#106602) 2023-12-28 12:24:36 -10:00
J. Nick Koston
eb3fde7261
Avoid clearing the attr cache in setter when nothing has changed (#106384) 2023-12-25 09:13:48 -10:00
J. Nick Koston
b757984031
Optimize use_device_name check in base entity class (#106209) 2023-12-24 00:30:33 +01:00
J. Nick Koston
1c8d961832
Add support for attribute caching to ToggleEntity (#106272) 2023-12-23 11:11:14 +01:00