Example #1
0
def trace_automation(hass, unique_id, config, context):
    """Trace action execution of automation with automation_id."""
    automation_trace = AutomationTrace(unique_id, config, context)
    trace_id_set((unique_id, automation_trace.run_id))

    if unique_id:
        automation_traces = hass.data[DATA_AUTOMATION_TRACE]
        if unique_id not in automation_traces:
            automation_traces[unique_id] = LimitedSizeDict(size_limit=STORED_TRACES)
        automation_traces[unique_id][automation_trace.run_id] = automation_trace

    try:
        yield automation_trace
    except Exception as ex:  # pylint: disable=broad-except
        if unique_id:
            automation_trace.set_error(ex)
        raise ex
    finally:
        if unique_id:
            automation_trace.finished()
Example #2
0
 def __init__(
     self,
     key: tuple[str, str],
     config: dict[str, Any],
     blueprint_inputs: dict[str, Any],
     context: Context,
 ):
     """Container for script trace."""
     self._trace: dict[str, deque[TraceElement]] | None = None
     self._config: dict[str, Any] = config
     self._blueprint_inputs: dict[str, Any] = blueprint_inputs
     self.context: Context = context
     self._error: Exception | None = None
     self._state: str = "running"
     self._script_execution: str | None = None
     self.run_id: str = str(next(self._run_ids))
     self._timestamp_finish: dt.datetime | None = None
     self._timestamp_start: dt.datetime = dt_util.utcnow()
     self.key: tuple[str, str] = key
     if trace_id_get():
         trace_set_child_id(self.key, self.run_id)
     trace_id_set((key, self.run_id))
Example #3
0
 def __init__(
     self,
     item_id: str,
     config: dict[str, Any],
     blueprint_inputs: dict[str, Any],
     context: Context,
 ) -> None:
     """Container for script trace."""
     self._trace: dict[str, deque[TraceElement]] | None = None
     self._config: dict[str, Any] = config
     self._blueprint_inputs: dict[str, Any] = blueprint_inputs
     self.context: Context = context
     self._error: Exception | None = None
     self._state: str = "running"
     self._script_execution: str | None = None
     self.run_id: str = uuid_util.random_uuid_hex()
     self._timestamp_finish: dt.datetime | None = None
     self._timestamp_start: dt.datetime = dt_util.utcnow()
     self.key = f"{self._domain}.{item_id}"
     self._dict: dict[str, Any] | None = None
     self._short_dict: dict[str, Any] | None = None
     if trace_id_get():
         trace_set_child_id(self.key, self.run_id)
     trace_id_set((self.key, self.run_id))