Commit Graph

2809 Commits (53a59412bb12ff48dae11dd219bec593929cd4ec)

Author SHA1 Message Date
Michael Hansen f99ec87338
Fail if targeting all devices in the house in service intent handler (#117930)
* Fail if targeting all devices in the house

* Update homeassistant/helpers/intent.py

---------

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-05-22 13:53:31 -04:00
Denis Shulyaka 009c9e79ae
LLM Tools: Add device_id (#117884) 2024-05-21 21:24:46 -04:00
Sid c2b3bf3fb9
Enable Ruff RET502 (#115139) 2024-05-21 22:19:33 +02:00
Paulus Schoutsen f21226dd0e
Address late feedback Google LLM (#117873) 2024-05-21 20:11:18 +02:00
Michael Hansen 8079cc0464
Add description to intent handlers and use in LLM helper (#117864) 2024-05-21 12:54:34 -04:00
J. Nick Koston 266ce9e268
Cache area registry JSON serialize (#117847)
We already cache the entity and device registry, but since I never
used area until recently I did not have enough to notice that they
were not cached
2024-05-21 09:03:31 -04:00
J. Nick Koston 905692901c
Simplify service description cache logic (#117846) 2024-05-21 09:02:32 -04:00
Marc Mueller d44f949b19
Use PEP 695 misc (2) (#117814) 2024-05-21 09:45:57 +02:00
Marc Mueller 58d0ac7f21
Remove future import to fix broken typing.get_type_hints call (#117837) 2024-05-21 09:39:47 +02:00
J. Nick Koston c9d1b127d8
Improve error message when template is rendered from wrong thread (#117822)
* Improve error message when template is rendered from wrong thread

* Improve error message when template is rendered from wrong thread
2024-05-20 23:26:48 -04: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
Marc Mueller f50973c76c
Use PEP 695 misc (#117788) 2024-05-20 12:01:49 +02:00
Marc Mueller 0293315b23
Use PEP 695 for covariant class annotations (#117780) 2024-05-20 10:55:44 +02:00
Marc Mueller 8f0fb4db3e
Use PEP 695 for class annotations (4) (#117778) 2024-05-20 10:44:52 +02:00
Denis Shulyaka c3196a5667
LLM Tools support for Google Generative AI integration (#117644)
* initial commit

* Undo prompt chenges

* Move format_tool out of the class

* Only catch HomeAssistantError and vol.Invalid

* Add config flow option

* Fix type

* Add translation

* Allow changing API access from options flow

* Allow model picking

* Remove allowing HASS Access in main flow

* Move model to the top in options flow

* Make prompt conditional based on API access

* convert only once to dict

* Reduce debug logging

* Update title

* re-order models

* Address comments

* Move things

* Update labels

* Add tool call tests

* coverage

* Use LLM APIs

* Fixes

* Address comments

* Reinstate the title to not break entity name

---------

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-05-19 22:11:25 -04:00
Paulus Schoutsen d001e7daea
Add API class to LLM helper (#117707)
* Add API class to LLM helper

* Add more tests

* Rename intent to assist to broaden scope
2024-05-18 21:14:05 -04:00
Marc Mueller 10dfa91e54
Remove useless TypeVars (#117687) 2024-05-18 12:58:51 +02:00
Marc Mueller 97a4101900
Use PEP 695 for dispatcher helper typing (#117685) 2024-05-18 12:47:03 +02:00
Marc Mueller 900b6211ef
Use PEP 695 for function annotations (2) (#117659) 2024-05-18 11:44:39 +02:00
Marc Mueller 907b9c42e5
Use PEP 695 for decorator typing with type aliases (2) (#117663) 2024-05-18 11:41:46 +02:00
Marc Mueller 25d1ca747b
Use PEP 695 for decorator typing (3) (#117640) 2024-05-17 16:27:32 +02:00
Marc Mueller 87bb7ced79
Use PEP 695 for simple type aliases (#117633) 2024-05-17 14:42:21 +02:00
Marc Mueller 4edee94a81
Update mypy-dev to 1.11.0a2 (#117630) 2024-05-17 13:32:20 +02:00
Marc Mueller ab07bc5298
Improve ReloadServiceHelper typing (#117552) 2024-05-16 12:47:43 +02:00
Denis Shulyaka f31873a846
Add LLM tools (#115464)
* Add llm helper

* break out Tool.specification as class members

* Format state output

* Fix intent tests

* Removed auto initialization of intents - let conversation platforms do that

* Handle DynamicServiceIntentHandler.extra_slots

* Add optional description to IntentTool init

* Add device_id and conversation_id parameters

* intent tests

* Add LLM tools tests

* coverage

* add agent_id parameter

* Apply suggestions from code review

* Apply suggestions from code review

* Apply suggestions from code review

* Apply suggestions from code review

* Apply suggestions from code review

* Fix tests

* Fix intent schema

* Allow a Python function to be registered as am LLM tool

* Add IntentHandler.effective_slot_schema

* Ensure IntentHandler.slot_schema to be vol.Schema

* Raise meaningful error on tool not found

* Move this change to a separate PR

* Update todo integration intent

* Remove Tool constructor

* Move IntentTool to intent helper

* Convert custom serializer into class method

* Remove tool_input from FunctionTool auto arguments to avoid recursion

* Remove conversion into Open API format

* Apply suggestions from code review

* Fix tests

* Use HassKey for helpers (see #117012)

* Add support for functions with typed lists, dicts, and sets as type hints

* Remove FunctionTool

* Added API to get registered intents

* Move IntentTool to the llm library

* Return only handlers in intents.async.get

* Removed llm tool registration from intent library

* Removed tool registration

* Add bind_hass back for now

* removed area and floor resolving

* fix test

* Apply suggestions from code review

* Improve coverage

* Fix intent_type type

* Temporary disable HassClimateGetTemperature intent

* Remove bind_hass

* Fix usage of slot schema

* Fix test

* Revert some test changes

* Don't mutate tool_input

---------

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-05-15 19:16:47 -04:00
Paulus Schoutsen 4aba92ad04
Fix the type of slot schema of intent handlers (#117520)
Fix the slot schema of dynamic intenet handler
2024-05-15 16:45:15 -04:00
Matthias Alphart ec4c8ae228
Allow templates for enabling actions (#117049)
* Allow templates for enabling automation actions

* Use `cv.template` instead of `cv.template_complex`

* Rename test function
2024-05-15 21:03:52 +02:00
Matthias Alphart 076f57ee07
Allow templates for enabling conditions (#117047)
* Allow templates for enabling automation conditions

* Use `cv.template` instead of `cv.template_complex`
2024-05-15 21:03:28 +02:00
Paulus Schoutsen 8f9273e945
Fix intent_type type (#117469) 2024-05-14 21:32:11 -07:00
Erik Montnemery 7f3d6fe1f0
Fix lying docstring in entity_platform (#117450) 2024-05-14 21:15:05 +02:00
Michael Hansen 641754e0bb
Pass device_id to intent handlers (#117442) 2024-05-14 13:59:49 -05:00
Michael Hansen add6ffaf70
Add Assist timers (#117199)
* First pass at timers

* Move to separate file

* Refactor to using events

* Add pause/unpause/status

* Add ordinal

* Add test for timed Assist command

* Fix name matching

* Fix IntentHandleError

* Fix again

* Refactor to callbacks

* is_paused -> is_active

* Rename "set timer" to "start timer"

* Move tasks to timer manager

* More fixes

* Remove assist command

* Remove cancel by ordinal

* More tests

* Remove async on callbacks

* Export async_register_timer_handler
2024-05-14 14:42:32 -04:00
J. Nick Koston 7871e9279b
Adjust thread safety check messages to point to developer docs (#117392) 2024-05-14 15:20:31 +02:00
Matthias Alphart ba48da7678
Allow templates for enabling automation triggers (#114458)
* Allow templates for enabling automation triggers

* Test exception for non-limited template

* Use `cv.template` instead of `cv.template_complex`

* skip trigger with invalid enable template

instead of returning and thus not evaluating other triggers
2024-05-14 14:44:21 +02:00
Allen Porter b84829f70f
Import and cache supported feature enum flags only when needed (#117270)
* Import and cache supported feature enum flags only when needed

* Add comment aboud being loaded from executor.

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2024-05-13 21:07:39 -07:00
J. Nick Koston 9381462877
Migrate restore_state to use the singleton helper (#117385) 2024-05-14 09:13:44 +09:00
J. Nick Koston f318a3b5e2
Fix blocking I/O in the event loop to get MacOS system_info (#117290)
* Fix blocking I/O in the event look to get MacOS system_info

* split pr

* Update homeassistant/helpers/system_info.py

Co-authored-by: Jan-Philipp Benecke <jan-philipp@bnck.me>

* Update homeassistant/helpers/system_info.py

---------

Co-authored-by: Jan-Philipp Benecke <jan-philipp@bnck.me>
2024-05-12 08:16:21 -04:00
J. Nick Koston eac4aaef10
Use a dictcomp to reconstruct DeviceInfo in the device_registry (#117286)
Use a dictcomp to reconstruct DeviceInfo

a dictcomp is faster than many sets on the dict by at least
25%

We call this for nearly every device in the registry at
startup
2024-05-12 08:07:12 +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
J. Nick Koston d7aa24fa50
Only load translations for an integration once per test session (#117118) 2024-05-11 12:00:02 +09:00
Marc Mueller 04c0b7d3df
Use HassKey for importlib helper (#117116) 2024-05-08 17:42:28 -05:00
Sid ac54cdcdb4
Enable Ruff RUF010 (#115371)
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-05-08 23:54:49 +02:00
J. Nick Koston 03dcede211
Avoid creating inner tasks to load storage (#117099) 2024-05-08 23:41:20 +02:00
J. Nick Koston 84a91a86a9
Improve config entry has already been setup error message (#117091) 2024-05-08 14:16:08 -05:00
Troon cc99a9b62a
Add an add template filter (#109884)
* Addition of add filter

This change adds an `add` filter, the addition equivalent of the existing `multiply` filter.

* Test for add filter

* Update test_template.py

* Update tests/helpers/test_template.py

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-05-08 15:39:36 +02:00
Michael Hansen 7923471b94
Intent target matching and media player enhancements (#115445)
* Working

* Tests are passing

* Fix climate

* Requested changes from review
2024-05-07 22:01:03 -04:00
J. Nick Koston 8401b05d40
Move thread safety check in category_registry sooner (#117050) 2024-05-07 19:55:43 -05:00
J. Nick Koston 0b2c29fdb9
Move thread safety in floor_registry sooner (#117044) 2024-05-07 18:48:38 -05:00
J. Nick Koston fc3c384e0a
Move thread safety in label_registry sooner (#117026) 2024-05-07 15:15:30 -05:00
J. Nick Koston 26cc1cd3db
Use singleton helper for registries (#117027) 2024-05-07 21:04:01 +02:00
Marc Mueller f9e2ab2e81
Improve issue_registry event typing (#117023) 2024-05-07 19:49:02 +02:00
Marc Mueller 018e7731ae
Add SignificantChangeProtocol to improve platform typing (#117002) 2024-05-07 18:40:57 +02:00
Marc Mueller 2db64c7e6d
Use HassKey for helpers (1) (#117012) 2024-05-07 11:25:16 -05:00
Marc Mueller 8f614fb06d
Use HassKey for helpers (2) (#117013) 2024-05-07 11:24:13 -05:00
Marc Mueller fd5885ec83
Use HassKey for registries (#117000) 2024-05-07 18:03:14 +02:00
Sid 2cc916db6d
Replace pylint broad-except with Ruff BLE001 (#116250) 2024-05-07 14:00:27 +02:00
Marc Mueller 3d700e2b71
Add HassDict implementation (#103844) 2024-05-07 10:53:13 +02:00
Sid b456d97e65
Replace pylint protected-access with Ruff SLF001 (#115735) 2024-05-06 20:33:26 +02:00
J. Nick Koston 5d5f311898
Move thread safety check in issue_registry sooner (#116899) 2024-05-05 20:32:55 -05:00
J. Nick Koston 91fa8b50cc
Turn on thread safety checks in async_dispatcher_send (#116867)
* Turn on thread safety checks in async_dispatcher_send

We keep seeing issues where async_dispatcher_send is called from
a thread which means we call the callback function on the other
side in the thread as well which usually leads to a crash

* Turn on thread safety checks in async_dispatcher_send

We keep seeing issues where async_dispatcher_send is called from
a thread which means we call the callback function on the other
side in the thread as well which usually leads to a crash

* adjust
2024-05-05 16:29:43 -04: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 0380116ef6
Improve logging of _TrackPointUTCTime objects (#116711) 2024-05-04 17:35:44 -05:00
Jan Bouwhuis 84308c9e53
Add title feature to notify entity platform (#116426)
* Add title feature to notify entity platform

* Add overload variants

* Remove overloads, update signatures

* Improve test coverage

* Apply suggestions from code review

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

* Do not use const

* fix typo

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-05-03 11:17:28 +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
G Johansson 822646749d
Remove entity category "system" check from entity registry (#116412) 2024-04-30 04:01:12 +02: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 66e86170b1
Make storage load tasks background tasks to avoid delaying shutdown (#116332) 2024-04-28 08:14:15 -05:00
J. Nick Koston 76639252c9
Make discovery flow tasks background tasks (#116327) 2024-04-28 08:13:37 -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
J. Nick Koston 7715bee6b0
Fix script in restart mode that is fired from the same trigger (#116247) 2024-04-27 07:08:29 -05:00
J. Nick Koston b403c9f92e
Move thread safety check in area_registry sooner (#116265)
It turns out we have custom components that are writing to the area registry using the async APIs from threads. We now catch it at the point async_fire is called. Instead we should check sooner and use async_fire_internal so we catch the unsafe operation before it can corrupt the registry.
2024-04-27 09:26:35 +02:00
J. Nick Koston 244433aeca
Move thread safety check in entity_registry sooner (#116263)
* Move thread safety check in entity_registry sooner

It turns out we have a lot of custom components that are writing
to the entity registry using the async APIs from threads. We now
catch it at the point async_fire is called. Instread we should check
sooner and use async_fire_internal so we catch the unsafe operation
before it can corrupt the registry.

* coverage

* Apply suggestions from code review
2024-04-27 09:25:19 +02:00
J. Nick Koston 09ebbfa0e1
Move thread safety check in device_registry sooner (#116264)
It turns out we have custom components that are writing to the device registry using the async APIs from threads. We now catch it at the point async_fire is called. Instead we should check sooner and use async_fire_internal so we catch the unsafe operation before it can corrupt the registry.
2024-04-27 09:24:55 +02: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
Erik Montnemery 623d34e1e0
Remove early return when validating entity registry items (#116160) 2024-04-26 08:38:24 +02:00
Jan Bouwhuis 372c6c7874
Use existing monotonic timestamp on mqtt messages for debugging (#116196) 2024-04-25 19:09:54 -05:00
Erik Montnemery 6bff0c384f
Remove deprecation warnings for relative_time (#116144)
* Remove deprecation warnings for relative_time

* Update homeassistant/helpers/template.py

Co-authored-by: Simon <80467011+sorgfresser@users.noreply.github.com>

---------

Co-authored-by: Simon <80467011+sorgfresser@users.noreply.github.com>
2024-04-25 13:02:18 +02:00
Erik Montnemery 2e88ba40ff
Fix lying docstring for relative_time template function (#116146)
* Fix lying docstring for relative_time template function

* Update homeassistant/helpers/template.py

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

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-04-25 13:01:41 +02:00
J. Nick Koston df12789e08
Remove duplicate async_write_ha_state thread safety check (#116086) 2024-04-24 12:46:16 +02:00
rlippmann 1120246194
Deprecate relative_time() in favor of time_since() and time_until() (#111177)
* add time_since/time_until.  add deprecation of relative_time

* fix merge conflicts

* Apply suggestions from code review

* Update homeassistant/helpers/template.py

* Update homeassistant/helpers/template.py

* Update homeassistant/helpers/template.py

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-04-24 11:13:07 +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
Robert Resch a4829330f6
Add strict connection for cloud (#115814)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-04-24 09:57:38 +02:00
J. Nick Koston b520efb87a
Small speed up to async_track_event (#116083) 2024-04-24 09:56:59 +02:00
Sid b37f7b1ff0
Enable Ruff RUF019 (#115396)
* Enable Ruff RUF019

* fix tado tests

* review comments
2024-04-24 07:23:24 +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
J. Nick Koston a22c221722
Rename bus._async_fire to bus.async_fire_internal (#116027) 2024-04-23 22:28:31 +02:00
J. Nick Koston 8f1761343e
Only work out job type once when setting up dispatcher (#116030) 2024-04-23 22:24:36 +02:00
Martijn van der Pol e90d76b18d
Don't raise errors when using datetime objects in `as_datetime` Jinja function/filter (#109062)
* add support for datetime objects to as_datetime

* change import of datetime.date

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-04-23 09:55:58 +02:00
Sid 895f73d8e4
Enable Ruff A001 (#115654) 2024-04-21 23:25:27 +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 4529268544
Ensure scripts with timeouts of zero timeout immediately (#115830) 2024-04-19 18:24:54 +02:00
J. Nick Koston d48bd9b016
Deprecate async_track_state_change in favor of async_track_state_change_event (#115558) 2024-04-18 10:45:14 -05:00
J. Nick Koston 80d6cdad67
Small cleanups to translation loading (#115583)
- Add missing typing
- Convert a update loop to a set comp
- Save some indent
2024-04-18 10:42:44 -04:00
J. Nick Koston 11931cdb56
Simplify labels and areas template calls (#115673)
The labels and areas are already exposed on the object
2024-04-17 21:28:09 +02:00
J. Nick Koston bd2efffb4a
Reduce duplicate code in the device registry (#115677) 2024-04-17 15:50:39 +02:00
J. Nick Koston 45f025480e
Avoid linear search to remove a label from the entity registry (#115674)
* Avoid linear search to remove a label from the entity registry

* simplify
2024-04-17 15:47:56 +02:00
J. Nick Koston 8cf14c9268
Avoid linear search to clear labels and areas in the device registry (#115676) 2024-04-17 15:46:59 +02:00
J. Nick Koston 9ca24ab2a2
Avoid linear search to remove labels and floors from area registry (#115675)
* Avoid linear search to remove labels and floors from area registry

* simplify
2024-04-17 15:45:40 +02:00
J. Nick Koston cb16465539
Keep track of top level components (#115586)
* Keep track of top level components

Currently we have to do a set comp for icons, translations,
and integration platforms every time to split the top level
components from the platforms. Keep track of the top level
components in a seperate set so avoid having to do the setcomp
every time.

* remove impossible paths

* remove unused code

* preen

* preen

* fix

* coverage and fixes

* Update homeassistant/core.py

* Update homeassistant/core.py

* Update tests/test_core.py
2024-04-17 13:23:20 +02:00
Erik Montnemery 7cd0fe3c5f
Don't reload other automations when saving an automation (#80254)
* Only reload modified automation

* Correct check for existing automation

* Add tests

* Remove the new service, improve ReloadServiceHelper

* Revert unneeded changes

* Update tests

* Address review comments

* Improve test coverage

* Address review comments

* Tweak reloader code + add a targetted test

* Apply suggestions from code review

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

* Explain the tests + add more variations

* Fix copy-paste mistake in test

* Rephrase explanation of expected test outcome

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-04-16 15:58:57 +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
J. Nick Koston 3963b3994b
Small cleanups to the rate limit helper (#115621) 2024-04-15 13:42:28 +02:00
J. Nick Koston 33412dd9f6
Remove unused legacy state translations (#112023)
* Remove unused state translations

There have been replaced with entity translations
https://github.com/home-assistant/developers.home-assistant/pull/1557
https://github.com/home-assistant/core/pull/82701

* nothing does merging anymore

* useless dispatch

* remove

* remove platform code from hassfest

* preen

* Update homeassistant/helpers/translation.py

* ruff

* fix merge

* check is impossible now since we already know if translations exist or not

* keep the function for now

* remove unreachable code since we filter out `.` before now

* reduce

* reduce

* fix merge conflict (again)
2024-04-14 07:13:17 -04:00
Sid 3799d20d43
Enable Ruff B905 (#114197) 2024-04-14 00:14:26 -05:00
J. Nick Koston 8da7de1fea
Remove attr usage in event helper (#115554) 2024-04-13 19:46:23 -05:00
J. Nick Koston edd75a9d5f
Fix race in TimestampDataUpdateCoordinator (#115542)
* Fix race in TimestampDataUpdateCoordinator

The last_update_success_time value was being set after the listeners
were fired which could lead to a loop because the listener may
re-trigger an update because it thinks the data is stale

* coverage

* docstring
2024-04-13 16:35:07 -04:00
Marc Mueller 1b24e78dd9
Improve FlowHandler menu_options typing (#115296) 2024-04-11 22:14:37 -04:00
Jan Bouwhuis 10076e6523
Add notify entity component (#110950)
* Add notify entity component

* Device classes, restore state, icons

* Add icons file

* Add tests for kitchen_sink

* Remove notify from no_entity_platforms in hassfest icons, translation link

* ruff

* Remove `data` feature

* Only message support

* Complete initial device classes

* mypy pylint

* Remove device_class implementation

* format

* Follow up comments

* Remove _attr_supported_features

* Use setup_test_component_platform

* User helper at other places

* last comment

* Add entry unload test and non async test

* Avoid default mutable object in constructor
2024-04-11 12:04:08 +02:00
J. Nick Koston f0c8c2a684
Adjust importlib helper to avoid leaking memory on re-raise (#115377) 2024-04-10 15:19:17 -10: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 f80894d56f
Stop scripts with eager tasks (#115340) 2024-04-10 08:41:13 -04:00
Sid d61db732da
Enable Ruff SLOT rules (#115043) 2024-04-09 18:57:27 -10:00
Marc Mueller d8c8d1a297
Use dict instead of MutableMapping [extra_state_attributes] (#115319) 2024-04-09 15:06:11 -10:00
J. Nick Koston 11af7d91ff
Optimize _async_track_event for the single key common case (#115242) 2024-04-09 07:04:50 -10:00
J. Nick Koston 95958ac0ef
Increase discovery flow init concurrency limit to 20 (#115230) 2024-04-08 11:05:40 -10:00
J. Nick Koston ca5ed274cb
Deprecate calling async_listen and async_listen_once with run_immediately (#115169) 2024-04-08 10:07:54 -10:00
Sid 9cbed10372
Enable Ruff PYI041 (#115229) 2024-04-08 09:29:05 -10:00
Marc Mueller 4e94f11665
Use EventType for entity_registry_updated (#115187) 2024-04-08 08:44:59 -10:00
Marc Mueller 2fc0d8494d
Use EventType for device_registry_updated (#115188) 2024-04-08 08:25:57 -10:00
Marc Mueller 0d18679c8f
Use EventType for remaining registry events (#115189) 2024-04-08 08:25:39 -10:00
Marc Mueller 6116f11e6c
Use EventType for system events (#115190) 2024-04-08 08:25:34 -10:00
J. Nick Koston 9ef28f83ea
Switch async_track_state_change to use run_immediately (#115164) 2024-04-07 16:38: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
Marc Mueller a0e6fd6ec5
Add improved typing for event fire and listen methods (#114906)
* Add EventType implementation

* Update integrations for EventType

* Change state_changed to EventType

* Fix tests

* Remove runtime impact

* Add tests

* Move to stub file

* Apply pre-commit to stub files

* Fix ruff PYI checks

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2024-04-07 13:28:24 -10:00
Sid 8e98ba7312
Add first batch of Ruff PYI rules (#115100)
Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>
2024-04-07 11:30:50 -10:00
J. Nick Koston 569f54d8e3
Terminate scripts with until and while conditions that execute more than 10000 times (#115110) 2024-04-07 11:02:53 -10:00
Marc Mueller cb9352110c
Improve registry store data typing (#115066) 2024-04-06 14:34:49 -10:00
J. Nick Koston a0936902c2
Use identity checks for EntityPlatformState enum (#115067) 2024-04-07 02:31:23 +02:00
Marc Mueller 8324fd5d1d
Deprecated old backports and typing aliases (#114883) 2024-04-06 13:15:30 -10:00
J. Nick Koston c4b5a7c027
Migrate start helper to use run_immediately (#115055) 2024-04-06 12:35:46 -10:00
Marc Mueller 81d682874f
Update typing extensions to 4.11.0 (#114985) 2024-04-06 14:23:32 +02:00
Sid 0d66d298ec
Enable Ruff RET504 (#114528)
* Enable Ruff RET504

* fix test

* Use noqa instead of cast

* fix sonos RET504

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-04-06 11:07:37 +02:00
J. Nick Koston f497c461ed
Switch to using the AsyncResolver with aiohttp (#114529)
* Bump aiodns to 3.2.0

changelog: https://github.com/saghul/aiodns/compare/v3.1.1...v3.2.0

* Switch to using the AsyncResolver with aiohttp

This avoids creating executor jobs to do DNS resolution

AsyncResolver was not usable before https://github.com/aio-libs/aiohttp/pull/8270
because it did not fallback to fallback to A records and only returned AAAA records
in most cases when IPv6 was available

This is a backport of https://github.com/aio-libs/aiohttp/pull/8270

* Switch to using the AsyncResolver with aiohttp

This avoids creating executor jobs to do DNS resolution

AsyncResolver was not usable before https://github.com/aio-libs/aiohttp/pull/8270
because it did not fallback to fallback to A records and only returned AAAA records
in most cases when IPv6 was available

This is a backport of https://github.com/aio-libs/aiohttp/pull/8270

* Switch to using the AsyncResolver with aiohttp

This avoids creating executor jobs to do DNS resolution

AsyncResolver was not usable before https://github.com/aio-libs/aiohttp/pull/8270
because it did not fallback to fallback to A records and only returned AAAA records
in most cases when IPv6 was available

This is a backport of https://github.com/aio-libs/aiohttp/pull/8270

* Switch to using the AsyncResolver with aiohttp

This avoids creating executor jobs to do DNS resolution

AsyncResolver was not usable before https://github.com/aio-libs/aiohttp/pull/8270
because it did not fallback to fallback to A records and only returned AAAA records
in most cases when IPv6 was available

This is a backport of https://github.com/aio-libs/aiohttp/pull/8270

* fixes

* fix mocking in next_dns

* fix unmocked calls in blink

* more mocking fixes

* more fixes

* more fixes

* Fix missing mocking in nextdns tests

extracted from #114539

* extract from context
2024-04-05 23:15:51 -04:00
J. Nick Koston fb98a6f026
Make run_immediately the default for core EventBus listeners (#113752)
* DNM: Make run_immediately the default for listeners

This is a test to see how much progress we have made twords this goal

https://github.com/home-assistant/core/pull/113727#issuecomment-2004587947

* fix shutdown

* Revert "fix shutdown"

This reverts commit a8969d7db9.

* set false since it break utility meter tests

* one more

* fix rfxtrx test

* test needs to be explict now

* fix matrix

* fail sooner
2024-04-05 22:14:20 -04:00
J. Nick Koston 00db97a765
Run device_registry stop listener immediately (#114978) 2024-04-05 21:59:27 -04:00
J. Nick Koston d25ac06326
Run storage final write listener immediately (#114976)
This one should not need a call_soon
2024-04-05 21:59:11 -04:00
J. Nick Koston aeaed83578
Start async_schedule_update_ha_state task eagerly (#114704) 2024-04-05 08:14:21 -10:00
J. Nick Koston bfe944f666
Handle ambiguous script actions by using action map order (#114825) 2024-04-05 08:42:57 +02:00
J. Nick Koston d321906342
Always run keyed event trackers immediately (#114709) 2024-04-04 15:30:01 -10:00
Erik Montnemery 7c95ecff20
Validate unique_id in entity registry (#114648)
Co-authored-by: Shay Levy <levyshay1@gmail.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-04-04 09:51:44 -10:00
J. Nick Koston cceea6dac2
Refactor ConfigStore to avoid needing to pass config_dir (#114827)
Co-authored-by: Erik <erik@montnemery.com>
2024-04-04 09:30:10 -10:00
Marc Mueller 56ef9500f7
Use EventStateChangedData type when firing state changed event (#114740) 2024-04-04 09:27:44 -10:00
J. Nick Koston a9d43db315
Avoid linear search to clear a config entry in the device registry (#114802) 2024-04-04 08:35:07 -10:00
Marc Mueller 816ce116bf
Remove unnecessary functools.cached_property backport (#114239) 2024-04-04 11:24:26 +02:00
J. Nick Koston aedfd6c983
Add index for floor/label to the area registry (#114777) 2024-04-03 21:04:26 -10:00
J. Nick Koston 56d0ad27f0
Adjust async_load_platform comment to remove dead lock reference (#114771)
* Adjust async_load_platform comment

Its likely the deadlock here has been fixed for a long time, however
we should still do these in a task because it has to wait for base
components if they are not loaded yet.

* Adjust async_load_platform comment

Its likely the deadlock here has been fixed for a long time, however
we should still do these in a task because it has to wait for base
components if they are not loaded yet.
2024-04-03 22:53:31 -04:00
J. Nick Koston 3f76d1f056
Add index for area/config_entry/label to the device registry (#114776)
* Add index for area/config_entry/label to the device registry

* use it for services

* naming

* naming

* tweak
2024-04-03 22:52:17 -04:00
J. Nick Koston e86fec310b
Improve performance of extracting entities by label (#114720) 2024-04-03 10:24:44 -10:00
Robert Resch 7adced6876
Allow passing area/device/entity IDs to floor_id and floor_name (#114748) 2024-04-03 16:33:58 +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
J. Nick Koston adbaed2c6d
Reduce code for registry items with a base class (#114689) 2024-04-03 09:02:32 +02:00
Franck Nijhof 4a93b4a4b4
Add floor selector (#114614) 2024-04-02 10:43:14 +02:00
J. Nick Koston 5856bbc07b
Add missing platforms_exist guard to check_config (#114600)
* Add missing platforms_exist guard to check_config

related issue #112811

When the exception hits, the config will end up being saved in the traceback
so the memory is never released.

This matches the check_config code to homeassistant.config to avoid having
the exception thrown.

* patch

* merge branch
2024-04-01 21:37:30 -04:00
Michael Hansen d23b22b566
Add initial support for floors to intents (#114456)
* Add initial support for floors to intents

* Fix climate intent

* More tests

* No return value

* Add requested changes

* Reuse event handler
2024-03-30 16:59:20 -04:00
Jan-Philipp Benecke 502231b7d2
Avoid call to `hass.helpers.store` in CategoryRegistry (#114485) 2024-03-30 21:15:52 +01:00
Sid 6587ee20db
Enable Ruff TRY300 (#114437)
* Enable Ruff TRY300

* Update validation.py

* Address review comments
2024-03-30 10:37:59 +01:00
Sid a5b609f081
Enable ruff TRY401 (#114395)
* Enable ruff TRY401

* fix tests
2024-03-29 07:20:36 +01:00
Sid f7b7f74d10
Enable Ruff TRY201 (#114269)
* Enable Ruff TRY201

* remove redundant rules
2024-03-28 10:18:07 +01:00
J. Nick Koston f4922edb4b
Fix empty delays in script helper (#114346)
fixes
```
Logger: homeassistant.components.automation.kamermaster_knop_4_acties_licht
Bron: components/automation/__init__.py:726
integratie: Automatisering (documentatie, problemen)
Eerst voorgekomen: 22:17:29 (5 gebeurtenissen)
Laatst gelogd: 22:59:24

While executing automation automation.kamermaster_knop_4_acties_licht
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 726, in async_trigger
    return await self.action_script.async_run(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1645, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 454, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 506, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 536, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 504, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 626, in _async_delay_step
    if timeout_future.done():
       ^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'done'
```
2024-03-28 00:29:43 -04:00
Marc Mueller 911a31f860
Use SignalType to improve typing [core] (#114298) 2024-03-27 14:25:02 +01:00
Marc Mueller 1d2c2d2055
Move SignalTypes to util (#114236) 2024-03-27 08:41:44 +01:00
Franck Nijhof 9a32d1bbd5
Add label selector (#111029)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-03-26 20:31:06 +01:00
Franck Nijhof 9a1906322b
Allow numeric state trigger/condition against zone entities (#114221) 2024-03-26 19:41:46 +01:00
Franck Nijhof c247534731
Default floor level to None (and allow unsetting it) (#114249) 2024-03-26 18:58:25 +01:00
Marc Mueller eb81a4204e
Allow string formatting for dispatcher SignalType (#114174) 2024-03-26 10:38:29 +01:00
Franck Nijhof 5c69e0d2c6
Add label template functions (#111024) 2024-03-26 10:32:29 +01:00
J. Nick Koston 54a69a2687
Remove async_get_device_class_lookup from entity_registry (#114212)
This function was only ever used in homekit, and since there is
now an index of devices in the entity registry, homekit no longer
uses it.

I searched github code for all references to async_get_device_class_lookup
and the only think I could find using it were forks of core. It seems
unlikely that any custom components are affected by removing this
function
2024-03-26 09:22:53 +01:00
Marc Mueller d0ecad78ac
Revert "Update typing-extensions to 4.11.0rc1 (#114116)" (#114216) 2024-03-25 20:44:57 -10:00
J. Nick Koston cabc4f797a
Preload storage for integrations we know we are going to setup (#114192) 2024-03-25 15:49:54 -10: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
Marc Mueller 188dbfbd2a
Update typing-extensions to 4.11.0rc1 (#114116) 2024-03-25 11:27:47 +01:00
J. Nick Koston de831b6e87
Small performance improvement to template expand (#114086)
* Small performance improvement to template expand

- Avoid fetching entity sources each loop
- Skip already found entities
- Avoid startswith in favor of equality check

* unneeded changes
2024-03-24 00:24:52 -04:00
J. Nick Koston 1c1d8d0317
Avoid creating inner function in EntityComponent setup (#114050) 2024-03-23 11:31:23 -10:00
Jan Bouwhuis a4f52cc622
Use a constant to reference `homeassistant` domain (#113889)
* Use CONF_CORE to reference `homeassistant` domain

* Just use DOMAIN

* USE DOMAIN for `homeasistant` domain in config_schema.py

* Use DOMAIN_HA as constant for homeassistant domain

* Rename CONF_CORE to DOMAIN_HA

* Rename DOMAIN_HA to HA_DOMAIN

* Use relative import

* Use direct imports
2024-03-23 19:58:39 +01:00
Marc Mueller efc54971d3
Update empty line formatting after module docstring (#114040) 2024-03-23 00:27:57 +01: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
J. Nick Koston aebc95b1d2
Reduce overhead to construct and validate entity service schema (#113920) 2024-03-20 16:07:17 -10:00
J. Nick Koston e015fd2440
Use intersection for determine_script_action (#113915) 2024-03-20 16:06:59 -10:00
J. Nick Koston b574220247
Refactor rate limit helper to track time in seconds (#113898)
* Refactor rate limit helper to track time in seconds

Currently we created datetime and timedelta objects to enforce the
rate limit. When the rate limit was being hit hard, this got expensive.

We now use floats everywhere instead as they are much cheaper which
is important when we are running up against a rate limit, which is
by definition a hot path

The rate limit helper is currently only used for templates and
we do not have any code in the code base that directly passes
in a rate limit so the impact to custom components is expected
to be negligible if any

* misesd two
2024-03-20 19:49:37 -04:00
J. Nick Koston e9c1753f3a
Cache parsing the url for the device registry (#113910)
* Cache parsing the url for the device registry

There are lots of hub integrations that use the same url for every
sub-device which results in a lot of url parsing at startup. The
logic can be simplified quite a bit here by only using yarl
for URLs

* fix onvif
2024-03-20 19:35:01 -04:00
J. Nick Koston 267fe3dc34
Fix system_info importing hassio in the event loop (#113903) 2024-03-20 12:06:40 -10:00
Erik Montnemery 426f73b1f4
Add State.last_reported (#113511)
* Add State.last_reported

* Update tests

* Update test snapshots

* Call state_reported listeners when firing state_changed event

* Add tests
2024-03-20 21:05:07 +01:00
Franck Nijhof fc6a83559f
Add floor template functions (#110847) 2024-03-20 11:58:04 +01:00
Erik Montnemery d31124d5d4
Avoid creating unneeded Context and Event objects when firing events (#113798)
* Avoid creating unneeded Context and Event objects when firing events

* Add test

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2024-03-20 09:40:06 +01:00
Franck Nijhof 670bd97777
Find referenced labels in automations & scripts (#113812) 2024-03-19 16:28:37 +01:00
Franck Nijhof 38d0854b70
Find referenced floors in automations & scripts (#113802) 2024-03-19 14:18:53 +01:00
J. Nick Koston d740e4c3d7
Migrate restore_state shutdown to use run_immediately (#113786) 2024-03-19 08:42:49 +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
Franck Nijhof 167e66d45c
Add labels to service target (#113753) 2024-03-18 22:32:23 +01:00
Franck Nijhof 51b8ffc69d
Add WebSocket support for handling labels on device registry (#113758) 2024-03-18 21:19:27 +01:00
Sid 82a60fe8ad
Enable Ruff RSE (#113695) 2024-03-18 00:40:38 +01:00
J. Nick Koston 4d75940cd2
Start and stop template cache watcher to run_immediately (#113644) 2024-03-17 08:16:26 -10:00
J. Nick Koston 68320b1278
Migrate registry for labels and categories to run_immediately (#113645) 2024-03-17 08:16:11 -10:00
J. Nick Koston 93497dde8b
Run registry cleanup listeners immediately (#113646) 2024-03-17 08:15:55 -10:00
J. Nick Koston 091199d24a
Run entity registry write_unavailable_states immediately at start (#113647) 2024-03-17 08:15:41 -10:00
Jan-Philipp Benecke 681705394d
Remove deprecated `hass.components` from network helper function (#113615)
* Remove deprecated `hass.components` from network helper function

* Remove deprecated use of `hass.components` in alexa camera tests
2024-03-17 17:42:48 +01:00