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.

synchronisation.py 4.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import report
  2. from tests import testcase, DT_TOGGLE
  3. import time
  4. from unittest.test import equivalency_chk
  5. class testcase_synchronisation(testcase):
  6. def __init__(self, tcl, sw_master, br_master, ct_master, *follower):
  7. super().__init__(tcl)
  8. self.sw_master = sw_master
  9. self.br_master = br_master
  10. self.ct_master = ct_master
  11. self.follower = follower
  12. #
  13. self.__test_list__ = []
  14. if sw_master is not None:
  15. self.__test_list__.append('test_power_on_off_sync')
  16. if br_master is not None:
  17. self.__test_list__.append('test_brightness_sync')
  18. if ct_master is not None:
  19. self.__test_list__.append('test_color_temp_sync')
  20. def test_power_on_off_sync(self, tcel=report.TCEL_FULL):
  21. self.tcl.testCase("Power On/ Off synchronisation test: %s" % self.sw_master.topic, tcel, self.__test_power_on_off_sync__, tcel)
  22. def __test_power_on_off_sync__(self, tLogger, tcel):
  23. f_state = self.follower[0].get(self.follower[0].KEY_OUTPUT_0)
  24. self.sw_master.set(self.sw_master.KEY_OUTPUT_0, f_state)
  25. time.sleep(DT_TOGGLE)
  26. tLogger.debug("Setting preconditions for master device '%s'", f_state)
  27. for i in range(0, 2):
  28. f_state = not f_state
  29. self.sw_master.set(self.sw_master.KEY_OUTPUT_0, f_state)
  30. time.sleep(DT_TOGGLE)
  31. tLogger.debug("Changing master device state to '%s'", f_state)
  32. for fo in self.follower:
  33. equivalency_chk(fo.get(fo.KEY_OUTPUT_0), f_state, tLogger, "Follower device (%s) state" % fo.topic)
  34. def test_brightness_sync(self, tcel=report.TCEL_FULL):
  35. self.tcl.testCase("Brightness synchronisation test: %s" % self.br_master.topic, tcel, self.__test_brightness_sync__, tcel)
  36. def __test_brightness_sync__(self, tLogger, tcel):
  37. sw_state = self.sw_master.get(self.sw_master.KEY_OUTPUT_0)
  38. self.sw_master.set(self.sw_master.KEY_OUTPUT_0, True)
  39. time.sleep(DT_TOGGLE)
  40. tLogger.debug("Setting preconditions for master device '%s' (Power on)", True)
  41. target = self.follower[0].get(self.follower[0].KEY_BRIGHTNESS)
  42. delta = 15 if target < 50 else -15
  43. for i in range(0, 2):
  44. target = target + delta
  45. self.br_master.set(self.br_master.KEY_BRIGHTNESS, target)
  46. time.sleep(DT_TOGGLE)
  47. tLogger.debug("Changing master device brightness to '%d'", target)
  48. for fo in self.follower:
  49. equivalency_chk(fo.get(fo.KEY_BRIGHTNESS), target, tLogger, "Follower device (%s) brightness" % fo.topic)
  50. delta = -delta
  51. # reset changes of precondition
  52. self.sw_master.set(self.sw_master.KEY_OUTPUT_0, sw_state)
  53. time.sleep(DT_TOGGLE)
  54. tLogger.debug("Resetting preconditions for master device '%s' (Power off)", sw_state)
  55. def test_color_temp_sync(self, tcel=report.TCEL_FULL):
  56. self.tcl.testCase("Color temperature synchronisation test: %s" % self.ct_master.topic, tcel, self.__test_color_temp_sync__, tcel)
  57. def __test_color_temp_sync__(self, tLogger, tcel):
  58. sw_state = self.sw_master.get(self.sw_master.KEY_OUTPUT_0)
  59. self.sw_master.set(self.sw_master.KEY_OUTPUT_0, True)
  60. time.sleep(DT_TOGGLE)
  61. tLogger.debug("Setting preconditions for master device '%s' (Power on)", True)
  62. target = self.follower[0].get(self.follower[0].KEY_COLOR_TEMP)
  63. delta = 3 if target < 5 else -3
  64. for i in range(0, 2):
  65. target = target + delta
  66. self.ct_master.set(self.br_master.KEY_COLOR_TEMP, target)
  67. time.sleep(DT_TOGGLE)
  68. tLogger.debug("Changing master device color temperature to '%d'", target)
  69. for fo in self.follower:
  70. equivalency_chk(fo.get(fo.KEY_COLOR_TEMP), target, tLogger, "Follower device (%s) color temperature" % fo.topic)
  71. delta = -delta
  72. # reset changes of precondition
  73. self.sw_master.set(self.sw_master.KEY_OUTPUT_0, sw_state)
  74. time.sleep(DT_TOGGLE)
  75. tLogger.debug("Resetting preconditions for master device '%s' (Power off)", sw_state)