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


Python Environment.wait方法代码示例

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


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

示例1: mainloop

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import wait [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

示例2: mainloop

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

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

    @receiver(statechange)
    def motion(sender, **kwargs):
        if matches(sender.name):
            print "{} state is {state}".format(
                sender.name, state="on" if kwargs.get('state') else "off")

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

示例3: mainloop

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

    def is_standby(name):
        print "Waiting for standby or powerof"
        switch = env.get_switch(name)
        time.sleep(10)
        normal_power = switch.current_power
        time.sleep(10)

        while switch.get_state():
            if switch.current_power < (normal_power * 0.2):
                print "Device in standby mode!"
                break
            time.sleep(10)

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

    @receiver(statechange)
    def on_off(sender, **kwargs):
        if matches(sender.name):
            print "{} state is {state}".format(
                sender.name, state="on" if kwargs.get('state') else "off")
            if kwargs.get('state'):
                is_standby(sender.name)

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

示例4: Environment

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import wait [as 别名]
from ouimeaux.environment import Environment

# http://pydoc.net/Python/ouimeaux/0.7.3/ouimeaux.examples.watch/
if __name__ == "__main__":
    print ""
    print "WeMo Randomizer"
    print "---------------"
    env = Environment()
    # TODO: run from 10am to 10pm
    try:
        env.start()
        env.discover(100)
        print env.list_switches()
        print env.list_motions()
        print "---------------"
        while True:
            # http://stackoverflow.com/questions/306400/how-do-i-randomly-select-an-item-from-a-list-using-python
            switchRND = env.get_switch( random.choice( env.list_switches() ) )
            print switchRND
            switchRND.toggle()
            env.wait(90)
        
    except (KeyboardInterrupt, SystemExit):
        print "---------------"
        print "Goodbye!"
        print "---------------"
        # Turn off all switches
        for switch in ( env.list_switches() ):
            print "Turning Off: " + switch
            env.get_switch( switch ).off()
开发者ID:Critter,项目名称:ouimeaux,代码行数:32,代码来源:Randomize.py

示例5: print

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import wait [as 别名]
print("Connected to switch {}".format(switch))

reset_chromecast()


def safe_volume_toggle(direction, notches):
    try:
        if direction == 1:
            for _ in notches:
                print("TURN DOWN FOR WHAT!")
                cast.volume_up()
        elif direction == 8:
            for _ in notches:
                print("OKAY MOM!")
                cast.volume_down()
    except Exception:
        print("Oh noes, think we lost connection to the chromecast."
              "Give me a moment and I'll fix er up...")
        reset_chromecast()
        safe_volume_toggle(direction, notches)


@receiver(statechange, sender=switch)
def volume_event(**kwargs):
    """Handles volume control based on wemo on/off events"""
    notches = CONFIG['notches']
    safe_volume_toggle(kwargs['state'], range(notches))

if __name__ == '__main__':
    env.wait()
开发者ID:Raynes,项目名称:fucktheac,代码行数:32,代码来源:__main__.py

示例6: mainloop

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import wait [as 别名]
def mainloop(name):
    matches = matcher(name)
    queueName = 'HUECOMMANDS'
    channel = None
    def connect():
        global channel
        global queue
        print "Connecting to RabbitMQ"
        connection = pika.BlockingConnection(pika.ConnectionParameters(
               '54.69.168.245'))
        channel = connection.channel()
        channel.queue_declare(queue=queueName)
        print "Connected to RabbitMQ"

    def postState():
        global channel
        
        print "motion detected ", datetime.now().time()
        
        #TODO: this should be posting events, not commands, but this works for now...
        if channel is not None:
            channel.basic_publish(exchange='',
                      routing_key=queueName,
                      body=buildMessage("5").SerializeToString())
            channel.basic_publish(exchange='',
                      routing_key=queueName,
                      body=buildMessage("6").SerializeToString())
            channel.basic_publish(exchange='',
                      routing_key=queueName,
                      body=buildMessage("7").SerializeToString())
            print "message posted"
        
    def buildMessage( id ):
        m = UpdateLightCommand.UpdateLightCommand()
        m.is_on = True
        m.msg_version = 1
        m.light_id = id
        m.rgb_red = 255
        m.rgb_green = 255
        m.rgb_blue = 255
        return m
    
    @receiver(devicefound)
    def found(sender, **kwargs):
        if matches(sender.name):
            print "Found device:", sender.name
            connect()

    @receiver(statechange)
    def motion(sender, **kwargs):
        if matches(sender.name) and kwargs.get('state'):
            postState()

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

示例7: motion_detected

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import wait [as 别名]
@receiver(statechange, sender=motion)
def motion_detected(state, sender, signal):
	global lastMovedTime
	if (state == 1):
		print "Motion detected"
		lastMovedTime = time.time()
		
@receiver(statechange, sender=switch)
def switch_detected(state, sender, signal):
	global lastMovedTime
	global timedOut
	if (state == 1):
		print "Switch detected"
		lastMovedTime = time.time()
		timedOut = False
		

print "Waiting for events"
while True:
	env.wait(waitTime)
	print "Switch state is: ", switch.basicevent.GetBinaryState()['BinaryState']
	if ((time.time() - lastMovedTime) > timeoutTime) & (switch.basicevent.GetBinaryState()['BinaryState'] == "1"):
		print "Turning switch off"
		switch.basicevent.SetBinaryState(BinaryState=0)
		timedOut = True
		
	if timedOut & ((time.time() - lastMovedTime) < reactivateTime):
		print "Turning switch back on"
		switch.basicevent.SetBinaryState(BinaryState=1)
		timedOut = False
开发者ID:jeffsharris,项目名称:jarvis,代码行数:32,代码来源:wemo.py

示例8: mainloop

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import wait [as 别名]
def mainloop():
    #source_matcher = matcher(source)
    random_port = randint(54300, 54499)

    env = Environment(bind="%s:%d"%(get_ip_address(), random_port), with_cache=False)


    @receiver(devicefound)
    def found(sender, **kwargs):
        all_targets = []
        for target in triggers.values():
            if isinstance(target, list):
                all_targets.extend(target)
            else:
                all_targets.append(target)

        for key in (triggers.keys() + all_targets):
            if matcher(key)(sender.name):
                print "Found device:", sender.name

    @receiver(statechange)
    def something_happened(sender, **kwargs):
        print "Something happened with %s"%sender
        for key in triggers.keys():
            if matcher(key)(sender.name):
                state = 1 if kwargs.get('state') else 0
                print "{} state is {state}".format(sender.name, state=state)
                if isinstance(triggers[key], list):
                    for target in triggers[key]:
                        set_target_state(target, state)
                else:
                    set_target_state(triggers[key], state)


    #this will intentionally not stop after it finds a first match so that we can use common prefixes to form groups
    def set_target_state(name, state):
        print "!!!  Set '%s' State = %s"%(name, state)
        for switch_name in env.list_switches():
            if matcher(name)(switch_name):
                print "Found a switch matching name %s" % name
                switch = env.get_switch(switch_name)
                switch.set_state(state)

        if len(env.list_bridges()) > 0:
            bridge = env.get_bridge(env.list_bridges()[0])
            for light_name in bridge.bridge_get_lights():
                if matcher(name)(light_name):
                    print "telling target (via bridge) to set state to %s"%state
                    light = bridge.bridge_get_lights()[light_name]
                    bridge.light_set_state(light, state=state, dim=254 if state==1 else None)

    try:
        print "Starting..."
        env.start()
        #env.upnp.server
        env.discover(2)
        sock = env.upnp.server._socket
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        print "\t... discovering nearby devices"
        env.discover(10)
        print "Entering main loop"
        env.wait()
    except (KeyboardInterrupt, SystemExit):
        print "Goodbye!"
        sys.exit(0)
开发者ID:bennytheshap,项目名称:meredith,代码行数:67,代码来源:meredith.py


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