devices.py 3.1 KB

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