mode.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # -*- coding: utf-8 -*-
  2. from app.api.errors.iot import MissingIOTDataError
  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. try:
  14. if self._season == Season.cooling:
  15. cold_space_count, hot_space_count = 0, 0
  16. for item in self._space_temperature:
  17. if item < 22.0:
  18. cold_space_count += 1
  19. if item > 26.0:
  20. hot_space_count += 1
  21. if (
  22. cold_space_count / len(self._space_temperature) > 0.6
  23. and hot_space_count < 1
  24. ):
  25. new_mode = "ventilation"
  26. else:
  27. new_mode = "cooling"
  28. elif self._season == Season.transition:
  29. new_mode = "ventilation"
  30. else:
  31. cold_space_count, hot_space_count = 0, 0
  32. for item in self._space_temperature:
  33. if item < 22.0:
  34. cold_space_count += 1
  35. if item > 25.0:
  36. hot_space_count += 1
  37. if (
  38. hot_space_count / len(self._space_temperature) > 0.6
  39. and cold_space_count < 1
  40. ):
  41. new_mode = "ventilation"
  42. else:
  43. new_mode = "heating"
  44. except ZeroDivisionError:
  45. raise MissingIOTDataError
  46. self._new_mode = new_mode
  47. def get_results(self) -> str:
  48. return self._new_mode
  49. async def build_acatvi_mode(params: ACATVIModeRequest) -> str:
  50. controller = VRFModeController(params.season, params.space_temperature_list)
  51. controller.run()
  52. new_mode = controller.get_results()
  53. return new_mode