1
0
mirror of https://github.com/home-assistant/core.git synced 2025-08-15 16:30:04 +00:00
Commit Graph

248 Commits

Author SHA1 Message Date
alorente
63df2474a9 Fix missing response for queued mode scripts () 2025-03-28 10:47:41 +00:00
Artur Pragacz
798ee60ae5 Make variables action not restricted to local scopes ()
Make variables action in scripts not restricted to local scopes
2025-03-23 14:07:52 +01:00
Artur Pragacz
b964bc58be Fix variable scopes in scripts ()
Co-authored-by: Erik <erik@montnemery.com>
2025-02-26 16:19:19 +01:00
Artur Pragacz
7117708937 Improve reading clarity of steps code in scripts helper ()
* Reorganize steps code in scripts helper

* Address feedback

* Revert to getattr
2025-02-19 19:37:36 +01:00
Artur Pragacz
6c3a9cb1a8 Improve reading clarity of steps code in scripts helper part 1 () 2025-02-19 11:18:28 -06:00
Ville Skyttä
40eb8b91cc Adjust to recommended propcache.api import paths () 2025-01-21 10:58:22 +01:00
Joost Lekkerkerker
b4f4b06f29 Enable RUF021 () 2025-01-17 10:20:45 +01:00
Artur Pragacz
b009f11013 Fix referenced objects in script sequences () 2025-01-13 11:40:53 +01:00
epenet
5df7092f41 Improve formatting in core files ()
* Adjust core files formatting

* Adjust translations script
2025-01-10 09:08:37 +01:00
Franck Nijhof
56b4733e4a Clean up early assignment in script response () 2024-11-27 10:24:06 +01:00
Petro31
33222436d2 Nested stop actions will now return response_variables ()
fix-nested-stop-variable-response
2024-11-27 09:18:02 +01:00
Jonas Bergler
756a866ffd Add completed to the wait variable when using triggers (wait_for_trigger) ()
* Add support for the wait.completed variable when using wait with triggers

* Remove junk comment

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-10-23 17:19:07 +02:00
J. Nick Koston
0f29fd3e10 Switch to using fast cached_property implementation in propcache () 2024-10-03 13:11:02 -05:00
chammp
b3377fe5fb Add condition to trigger template entities ()
* Add conditions to trigger template entities

* Add tests

* Fix ruff error

* Ruff

* Apply suggestions from code review

* Deduplicate

* Tweak name used in debug message

* Add and improve type annotations of modified code

* Adjust typing

* Adjust typing

* Add typing and remove unused parameter

* Adjust typing

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

* Adjust return type

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

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-09-11 09:36:49 +02:00
Erik Montnemery
992de497f2 Remove unnecessary assignment of Template.hass from script helper () 2024-08-13 11:55:37 +02:00
Erik Montnemery
efb7bede40 Enable strict typing on script helper () 2024-07-17 13:51:59 +02:00
Erik Montnemery
385f5be7e8 Remove dead code from script helper () 2024-07-17 13:16:57 +02:00
Marc Mueller
ca55986057 Import Generator from collections.abc (1) () 2024-07-01 11:51:51 +02:00
J. Nick Koston
ad7097399e Ensure multiple executions of a restart automation in the same event loop iteration are allowed ()
* Add test for restarting automation

related issue 

* fix

* add a delay since restart is an infinite loop

