123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- import inspect
- import report
- from tests import testcase, DT_TOGGLE
- import time
- from unittest.test import equivalency_chk
-
-
- class testcase_light(testcase):
- def __init__(self, tcl, videv, sw_device, li_device):
- super().__init__(tcl)
- self.videv = videv
- self.sw_device = sw_device
- self.li_device = li_device
- self.__test_list__ = []
- if self.videv.enable_state:
- self.__test_list__.append('test_power_on_off')
- if self.videv.enable_brightness:
- self.__test_list__.append('test_brightness')
- if self.videv.enable_color_temp:
- self.__test_list__.append('test_color_temp')
-
- def test_power_on_off(self, tcel=report.TCEL_FULL):
- fname = inspect.currentframe().f_code.co_name
- if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False):
- self.METHOD_EXECUTED[fname] = True
- #
- self.tcl.testCase("Power On/ Off test for device and virtual device: %s" % self.sw_device.topic, tcel, self.__test_power_on_off__, tcel)
-
- def __test_power_on_off__(self, tLogger, tcel):
- sw_state = self.sw_device.get(self.sw_device.KEY_OUTPUT_0)
-
- for i in range(0, 2):
- equivalency_chk(self.videv.get(self.videv.KEY_OUTPUT_0), sw_state, tLogger, "Virtual device state")
- self.sw_device.set(self.sw_device.KEY_OUTPUT_0, not sw_state)
- time.sleep(DT_TOGGLE)
- tLogger.debug("Changing switching device state to '%s'", not sw_state)
- equivalency_chk(self.videv.get(self.videv.KEY_OUTPUT_0), not sw_state, tLogger, "Virtual device state")
- #
- equivalency_chk(self.sw_device.get(self.sw_device.KEY_OUTPUT_0), not sw_state, tLogger, "Switching device state")
- self.videv.set(self.videv.KEY_OUTPUT_0, sw_state)
- time.sleep(DT_TOGGLE)
- tLogger.debug("Changing virtual device state to '%s'", sw_state)
- equivalency_chk(self.sw_device.get(self.sw_device.KEY_OUTPUT_0), sw_state, tLogger, "Switching device state")
-
- def test_brightness(self, tcel=report.TCEL_FULL):
- fname = inspect.currentframe().f_code.co_name
- if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False):
- self.METHOD_EXECUTED[fname] = True
- #
- self.tcl.testCase("Brightness test for device and virtual device: %s" % self.li_device.topic, tcel, self.__test_brightness__, tcel)
-
- def __test_brightness__(self, tLogger, tcel):
- br_state = self.li_device.get(self.li_device.KEY_BRIGHTNESS)
- delta = -15 if br_state > 50 else 15
- self.sw_device.set(self.sw_device.KEY_OUTPUT_0, True)
- time.sleep(DT_TOGGLE)
- tLogger.debug("Setting preconditions (Power on)")
-
- for i in range(0, 2):
- equivalency_chk(self.videv.get(self.videv.KEY_BRIGHTNESS), br_state, tLogger, "Virtual device brightness")
- self.li_device.set(self.li_device.KEY_BRIGHTNESS, br_state + delta)
- time.sleep(DT_TOGGLE)
- tLogger.debug("Changing light device brightness to '%d'", br_state + delta)
- equivalency_chk(self.videv.get(self.videv.KEY_BRIGHTNESS), br_state + delta, tLogger, "Virtual device brightness")
- #
- equivalency_chk(self.li_device.get(self.li_device.KEY_BRIGHTNESS), br_state + delta, tLogger, "Light device brightness")
- self.videv.set(self.videv.KEY_BRIGHTNESS, br_state)
- time.sleep(DT_TOGGLE)
- tLogger.debug("Changing virtual device brightness to '%d'", br_state)
- equivalency_chk(self.li_device.get(self.li_device.KEY_BRIGHTNESS), br_state, tLogger, "Light device brightness")
- #
- self.sw_device.set(self.sw_device.KEY_OUTPUT_0, False)
- time.sleep(DT_TOGGLE)
- tLogger.debug("Resetting precondition (Power off)")
-
- def test_color_temp(self, tcel=report.TCEL_FULL):
- fname = inspect.currentframe().f_code.co_name
- if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False):
- self.METHOD_EXECUTED[fname] = True
- #
- self.tcl.testCase("Color temperature test for device and virtual device: %s" % self.li_device.topic, tcel, self.__test_color_temp__, tcel)
-
- def __test_color_temp__(self, tLogger, tcel):
- ct_state = self.li_device.get(self.li_device.KEY_COLOR_TEMP)
- delta = -3 if ct_state > 5 else 3
- self.sw_device.set(self.sw_device.KEY_OUTPUT_0, True)
- time.sleep(DT_TOGGLE)
- tLogger.debug("Setting preconditions (Power on)")
-
- for i in range(0, 2):
- equivalency_chk(self.videv.get(self.videv.KEY_COLOR_TEMP), ct_state, tLogger, "Virtual device color temperature")
- self.li_device.set(self.li_device.KEY_COLOR_TEMP, ct_state + delta)
- time.sleep(DT_TOGGLE)
- tLogger.debug("Changing light device color temperature to '%d'", ct_state)
- equivalency_chk(self.videv.get(self.videv.KEY_COLOR_TEMP), ct_state + delta, tLogger, "Virtual device color temperature")
- #
- equivalency_chk(self.li_device.get(self.li_device.KEY_COLOR_TEMP), ct_state + delta, tLogger, "Light device brightness")
- self.videv.set(self.videv.KEY_COLOR_TEMP, ct_state)
- time.sleep(DT_TOGGLE)
- tLogger.debug("Changing virtual device color temperature to '%d'", ct_state)
- equivalency_chk(self.li_device.get(self.li_device.KEY_COLOR_TEMP), ct_state, tLogger, "Light device brightness")
- #
- self.sw_device.set(self.sw_device.KEY_OUTPUT_0, False)
- time.sleep(DT_TOGGLE)
- tLogger.debug("Resetting precondition (Power off)")
|