Test Smart Brain implementation
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

heating.py 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import config
  2. import inspect
  3. import report
  4. from tests import testcase, DT_TOGGLE
  5. import time
  6. from unittest.test import equivalency_chk, greater_chk
  7. class testcase_heating(testcase):
  8. def __init__(self, tcl, videv, valve):
  9. super().__init__(tcl)
  10. self.__videv__ = videv
  11. self.__valve__ = valve
  12. self.__default_temperature__ = config.DEFAULT_TEMPERATURE.get(self.__valve__.topic)
  13. self.__test_list__ = ["test_user_temperature_setpoint", "test_default_temperature", "test_summer_mode", "test_away_mode", "test_boost_mode"]
  14. def test_user_temperature_setpoint(self, tcel=report.TCEL_FULL):
  15. fname = inspect.currentframe().f_code.co_name
  16. if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False):
  17. self.METHOD_EXECUTED[fname] = True
  18. #
  19. self.tcl.testCase("User temperature setpoint test for device and virtual device: %s" %
  20. self.__valve__.topic, tcel, self.__test_user_temperature_setpoint__, tcel)
  21. def __test_user_temperature_setpoint__(self, tLogger, tcel):
  22. mtemp = round(self.__valve__.TEMP_RANGE[0] + (self.__valve__.TEMP_RANGE[1] - self.__valve__.TEMP_RANGE[0]) / 2, 1)
  23. setp = self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT)
  24. delta = 5 if setp < mtemp else -5
  25. for i in range(0, 2):
  26. self.__valve__.set(self.__valve__.KEY_TEMPERATURE_SETPOINT, setp + delta)
  27. time.sleep(DT_TOGGLE)
  28. tLogger.debug("Changing valve temperature setpoint to '%.1f'", setp + delta)
  29. equivalency_chk(self.__videv__.get(self.__videv__.KEY_VALVE_TEMPERATURE_SETPOINT),
  30. setp + delta, tLogger, "Virtual device valve temperature")
  31. equivalency_chk(self.__videv__.get(self.__videv__.KEY_USER_TEMPERATURE_SETPOINT),
  32. setp + delta, tLogger, "Virtual device user temperature")
  33. #
  34. self.__videv__.set(self.__videv__.KEY_USER_TEMPERATURE_SETPOINT, setp)
  35. time.sleep(DT_TOGGLE)
  36. tLogger.debug("Changing videv user temperature setpoint to '%.1f'", setp)
  37. equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), setp, tLogger, "Valve device temperature setpoint")
  38. equivalency_chk(self.__videv__.get(self.__videv__.KEY_VALVE_TEMPERATURE_SETPOINT), setp, tLogger, "Virtual device valve temperature")
  39. def test_default_temperature(self, tcel=report.TCEL_FULL):
  40. fname = inspect.currentframe().f_code.co_name
  41. if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False):
  42. self.METHOD_EXECUTED[fname] = True
  43. #
  44. self.tcl.testCase("Default temperature test for device and virtual device: %s" %
  45. self.__valve__.topic, tcel, self.__test_default_temperature__, tcel)
  46. def __test_default_temperature__(self, tLogger, tcel):
  47. dtemp = config.DEFAULT_TEMPERATURE.get(self.__valve__.topic)
  48. mtemp = round(self.__valve__.TEMP_RANGE[0] + (self.__valve__.TEMP_RANGE[1] - self.__valve__.TEMP_RANGE[0]) / 2, 1)
  49. ptemp = dtemp + (5 if dtemp < mtemp else -5)
  50. self.__valve__.set(self.__valve__.KEY_TEMPERATURE_SETPOINT, ptemp)
  51. time.sleep(DT_TOGGLE)
  52. tLogger.debug("Setting preconditions (Valve setpoint to %.1f)", ptemp)
  53. equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT) != dtemp,
  54. True, tLogger, "Valve temperature setpoint (is not default temperature)")
  55. self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, None)
  56. time.sleep(DT_TOGGLE)
  57. tLogger.debug("Triggering set to default temperature (%.1f)", dtemp)
  58. equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), dtemp, tLogger, "Valve temperature setpoint")
  59. def test_summer_mode(self, tcel=report.TCEL_FULL):
  60. fname = inspect.currentframe().f_code.co_name
  61. if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False):
  62. self.METHOD_EXECUTED[fname] = True
  63. #
  64. self.tcl.testCase("Summer mode test: %s" % self.__valve__.topic, tcel, self.__test_summer_mode__, tcel)
  65. def __test_summer_mode__(self, tLogger, tcel):
  66. self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, None)
  67. time.sleep(DT_TOGGLE)
  68. tLogger.debug("Setting preconditions (Default setpoint)")
  69. vtemp = self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT)
  70. equivalency_chk(self.__videv__.get(self.__videv__.KEY_SUMMER_MODE), False, tLogger, "Summer mode")
  71. self.__videv__.set(self.__videv__.KEY_SUMMER_MODE, True)
  72. time.sleep(DT_TOGGLE)
  73. tLogger.debug("Activating summer mode")
  74. equivalency_chk(self.__videv__.get(self.__videv__.KEY_SUMMER_MODE), True, tLogger, "Summer mode")
  75. equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), 5, tLogger, "Temperature setpoint")
  76. self.__videv__.set(self.__videv__.KEY_SUMMER_MODE, False)
  77. time.sleep(DT_TOGGLE)
  78. tLogger.debug("Deactivating summer mode")
  79. equivalency_chk(self.__videv__.get(self.__videv__.KEY_SUMMER_MODE), False, tLogger, "Summer mode")
  80. equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), vtemp, tLogger, "Temperature setpoint")
  81. def test_away_mode(self, tcel=report.TCEL_FULL):
  82. fname = inspect.currentframe().f_code.co_name
  83. if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False):
  84. self.METHOD_EXECUTED[fname] = True
  85. #
  86. self.tcl.testCase("Away mode test: %s" % self.__valve__.topic, tcel, self.__test_away_mode__, tcel)
  87. def __test_away_mode__(self, tLogger, tcel):
  88. self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, None)
  89. time.sleep(DT_TOGGLE)
  90. tLogger.debug("Setting preconditions (Default setpoint)")
  91. vtemp = self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT)
  92. equivalency_chk(self.__videv__.get(self.__videv__.KEY_AWAY_MODE), False, tLogger, "Away mode")
  93. self.__videv__.set(self.__videv__.KEY_AWAY_MODE, True)
  94. time.sleep(DT_TOGGLE)
  95. tLogger.debug("Activating away mode")
  96. equivalency_chk(self.__videv__.get(self.__videv__.KEY_AWAY_MODE), True, tLogger, "Away mode")
  97. equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), vtemp - 5, tLogger, "Temperature setpoint")
  98. self.__videv__.set(self.__videv__.KEY_AWAY_MODE, False)
  99. time.sleep(DT_TOGGLE)
  100. tLogger.debug("Deactivating away mode")
  101. equivalency_chk(self.__videv__.get(self.__videv__.KEY_AWAY_MODE), False, tLogger, "Away mode")
  102. equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), vtemp, tLogger, "Temperature setpoint")
  103. def test_boost_mode(self, tcel=report.TCEL_FULL):
  104. fname = inspect.currentframe().f_code.co_name
  105. if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False):
  106. self.METHOD_EXECUTED[fname] = True
  107. #
  108. self.tcl.testCase("Boost mode test: %s" % self.__valve__.topic, tcel, self.__test_boost_mode__, tcel)
  109. def __test_boost_mode__(self, tLogger, tcel):
  110. self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, None)
  111. time.sleep(DT_TOGGLE)
  112. tLogger.debug("Setting preconditions (Default setpoint)")
  113. vtemp = self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT)
  114. equivalency_chk(self.__videv__.get(self.__videv__.KEY_BOOST_TIMER), 0, tLogger, "Boost timer")
  115. self.__videv__.set(self.__videv__.KEY_START_BOOST, True)
  116. time.sleep(DT_TOGGLE)
  117. tLogger.debug("Activating boost mode")
  118. greater_chk(self.__videv__.get(self.__videv__.KEY_BOOST_TIMER), 0, tLogger, "Boost timer")
  119. self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, True)
  120. time.sleep(DT_TOGGLE)
  121. tLogger.debug("Setting postconditions (Default setpoint)")
  122. equivalency_chk(self.__videv__.get(self.__videv__.KEY_BOOST_TIMER), 0, tLogger, "Boost timer")
  123. if tcel == report.TCEL_FULL:
  124. # test boost timer
  125. pass