Commit Graph

373 Commits

Author SHA1 Message Date
jbouwh
bc8d7fc02e Move logic into Entity class 2025-10-17 13:13:44 +00:00
jbouwh
20a494e4f8 Use platform domain attribute 2025-10-17 13:13:44 +00:00
jbouwh
64ad83b1cd Fix typo 2025-10-17 13:13:44 +00:00
jbouwh
254a4de025 Follow up on code review 2025-10-17 13:13:44 +00:00
jbouwh
ec43e01d51 Implement mixin class and add feature to maintain included entities from unique IDs 2025-10-17 13:13:44 +00:00
jbouwh
4f25518671 Add included_entities attribute to base Entity class 2025-10-17 13:13:44 +00:00
Erik Montnemery
dd399ef59f Refactor EntityPlatform (#147927) 2025-07-22 14:35:57 +02:00
Erik Montnemery
943fb9948b Adjust logic related to entity platform state (#147882)
* Adjust logic related to entity platform state

* Break up hard to read if-statement

* Add and improve tests
2025-07-02 14:57:53 +02:00
Erik Montnemery
91c3b43d7f Improve comment for helpers.entity.entity_sources (#146529) 2025-06-27 20:54:19 +02:00
G Johansson
db3090078b Remove deprecated support feature values in camera (#146988) 2025-06-22 09:31:16 +02:00
Erik Montnemery
e39edcc234 Remove unused attribute EntityInfo.custom_component (#146550) 2025-06-11 17:27:17 +02:00
Joost Lekkerkerker
4cd3527761 Enable B009 (#144192) 2025-05-21 16:37:51 +01:00
J. Nick Koston
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
J. Nick Koston
d61e39743b Reduce ref counting in _async_write_ha_state (#143634)
* Reduce ref counting in _async_write_ha_state

It no longer makes sense to keep a temp reference
to entity_id and hass since the function was
refactored and there are very few accesses now.

* one more place we can reduce ref counts
2025-04-25 18:25:16 +02:00
J. Nick Koston
cb0523660d Improve error logging when state is too long (#143636) 2025-04-24 18:37:32 -10:00
Joost Lekkerkerker
dcc63a6f2e Bump ruff to 0.10.0 (#140541)
* Bump ruff to 0.10.0

* Bump ruff to 0.10.0

* Bump ruff to 0.10.0

* Bump ruff to 0.10.0

* Update pyproject.toml

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>

* Fix

---------

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
2025-03-14 12:32:50 +00:00
J. Nick Koston
d97194303a Improve performance of calculating state (#138832)
```
print(timeit.timeit("x.update(y)", setup=x={a:b}
2025-02-19 09:43:41 +01:00
Ville Skyttä
40eb8b91cc Adjust to recommended propcache.api import paths (#136150) 2025-01-21 10:58:22 +01:00
Joost Lekkerkerker
8a35261fd8 Remove unused noqas (#135583) 2025-01-15 10:02:18 +01:00
Joost Lekkerkerker
8db63adc11 Bump ruff to 0.9.1 (#135197) 2025-01-14 11:46:12 +01:00
Franck Nijhof
00c052bb22 Revert "Remove deprecated supported features warning in ..." (multiple) (#134933) 2025-01-07 00:08:02 +01:00
epenet
f2500e5a32 Remove deprecated supported features warning in MediaPlayer (#132365) 2024-12-09 23:03:55 +01:00
Abílio Costa
208b14dd2b Use translations on NumberEntity unit_of_measurement property (#132095)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-12-03 17:08:09 +01:00
Erik Montnemery
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
Erik Montnemery
0d447c9d50 Improve entity cached attributes (#128876) 2024-10-21 10:29:01 +02:00
J. Nick Koston
0f29fd3e10 Switch to using fast cached_property implementation in propcache (#127339) 2024-10-03 13:11:02 -05:00
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