当前位置: 首页>>代码示例>>Python>>正文


Python Light.on方法代码示例

本文整理汇总了Python中pytomation.devices.Light.on方法的典型用法代码示例。如果您正苦于以下问题:Python Light.on方法的具体用法?Python Light.on怎么用?Python Light.on使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pytomation.devices.Light的用法示例。


在下文中一共展示了Light.on方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_time_cron2

# 需要导入模块: from pytomation.devices import Light [as 别名]
# 或者: from pytomation.devices.Light import on [as 别名]
 def test_time_cron2(self):
     ttime = datetime.now().timetuple()[3:7]
     l = Light(address='12.03.BB',
                 time={
                 Attribute.TIME: (ttime[2]+2,ttime[1], ttime[0], '*','*','*'),
                 Attribute.COMMAND: Command.OFF
                 },
                 name='test')
     l.on()
     self.assertEqual(l.state, State.ON)
     time.sleep(2)
     self.assertEqual(l.state, State.OFF)
开发者ID:chrisleck-old-personal,项目名称:pytomation,代码行数:14,代码来源:light.py

示例2: test_ignore_subcommand_wildcard

# 需要导入模块: from pytomation.devices import Light [as 别名]
# 或者: from pytomation.devices.Light import on [as 别名]
 def test_ignore_subcommand_wildcard(self):
     s1 = Light()
     s2 = Light(devices = s1,
                       ignore={
                               Attribute.COMMAND: Command.LEVEL,
                               },
                       )
     s1.on()
     self.assertEqual(s2.state, State.ON)
     s1.off()
     self.assertEqual(s2.state, State.OFF)
     s1.level(80)
     self.assertEqual(s2.state, State.OFF)
开发者ID:E3Dev,项目名称:pytomation,代码行数:15,代码来源:light.py

示例3: test_scenario_g2

# 需要导入模块: from pytomation.devices import Light [as 别名]
# 或者: from pytomation.devices.Light import on [as 别名]
 def test_scenario_g2(self):
     d = StateDevice()
     l = Light(address='1E.39.5C', 
            devices=(d),
            delay={
                Attribute.COMMAND: Command.OFF,
                Attribute.SECS: 2
                },
            name='Stair Lights up')
     self.assertEqual(l.state, State.UNKNOWN)
     l.off()
     time.sleep(3)
     self.assertEqual(l.state, State.OFF)
     l.on()
     self.assertEqual(l.state, State.ON)
开发者ID:chrisleck-old-personal,项目名称:pytomation,代码行数:17,代码来源:light.py

示例4: test_read_only

# 需要导入模块: from pytomation.devices import Light [as 别名]
# 或者: from pytomation.devices.Light import on [as 别名]
 def test_read_only(self):
     self.loc.local_time = datetime(2012,6,1,0,0,0)
     self.assertEqual(self.loc.state, State.DARK)
     l2 = Light()
     l = Light(devices=(self.loc, l2))
     self.assertEqual(self.loc.state, State.DARK)
     l.on()
     self.assertEqual(l.state, State.ON)
     self.assertEqual(self.loc.state, State.DARK)
     l.off()
     self.assertEqual(self.loc.state, State.DARK)
     l2.off()
     self.assertEqual(self.loc.state, State.DARK)
     l2.on()
     self.assertEqual(self.loc.state, State.DARK)
开发者ID:E3Dev,项目名称:pytomation,代码行数:17,代码来源:location.py

示例5: test_light_idle

# 需要导入模块: from pytomation.devices import Light [as 别名]
# 或者: from pytomation.devices.Light import on [as 别名]
 def test_light_idle(self):
     m = Motion()
     m.still()
     l = Light(
               devices=(m),
               idle={Attribute.MAPPED: (Command.LEVEL, 30),
                     Attribute.SECS: 2,
                     }
               )
     l.on()
     self.assertEqual(l.state, State.ON)
     time.sleep(3)
     self.assertEqual(l.state, (State.LEVEL, 30))
     #Light shouldnt idle if it is off
     l.off()
     self.assertEqual(l.state, State.OFF)
     time.sleep(3)
     self.assertEqual(l.state, State.OFF)
