本文整理汇总了Python中pytomation.devices.StateDevice.on_off方法的典型用法代码示例。如果您正苦于以下问题:Python StateDevice.on_off方法的具体用法?Python StateDevice.on_off怎么用?Python StateDevice.on_off使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pytomation.devices.StateDevice
的用法示例。
在下文中一共展示了StateDevice.on_off方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StateDevice_Tests
# 需要导入模块: from pytomation.devices import StateDevice [as 别名]
# 或者: from pytomation.devices.StateDevice import on_off [as 别名]
class StateDevice_Tests(TestCase):
def setUp(self):
self.interface = Mock()
self.device = StateDevice()
def test_instantiation(self):
self.assertIsNotNone(self.device,
'HADevice could not be instantiated')
def test_instances(self):
prev = len(self.device.instances)
device = StateDevice()
self.assertTrue(len(device.instances) > prev)
def test_idle_property(self):
self.device.on()
time.sleep(2)
self.assertTrue(self.device.idle >= 2)
def test_on(self):
self.assertEqual(self.device.state, self.device.UNKNOWN)
self.device.on()
self.assertEqual(self.device.state, self.device.ON)
def test_on_off(self):
callback_obj = Mock()
self.device.on_off(callback_obj.callback)
self.device.off()
self.assertTrue(callback_obj.callback.called)
callback_obj.callback.assert_called_once_with(state=self.device.OFF, previous_state=self.device.UNKNOWN, source=self.device)
# def test_time_on(self):
# now = datetime.now()
# hours, mins, secs = now.timetuple()[3:6]
# secs = (secs + 2) % 60
# mins += (secs + 2) / 60
# trigger_time = '{h}:{m}:{s}'.format(
# h=hours,
# m=mins,
# s=secs,
# )
# print 'Trigger Time' + trigger_time
# self.device.time_on(trigger_time)
# time.sleep(4)
# self.assertEqual(self.device.state, self.device.ON)
def test_time_on_multiple(self):
now = datetime.now()
hours, mins, secs = now.timetuple()[3:6]
secs = (secs + 2) % 60
mins += (secs + 2) / 60
trigger_time = '{h}:{m}:{s}'.format(
h=hours,
m=mins,
s=secs,
)
print 'Trigger Time' + trigger_time
self.device.time_on(trigger_time)
hours, mins, secs = now.timetuple()[3:6]
secs = (secs + 5) % 60
mins += (secs + 5) / 60
trigger_time = '{h}:{m}:{s}'.format(
h=hours,
m=mins,
s=secs,
)
print 'Trigger Time2' + trigger_time
self.device.time_on(trigger_time)
time.sleep(4)
print datetime.now()
self.assertEqual(self.device.state, self.device.ON)
self.device.off()
self.assertEqual(self.device.state, self.device.OFF)
time.sleep(3)
print datetime.now()
self.assertEqual(self.device.state, self.device.ON)
def test_bind_devices(self):
s2 = StateDevice(self.device)
self.device.on()
self.assertIsNotNone(s2)
def test_bind_devices_initial_state(self):
s1 = StateDevice()
self.assertEqual(s1.state, State.UNKNOWN)
s1.on()
self.assertEqual(s1.state, State.ON)
s2 = StateDevice(s1)
self.assertEqual(s2.state, State.ON)
s3 = StateDevice(s1, initial_state=State.OFF)
self.assertEqual(s3.state, State.OFF)
def test_invalid_state(self):
try:
self.device.invalid_state()
except AttributeError, ex:
return
except TypeError, ex:
#.........这里部分代码省略.........