예제 #1
0
파일: base.py 프로젝트: jfarmer08/wyze-sdk
 def ts(self, value: Union[str, int, datetime]) -> datetime:
     if isinstance(value, str):
         try:
             value = int(str)
         except ValueError:
             self.logger.warning(
                 f"could not cast value `{value}` into timestamp")
             return
         value = epoch_to_datetime(value, ms=True)
     if isinstance(value, int):
         value = epoch_to_datetime(value, ms=True)
     self._ts = value
예제 #2
0
파일: base.py 프로젝트: jfarmer08/wyze-sdk
 def __init__(
     self,
     *,
     definition: PropDef,
     ts: Optional[int] = None,
     value: Any = None,
     **kwargs,
 ):
     self._definition = definition
     if isinstance(ts, datetime):
         self._ts = ts
     elif ts is not None:
         self._ts = epoch_to_datetime(ts, ms=True)
     else:
         self._ts = None
     if value is not None and not isinstance(value, self._definition.type):
         try:
             value = bool(
                 distutils.util.strtobool(str(value))
             ) if self._definition.type == bool else self._definition._type(
                 value)
         except ValueError:
             self.logger.warning(
                 f"could not cast value `{value}` into expected type {self._definition.type}"
             )
     self._value = value
예제 #3
0
 def __init__(self,
              *,
              device_mac: str = None,
              event_id: int = None,
              event_ts: datetime = None,
              event_category: int = None,
              event_params: dict = None,
              event_value: str = None,
              file_list: Sequence[dict] = None,
              tag_list: Sequence[int] = None,
              read_state: int = None,
              **others: dict):
     self.id = event_id if event_id else self._extract_attribute(
         'event_id', others)
     self.mac = device_mac if device_mac else self._extract_attribute(
         'device_mac', others)
     self.time = event_ts if event_ts else epoch_to_datetime(
         self._extract_attribute('event_ts', others), ms=True)
     self.category = event_category if event_category else self._extract_attribute(
         'event_category', others)
     self.parameters = event_params if event_params else self._extract_attribute(
         'event_params', others)
     self.alarm_type = event_value if event_value else self._extract_attribute(
         'event_value', others)
     self.files = file_list if file_list is not None else self._extract_attribute(
         'file_list', others)
     self.tags = tag_list if tag_list is not None else self._extract_attribute(
         'tag_list', others)
     self.is_read = (read_state if read_state is not None else
                     self._extract_attribute('read_state', others)) == 1
     show_unknown_key_warning(self, others)
예제 #4
0
 def __init__(self,
              *,
              type: Optional[Union[int, LockEventType]] = None,
              details: Optional[Union[dict, LockRecordDetail]] = None,
              priority: int = None,
              processed: int = None,
              time: datetime = None,
              user_id: str = None,
              uuid: str = None,
              **others: dict):
     self.type = type if type is not None else self._extract_attribute(
         'eventid', others)
     if isinstance(details, LockRecordDetail):
         self.details = details
     elif details is not None:
         LockRecordDetail(**details)
     else:
         self.details = LockRecordDetail(
             **self._extract_attribute('detail', others))
     self.priority = priority if priority is not None else self._extract_attribute(
         'priority', others)
     self.processed = processed if processed is not None else self._extract_attribute(
         'processed', others)
     if isinstance(time, datetime):
         self.time = time
     else:
         self.time = epoch_to_datetime(
             time if time is not None else self._extract_attribute(
                 'time', others),
             ms=True)
     self.user_id = user_id if user_id else self._extract_attribute(
         'master', others)
     self.uuid = uuid if uuid else self._extract_attribute('uuid', others)
     show_unknown_key_warning(self, others)
예제 #5
0
 def __init__(self,
              *,
              id: str = None,
              created: datetime = None,
              current_weight: float = None,
              goal_weight: float = None,
              family_member_id: str = None,
              updated: datetime = None,
              user_id: int = None,
              **others: dict):
     self.id = id if id else str(self._extract_attribute('id', others))
     self.created = created if created else epoch_to_datetime(
         self._extract_attribute('create_time', others), ms=True)
     self._current_weight = current_weight if current_weight else self._extract_attribute(
         'current_weight', others)
     self.family_member_id = family_member_id if family_member_id else self._extract_attribute(
         'family_member_id', others)
     self._goal_weight = goal_weight if goal_weight else self._extract_attribute(
         'goal_weight', others)
     self.updated = updated if updated else epoch_to_datetime(
         self._extract_attribute('update_time', others), ms=True)
     self.user_id = user_id if user_id else self._extract_attribute(
         'user_id', others)
     show_unknown_key_warning(self, others)
예제 #6
0
 def __init__(self,
              *,
              id: int = None,
              avatar: str = None,
              email: str = None,
              left_open_time: Optional[Union[int, LockLeftOpenTime]] = None,
              receiver_name: str = None,
              role: str = None,
              sender_name: str = None,
              source: Optional[Union[int, LockEventSource]] = None,
              source_name: str = None,
              sourceid: int = None,
              time: datetime = None,
              **others: dict):
     self.id = id if id else self._extract_attribute('id', others)
     self.avatar = avatar if avatar else self._extract_attribute(
         'avatar', others)
     self.email = email if email else self._extract_attribute(
         'email', others)
     if isinstance(left_open_time, LockLeftOpenTime):
         self.left_open_time = left_open_time
     else:
         self.left_open_time = LockLeftOpenTime.parse(
             left_open_time if left_open_time is not None else self.
             _extract_attribute('left_open_time', others))
     self.receiver_name = receiver_name if receiver_name else self._extract_attribute(
         'receiver_name', others)
     self.role = role if role else self._extract_attribute('role', others)
     self.sender_name = sender_name if sender_name else self._extract_attribute(
         'sender_name', others)
     if isinstance(source, LockEventSource):
         self.source = source
     else:
         self.source = LockEventSource.parse(
             source if source is not None else self.
             _extract_attribute('source', others))
     self.source_name = source_name if source_name else self._extract_attribute(
         'source_name', others)
     self.sourceid = sourceid if sourceid else self._extract_attribute(
         'sourceid', others)
     self.time = time if time else epoch_to_datetime(
         self._extract_attribute('time', others), ms=True)
     show_unknown_key_warning(self, others)