#!/usr/bin/env python3 import enum from sqlalchemy.sql import func from db import db """ SQLAlchemy models """ __author__ = '@tormakris' __copyright__ = "Copyright 2020, Birbnetes Team" __module_name__ = "models" __version__text__ = "1" class StatusEnum(enum.Enum): online = "online" offline = "offline" class DeviceStatusEnum(StatusEnum): error = "error" class SensorStatusEnum(StatusEnum): unknown = "unknown" class Device(db.Model): __tablename__ = 'device' id = db.Column(db.Integer, primary_key=True) sensorid = db.Column(db.UUID, nullable=False) status = db.Column(db.Enum(DeviceStatusEnum), nullable=False) url = db.Column(db.String, nullable=False) lastupdate = db.Column(db.TIMESTAMP, nullable=False, server_default=func.now(), onupdate=func.current_timestamp()) sensors = db.relationship("Sensor", nullable=True) class Sensor(db.Model): __tablename__ = 'sensor' id = db.Column(db.UUID, primary_key=True) status = db.Column(db.Enum(SensorStatusEnum), nullable=False) device_id = db.Column(db.UUID, db.ForeignKey('device.id'))