Reduce automation state changes by using script helper's last_triggered attribute (#39323)

This commit is contained in:
Phil Bruckner 2020-08-28 14:51:15 -05:00 committed by GitHub
parent 92c06f0818
commit b315df2118
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 21 deletions

View file

@ -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