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


Python environment.Environment类代码示例

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


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

示例1: wemo_env

class wemo_env(object):

    def __init__(self):
        self._watcheux = {}
        self._env = Environment()
        try:
            self._env.start()
            self._env.discover(3)
        except:
            print("WeMo environment cannot start ;( !!!!")

    def start_watching(self):
        statechange.connect(self.update_state,
                        unique=False,
                        dispatch_uid=id(self))

    def get_device(self, name):
        return self._env.get(name)

    def register(self, name, fct):
        if name not in self._watcheux:
            self._watcheux[name] = []
        self._watcheux[name].append(fct)
        if len(self._watcheux) > 0:
            self.start_watching()

    def update_state(self, sender, **kwargs):
        state = kwargs.get('state')
        if state != 0:
            state = 1
        if sender.name in self._watcheux:
            for watcheu in self._watcheux[sender.name]:
                watcheu(state)
开发者ID:fjacob21,项目名称:MAX,代码行数:33,代码来源:wemo_env.py

示例2: main

def main():
    '''
    Server routine
    '''
    port = "9801"
    context = zmq.Context.instance()

    # Receive input from the outside world
    socket = context.socket(zmq.DEALER)
    # Specify unique identity
    socket.setsockopt(zmq.IDENTITY, b"WeMo")
    socket.connect("tcp://127.0.0.1:%s" % port)

    print "Ready to receive"

    # Where we will store references to the worker threads
    worker_sockets = {}

    # Start the ouimeaux environment for discovery
    env = Environment(with_subscribers = False, with_discovery=True, with_cache=False)
    env.start()
    discovered.connect(discovered_wemo)

    # Run the polling mechanism in the background
    BackgroundDiscovery(env).start()

    while True:
        # Get the outside message in several parts
        # Store the client_addr
        client_addr, _, msg = socket.recv_multipart()
        print "Received request {} from '{}'".format(msg, client_addr)
        msg = msg.split(' ')

        command = msg[0]

        # General commands
        if command == 'list':
            # Send the current set of devices (only switches supported)
            socket.send_multipart([client_addr, b'', ",".join(env.list_switches())])
            continue

        # Commands on objects
        switch_name = msg[1]
        print switch_name
        s = env.get_switch(switch_name)

        if command == 'on':
            s.on()
            socket.send_multipart([client_addr, b'', 'OK'])
        elif command == 'off':
            s.off()
            socket.send_multipart([client_addr, b'', 'OK'])
        elif command == 'state':
            st = s.get_state()
            st = 'on' if st else 'off'
            socket.send_multipart([client_addr, b'', st])
开发者ID:rudimk,项目名称:kasa,代码行数:56,代码来源:wemo.py

示例3: __init__

class WemoControl:
    def __init__(self, wemoConfig):
        self.wemoConfig = wemoConfig

    def process(self):
        try:
            self.env = Environment(bridge_callback=self.on_bridge, with_subscribers=False)
            self.env.start()
            self.env.discover(10)
        except Exception, e:
            log.exception("Failed to start environment.")
开发者ID:tfasz,项目名称:wemo-control,代码行数:11,代码来源:control.py

示例4: mainloop

def mainloop(names, pubsub_client, times=0, delay=10):
    env = Environment(with_cache=False)
    env.start()
    env.discover(5)

    if times < 1:
        while True:
            do(env,names,pubsub_client)
            time.sleep(delay)
    else:
        for i in range(0, times):
            do(env,names,pubsub_client)
            time.sleep(delay)
开发者ID:vicenteg,项目名称:wemomon,代码行数:13,代码来源:insight-logger-pubsub.py

示例5: WemoClient

class WemoClient():
    def __init__(self):
        self.env = Environment(_on_switch, _on_motion)
        self.env.start()
        self.env.discover(4)

    def toggle(self):
        _switch_map.values()[0].toggle()

    def switch_on(self):
        _switch_map.values()[0].on()

    def switch_off(self):
        _switch_map.values()[0].off()
开发者ID:kpsmith,项目名称:temp_monitor,代码行数:14,代码来源:wemo.py

示例6: process

 def process(self):
     try:
         self.env = Environment(bridge_callback=self.on_bridge, with_subscribers=False)
         self.env.start()
         self.env.discover(10)
     except Exception, e:
         log.exception("Failed to start environment.")
开发者ID:tfasz,项目名称:wemo-control,代码行数:7,代码来源:control.py

示例7: __init__

    def __init__(self):
        IPlugin.__init__(self)
        self.command_priority = 1
        self.voice = None
        bind_port = 54321  # number
        host = get_ip_addresses()[0]  # we just grab the first one that isn't local
        while bind_port < 54329:
            bind = '{0}:{1}'.format(host, str(bind_port))
            try:
                self.env = Environment(bind=bind, with_subscribers=False)
                self.env.start()
                break
            except:
                bind_port += 1

        # retrieve or create device cache
        self.devices = mc.get('footman_wemo_cache')
        if not self.devices:
            self.env.discover(5)
            self.devices = self.env.list_switches()
            mc.set('footman_wemo_cache', self.devices)
        self.log = logging.getLogger(__name__)

        self.commands = {
            '.*turn (?P<command>on|off).*(?P<device>' + '|'.join([d.lower() for d in self.devices]) + ').*': [
                {
                    'command': self.command,
                    'args': (None, None,),
                    'kwargs': {},
                    'command_priority': 0,
                }
            ]
        }
