Ejemplo n.º 1
0
    def phone(self) -> str:
        """Notification phone"""
        if self.col_phone is None:
            raise InvalidStateException(
                "Phone is missing on notification instance")

        return self.col_phone
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    def email(self) -> str:
        """Notification email"""
        if self.col_email is None:
            raise InvalidStateException(
                "Email is missing on notification instance")

        return self.col_email
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
    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(",")]
Ejemplo n.º 8
0
    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
Ejemplo n.º 9
0
    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
Ejemplo n.º 10
0
    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)
Ejemplo n.º 11
0
    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)
Ejemplo n.º 12
0
    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)
Ejemplo n.º 13
0
    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)
Ejemplo n.º 14
0
    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)