Commit Graph

214 Commits (dev)

Author SHA1 Message Date
Abílio Costa d8dd6a99b3
Use default translation on SensorEntity unit_of_measurement (#131633)
* Use translations on SensorEntity unit_of_measurement property

* Use default language for unit translation

* Update brother integration snapshot

* Update snapshots
2024-11-27 14:45:53 +01:00
Erik Montnemery 416ead5311
Improve docstring of EntityComponent and EntityPlatform (#128135) 2024-10-11 13:43:20 +02:00
Artur Pragacz c175a68a26
Skip unnecessary checks for entities with unique_id (#125051) 2024-10-01 11:27:14 -05:00
Erik Montnemery 69943af68a
Deduplicate async_register_entity_service (#124045) 2024-08-16 14:06:35 +02:00
Erik Montnemery f9ade788eb
Do sanity check EntityPlatform.async_register_entity_service schema (#123058)
* Do a sanity check of schema passed to EntityPlatform.async_register_entity_service

* Only attempt to check schema of Schema

* Handle All/Any wrapped in schema

* Clarify comment

* Apply suggestions from code review

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

---------

Co-authored-by: Robert Resch <robert@resch.dev>
2024-08-16 10:01:12 +02:00
Erik Montnemery 7063541733
Support None schema in EntityPlatform.async_register_entity_service (#123064) 2024-08-14 10:46:29 +02:00
Erik Montnemery 449afe9e6f
Correct type annotation for `EntityPlatform.async_register_entity_service` (#123054)
Correct type annotation for EntityPlatform.async_register_entity_service

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
2024-08-02 11:58:07 +02:00
Marc Mueller 49df0c4366
Improve schema typing (2) (#120475) 2024-06-26 02:25:30 +02:00
Marc Mueller b4eee166aa
Add voluptuous type aliases (#120399) 2024-06-25 11:58:27 +02:00
Paulus Schoutsen eb89ce47ea
Inline primary integration (#119860) 2024-06-18 08:08:08 +02:00
Paulus Schoutsen 836abe68c7
Track primary integration (#119741)
* Track primary integration

* Update snapshots

* More snapshots updated

* Uno mas

* Update snapshot
2024-06-16 13:26:06 -04:00
J. Nick Koston fd9d4dbb34
Use del instead of pop in the entity platform remove (#118337) 2024-05-28 15:26:22 -10:00
J. Nick Koston 7714f807b4
Detect incorrect exception in forwarded platforms (#117754)
* Detect incorrect exception in forwarded platforms

If an integration raises ConfigEntryError/ConfigEntryAuthFailed/ConfigEntryAuthFailed
in a forwarded platform it would affect the state of the config entry and cause it to
process unloads and setup retries in while the other platforms continued to setup

* Detect incorrect exception in forwarded platforms

If an integration raises ConfigEntryError/ConfigEntryAuthFailed/ConfigEntryAuthFailed
in a forwarded platform it would affect the state of the config entry and cause it to
process unloads and setup retries in while the other platforms continued to setup

* Update homeassistant/config_entries.py

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>

* adjust

* fix

---------

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-05-20 20:01:59 -04:00
Erik Montnemery 7f3d6fe1f0
Fix lying docstring in entity_platform (#117450) 2024-05-14 21:15:05 +02:00
J. Nick Koston b061e7d1aa
Small speed up to setting up integrations and config entries (#117278)
* Small speed up to setting up integration and config entries

When profiling tests, I noticed many calls to get_running_loop. In the places
where we are already in a coro, pass the existing loop so it does not have to
be looked up. I did not do this for places were we are not in a coro since there
is risk that an integration could be doing a non-thread-safe call and its better
that the code raises when trying to fetch the running loop vs the performance
improvement for these cases.

* fix merge

* missed some
2024-05-11 22:39:20 -04:00
Marc Mueller 2db64c7e6d
Use HassKey for helpers (1) (#117012) 2024-05-07 11:25:16 -05:00
Sid 2cc916db6d
Replace pylint broad-except with Ruff BLE001 (#116250) 2024-05-07 14:00:27 +02:00
J. Nick Koston b41b1bb998
Refactor entity_platform polling to avoid double time fetch (#116877)
* Refactor entity_platform polling to avoid double time fetch

Replace async_track_time_interval with loop.call_later
to avoid the useless time fetch every time the listener
fired since we always throw it away

* fix test
2024-05-05 16:28:01 -04: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 6bd6adc4f5
Avoid calling valid_entity_id when adding entities if they are already registered (#115388) 2024-04-10 15:18:47 -10:00
J. Nick Koston bbecb98927
Fix type on known_object_ids in _entity_id_available and async_generate_entity_id (#115378) 2024-04-10 11:44:25 -10:00
J. Nick Koston 89a2c89fe2
Avoid checking for polling if an entity fails to add (#115159)
* Avoid checking for polling if an entity fails to add

* no need to do protected access

* no need to do protected access

* no need to do protected access

* no need to do protected access

* coverage

* fix test

* fix

* broken one must be first
2024-04-07 21:25:55 -04:00
Sid 6587ee20db
Enable Ruff TRY300 (#114437)
* Enable Ruff TRY300

* Update validation.py

* Address review comments
2024-03-30 10:37:59 +01:00
Joost Lekkerkerker 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
J. Nick Koston c615b52840
Refactor integration startup time to show wall clock time (#113707)
* Refactor setup time tracking to exclude time waiting on other operations

We now exclude the import time and th time waiting on
base platforms to setup from the setup times

* tweak

* tweak

* tweak

* tweak

* adjust

* fixes

* fixes

* preen

* preen

* tweak

* tweak

* adjust

* tweak

* reduce

* do not count integrtion platforms against their parent integration

* handle legacy tts platforms

* stt as well

* one more wait

* use the same pattern in all the legacy

* fix tts and stt legacy

* fix

* fix

* reduce

* preen

* entity comp does not wait for platforms

* scene blocks as well

* fix test

* test fixes

* coverage

* coverage

* coverage

* fix test

* Update tests/test_setup.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update tests/test_setup.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/setup.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* strip

* strip WAIT_PLATFORM_INTEGRATION

* strip WAIT_PLATFORM_INTEGRATION

* strip WAIT_PLATFORM_INTEGRATION

* strip WAIT_PLATFORM_INTEGRATION

* remove complexity

* Apply suggestions from code review

* no longer works that way

* fixes

* fixes

* fixes

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-03-18 21:45:34 -04: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
J. Nick Koston 65358c129a
Replace periodic tasks with background tasks (#112726)
* Phase out periodic tasks

* false by default or some tests will block forever, will need to fix each one manually

* kwarg works

* kwarg works

* kwarg works

* fixes

* fix more tests

* fix more tests

* fix lifx

* opensky

* pvpc_hourly_pricing

* adjust more

* adjust more

* smarttub

* adjust more

* adjust more

* adjust more

* adjust more

* adjust

* no eager executor

* zha

* qnap_qsw

* fix more

* fix fix

* docs

* its a wrapper now

* add more coverage

* coverage

* cover all combos

* more fixes

* more fixes

* more fixes

* remaining issues are legit bugs in tests

* make tplink test more predictable

* more fixes

* feedreader

* grind out some more

* make test race safe

* one more
2024-03-08 21:45:10 -05:00
Marc Mueller 19ab3d6daf
Add empty line after module docstring [helpers + other] (#112707) 2024-03-08 10:36:11 -05:00
J. Nick Koston a6b17dbe68
Schedule polling as periodic tasks (#112640)
* Schedule periodic coordinator updates as background tasks.

Currently, the coordinator's periodic refreshes delay startup because they are not scheduled as background tasks. We will wait if the startup takes long enough for the first planned refresh. Another coordinator's scheduled refresh will be fired on busy systems, further delaying the startup. This chain of events results in the startup taking a long time and hitting the safety timeout because too many coordinators are refreshing.

This case can also happen with scheduled entity refreshes, but it's less common. A future PR will address that case.

* periodic_tasks

* periodic_tasks

* periodic_tasks

* merge

* merge

* merge

* merge

* merge

* fix test that call the sync api from async

* one more place

* cannot chain

* async_run_periodic_hass_job

* sun and pattern time changes from automations also block startup

* Revert "sun and pattern time changes from automations also block startup"

This reverts commit 6de2defa05.

* make sure polling is cancelled when config entry is unloaded

* Revert "Revert "sun and pattern time changes from automations also block startup""

This reverts commit e8f12aad55.

* remove DisabledError from homewizard test as it relies on a race

* fix race

* direct coverage
2024-03-07 23:32:26 -05:00
J. Nick Koston a6f4f6eae8
Use eager task creation to add entities to entity platform (#111553) 2024-02-27 09:54:51 -10:00
J. Nick Koston 08e0008d31
Use an eager task to setup entity platforms (#111574)
* Use an eager task to setup entity platforms

Ideally we would have awaited this function instead, but we want
to shield it from cancellation so we wrap it in asyncio.shield
which schedules it as a task. Since we have integrations that
never suspend in async_setup_entry, we can avoid scheduling on
the evnet loop with an eager task for this case

* its an executor future

* its an executor future

* fix

* doc string lied
2024-02-27 08:45:45 -05:00
J. Nick Koston f56e4d6a09
Use eager task creation for entity platform polling (#111575)
* Use eager task creation for entity platform polling

We have lots of places where `async_update` does not suspend and
is only a coro because its required to be a coro to run in the
event loop

* try again
2024-02-26 23:16:39 -05:00
J. Nick Koston b75277cc24
Use an eager task to update multiple entities (#111556)
If there are multiple entities on the same platform its likely
that only one of them will suspend in the update so schedule
them eagerly
2024-02-26 20:49:09 -05:00
J. Nick Koston 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 Koston 1a02330bd9
Avoid creating tasks to remove entities (#110967) 2024-02-20 21:32:36 -06:00
J. Nick Koston dc4008c518
Avoid creating tasks to shutdown entity platforms (#111026)
* Avoid creating tasks to shutdown entity platforms

Nothing needed to be awaited here

* fix mocking

* missed one test
2024-02-20 21:10:25 -05:00
J. Nick Koston 09c609459d
Fix entity services targeting entities outside the platform when using areas/devices (#109810) 2024-02-06 12:41:57 -06:00
Marc Mueller cd0ee98dba
Use builtin TimeoutError [core + helpers] (#109684) 2024-02-05 12:09:54 +01:00
J. Nick Koston 617e8dd8a5
Small cleanup to entity platform translation fetching (#108890)
* Small cleanup to entity platform translation fetching

While I could not realize the performance improvemnet I had
hoped in #108800, I pulled this out since its a nice cleanup to avoid
constructing the inner function over and over.

* stale docstring
2024-01-26 00:14:44 -05:00
G Johansson 65581e94ea
Add config flow for Time & Date (#104183)
Co-authored-by: Erik <erik@montnemery.com>
2024-01-23 12:18:31 +01:00
J. Nick Koston 4b7a313ece
Use identity checks for CoreState (#107846)
Some of the checks used ==, and some used is. Switch
everything to is as its faster
2024-01-12 10:21:26 +01:00
J. Nick Koston d260ed938a
Reduce overhead to call entity services (#106908) 2024-01-08 09:30:52 +01:00
J. Nick Koston 09b65f14b9
Index entities by domain for entity services (#106759) 2024-01-02 15:28:58 +01:00
J. Nick Koston dfb08e7efd
Remove unneeded usage of run_callback_threadsafe in entity helper (#106138)
We do not need to create a future here as we do not
need to wait for the result as its going to run
in the background in a task anyways
2023-12-20 23:57:20 +01:00
Erik Montnemery 84e74e4c74
Reverse component path (#104087)
* Reverse component path

* Update translations helper

* Fix

* Revert incorrect change of PLATFORM_FORMAT

* Fix use of PLATFORM_FORMAT in tts

* Fix ios
2023-12-05 08:43:58 +01:00
Ruslan Sayfutdinov 1a3475ea60
Fix typing for entity_platform.async_register_entity_service (#103777) 2023-11-13 20:00:09 +01:00
Kevin Stillhammer 06c9719cd6
Support multiple responses for service calls (#96370)
* add supports_response to platform entity services

* support multiple entities in entity_service_call

* support legacy response format for service calls

* revert changes to script/shell_command

* add back test for multiple responses for legacy service

* remove SupportsResponse.ONLY_LEGACY

* Apply suggestion

Co-authored-by: Allen Porter <allen.porter@gmail.com>

* test for entity_id remove None

* revert Apply suggestion

* return EntityServiceResponse from _handle_entity_call

* Use asyncio.gather

* EntityServiceResponse not Optional

* styling

---------

Co-authored-by: Allen Porter <allen.porter@gmail.com>
2023-11-02 18:37:35 -07:00
Erik Montnemery 97f3199d6d
Do not add entities with invalid device info (#98150) 2023-08-11 13:14:47 +02:00
Franck Nijhof 868a5f377f
Ruff: isort don't split imports based on trailing comma (#98162) 2023-08-10 14:27:03 +02:00
Erik Montnemery f0953dde95
Add comment to EntityPlatform._async_add_entity about update_before_add (#96891) 2023-07-19 13:07:23 +02:00