2022-06-16 01:18:43 +02:00
|
|
|
# March 2022
|
|
|
|
# Hesham T. Banafa <hishaminv@gmail.com>
|
|
|
|
|
2022-04-03 13:51:26 +02:00
|
|
|
from typing import Any, List, Optional
|
2022-03-03 13:49:26 +01:00
|
|
|
|
|
|
|
from pydantic import BaseModel
|
2022-05-23 12:46:09 +02:00
|
|
|
from datetime import datetime
|
2022-03-03 13:49:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
class IotEntityBase(BaseModel):
|
2022-04-13 08:39:25 +02:00
|
|
|
bluetooth_mac: str
|
2022-03-03 13:49:26 +01:00
|
|
|
description: str
|
|
|
|
|
2022-04-13 07:34:12 +02:00
|
|
|
class UserBase(BaseModel):
|
|
|
|
email: str
|
|
|
|
username: str
|
2022-03-03 13:49:26 +01:00
|
|
|
|
|
|
|
class IotEntityCreate(IotEntityBase):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2022-04-13 07:34:12 +02:00
|
|
|
class UserCreate(UserBase):
|
|
|
|
password: str
|
|
|
|
|
2022-03-03 13:49:26 +01:00
|
|
|
class IotEntity(IotEntityBase):
|
|
|
|
id: int
|
|
|
|
description: str
|
2022-04-13 08:39:25 +02:00
|
|
|
bluetooth_mac: str
|
2022-04-13 07:34:12 +02:00
|
|
|
#authorized_users: List[User] = []
|
2022-04-18 00:43:12 +02:00
|
|
|
open_request: bool # Flag to open
|
2022-05-23 13:58:30 +02:00
|
|
|
time_seconds: int
|
2022-06-07 14:48:28 +02:00
|
|
|
force_close: bool
|
2022-06-06 15:38:35 +02:00
|
|
|
acces_list_counter: int
|
2022-06-09 20:52:42 +02:00
|
|
|
state: bool
|
2022-03-03 13:49:26 +01:00
|
|
|
class Config:
|
|
|
|
orm_mode = True
|
|
|
|
|
2022-04-17 20:20:45 +02:00
|
|
|
class IotBluetoothMac(BaseModel):
|
|
|
|
bluetooth_mac : str
|
|
|
|
|
2022-06-09 20:52:42 +02:00
|
|
|
class Monitor(IotEntityBase):
|
|
|
|
# bluetooth_mac: str
|
|
|
|
# description: str
|
|
|
|
id: int
|
|
|
|
bluetooth_mac: str
|
|
|
|
description: str
|
|
|
|
humidity: int
|
|
|
|
people: int
|
|
|
|
temperature: int
|
|
|
|
smoke_sensor_reading: int
|
|
|
|
class Config:
|
|
|
|
orm_mode = True
|
|
|
|
|
|
|
|
class MonitorUpdateReadings(BaseModel):
|
|
|
|
humidity : int
|
|
|
|
people : int
|
|
|
|
temperature : int
|
|
|
|
smoke_sensor_reading : int
|
|
|
|
token: str # Contains mac
|
|
|
|
|
2022-03-03 13:49:26 +01:00
|
|
|
class User(UserBase):
|
|
|
|
id: int
|
|
|
|
is_active: bool
|
2022-04-03 13:51:26 +02:00
|
|
|
authorized_devices: List[IotEntity] = []
|
2022-03-03 13:49:26 +01:00
|
|
|
|
|
|
|
class Config:
|
|
|
|
orm_mode = True
|
2022-04-13 04:24:06 +02:00
|
|
|
|
2022-04-13 07:34:12 +02:00
|
|
|
|
2022-04-13 04:24:06 +02:00
|
|
|
class Token(BaseModel):
|
|
|
|
access_token : str
|
|
|
|
token_type : str
|
|
|
|
|
|
|
|
class TokenData(BaseModel):
|
|
|
|
username : str
|
|
|
|
# Token can conatin information. But we are already recording this in a database
|
|
|
|
# for scalability.
|
2022-04-13 07:34:12 +02:00
|
|
|
|
2022-04-14 00:37:30 +02:00
|
|
|
class UserAllowForIotEntityRequestByID(BaseModel):
|
2022-04-13 07:34:12 +02:00
|
|
|
user_id: int
|
2022-04-14 00:37:30 +02:00
|
|
|
iot_entity_id: int
|
|
|
|
|
|
|
|
class UserAllowForIotEntityRequestByUsername(BaseModel):
|
|
|
|
username: str
|
2022-04-18 00:43:12 +02:00
|
|
|
description: str
|
|
|
|
|
2022-06-08 11:00:12 +02:00
|
|
|
class UserUpdatePassword(BaseModel):
|
|
|
|
password: str
|
|
|
|
|
2022-04-18 00:43:12 +02:00
|
|
|
class OpenDoorRequestBase(BaseModel):
|
|
|
|
username: str
|
|
|
|
bluetooth_mac: str
|
|
|
|
|
|
|
|
class OpenDoorRequestTime(OpenDoorRequestBase):
|
2022-05-23 13:58:30 +02:00
|
|
|
time_seconds: int
|
2022-05-08 21:09:06 +02:00
|
|
|
|
2022-06-07 14:48:28 +02:00
|
|
|
class CloseDoorRequest(OpenDoorRequestBase):
|
|
|
|
pass
|
2022-05-08 21:09:06 +02:00
|
|
|
# Device sends this periodcally
|
|
|
|
class IotDoorPollingRequest(BaseModel):
|
|
|
|
bluetooth_mac : str
|
2022-06-07 17:58:23 +02:00
|
|
|
state: int
|
2022-05-08 21:09:06 +02:00
|
|
|
token : str
|
|
|
|
|
|
|
|
class IotDoorPollingResponse(BaseModel):
|
|
|
|
open_command : bool
|
|
|
|
acces_list_counter : int
|
2022-05-23 13:58:30 +02:00
|
|
|
time_seconds : int
|
2022-06-07 14:48:28 +02:00
|
|
|
force_close: bool
|
2022-06-09 21:41:07 +02:00
|
|
|
state: bool
|
2022-05-08 21:09:06 +02:00
|
|
|
|
|
|
|
class IotMonitorRoomInfo(BaseModel):
|
|
|
|
humidity : int
|
|
|
|
people : int
|
2022-05-08 21:20:39 +02:00
|
|
|
temperature : int
|
2022-05-08 21:09:06 +02:00
|
|
|
smoke_sensor_reading : int
|
2022-05-23 12:46:09 +02:00
|
|
|
token: str
|
2022-06-09 20:52:42 +02:00
|
|
|
# class Config:
|
|
|
|
# orm_mode = True
|
2022-05-23 12:46:09 +02:00
|
|
|
|
|
|
|
class IotMonitorRoomInfoTimestamped(IotMonitorRoomInfo):
|
|
|
|
time: datetime
|
|
|
|
class Config:
|
|
|
|
orm_mode = True
|
|
|
|
|
|
|
|
class DoorAccessLog(BaseModel):
|
|
|
|
user_id: int
|
2022-06-07 14:48:28 +02:00
|
|
|
iot_id: str
|
|
|
|
command: str
|
|
|
|
timestamp: datetime
|
2022-05-23 12:46:09 +02:00
|
|
|
class Config:
|
2022-05-23 18:02:54 +02:00
|
|
|
orm_mode = True
|
|
|
|
|
|
|
|
class AccessLogRequest(BaseModel):
|
2022-06-08 12:26:41 +02:00
|
|
|
iot_id : int
|
2022-05-23 18:44:04 +02:00
|
|
|
|
|
|
|
class UserAccessLogRequestUsername(BaseModel):
|
|
|
|
username : str
|
|
|
|
|
|
|
|
class UserAccessLogRequestEmail(BaseModel):
|
|
|
|
email : str
|
|
|
|
|
|
|
|
class UserAccessLogRequestID(BaseModel):
|
|
|
|
id : int
|
2022-06-07 11:56:10 +02:00
|
|
|
|
|
|
|
class RoomOverview(IotEntity):
|
|
|
|
humidity : int
|
|
|
|
people : int
|
|
|
|
temperature : int
|
|
|
|
smoke_sensor_reading : int
|