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


Python Light.l40方法代码示例

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


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

示例1: LightTests

# 需要导入模块: from pytomation.devices import Light [as 别名]
# 或者: from pytomation.devices.Light import l40 [as 别名]

#.........这里部分代码省略.........
        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
        motion = Motion()
        light = Light(address="D1", devices=(self.interface, motion), delay_off=3)
        motion.motion()
        self.assertEqual(light.state, State.ON)
        time.sleep(2)
        motion.still()
        self.assertEqual(light.state, State.ON)
        time.sleep(1)
        self.assertEqual(light.state, State.OFF)

    def test_light_photocell_intial(self):
        motion = Motion()
        motion.still()
        photo = Photocell(address="asdf")
        photo.dark()
        light = Light(address="e3", devices=(photo, motion), initial_state=photo)
        self.assertEqual(light.state, State.ON)

    def test_light_photocell_delay(self):
        # Delay off should not trigger when photocell tells us to go dark.
        # Do it immediately
        photo = Photocell()
        photo.dark()
        light = Light(address="e3", devices=photo, delay_off=3)
        self.assertEqual(light.state, State.ON)
        photo.light()
        self.assertEqual(light.state, State.OFF)

    def test_level(self):
        self.device.l40()
        self.assertTrue(self.interface.l40.called)

    def test_time_cron(self):
        light = Light("a2", time_off=(0, 30, range(0, 5), 0, 0))
        self.assertIsNotNone(light)
开发者ID:ssteinerx,项目名称:pytomation,代码行数:104,代码来源:light.py


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