开发者ID:maxvitek,项目名称:footman,代码行数:33,代码来源:wemo.py

示例8: __init__

    def __init__(self, name, callback_function, queue, threadlist):
        HomeAutomationQueueThread.__init__(self, name, callback_function, queue, threadlist)

        self.env = Environment()
        self.lights = {}
        self.relevant_light_attrs = ('name', 'on', 'saturation', 'hue', 'brightness')
        self.cache = []
        self.lock = threading.Lock()
开发者ID:hwinther,项目名称:homeautomation,代码行数:8,代码来源:habelkinwemo.py

示例9: __init__

 def __init__(self):
     self._watcheux = {}
     self._env = Environment()
     try:
         self._env.start()
         self._env.discover(3)
     except:
         print("WeMo environment cannot start ;( !!!!")
开发者ID:fjacob21,项目名称:MAX,代码行数:8,代码来源:wemo_env.py

示例10: connect

    def connect(self):
	self._env = Environment(self._on_switch, self._on_motion)
	try:
	    self._env.start()
	except TypeError:
	    print "Start error"
	try:
	    self._env.discover(seconds=3)
	except TypeError:
	    print "Discovery error"
开发者ID:pierreca,项目名称:Tyler,代码行数:10,代码来源:wemo.py

示例11: __init__

 def __init__(self, callback):
     self.callback = callback
     self.motion = False
     self.env = Environment(with_cache=False)
     self.event = None
     receiver(statechange)(self.state)
     self.mappings = {
         "zone1": Zone(0, callback),
         "zone2": Zone(1, callback),
         "zone3": Zone(2, callback),
         "zone4": Zone(3, callback)
     }
开发者ID:johnASebastian,项目名称:bearded-cyril,代码行数:12,代码来源:wemo.py

示例12: get_switch_state

def get_switch_state(switch_name):
  env = Environment(on_switch, on_motion)
  env.start()
  env.discover(seconds=1)
  #time.sleep(2)
  switch = env.get_switch(switch_name)
  return switch.basicevent.GetBinaryState()['BinaryState']
开发者ID:ramrom,项目名称:haus,代码行数:7,代码来源:wemo.py

示例13: toggle_switch

def toggle_switch(switch_name):
  env = Environment(on_switch, on_motion)
  env.start()
  env.discover(seconds=1)
  #time.sleep(2)
  switch = env.get_switch(switch_name)
  switch.blink()
开发者ID:ramrom,项目名称:haus,代码行数:7,代码来源:wemo.py

示例14: Controller

class Controller(object):

    def __init__(self, callback):
        self.callback = callback
        self.motion = False
        self.env = Environment(with_cache=False)
        self.event = None
        receiver(statechange)(self.state)
        self.mappings = {
            "zone1": Zone(0, callback),
            "zone2": Zone(1, callback),
            "zone3": Zone(2, callback),
            "zone4": Zone(3, callback)
        }


    def start(self):
        print "Starting environment"
        self.env.start()
        print "Discover stuff"
        self.env.discover(5)
        print "Wait for stuff"
        Process(target=self.env.wait).start()

    def state(self, sender=None, state=None, **kwargs):
        motion = bool(state)
        print "Got state change {} {}".format(sender.name, motion)
        zone = self.mappings.get(sender.name)

        if zone == None:
            return

        if motion:
            zone.cancel()

        if zone.motion and not motion:
            zone.schedule()

        if not zone.motion and motion:
            zone.trigger(motion)
开发者ID:johnASebastian,项目名称:bearded-cyril,代码行数:40,代码来源:wemo.py

示例15: _on_switch

class WemoController:
    _env = None

    def _on_switch(self, switch):
	print "Light Switch found: ", switch.name

    def _on_motion(self, motion):
	print "Motion Sensor found: ", motion.name

    def connect(self):
	self._env = Environment(self._on_switch, self._on_motion)
	try:
	    self._env.start()
	except TypeError:
	    print "Start error"
	try:
	    self._env.discover(seconds=3)
	except TypeError:
	    print "Discovery error"

    def find_switches(self):
	result = []
	switches = self._env.list_switches()
	print "Found " + str(len(switches))
	print switches
	for s in switches:
	    print "Found " + s
	    result.append({ "name" : s, "state" : self._env.get_switch(s).get_state() }) 
	return result

    def switch_on(self, switch_name):
	switch = self._env.get_switch(switch_name)
	switch.on()

    def switch_off(self, switch_name):
	switch = self._env.get_switch(switch_name)
	switch.off()

    def switch_state(self, switch_name):
	switch = self._env.get_switch(switch_name)
	return switch.get_state()
开发者ID:pierreca,项目名称:Tyler,代码行数:41,代码来源:wemo.py


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