devices.py 3.7 KB

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