當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。