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


Python devices.StateDevice类代码示例

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


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

示例1: run

    def run(self):
        if self._ssl_path:
            self.ws = WebSocketServer(
                (self._address, self._port),
                Resource(
                    {
                        "/api/bridge": PytoWebSocketApp,
                        "/api/device*": self.api_app,
                        "/api/voice": self.api_app,
                        "/": self.http_file_app,
                    }
                ),
                pre_start_hook=auth_hook,
                keyfile=self._ssl_path + "/server.key",
                certfile=self._ssl_path + "/server.crt",
            )
        else:
            self.ws = WebSocketServer(
                (self._address, self._port),
                Resource(
                    {
                        "/api/bridge": PytoWebSocketApp,
                        "/api/device*": self.api_app,
                        "/api/voice": self.api_app,
                        "/": self.http_file_app,
                    }
                ),
                pre_start_hook=auth_hook,
            )

        print "Serving WebSocket Connection on", self._address, "port", self._port, "..."
        StateDevice.onStateChangedGlobal(self.broadcast_state)
        self.ws.serve_forever()
开发者ID:aashir789,项目名称:pytomation,代码行数:33,代码来源:websocket_server.py

示例2: test_trigger_out_range_gc

    def test_trigger_out_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,
                                                                 ),
                            }
                   )

        time.sleep(3)
        self.assertEqual(d2.state, State.UNKNOWN)
        d1.on()
        self.assertEqual(d2.state, State.ON)
        time.sleep(3)
        self.assertEqual(d2.state, State.ON)
开发者ID:E3Dev,项目名称:pytomation,代码行数:31,代码来源:light.py

