1 """Containers for a script or automation trace."""
3 from __future__
import annotations
6 from collections
import deque
22 type TraceData = dict[str, LimitedSizeDict[str, BaseTrace]]
26 """Base container for a script or automation trace."""
33 """Return an dictionary version of this ActionTrace for saving."""
41 """Return an extended dictionary version of this ActionTrace."""
45 """Return a brief dictionary version of this ActionTrace."""
48 class ActionTrace(BaseTrace):
49 """Base container for a script or automation trace."""
51 _domain: str |
None =
None
56 config: dict[str, Any] |
None,
57 blueprint_inputs: dict[str, Any] |
None,
60 """Container for script trace."""
61 self.
_trace_trace: dict[str, deque[TraceElement]] |
None =
None
64 self.context: Context = context
65 self.
_error_error: Exception |
None =
None
66 self.
_state_state: str =
"running"
68 self.run_id: str = uuid_util.random_uuid_hex()
70 self._timestamp_start: dt.datetime = dt_util.utcnow()
71 self.
keykey = f
"{self._domain}.{item_id}"
72 self.
_dict_dict: dict[str, Any] |
None =
None
73 self.
_short_dict_short_dict: dict[str, Any] |
None =
None
78 def set_trace(self, trace: dict[str, deque[TraceElement]] |
None) ->
None:
79 """Set action trace."""
87 """Set finish time."""
93 """Return an extended dictionary version of this ActionTrace."""
95 return self.
_dict_dict
101 for key, trace_list
in self.
_trace_trace.items():
102 traces[key] = [item.as_dict()
for item
in trace_list]
109 "context": self.context,
113 if self.
_state_state ==
"stopped":
119 """Return a brief dictionary version of this ActionTrace."""
127 domain, item_id = self.
keykey.split(
".", 1)
130 "last_step": last_step,
131 "run_id": self.run_id,
132 "state": self.
_state_state,
135 "start": self._timestamp_start,
141 if self.
_error_error
is not None:
144 if self.
_state_state ==
"stopped":
151 """Container for a restored script or automation trace."""
154 """Restore from dict."""
155 extended_dict = data[
"extended_dict"]
156 short_dict = data[
"short_dict"]
158 user_id=extended_dict[
"context"][
"user_id"],
159 parent_id=extended_dict[
"context"][
"parent_id"],
160 id=extended_dict[
"context"][
"id"],
163 self.
keykey = f
"{extended_dict['domain']}.{extended_dict['item_id']}"
164 self.
run_idrun_id = extended_dict[
"run_id"]
169 """Return an extended dictionary version of this RestoredTrace."""
170 return self.
_dict_dict
173 """Return a brief dictionary version of this RestoredTrace."""
dict[str, Any] as_short_dict(self)
None __init__(self, str|None item_id, dict[str, Any]|None config, dict[str, Any]|None blueprint_inputs, Context context)
dict[str, Any] as_extended_dict(self)
None set_trace(self, dict[str, deque[TraceElement]]|None trace)
None set_error(self, Exception ex)
dict[str, Any] as_extended_dict(self)
dict[str, Any] as_short_dict(self)
dict[str, Any] as_dict(self)
dict[str, Any] as_short_dict(self)
None __init__(self, dict[str, Any] data)
dict[str, Any] as_extended_dict(self)
None trace_id_set(tuple[str, str] trace_id)
tuple[str, str]|None trace_id_get()
str|None script_execution_get()
None trace_set_child_id(str child_key, str child_run_id)