devices.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.controllers.equipment.pau.switch import get_switch_action
  6. from app.models.domain.devices import DevicesInstructionsBaseResponse
  7. router = APIRouter()
  8. @router.get('/instructions/acatah/thermal-mode-set', response_model=DevicesInstructionsBaseResponse)
  9. async def get_acatah_thermal_mode_set(
  10. project_id: str = Query(..., max_length=50, regex='^Pj', alias='projectId'),
  11. device_id: str = Query(..., max_length=50, regex='^Eq', alias='equipId')
  12. ):
  13. thermal_mode = await get_thermal_mode(project_id, device_id)
  14. return {
  15. 'projectId': project_id,
  16. 'equipId': device_id,
  17. 'output': {
  18. 'thermalModeSet': thermal_mode
  19. }
  20. }
  21. @router.get('/instructions/acatah/supply-air-temperature-set', response_model=DevicesInstructionsBaseResponse)
  22. async def get_acatah_supply_air_temperature_set(
  23. project_id: str = Query(..., max_length=50, regex='^Pj', alias='projectId'),
  24. device_id: str = Query(..., max_length=50, regex='^Eq', alias='equipId')
  25. ):
  26. next_supply_air_temperature_set = await get_next_supply_air_temperature_set(project_id, device_id)
  27. return {
  28. 'projectId': project_id,
  29. 'equipId': device_id,
  30. 'output': {
  31. 'supplyAirTemperatureSet': next_supply_air_temperature_set
  32. }
  33. }
  34. @router.post('/on-ratio-experiment/fcu/{fcu_id}/target/{target}/period/{period}')
  35. async def run_on_ratio_experiment(fcu_id: str, target: float, period: int, background_tasks: BackgroundTasks):
  36. background_tasks.add_task(start_on_ratio_mode, fcu_id, target, period)
  37. return {
  38. 'fcu': fcu_id,
  39. 'target': target,
  40. 'period': period
  41. }
  42. @router.get('/instructions/acatfu/equip-switch-set', response_model=DevicesInstructionsBaseResponse)
  43. async def get_acatfu_equip_switch_set(
  44. project_id: str = Query(..., max_length=50, regex='^Pj', alias='projectId'),
  45. device_id: str = Query(..., max_length=50, regex='^Eq', alias='equipId')
  46. ):
  47. action = await get_switch_action(project_id, device_id)
  48. return {
  49. 'projectId': project_id,
  50. 'equipId': device_id,
  51. 'output': {
  52. 'equipSwitchSet': action
  53. }
  54. }
  55. @router.get('/instructions/acatfu/supply-ari-temperature-set', response_model=DevicesInstructionsBaseResponse)
  56. async def get_acatfu_supply_air_temperature_set(
  57. project_id: str = Query(..., max_length=50, regex='^Pj', alias='projectId'),
  58. device_id: str = Query(..., max_length=50, regex='^Eq', alias='equipId')
  59. ):
  60. pass