hass-core/homeassistant/components/script/trace.py
Erik Montnemery 8896ae0d56
Add support for tracing script execution ()
* Add support for tracing script execution

* Tweak
2021-03-24 17:56:22 +01:00

23 lines
594 B
Python

"""Trace support for script."""
from __future__ import annotations
from contextlib import contextmanager
from homeassistant.components.trace import ScriptTrace, async_store_trace
@contextmanager
def trace_script(hass, item_id, config, context):
"""Trace execution of a script."""
trace = ScriptTrace(item_id, config, context)
async_store_trace(hass, trace)
try:
yield trace
except Exception as ex: # pylint: disable=broad-except
if item_id:
trace.set_error(ex)
raise ex
finally:
if item_id:
trace.finished()