Reduce automation state changes by using script helper's last_triggered attribute (#39323)
This commit is contained in:
1 parent
92c06f0818
commit
b315df2118
4 files changed
+39
-21
No files matched your search
@@ -73,7 +73,7 @@ async def test_service_specify_data(hass, calls):
|
||||
|
||||
time = dt_util.utcnow()
|
||||
|
||||
with patch("homeassistant.components.automation.utcnow", return_value=time):
|
||||
with patch("homeassistant.helpers.script.utcnow", return_value=time):
|
||||
hass.bus.async_fire("test_event")
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@@ -587,11 +587,7 @@ async def test_automation_stops(hass, calls, service):
|
||||
],
|
||||
}
|
||||
}
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
automation.DOMAIN,
|
||||
config,
|
||||
)
|
||||
assert await async_setup_component(hass, automation.DOMAIN, config)
|
||||
|
||||
running = asyncio.Event()
|
||||
|
||||
|
||||
@@ -1706,3 +1706,22 @@ async def test_update_logger(hass, caplog):
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert log_name in caplog.text
|
||||
|
||||
|
||||
async def test_started_action(hass, caplog):
|
||||
"""Test the callback of started_action."""
|
||||
event = "test_event"
|
||||
log_message = "The script started!"
|
||||
logger = logging.getLogger("TEST")
|
||||
|
||||
sequence = cv.SCRIPT_SCHEMA({"event": event})
|
||||
script_obj = script.Script(hass, sequence, "Test Name", "test_domain")
|
||||
|
||||
@callback
|
||||
def started_action():
|
||||
logger.info(log_message)
|
||||
|
||||
await script_obj.async_run(context=Context(), started_action=started_action)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert log_message in caplog.text
|
||||
Reference in new issue
Block a user