예제 #1
0
def row_to_event(row):
    """ Convert a databse row to an event. """
    try:
        return Event(row[1], json.loads(row[2]), EventOrigin(row[3]),
                     dt_util.utc_from_timestamp(row[5]))
    except ValueError:
        # When json.loads fails
        _LOGGER.exception("Error converting row to event: %s", row)
        return None
예제 #2
0
 def to_native(self):
     """Convert to a natve HA Event."""
     try:
         return Event(self.event_type, json.loads(self.event_data),
                      EventOrigin(self.origin),
                      _process_timestamp(self.time_fired))
     except ValueError:
         # When json.loads fails
         _LOGGER.exception("Error converting to event: %s", self)
         return None
예제 #3
0
 def to_native(self):
     """Convert to a natve HA Event."""
     context = Context(id=self.context_id, user_id=self.context_user_id)
     try:
         return Event(
             self.event_type,
             json.loads(self.event_data),
             EventOrigin(self.origin),
             process_timestamp(self.time_fired),
             context=context,
         )
     except ValueError:
         # When json.loads fails
         _LOGGER.exception("Error converting to event: %s", self)
         return None
예제 #4
0
파일: db_schema.py 프로젝트: jbouwh/core
 def to_native(self, validate_entity_id: bool = True) -> Event | None:
     """Convert to a native HA Event."""
     context = Context(
         id=self.context_id,
         user_id=self.context_user_id,
         parent_id=self.context_parent_id,
     )
     try:
         return Event(
             self.event_type,
             json_loads(self.event_data) if self.event_data else {},
             EventOrigin(self.origin)
             if self.origin else EVENT_ORIGIN_ORDER[self.origin_idx],
             process_timestamp(self.time_fired),
             context=context,
         )
     except JSON_DECODE_EXCEPTIONS:
         # When json_loads fails
         _LOGGER.exception("Error converting to event: %s", self)
         return None