1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Make it possible to list debug traces for a specific automation (#47744)

This commit is contained in:
Erik Montnemery
2021-03-16 00:51:04 +01:00
committed by GitHub
parent 5f627df6f8
commit f82e59c32a
6 changed files with 86 additions and 39 deletions

View File

@@ -11,9 +11,10 @@ import homeassistant.util.dt as dt_util
class TraceElement:
"""Container for trace data."""
def __init__(self, variables: TemplateVarsType):
def __init__(self, variables: TemplateVarsType, path: str):
"""Container for trace data."""
self._error: Optional[Exception] = None
self.path: str = path
self._result: Optional[dict] = None
self._timestamp = dt_util.utcnow()
@@ -42,7 +43,7 @@ class TraceElement:
def as_dict(self) -> Dict[str, Any]:
"""Return dictionary version of this TraceElement."""
result: Dict[str, Any] = {"timestamp": self._timestamp}
result: Dict[str, Any] = {"path": self.path, "timestamp": self._timestamp}
if self._variables:
result["changed_variables"] = self._variables
if self._error is not None:
@@ -129,10 +130,10 @@ def trace_path_get() -> str:
def trace_append_element(
trace_element: TraceElement,
path: str,
maxlen: Optional[int] = None,
) -> None:
"""Append a TraceElement to trace[path]."""
path = trace_element.path
trace = trace_cv.get()
if trace is None:
trace = {}