sql_app: Added state to Iot Door
Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
parent
2eed2db77e
commit
3bcb333df6
@ -126,6 +126,12 @@ def set_user_last_token(db: Session, username: str, token: str):
|
||||
db.refresh(user)
|
||||
return True
|
||||
|
||||
def set_door_state(db: Session, iot_device: models.IotEntity, state: bool):
|
||||
iot_device.state = state
|
||||
db.add(iot_device)
|
||||
db.commit()
|
||||
db.refresh(iot_device)
|
||||
|
||||
def get_user_last_token(db: Session, username: str):
|
||||
user : models.User = get_user_by_username(db, username)
|
||||
return user.last_token # This method is bad security practice.
|
||||
|
@ -304,6 +304,8 @@ def polling_method_for_iot_entity(request: schemas.IotDoorPollingRequest,
|
||||
# Reset open_request to False
|
||||
crud.clear_open_door_request(db, device.id)
|
||||
crud.clear_close_door_request(db, device.id)
|
||||
crud.set_door_state(db, device, device.state)
|
||||
|
||||
return response
|
||||
|
||||
@app.post("/iotdevice/monitor/status", tags=['Iot'])
|
||||
|
@ -28,6 +28,7 @@ class IotEntity(Base):
|
||||
time_seconds = Column(Integer, default=10)
|
||||
acces_list_counter = Column(Integer, default=0)
|
||||
force_close = Column(Boolean, default=False)
|
||||
state = Column(Boolean, default=False) # True is open, False is closed
|
||||
authorized_users = relationship("User", secondary="user_iot_link", back_populates="authorized_devices")
|
||||
|
||||
class UserAuthToIoTDev(Base):
|
||||
@ -63,4 +64,6 @@ class UserConnectionHistory(Base):
|
||||
reading_id = Column(Integer, primary_key=True)
|
||||
user_id = Column(Integer,ForeignKey("user_accounts.id"), index=True)
|
||||
timestamp = Column(DateTime)
|
||||
# TODO: add ip
|
||||
|
||||
# TODO: Add table to store active sessions. May periodically clear.
|
@ -72,6 +72,7 @@ class CloseDoorRequest(OpenDoorRequestBase):
|
||||
# Device sends this periodcally
|
||||
class IotDoorPollingRequest(BaseModel):
|
||||
bluetooth_mac : str
|
||||
state: int
|
||||
token : str
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
Loading…
Reference in New Issue
Block a user