Test Smart Brain implementation
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

light.py 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import inspect
  2. import report
  3. from tests import testcase, DT_TOGGLE
  4. import time
  5. from unittest.test import equivalency_chk
  6. class testcase_light(testcase):
  7. def __init__(self, tcl, videv, sw_device, li_device):
  8. super().__init__(tcl)
  9. self.videv = videv
  10. self.sw_device = sw_device
  11. self.li_device = li_device
  12. self.__test_list__ = []
  13. if self.videv.enable_state:
  14. self.__test_list__.append('test_power_on_off')
  15. if self.videv.enable_brightness:
  16. self.__test_list__.append('test_brightness')
  17. if self.videv.enable_color_temp:
  18. self.__test_list__.append('test_color_temp')
  19. def test_power_on_off(self, tcel=report.TCEL_FULL):
  20. fname = inspect.currentframe().f_code.co_name
  21. if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False):
  22. self.METHOD_EXECUTED[fname] = True
  23. #
  24. self.tcl.testCase("Power On/ Off test for device and virtual device: %s" % self.sw_device.topic, tcel, self.__test_power_on_off__, tcel)
  25. def __test_power_on_off__(self, tLogger, tcel):
  26. sw_state = self.sw_device.get(self.sw_device.KEY_OUTPUT_0)
  27. for i in range(0, 2):
  28. equivalency_chk(self.videv.get(self.videv.KEY_OUTPUT_0), sw_state, tLogger, "Virtual device state")
  29. self.sw_device.set(self.sw_device.KEY_OUTPUT_0, not sw_state)
  30. time.sleep(DT_TOGGLE)
  31. tLogger.debug("Changing switching device state to '%s'", not sw_state)
  32. equivalency_chk(self.videv.get(self.videv.KEY_OUTPUT_0), not sw_state, tLogger, "Virtual device state")
  33. #
  34. equivalency_chk(self.sw_device.get(self.sw_device.KEY_OUTPUT_0), not sw_state, tLogger, "Switching device state")
  35. self.videv.set(self.videv.KEY_OUTPUT_0, sw_state)
  36. time.sleep(DT_TOGGLE)
  37. tLogger.debug("Changing virtual device state to '%s'", sw_state)
  38. equivalency_chk(self.sw_device.get(self.sw_device.KEY_OUTPUT_0), sw_state, tLogger, "Switching device state")
  39. def test_brightness(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("Brightness test for device and virtual device: %s" % self.li_device.topic, tcel, self.__test_brightness__, tcel)
  45. def __test_brightness__(self, tLogger, tcel):
  46. br_state = self.li_device.get(self.li_device.KEY_BRIGHTNESS)
  47. delta = -15 if br_state > 50 else 15
  48. self.sw_device.set(self.sw_device.KEY_OUTPUT_0, True)
  49. time.sleep(DT_TOGGLE)
  50. tLogger.debug("Setting preconditions (Power on)")
  51. for i in range(0, 2):
  52. equivalency_chk(self.videv.get(self.videv.KEY_BRIGHTNESS), br_state, tLogger, "Virtual device brightness")
  53. self.li_device.set(self.li_device.KEY_BRIGHTNESS, br_state + delta)
  54. time.sleep(DT_TOGGLE)
  55. tLogger.debug("Changing light device brightness to '%d'", br_state + delta)
  56. equivalency_chk(self.videv.get(self.videv.KEY_BRIGHTNESS), br_state + delta, tLogger, "Virtual device brightness")
  57. #
  58. equivalency_chk(self.li_device.get(self.li_device.KEY_BRIGHTNESS), br_state + delta, tLogger, "Light device brightness")
  59. self.videv.set(self.videv.KEY_BRIGHTNESS, br_state)
  60. time.sleep(DT_TOGGLE)
  61. tLogger.debug("Changing virtual device brightness to '%d'", br_state)
  62. equivalency_chk(self.li_device.get(self.li_device.KEY_BRIGHTNESS), br_state, tLogger, "Light device brightness")
  63. #
  64. self.sw_device.set(self.sw_device.KEY_OUTPUT_0, False)
  65. time.sleep(DT_TOGGLE)
  66. tLogger.debug("Resetting precondition (Power off)")
  67. def test_color_temp(self, tcel=report.TCEL_FULL):
  68. fname = inspect.currentframe().f_code.co_name
  69. if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False):
  70. self.METHOD_EXECUTED[fname] = True
  71. #
  72. self.tcl.testCase("Color temperature test for device and virtual device: %s" % self.li_device.topic, tcel, self.__test_color_temp__, tcel)
  73. def __test_color_temp__(self, tLogger, tcel):
  74. ct_state = self.li_device.get(self.li_device.KEY_COLOR_TEMP)
  75. delta = -3 if ct_state > 5 else 3
  76. self.sw_device.set(self.sw_device.KEY_OUTPUT_0, True)
  77. time.sleep(DT_TOGGLE)
  78. tLogger.debug("Setting preconditions (Power on)")
  79. for i in range(0, 2):
  80. equivalency_chk(self.videv.get(self.videv.KEY_COLOR_TEMP), ct_state, tLogger, "Virtual device color temperature")
  81. self.li_device.set(self.li_device.KEY_COLOR_TEMP, ct_state + delta)
  82. time.sleep(DT_TOGGLE)
  83. tLogger.debug("Changing light device color temperature to '%d'", ct_state)
  84. equivalency_chk(self.videv.get(self.videv.KEY_COLOR_TEMP), ct_state + delta, tLogger, "Virtual device color temperature")
  85. #
  86. equivalency_chk(self.li_device.get(self.li_device.KEY_COLOR_TEMP), ct_state + delta, tLogger, "Light device brightness")
  87. self.videv.set(self.videv.KEY_COLOR_TEMP, ct_state)
  88. time.sleep(DT_TOGGLE)
  89. tLogger.debug("Changing virtual device color temperature to '%d'", ct_state)
  90. equivalency_chk(self.li_device.get(self.li_device.KEY_COLOR_TEMP), ct_state, tLogger, "Light device brightness")
  91. #
  92. self.sw_device.set(self.sw_device.KEY_OUTPUT_0, False)
  93. time.sleep(DT_TOGGLE)
  94. tLogger.debug("Resetting precondition (Power off)")