clear open_door attr from doors when read.
Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
parent
bae51c3f67
commit
e9925d32b4
@ -83,6 +83,14 @@ def set_open_door_request(db: Session, iot_entity_id: int):
|
|||||||
db.refresh(device)
|
db.refresh(device)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def clear_open_door_request(db: Session, iot_entity_id: int):
|
||||||
|
device = get_iot_entity(db, iot_entity_id)
|
||||||
|
setattr(device, "open_request", False)
|
||||||
|
db.add(device)
|
||||||
|
db.commit()
|
||||||
|
db.refresh(device)
|
||||||
|
return True
|
||||||
|
|
||||||
def record_door_access_log(db: Session, entry: schemas.DoorAccessLog):
|
def record_door_access_log(db: Session, entry: schemas.DoorAccessLog):
|
||||||
db_item = models.DoorAccessLog(user_id=entry.user_id,
|
db_item = models.DoorAccessLog(user_id=entry.user_id,
|
||||||
iot_dev_bluetooth_mac=entry.door_bluetooth_mac,
|
iot_dev_bluetooth_mac=entry.door_bluetooth_mac,
|
||||||
|
@ -209,17 +209,18 @@ def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends(), db:
|
|||||||
@app.post("/iotdevice/door/status", response_model=schemas.IotDoorPollingResponse, tags=['Iot'])
|
@app.post("/iotdevice/door/status", response_model=schemas.IotDoorPollingResponse, tags=['Iot'])
|
||||||
def polling_method_for_iot_entity(request: schemas.IotDoorPollingRequest,
|
def polling_method_for_iot_entity(request: schemas.IotDoorPollingRequest,
|
||||||
db: Session = Depends(get_db)):
|
db: Session = Depends(get_db)):
|
||||||
# We need db session
|
|
||||||
# API schema request
|
|
||||||
# API schema response
|
|
||||||
device: schemas.IotEntity = auth_helper.valid_iot_token(request.token, db)
|
device: schemas.IotEntity = auth_helper.valid_iot_token(request.token, db)
|
||||||
if not device:
|
if not device:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
detail="Could not validate credentials")
|
detail="Could not validate credentials")
|
||||||
|
|
||||||
response : schemas.IotEntityPollingResponse(open_command=device.open_request,
|
response : schemas.IotDoorPollingResponse = schemas.IotDoorPollingResponse(
|
||||||
|
open_command=device.open_request,
|
||||||
acces_list_counter=0)
|
acces_list_counter=0)
|
||||||
|
# Reset open_request to False
|
||||||
|
crud.clear_open_door_request(db, device.id)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@app.post("/iotdevice/monitor/status", tags=['Iot'])
|
@app.post("/iotdevice/monitor/status", tags=['Iot'])
|
||||||
|
@ -35,8 +35,9 @@ class UserAuthToIoTDev(Base):
|
|||||||
class DoorAccessLog(Base):
|
class DoorAccessLog(Base):
|
||||||
__tablename__ = "door_access_log"
|
__tablename__ = "door_access_log"
|
||||||
|
|
||||||
user_id = Column(Integer, ForeignKey('user_accounts.id'), primary_key=True, index=True)
|
entry_id = Column(Integer, primary_key=True, index=True)
|
||||||
iot_dev_bluetooth_mac = Column(Integer, ForeignKey('iot_entities.id'), primary_key=True, index=True)
|
user_id = Column(Integer, ForeignKey('user_accounts.id'))
|
||||||
|
iot_dev_bluetooth_mac = Column(Integer, ForeignKey('iot_entities.id'))
|
||||||
timestamp = Column(DateTime)
|
timestamp = Column(DateTime)
|
||||||
|
|
||||||
class RoomSensorData(Base):
|
class RoomSensorData(Base):
|
||||||
|
Loading…
Reference in New Issue
Block a user