devices.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from fastapi import APIRouter, BackgroundTasks, Query
  2. from app.controllers.equipment.ahu.supply_air_temperature_set import get_next_supply_air_temperature_set
  3. from app.controllers.equipment.ahu.thermal_mode import get_thermal_mode
  4. from app.controllers.equipment.fcu.on_ratio import start_on_ratio_mode
  5. from app.models.domain.devices import DevicesInstructionsBaseResponse
  6. router = APIRouter()
  7. @router.get('/instructions/acatah/thermal-mode-set', response_model=DevicesInstructionsBaseResponse)
  8. async def get_acatah_thermal_mode_set(
  9. project_id: str = Query(..., max_length=50, regex='^Pj', alias='projectId'),
  10. device_id: str = Query(..., max_length=50, regex='^Eq', alias='equipId')
  11. ):
  12. thermal_mode = await get_thermal_mode(project_id, device_id)
  13. return {
  14. 'projectId': project_id,
  15. 'equipId': device_id,
  16. 'output': {
  17. 'thermalModeSet': thermal_mode
  18. }
  19. }
  20. @router.get('/instructions/acatah/supply-air-temperature-set', response_model=DevicesInstructionsBaseResponse)
  21. async def get_acatah_supply_air_temperature_set(
  22. project_id: str = Query(..., max_length=50, regex='^Pj', alias='projectId'),
  23. device_id: str = Query(..., max_length=50, regex='^Eq', alias='equipId')
  24. ):
  25. next_supply_air_temperature_set = await get_next_supply_air_temperature_set(project_id, device_id)
  26. return {
  27. 'projectId': project_id,
  28. 'equipId': device_id,
  29. 'output': {
  30. 'supplyAirTemperatureSet': next_supply_air_temperature_set
  31. }
  32. }
  33. @router.post('/on-ratio-experiment/fcu/{fcu_id}/target/{target}/period/{period}')
  34. async def run_on_ratio_experiment(fcu_id: str, target: float, period: int, background_tasks: BackgroundTasks):
  35. background_tasks.add_task(start_on_ratio_mode, fcu_id, target, period)
  36. return {
  37. 'fcu': fcu_id,
  38. 'target': target,
  39. 'period': period
  40. }