2020-07-20 17:09:05 +02:00
|
|
|
#!/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"
|
|
|
|
|
|
|
|
|
2020-08-06 16:37:44 +02:00
|
|
|
class DeviceStatusEnum(enum.Enum):
|
|
|
|
error = "error"
|
2020-07-20 17:09:05 +02:00
|
|
|
online = "online"
|
|
|
|
offline = "offline"
|
|
|
|
|
|
|
|
|
2020-08-06 16:37:44 +02:00
|
|
|
class SensorStatusEnum(enum.Enum):
|
2020-07-20 17:09:05 +02:00
|
|
|
unknown = "unknown"
|
2020-08-06 16:37:44 +02:00
|
|
|
online = "online"
|
|
|
|
offline = "offline"
|
2020-07-20 17:09:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Device(db.Model):
|
|
|
|
__tablename__ = 'device'
|
2020-07-20 18:19:31 +02:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2020-08-06 20:53:27 +02:00
|
|
|
deviceid = db.Column(db.String, nullable=False)
|
2020-07-20 17:09:05 +02:00
|
|
|
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())
|
2020-08-06 19:57:16 +02:00
|
|
|
sensors = db.relationship("Sensor")
|
2020-07-20 17:09:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Sensor(db.Model):
|
|
|
|
__tablename__ = 'sensor'
|
2020-08-06 20:49:25 +02:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
sensorid = db.Column(db.String, nullable=False)
|
2020-07-20 17:09:05 +02:00
|
|
|
status = db.Column(db.Enum(SensorStatusEnum), nullable=False)
|
2020-08-06 20:53:27 +02:00
|
|
|
device_id = db.Column(db.Integer, db.ForeignKey('device.id'))
|