90 行
4.1 KiB
Python
90 行
4.1 KiB
Python
import report
|
|
from tests import testcase, DT_TOGGLE
|
|
import time
|
|
from unittest.test import equivalency_chk
|
|
|
|
|
|
class testcase_synchronisation(testcase):
|
|
def __init__(self, tcl, sw_master, br_master, ct_master, *follower):
|
|
super().__init__(tcl)
|
|
self.sw_master = sw_master
|
|
self.br_master = br_master
|
|
self.ct_master = ct_master
|
|
self.follower = follower
|
|
#
|
|
self.__test_list__ = []
|
|
if sw_master is not None:
|
|
self.__test_list__.append('test_power_on_off_sync')
|
|
if br_master is not None:
|
|
self.__test_list__.append('test_brightness_sync')
|
|
if ct_master is not None:
|
|
self.__test_list__.append('test_color_temp_sync')
|
|
|
|
def test_power_on_off_sync(self, tcel=report.TCEL_FULL):
|
|
self.tcl.testCase("Power On/ Off synchronisation test: %s" % self.sw_master.topic, tcel, self.__test_power_on_off_sync__, tcel)
|
|
|
|
def __test_power_on_off_sync__(self, tLogger, tcel):
|
|
f_state = self.follower[0].get(self.follower[0].KEY_OUTPUT_0)
|
|
self.sw_master.set(self.sw_master.KEY_OUTPUT_0, f_state)
|
|
time.sleep(DT_TOGGLE)
|
|
tLogger.debug("Setting preconditions for master device '%s'", f_state)
|
|
|
|
for i in range(0, 2):
|
|
f_state = not f_state
|
|
self.sw_master.set(self.sw_master.KEY_OUTPUT_0, f_state)
|
|
time.sleep(DT_TOGGLE)
|
|
tLogger.debug("Changing master device state to '%s'", f_state)
|
|
|
|
for fo in self.follower:
|
|
equivalency_chk(fo.get(fo.KEY_OUTPUT_0), f_state, tLogger, "Follower device (%s) state" % fo.topic)
|
|
|
|
def test_brightness_sync(self, tcel=report.TCEL_FULL):
|
|
self.tcl.testCase("Brightness synchronisation test: %s" % self.br_master.topic, tcel, self.__test_brightness_sync__, tcel)
|
|
|
|
def __test_brightness_sync__(self, tLogger, tcel):
|
|
sw_state = self.sw_master.get(self.sw_master.KEY_OUTPUT_0)
|
|
self.sw_master.set(self.sw_master.KEY_OUTPUT_0, True)
|
|
time.sleep(DT_TOGGLE)
|
|
tLogger.debug("Setting preconditions for master device '%s' (Power on)", True)
|
|
|
|
target = self.follower[0].get(self.follower[0].KEY_BRIGHTNESS)
|
|
delta = 15 if target < 50 else -15
|
|
for i in range(0, 2):
|
|
target = target + delta
|
|
self.br_master.set(self.br_master.KEY_BRIGHTNESS, target)
|
|
time.sleep(DT_TOGGLE)
|
|
tLogger.debug("Changing master device brightness to '%d'", target)
|
|
for fo in self.follower:
|
|
equivalency_chk(fo.get(fo.KEY_BRIGHTNESS), target, tLogger, "Follower device (%s) brightness" % fo.topic)
|
|
delta = -delta
|
|
|
|
# reset changes of precondition
|
|
self.sw_master.set(self.sw_master.KEY_OUTPUT_0, sw_state)
|
|
time.sleep(DT_TOGGLE)
|
|
tLogger.debug("Resetting preconditions for master device '%s' (Power off)", sw_state)
|
|
|
|
def test_color_temp_sync(self, tcel=report.TCEL_FULL):
|
|
self.tcl.testCase("Color temperature synchronisation test: %s" % self.ct_master.topic, tcel, self.__test_color_temp_sync__, tcel)
|
|
|
|
def __test_color_temp_sync__(self, tLogger, tcel):
|
|
sw_state = self.sw_master.get(self.sw_master.KEY_OUTPUT_0)
|
|
self.sw_master.set(self.sw_master.KEY_OUTPUT_0, True)
|
|
time.sleep(DT_TOGGLE)
|
|
tLogger.debug("Setting preconditions for master device '%s' (Power on)", True)
|
|
|
|
target = self.follower[0].get(self.follower[0].KEY_COLOR_TEMP)
|
|
delta = 3 if target < 5 else -3
|
|
for i in range(0, 2):
|
|
target = target + delta
|
|
self.ct_master.set(self.br_master.KEY_COLOR_TEMP, target)
|
|
time.sleep(DT_TOGGLE)
|
|
tLogger.debug("Changing master device color temperature to '%d'", target)
|
|
for fo in self.follower:
|
|
equivalency_chk(fo.get(fo.KEY_COLOR_TEMP), target, tLogger, "Follower device (%s) color temperature" % fo.topic)
|
|
delta = -delta
|
|
|
|
# reset changes of precondition
|
|
self.sw_master.set(self.sw_master.KEY_OUTPUT_0, sw_state)
|
|
time.sleep(DT_TOGGLE)
|
|
tLogger.debug("Resetting preconditions for master device '%s' (Power off)", sw_state)
|