2022-05-23 12:46:09 +02:00
|
|
|
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, DateTime
|
2022-03-03 13:49:26 +01:00
|
|
|
from sqlalchemy.orm import relationship
|
|
|
|
|
|
|
|
from .database import Base
|
|
|
|
|
|
|
|
|
|
|
|
class User(Base):
|
|
|
|
__tablename__ = "user_accounts"
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
2022-04-13 08:52:37 +02:00
|
|
|
email = Column(String, unique=True, index=True, nullable=False)
|
|
|
|
username = Column(String, unique=True, index=True, nullable=False)
|
|
|
|
hashed_password = Column(String, nullable=False)
|
|
|
|
passwd_salt = Column(String, nullable=False)
|
|
|
|
is_active = Column(Boolean, default=True, nullable=False)
|
2022-06-05 15:25:20 +02:00
|
|
|
last_token = Column(String, nullable=True)
|
2022-03-03 13:49:26 +01:00
|
|
|
|
2022-06-05 16:10:35 +02:00
|
|
|
authorized_devices = relationship("IotEntity", secondary="user_iot_link", back_populates="authorized_users")
|
|
|
|
#authorized_devices = relationship("IotEntity", secondary= 'user_iot_link')
|
2022-03-03 13:49:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
class IotEntity(Base):
|
|
|
|
__tablename__ = "iot_entities"
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
2022-04-13 08:52:37 +02:00
|
|
|
bluetooth_mac = Column(String(512))
|
|
|
|
description = Column(String(512))
|
2022-04-18 00:43:12 +02:00
|
|
|
open_request = Column(Boolean, default=False)
|
2022-05-23 13:58:30 +02:00
|
|
|
time_seconds = Column(Integer, default=10)
|
2022-06-05 16:10:35 +02:00
|
|
|
authorized_users = relationship("User", secondary="user_iot_link", back_populates="authorized_devices")
|
|
|
|
#authorized_users = relationship("User", secondary= 'user_iot_link')
|
2022-03-16 20:29:34 +01:00
|
|
|
|
|
|
|
class UserAuthToIoTDev(Base):
|
|
|
|
__tablename__ = "user_iot_link"
|
|
|
|
|
2022-06-05 16:10:35 +02:00
|
|
|
user_id = Column(Integer, ForeignKey("user_accounts.id"), primary_key=True)
|
|
|
|
iot_id = Column(Integer, ForeignKey("iot_entities.id"), primary_key=True)
|
|
|
|
timestamp = Column(DateTime)
|
2022-05-23 12:46:09 +02:00
|
|
|
|
|
|
|
class DoorAccessLog(Base):
|
|
|
|
__tablename__ = "door_access_log"
|
|
|
|
|
2022-05-23 13:36:29 +02:00
|
|
|
entry_id = Column(Integer, primary_key=True, index=True)
|
|
|
|
user_id = Column(Integer, ForeignKey('user_accounts.id'))
|
|
|
|
iot_dev_bluetooth_mac = Column(Integer, ForeignKey('iot_entities.id'))
|
2022-05-23 12:46:09 +02:00
|
|
|
timestamp = Column(DateTime)
|
|
|
|
|
|
|
|
class RoomSensorData(Base):
|
|
|
|
__tablename__ = "room_sensor_data"
|
|
|
|
|
|
|
|
# Data is now not related to a room. We should have a construct for rooms
|
|
|
|
reading_id = Column(Integer, primary_key=True, index=True)
|
|
|
|
humidity = Column(Integer)
|
|
|
|
people = Column(Integer)
|
|
|
|
temperature = Column(Integer)
|
|
|
|
smoke_sensor_reading = Column(Integer)
|
2022-05-23 18:02:54 +02:00
|
|
|
timestamp = Column(DateTime)
|
|
|
|
|
|
|
|
# TODO: Add table to store active sessions. May periodically clear.
|