* tests
2024-06-08 17:07:39 -04:00
Marc Mueller
fe21e2b8ba Import Generator from typing_extensions (1) () 2024-06-06 17:02:13 +02:00
J. Nick Koston
7bbb33b415 Improve script disallowed recursion logging () 2024-05-26 12:58:34 +02:00
Marc Mueller
0e03e591e7 Improve callable annotations () 2024-05-24 10:24:09 +02:00
Franck Nijhof
9224997411 Add sequence action for automations & scripts ()
Co-authored-by: Robert Resch <robert@resch.dev>
2024-05-24 09:34:49 +02:00
Marc Mueller
900b6211ef Use PEP 695 for function annotations (2) () 2024-05-18 11:44:39 +02:00
Marc Mueller
87bb7ced79 Use PEP 695 for simple type aliases () 2024-05-17 14:42:21 +02:00
Matthias Alphart
ec4c8ae228 Allow templates for enabling actions ()
* 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
Sid
ac54cdcdb4 Enable Ruff RUF010 ()
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-05-08 23:54:49 +02:00
Marc Mueller
8f614fb06d Use HassKey for helpers (2) () 2024-05-07 11:24:13 -05:00
Sid
2cc916db6d Replace pylint broad-except with Ruff BLE001 () 2024-05-07 14:00:27 +02:00
Sid
b456d97e65 Replace pylint protected-access with Ruff SLF001 () 2024-05-06 20:33:26 +02:00
J. Nick Koston
91fa8b50cc Turn on thread safety checks in async_dispatcher_send ()
* 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
164403de20 Add thread safety checks to async_create_task ()
* 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
7715bee6b0 Fix script in restart mode that is fired from the same trigger () 2024-04-27 07:08:29 -05:00
J. Nick Koston
a22c221722 Rename bus._async_fire to bus.async_fire_internal () 2024-04-23 22:28:31 +02:00
J. Nick Koston
4529268544 Ensure scripts with timeouts of zero timeout immediately () 2024-04-19 18:24:54 +02:00
J. Nick Koston
f80894d56f Stop scripts with eager tasks () 2024-04-10 08:41:13 -04:00
J. Nick Koston
569f54d8e3 Terminate scripts with until and while conditions that execute more than 10000 times () 2024-04-07 11:02:53 -10:00
Sid
0d66d298ec Enable Ruff RET504 ()
* 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
Marc Mueller
816ce116bf Remove unnecessary functools.cached_property backport () 2024-04-04 11:24:26 +02:00
Sid
f7b7f74d10 Enable Ruff TRY201 ()
* Enable Ruff TRY201

* remove redundant rules
2024-03-28 10:18:07 +01:00
J. Nick Koston
f4922edb4b Fix empty delays in script helper ()
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] () 2024-03-27 14:25:02 +01:00
Franck Nijhof
670bd97777 Find referenced labels in automations & scripts () 2024-03-19 16:28:37 +01:00
Franck Nijhof
38d0854b70 Find referenced floors in automations & scripts () 2024-03-19 14:18:53 +01:00
Sid
ccd2e989c3 Enable ruff RUF005 and fix occurrences () 2024-03-16 07:37:20 -10:00
J. Nick Koston
bdede0e0da Start script runs eagerly () 2024-03-14 16:53:26 -10:00
J. Nick Koston
09934d44c4 Reduce script overhead by avoiding creation of many tasks ()
* Reduce script overhead by avoiding creation of many tasks

* no eager stop

* reduce

* make sure wait being cancelled is handled

* make sure wait being cancelled is handled

* make sure wait being cancelled is handled

* preen

* preen

* result already raises cancelled error, remove redundant code

* no need to raise it into the future

* will never set an exception

* Simplify long action script implementation

* comment

* preen

* dry

* dry

* preen

* dry

* preen

* no need to access protected

* no need to access protected

* dry

* name

* dry

* dry

* dry

* dry

* reduce name changes

* drop one more task

* stale comment

* stale comment
2024-03-14 20:28:27 -04:00
J. Nick Koston
427de00524 Remove unnecessary use of async_run_job in script helper ()
The function being passed to `async_run` was always a callback
2024-03-11 21:36:18 -04:00
J. Nick Koston
324266a4e6 Fix race in script stop that could cause async_stop to hang forever () 2024-03-11 10:48:11 -10:00
Marc Mueller
19ab3d6daf Add empty line after module docstring [helpers + other] () 2024-03-08 10:36:11 -05:00