• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python devices.Light类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_delay_normal

    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)
        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)
开发者ID:chrisleck-old-personal,项目名称:pytomation,代码行数:27,代码来源:light.py


示例2: test_device_level_encoded

 def test_device_level_encoded(self):
     d=Light(name='device_test_1')
     d.off()
     self.assertEqual(d.state, State.OFF)
     response = self.api.get_response(method='POST', path="device/" + str(d.type_id), data=['command=level%2C72'])
     self.assertEqual(d.state, (State.LEVEL, 72))
     self.assertTrue('"name": "device_test_1"' in response)
开发者ID:E3Dev,项目名称:pytomation,代码行数:7,代码来源:pytomation_api.py


示例3: test_light_scenario_2

 def test_light_scenario_2(self):
     m = Motion()
     l = Light(
             address=(49, 3),
             devices=(m),
              ignore=({
                      Attribute.COMMAND: Command.DARK,
                      },
                      {
                       Attribute.COMMAND: Command.STILL}
                      ),
              time={
                    Attribute.TIME: '11:59pm',
                    Attribute.COMMAND: Command.OFF
                    },
              mapped={
                      Attribute.COMMAND: (
                                          Command.MOTION, Command.OPEN,
                                           Command.CLOSE, Command.LIGHT,
                                           ),
                      Attribute.MAPPED: Command.OFF,
                      Attribute.SECS: 2,
                      },
      name='Foyer Light',
             )
     l.off()
     self.assertEqual(l.state, State.OFF)
     m.motion()
     self.assertEqual(l.state, State.OFF)
     time.sleep(3)
     self.assertEqual(l.state, State.OFF)
开发者ID:chrisleck-old-personal,项目名称:pytomation,代码行数:31,代码来源:light.py


示例4: test_time_cron2

 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,代码行数:12,代码来源:light.py


示例5: test_light_restricted

 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)
开发者ID:ssteinerx,项目名称:pytomation,代码行数:13,代码来源:light.py


示例6: test_scenario_g2

 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,代码行数:15,代码来源:light.py


示例7: test_light_restricted

 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)
开发者ID:chrisleck-old-personal,项目名称:pytomation,代码行数:15,代码来源:light.py


示例8: test_read_only

 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,代码行数:15,代码来源:location.py


示例9: test_light_scenario_g3

 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)
开发者ID:chrisleck-old-personal,项目名称:pytomation,代码行数:47,代码来源:light.py


示例10: test_light_idle

 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,代码行数:18,代码来源:light.py


示例11: test_motion_retrigger

 def test_motion_retrigger(self):
     i = Mock()
     m = Motion(devices=i,
                retrigger_delay={
                                 Attribute.SECS: 2,
                                 },
                )
     s = Light(devices=m)
     s.off()
     self.assertEqual(s.state, State.OFF)
     m.command(command=Command.ON, source=i)
     self.assertEqual(s.state, State.ON)
     s.off()
     self.assertEqual(s.state, State.OFF)
     m.command(command=Command.ON, source=i)
     self.assertEqual(s.state, State.OFF)
     time.sleep(3)
     m.command(command=Command.ON, source=i)
     self.assertEqual(s.state, State.ON)
开发者ID:E3Dev,项目名称:pytomation,代码行数:19,代码来源:motion.py


示例12: test_light_scenario_g1

 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,代码行数:21,代码来源:light.py


示例13: test_door_closed

    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)
开发者ID:chrisleck-old-personal,项目名称:pytomation,代码行数:12,代码来源:light.py


示例14: test_trigger_in_range_gc

    def test_trigger_in_range_gc(self):
        (s_h, s_m, s_s) = datetime.now().timetuple()[3:6]
        e_h = s_h
        e_m = s_m
        e_s = s_s + 2
        d1 = StateDevice()
        d2 = Light(
                   devices=d1,
                   trigger={
                            Attribute.COMMAND: Command.ON,
                            Attribute.MAPPED: Command.OFF,
                            Attribute.SECS: 2,
                            Attribute.START: '{h}:{m}:{s}'.format(
                                                                 h=s_h,
                                                                 m=s_m,
                                                                 s=s_s,
                                                                 ),
                            Attribute.END: '{h}:{m}:{s}'.format(
                                                                 h=e_h,
                                                                 m=e_m,
                                                                 s=e_s,
                                                                 ),
                            }
                   )
        self.assertEqual(d2.state, State.UNKNOWN)
        d1.on()
        self.assertEqual(d2.state, State.ON)
        time.sleep(3)
        self.assertEqual(d2.state, State.OFF)
 
        #Out range
        d2.off()
        self.assertEqual(d2.state, State.OFF)
        d1.on()
        self.assertEqual(d2.state, State.ON)
        time.sleep(3)
        self.assertEqual(d2.state, State.ON)
开发者ID:E3Dev,项目名称:pytomation,代码行数:37,代码来源:light.py


示例15: test_ignore_subcommand_wildcard

 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,代码行数:13,代码来源:light.py


示例16: LightTests

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,代码行数:101,代码来源:light.py


示例17: Door

# invert the DIO channels for these contact sensors
sg.dio_invert(1)
sg.dio_invert(8)

###################### DEVICE CONFIG #########################

d_foyer = Door('D1', sg)

m_family = Motion('D8', sg)
# Motion sensor is hardwired and immediate OFF.. Want to give it some time to still detect motion right after
m_family.delay_still(2*60) 

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):
开发者ID:ssteinerx,项目名称:pytomation,代码行数:31,代码来源:instance-example.py


示例18: LightTests

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,代码行数:101,代码来源:light.py


示例19: test_door_triggered

 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)
开发者ID:chrisleck-old-personal,项目名称:pytomation,代码行数:6,代码来源:light.py


示例20: setUp

 def setUp(self):
     self.interface = Mock()
     self.interface.state = State.UNKNOWN
     self.device = Light('D1', self.interface)
开发者ID:chrisleck-old-personal,项目名称:pytomation,代码行数:4,代码来源:light.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python devices.Motion类代码示例发布时间:2022-05-27
下一篇:
Python timeparse.timeparse函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap