def phone(self) -> str: """Notification phone""" if self.col_phone is None: raise InvalidStateException( "Phone is missing on notification instance") return self.col_phone
def update_entity( self, data: Dict, entity_id: uuid.UUID, entity_type: Type[Base], writable_fields: List[str], ) -> T: """Update entity""" stored_entity: Optional[T] = self.__session.query(entity_type).get( entity_id.bytes) if stored_entity is None: raise InvalidStateException("Entity was not found in database") for key, value in data.items(): if hasattr(stored_entity, key) and key in writable_fields: try: setattr(stored_entity, key, value) except AttributeError: pass self.__session.commit() return stored_entity
def email(self) -> str: """Notification email""" if self.col_email is None: raise InvalidStateException( "Email is missing on notification instance") return self.col_email
def operand(self) -> Union[str, ButtonPayload, SwitchPayload]: """Condition operand""" if self.col_operand is None: raise InvalidStateException("Condition operand is missing on condition instance") if ButtonPayload.has_value(self.col_operand): return ButtonPayload(self.col_operand) if SwitchPayload.has_value(self.col_operand): return SwitchPayload(self.col_operand) return self.col_operand
def delete_entity(self, entity_id: uuid.UUID, entity_type: Type[Base]) -> bool: """Delete entity""" stored_entity = self.__session.query(entity_type).get(entity_id.bytes) if stored_entity is None: raise InvalidStateException("Entity was not found in database") self.__session.delete(stored_entity) self.__session.commit() return True
def value(self) -> Union[str, ButtonPayload, SwitchPayload]: """Action value""" if self.col_value is None: raise InvalidStateException("Action value is missing on action instance") if ButtonPayload.has_value(self.col_value): return ButtonPayload(self.col_value) if SwitchPayload.has_value(self.col_value): return SwitchPayload(self.col_value) return self.col_value
def days(self) -> List[int]: """Condition days""" if self.col_days is None: raise InvalidStateException("Days are missing on condition instance") return [int(day) for day in self.col_days.split(",")]
def time(self) -> datetime.time: """Condition time""" if self.col_time is None: raise InvalidStateException("Time is missing on condition instance") return self.col_time
def date(self) -> datetime.date: """Condition date""" if self.col_date is None: raise InvalidStateException("Date is missing on condition instance") return self.col_date
def operator(self) -> ConditionOperator: """Condition operator""" if self.col_operator is None: raise InvalidStateException("Condition operator is missing on condition instance") return ConditionOperator(self.col_operator)
def channel_property(self) -> uuid.UUID: """Condition property database identifier""" if self.col_channel_property is None: raise InvalidStateException("Property identifier is missing on condition instance") return uuid.UUID(bytes=self.col_channel_property)
def device(self) -> uuid.UUID: """Condition device database identifier""" if self.col_device is None: raise InvalidStateException("Device identifier is missing on condition instance") return uuid.UUID(bytes=self.col_device)
def channel(self) -> uuid.UUID: """Action channel database identifier""" if self.col_channel is None: raise InvalidStateException("Channel identifier is missing on action instance") return uuid.UUID(bytes=self.col_channel)
def device_property(self) -> uuid.UUID: """Action property database identifier""" if self.col_device_property is None: raise InvalidStateException("Property identifier is missing on action instance") return uuid.UUID(bytes=self.col_device_property)