本文整理汇总了Python中pytomation.devices.Light.command方法的典型用法代码示例。如果您正苦于以下问题:Python Light.command方法的具体用法?Python Light.command怎么用?Python Light.command使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pytomation.devices.Light
的用法示例。
在下文中一共展示了Light.command方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_light_scenario_g3
# 需要导入模块: from pytomation.devices import Light [as 别名]
# 或者: from pytomation.devices.Light import command [as 别名]
def test_light_scenario_g3(self):
m1 = Motion()
m2 = Motion()
interface = Mock()
l = Light(
devices=(interface, m1, m2),
ignore={
Attribute.COMMAND: Command.STILL,
},
trigger=(
{
Attribute.COMMAND: Command.ON,
Attribute.MAPPED: Command.OFF,
Attribute.SOURCE: m2,
Attribute.SECS: 2
},
{
Attribute.COMMAND: Command.ON,
Attribute.MAPPED: Command.OFF,
Attribute.SOURCE: m1,
Attribute.SECS: 10
},
),
initial=State.OFF,
)
self.assertEqual(l.state, State.OFF)
m1.motion()
self.assertEqual(l.state, State.ON)
# Interface updates us on the status
l.command(command=Command.ON, source=interface)
# call still just to add some noise. Should be ignored
m1.still()
self.assertEqual(l.state, State.ON)
time.sleep(2)
# Light should still be on < 10 secs
self.assertEqual(l.state, State.ON)
m2.motion()
self.assertEqual(l.state, State.ON)
# more noise to try and force an issue. Should be ignored
m2.still()
m1.still()
self.assertEqual(l.state, State.ON)
time.sleep(3)
# total of 5 secs have elapsed since m1 and 3 since m2
# Light should be off as m2 set the new time to only 2 secs
self.assertEqual(l.state, State.OFF)
示例2: LightTests
# 需要导入模块: from pytomation.devices import Light [as 别名]
# 或者: from pytomation.devices.Light import command [as 别名]
class LightTests(TestCase):
def setUp(self):
self.interface = Mock()
self.interface.state = State.UNKNOWN
self.device = Light('D1', self.interface)
def test_instantiation(self):
self.assertIsNotNone(self.device,
'Light Device could not be instantiated')
def test_on(self):
self.assertEqual(self.device.state, State.UNKNOWN)
self.device.on()
self.assertEqual(self.device.state, State.ON)
self.assertTrue(self.interface.on.called)
def test_on_time(self):
pass
def test_door_triggered(self):
door = Door()
self.assertIsNotNone(door)
self.device = Light('D1', devices=(self.interface, door))
door.open()
self.assertTrue(self.interface.on.called)
def test_door_closed(self):
door = Door()
self.assertIsNotNone(door)
door.open()
self.device = Light('D1', devices=(self.interface, door))
# self.assertTrue(self.interface.initial.called)
self.assertFalse(self.interface.off.called)
door.close()
self.assertTrue(self.interface.off.called)
# self.interface.on.assert_called_once_with('')
door.open()
self.assertTrue(self.interface.on.called)
def test_location_triggered(self):
home = Location('35.2269', '-80.8433')
home.local_time = datetime(2012,6,1,12,0,0)
light = Light('D1', home)
self.assertEqual(light.state, State.OFF)
home.local_time = datetime(2012,6,1,0,0,0)
self.assertEqual(home.state, State.DARK)
self.assertEqual(light.state, State.ON)
def test_motion_triggered(self):
motion = Motion('D1', initial=State.STILL)
self.assertEqual(motion.state, State.STILL)
light = Light('D1', devices=motion)
self.assertEqual(light.state, State.OFF)
motion.motion()
self.assertEqual(light.state, State.ON)
def test_photocell_triggered(self):
photo = Photocell('D1', initial=State.LIGHT)
light = Light('D1', devices=photo)
self.assertEquals(light.state, State.OFF)
photo.dark()
self.assertEquals(light.state, State.ON)
def test_light_restricted(self):
photo = Photocell('D1', initial=State.LIGHT)
self.assertEqual(photo.state, State.LIGHT)
motion = Motion('D1', initial=State.STILL)
light = Light('D2', devices=(motion, photo),
initial=photo)
self.assertEqual(light.state, State.OFF)
motion.motion()
self.assertEqual(light.state, State.OFF)
photo.dark()
self.assertEqual(light.state, State.ON)
light.off()
self.assertEqual(light.state, State.OFF)
motion.motion()
self.assertEqual(light.state, State.ON)
def test_delay_normal(self):
# Door Open events retrigger delay
# Instead of turning off in 2 secs should be 4
door = Door()
self.assertIsNotNone(door)
light = Light(address='D1',
devices=(self.interface, door),
delay={
'command': Command.OFF,
'secs': 3,
'source': door}
)
door.open()
self.assertEqual(light.state, State.ON)
door.close()
self.assertEqual(light.state, State.ON)
time.sleep(2)
self.assertEqual(light.state, State.ON)
time.sleep(2)
#.........这里部分代码省略.........