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


Python Environment.discover方法代码示例

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


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

示例1: toggle_switch

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import discover [as 别名]
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,代码行数:9,代码来源:wemo.py

示例2: wemo_env

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import discover [as 别名]
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,代码行数:35,代码来源:wemo_env.py

示例3: get_switch_state

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import discover [as 别名]
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,代码行数:9,代码来源:wemo.py

示例4: devices

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import discover [as 别名]
def devices():
	try:
		env = Environment()
		env.start()
		env.discover(seconds=3)
		result = env.list_switches()
	
	except:
		raise
	
	return result
开发者ID:flann321,项目名称:HomeCoolingPi,代码行数:13,代码来源:wemo.py

示例5: __init__

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import discover [as 别名]
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,代码行数:13,代码来源:control.py

示例6: mainloop

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import discover [as 别名]
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,代码行数:15,代码来源:insight-logger-pubsub.py

示例7: init

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import discover [as 别名]
def init(devname):
	try:
		env = Environment()
		env.start()
		env.discover(seconds=3)
		switch = env.get_switch(devname)

	#except UnknownDevice:
	#	return None, None
	except:
		raise

	return env, switch
开发者ID:flann321,项目名称:HomeCoolingPi,代码行数:15,代码来源:wemo.py

示例8: WemoClient

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import discover [as 别名]
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,代码行数:16,代码来源:wemo.py

示例9: toggleLight

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import discover [as 别名]
def toggleLight():
    env = Environment()
    try:
        env.start()
    except:
        print "server may have been started already"
    for i in range(1, 5):
        try:
            env.discover(i)
            switch = env.get_switch("WeMo Switch")
            switch.toggle()
        except:
            continue
        break
开发者ID:rpetti,项目名称:lg-tv-automation,代码行数:16,代码来源:wemo.py

示例10: Wemo

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import discover [as 别名]
class Wemo(object):
    state_map = {'on': 1, 'off': 0}
    state_map_wemo = {'1': 'on', '0': 'off'}

    def __init__(self):
        self.env = Environment(with_cache=False)
        self.env.start()
        self.env.discover()
        self.list_switches = self.env.list_switches()
        print self.list_switches

    def get(self, name, use_cache=False):
        '''
        get - returns the state of the given device
        '''

        status = 0
        state = None
        s = self.env.get_switch(name)
        try:
            state = s.basicevent.GetBinaryState()
            if 'BinaryState' in state:
                print 'get info: {}'.format(state)
                state = Wemo.state_map_wemo[state['BinaryState']]
                return status, state

        except Exception as e:
            print 'exception {}'.format(e)
            status = 2

        return status, state

    def set(self, name, val_on_off, use_cache=False):
        '''
        set - turns the wemo switch either on or off. Will
        execute for all the switches in the list
        '''

        status = 0
        s = self.env.get_switch(name)

        print 'state: {}'.format(val_on_off)
        state = Wemo.state_map[val_on_off.lower()]
        try:
            s.basicevent.SetBinaryState(BinaryState=state)
        except:
            status = 2
        return status
开发者ID:tmackall,项目名称:django_home,代码行数:50,代码来源:tasks.py

示例11: get_switch

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import discover [as 别名]
def get_switch():
    env = Environment()

    try:
        env.start()
    except:
        pass

    env.discover(5)
    found = None
    for switch in env.list_switches():
        if matches(switch):
            found = env.get_switch(switch)
            break
    else:
        raise Exception('Switch not found!')

    return found
开发者ID:kyokley,项目名称:alexa_command,代码行数:20,代码来源:start_up.py

示例12: main

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import discover [as 别名]
def main():
    # define input parameters
    parser = OptionParser()
    parser.add_option("-a", help="all of the wemo devices", default=False, action="store_true")
    parser.add_option("-g", help="get switch state", default=False, action="store_true")
    parser.add_option("-l", help="list all the switches", default=False, action="store_true")
    parser.add_option("--off", help="off flag - default is on", default=False, action="store_true")
    parser.add_option("-s", help="switch name", default=None)

    # read input values
    (options, args) = parser.parse_args()
    flag_on_off = ON
    if options.off:
        flag_on_off = OFF
    flag_list = options.l
    flag_get = options.g
    switch_name = options.s

    #
    # environment - wemo
    env = Environment()
    env.start()
    env.discover()
    switches = env.list_switches()

    if switch_name is not None:
        if switch_name not in switches:
            print "%s is not available" % switch_name
            return {"status": 1}
        else:
            switches = [switch_name]

    if flag_list:
        return {"status": 0, "msg": switches}

    if flag_get:
        return {"status": 0, "msg": switch_get(env, switches)}

    #
    # switch - on/off
    switch_set(env, switches, flag_on_off)
    return {"status": 0, "msg": "switch(es):%s val:%s" % (switches, flag_on_off)}
开发者ID:tmackall,项目名称:bin-home,代码行数:44,代码来源:wemo.py

示例13: _on_switch

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import discover [as 别名]
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,代码行数:43,代码来源:wemo.py

示例14: Controller

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import discover [as 别名]
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,代码行数:42,代码来源:wemo.py

示例15: mainloop

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import discover [as 别名]
def mainloop(name):
    matches = matcher(name)

    @receiver(devicefound)
    def found(sender, **kwargs):
        if matches(sender.name):
            print "Found device:", sender.name

            while 1:
                print_some_times(sender)



   
    env = Environment(with_cache=False)
    try:
        env.start()
        env.discover(10)
        env.wait()
    except (KeyboardInterrupt, SystemExit):
        print "Goodbye!"
        sys.exit(0)
开发者ID:korostelevm,项目名称:wemoMonitor,代码行数:24,代码来源:wemoMonitor.py


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