mode.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # -*- coding: utf-8 -*-
  2. from loguru import logger
  3. from app.controllers.equipment.controller import EquipmentController
  4. from app.models.domain.devices import ACATVIModeRequest
  5. from app.schemas.season import Season
  6. class VRFModeController(EquipmentController):
  7. def __init__(self, season: Season, space_temperature: list):
  8. super().__init__()
  9. self._season = season
  10. self._space_temperature = space_temperature
  11. self._new_mode = "hold"
  12. def run(self) -> None:
  13. if self._season == Season.cooling:
  14. cold_space_count, hot_space_count = 0, 0
  15. for item in self._space_temperature:
  16. if item < 22.0:
  17. cold_space_count += 1
  18. if item > 26.0:
  19. hot_space_count += 1
  20. if (
  21. cold_space_count / len(self._space_temperature) > 0.6
  22. and hot_space_count < 1
  23. ):
  24. new_mode = "ventilation"
  25. else:
  26. new_mode = "cooling"
  27. elif self._season == Season.transition:
  28. new_mode = "ventilation"
  29. else:
  30. cold_space_count, hot_space_count = 0, 0
  31. for item in self._space_temperature:
  32. if item < 22.0:
  33. cold_space_count += 1
  34. if item > 25.0:
  35. hot_space_count += 1
  36. if (
  37. hot_space_count / len(self._space_temperature) > 0.6
  38. and cold_space_count < 1
  39. ):
  40. new_mode = "ventilation"
  41. else:
  42. new_mode = "heating"
  43. self._new_mode = new_mode
  44. def get_results(self) -> str:
  45. return self._new_mode
  46. @logger.catch()
  47. async def build_acatvi_mode(params: ACATVIModeRequest) -> str:
  48. controller = VRFModeController(params.season, params.space_temperature_list)
  49. controller.run()
  50. new_mode = controller.get_results()
  51. return new_mode