开发者ID:chrisleck-old-personal,项目名称:pytomation,代码行数:20,代码来源:light.py

示例6: test_light_scenario_g1

# 需要导入模块: from pytomation.devices import Light [as 别名]
# 或者: from pytomation.devices.Light import on [as 别名]
 def test_light_scenario_g1(self):
     d = Door()
     p = Photocell()
     p.light()
     l =  Light(address='xx.xx.xx', 
         devices=(d, p),
         mapped={
            Attribute.COMMAND: (Command.CLOSE),
            Attribute.MAPPED: Command.OFF,
            Attribute.SECS: 2,
         },
         ignore=({Attribute.COMMAND: Command.DARK}),
         name="Hallway Lights",)
     l.on()
     self.assertEqual(l.state, State.ON)
     d.close()
     self.assertEqual(l.state, State.ON)
     time.sleep(3)
     self.assertEqual(l.state, State.OFF)
     d.open()
     self.assertEqual(l.state, State.OFF)
开发者ID:chrisleck-old-personal,项目名称:pytomation,代码行数:23,代码来源:light.py

示例7: LightTests

# 需要导入模块: from pytomation.devices import Light [as 别名]
# 或者: from pytomation.devices.Light import on [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)
#.........这里部分代码省略.........
开发者ID:chrisleck-old-personal,项目名称:pytomation,代码行数:103,代码来源:light.py

示例8: Location

# 需要导入模块: from pytomation.devices import Light [as 别名]
# 或者: from pytomation.devices.Light import on [as 别名]
ph_sun = Location('35.2269', '-80.8433', tz='US/Eastern', mode=Location.MODE.STANDARD, is_dst=True)

# Turn on the foyer light at night when either the door is opened or family PIR is tripped.
l_foyer = Light((49, 3), (upb, d_foyer, m_family, ph_sun))
# After being turned on, turn off again after 2 minutes of inactivity.
l_foyer.delay_off(2*60)
# Turn off the light no matter what at 11:59pm
l_foyer.time_off('11:59pm')
# Do not turn on the light automatically when it is night time (indoor light)
# Only looks at dark for restricing the whether the light should come on
l_foyer.ignore_dark(True)

##################### USER CODE ###############################
#Manually controlling the light
l_foyer.on()
l_foyer.off()

# Loop control
def MainLoop(*args, **kwargs):
    print 'Im in a main loop!'
    if l_foyer.state == State.ON:
        l_foyer.off()
    else:
        l_foyer.on()
        

# Start the whole system.  pytomation.common.system.start()
start(
      loop_action=MainLoop,
      loop_time=1, # Loop every 1 sec
开发者ID:ssteinerx,项目名称:pytomation,代码行数:32,代码来源:instance-example.py

示例9: LightTests

# 需要导入模块: from pytomation.devices import Light [as 别名]
# 或者: from pytomation.devices.Light import on [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, self.device.UNKNOWN)
        self.device.on()
        self.assertEqual(self.device.state, self.device.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", (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", (self.interface, door))
        self.assertTrue(self.interface.on.called)
        self.assertFalse(self.interface.off.called)
        door.closed()
        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=State.STILL)
        self.assertEqual(motion.state, State.STILL)
        light = Light("D1", 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=State.LIGHT)
        light = Light("D1", 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=State.LIGHT)
        motion = Motion("D1", initial_state=State.STILL)
        light = Light("D2", (motion, 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_off=3)
        door.open()
        self.assertEqual(light.state, State.ON)
        door.closed()
        self.assertEqual(light.state, State.ON)
        time.sleep(2)
        self.assertEqual(light.state, State.ON)
        time.sleep(2)
        self.assertEqual(light.state, State.OFF)

        # Check to see if we can immediately and directly still turn off
        light.off()
        door.open()
        self.assertEqual(light.state, State.ON)
        light.off()
        self.assertEqual(light.state, State.OFF)

    def test_delay_light_specific(self):
        # Motion.Still and Photocell.Light events do not retrigger
#.........这里部分代码省略.........
开发者ID:ssteinerx,项目名称:pytomation,代码行数:103,代码来源:light.py


注:本文中的pytomation.devices.Light.on方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。