示例3: test_device_on

 def test_device_on(self):
     d=StateDevice(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=on'])
     self.assertEqual(d.state, State.ON)
     self.assertTrue('"name": "device_test_1"' in response)
开发者ID:E3Dev,项目名称:pytomation,代码行数:7,代码来源:pytomation_api.py

示例4: test_binding_default

 def test_binding_default(self):
     d1 = StateDevice()
     d1.off()
     d2 = StateDevice(d1)
     self.assertEqual(d2.state, State.OFF)
     d1.on()
     self.assertEqual(d2.state, State.ON)
开发者ID:Grant10k,项目名称:pytomation,代码行数:7,代码来源:state.py

示例5: test_trigger_time_range

 def test_trigger_time_range(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
     s = StateDevice()
     s2 = StateDevice(devices=s,
                      trigger={
                             Attribute.COMMAND: Command.ON,
                             Attribute.MAPPED: Command.OFF,
                             Attribute.SECS: 1,
                              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(s2.state, State.UNKNOWN)
     s.on()
     self.assertEqual(s2.state, State.ON)
     time.sleep(3)
     self.assertEqual(s2.state, State.OFF)
     ##
     time.sleep(2)
     s.on()
     time.sleep(3)
     self.assertEqual(s2.state, State.ON)
开发者ID:Grant10k,项目名称:pytomation,代码行数:34,代码来源:state.py

示例6: test_time_off

 def test_time_off(self):
     now = datetime.now()
     hours, mins, secs = now.timetuple()[3:6]
     secs = (secs + 2) % 60
     mins += (secs + 2) / 60
     trigger_time1 = '{h}:{m}:{s}'.format(
                                          h=hours,
                                          m=mins,
                                          s=secs,
                                              )
     print 'Trigger Time' + trigger_time1
     secs = (secs + 2) % 60
     mins += (secs + 2) / 60
     trigger_time2 = '{h}:{m}:{s}'.format(
                                          h=hours,
                                          m=mins,
                                          s=secs,
                                              )
     print 'Trigger Time' + trigger_time2
     device = StateDevice(
                           time={
                                 
                                 Attribute.COMMAND: Command.OFF,
                                 Attribute.TIME: (trigger_time1, trigger_time2),
                                 }
                           )
     self.assertEqual(device.state, State.UNKNOWN)
     time.sleep(3)
     print datetime.now()
     self.assertEqual(device.state, State.OFF)
     device.on()
     time.sleep(3)
     print datetime.now()
     print device._times
     self.assertEqual(device.state, State.OFF)
开发者ID:Grant10k,项目名称:pytomation,代码行数:35,代码来源:state.py

示例7: test_last_command

 def test_last_command(self):
     s1 = StateDevice()
     s1.on()
     self.assertEqual(s1.state, State.ON)
     s1.off()
     self.assertEqual(s1.state, State.OFF)
     self.assertEqual(s1.last_command, Command.OFF)
开发者ID:Grant10k,项目名称:pytomation,代码行数:7,代码来源:state.py

示例8: test_state_ignore_range

 def test_state_ignore_range(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
     s = StateDevice()
     s2 = StateDevice(devices=s,
                      ignore={
                              Attribute.SOURCE: s,
                              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(s2.state, State.UNKNOWN)
     s.on()
     self.assertEqual(s2.state, State.UNKNOWN)
     time.sleep(3)
     s.on()
     self.assertEqual(s2.state, State.ON)
开发者ID:Grant10k,项目名称:pytomation,代码行数:28,代码来源:state.py

示例9: test_initial_from_device

 def test_initial_from_device(self):
     d1 = StateDevice(
                       )
     self.assertEqual(d1.state, State.UNKNOWN)
     d1.on()
     self.assertEqual(d1.state, State.ON)
     d2 = StateDevice(devices=d1)
     self.assertEqual(d2.state, State.ON)
开发者ID:Grant10k,项目名称:pytomation,代码行数:8,代码来源:state.py

示例10: test_override_default_maps

 def test_override_default_maps(self):
     d = StateDevice(
                      mapped={
                              Attribute.COMMAND: Command.ON,
                              Attribute.MAPPED: Command.OFF,
                              }
                      )
     d.on()
     self.assertEqual(d.state, State.OFF)
开发者ID:Grant10k,项目名称:pytomation,代码行数:9,代码来源:state.py

示例11: test_bind_devices_initial_state

 def test_bind_devices_initial_state(self):
     s1 = StateDevice()
     self.assertEqual(s1.state, State.UNKNOWN)
     s1.on()
     self.assertEqual(s1.state, State.ON)
     s2 = StateDevice(s1)
     self.assertEqual(s2.state, State.ON)
     s3 = StateDevice(s1, initial_state=State.OFF)
     self.assertEqual(s3.state, State.OFF)
开发者ID:chrisleck-old-personal,项目名称:pytomation,代码行数:9,代码来源:state.py

示例12: test_ignore_device

 def test_ignore_device(self):
     s1 = StateDevice()
     s2 = StateDevice(devices=s1,
                      ignore={
                              Attribute.SOURCE: s1
                              }
                      )
     self.assertEqual(s2.state, State.UNKNOWN)
     s1.on()
     self.assertEqual(s2.state, State.UNKNOWN)
开发者ID:Grant10k,项目名称:pytomation,代码行数:10,代码来源:state.py

示例13: test_delay_zero_secs

 def test_delay_zero_secs(self):
     d1 = StateDevice()
     d2 = StateDevice()
     d3 = StateDevice(
                      devices=(d1, d2),
                      delay=({
                             Attribute.COMMAND: Command.OFF,
                             Attribute.SECS: 2
                             },
                             {
                              Attribute.COMMAND: Command.OFF,
                              Attribute.SECS: 0,
                              Attribute.SOURCE: d2,
                              }
                             ),
                      initial=State.ON,
                      )    
     self.assertEqual(d3.state, State.ON)
     d1.off()
     self.assertEqual(d3.state, State.ON)
     time.sleep(3)
     self.assertEqual(d3.state, State.OFF)
     d3.on()
     self.assertEqual(d3.state, State.ON)
     d2.off()
     self.assertEqual(d3.state, State.OFF)
开发者ID:Grant10k,项目名称:pytomation,代码行数:26,代码来源:state.py

示例14: test_idle

 def test_idle(self):
     s1 = StateDevice()
     s2 = StateDevice(devices=s1,
                      idle_off=2
                      )
     s1.on()
     self.assertEqual(s2.state, State.ON)
     time.sleep(3)
     self.assertEqual(s2.state, State.OFF)
     s1.on()
     self.assertEqual(s2.state, State.ON)
开发者ID:chrisleck-old-personal,项目名称:pytomation,代码行数:11,代码来源:state.py

示例15: test_trigger

 def test_trigger(self):
     s1 = StateDevice(
                       trigger={
                                Attribute.COMMAND: Command.ON,
                                Attribute.MAPPED: Command.OFF,
                                Attribute.SECS: 2
                                }
                       )
     s1.on();
     self.assertEqual(s1.state, State.ON)
     time.sleep(3)
     self.assertEqual(s1.state, State.OFF)
开发者ID:Grant10k,项目名称:pytomation,代码行数:12,代码来源:state.py


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