From 99ac2acc0d0c12b1d632411d47d88745a5f8b430 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Sun, 12 Jun 2022 19:30:14 +0300 Subject: [PATCH] sql_app: open door on emergency Signed-off-by: HeshamTB --- sql_app/main.py | 7 ++++--- sql_app/utils.py | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/sql_app/main.py b/sql_app/main.py index 307c8a4..0f3bfd6 100644 --- a/sql_app/main.py +++ b/sql_app/main.py @@ -6,7 +6,7 @@ from sqlalchemy.orm import Session from . import crud, models, schemas, auth_helper, init_db from .database import SessionLocal, engine -from .utils import get_db, EMERG_SMOKE, EMERG_TEMP +from .utils import get_db, EMERG_SMOKE, EMERG_TEMP, T_HOUR_SEC from typing import List from datetime import timedelta, datetime @@ -394,7 +394,7 @@ def polling_method_for_iot_entity(request: schemas.IotDoorPollingRequest, @app.post("/iotdevice/monitor/status", tags=['Iot']) def polling_method_for_room_monitor(request: schemas.MonitorUpdateReadings, db: Session = Depends(get_db)): - device : schemas.Monitor = auth_helper.valid_monitor_token(request.token, db) + device : models.Monitors = auth_helper.valid_monitor_token(request.token, db) if not device: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, @@ -402,7 +402,8 @@ def polling_method_for_room_monitor(request: schemas.MonitorUpdateReadings, crud.record_room_sensor_data(db, request, device) if request.temperature >= EMERG_TEMP or request.smoke_sensor_reading >= EMERG_SMOKE: print("********EMERGENCY AT %s********" % device.description) - # TODO: Get door, and open + door : models.IotEntity = device.door + crud.set_open_door_request(db, door.id, T_HOUR_SEC) crud.record_emergancy_entry(db, request, device.id) # Call into a hook to notify with room and people diff --git a/sql_app/utils.py b/sql_app/utils.py index ea7648d..e2daf78 100644 --- a/sql_app/utils.py +++ b/sql_app/utils.py @@ -9,4 +9,5 @@ def get_db(): db.close() EMERG_TEMP = 50 -EMERG_SMOKE = 1000 \ No newline at end of file +EMERG_SMOKE = 1000 +T_HOUR_SEC = 3600