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


Python Environment.get_switch方法代码示例

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


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

示例1: Wemo

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import get_switch [as 别名]
class Wemo(Command):
    def __init__(self):
        self.env = Environment(with_discovery=False, with_subscribers=False)
        self.env.start()

    def on(self, device):
        switch = self.env.get_switch(closest_match(device, self.env.list_switches()))
        switch.basicevent.SetBinaryState(BinaryState=1)

    def off(self, device):
        switch = self.env.get_switch(closest_match(device, self.env.list_switches())) 
        switch.basicevent.SetBinaryState(BinaryState=0)
开发者ID:maxvitek,项目名称:homespun_site,代码行数:14,代码来源:commands.py

示例2: Wemo

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

示例3: toggle_switch

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

示例4: get_switch_state

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

示例5: main

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

示例6: _on_switch

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

示例7: init

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

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import get_switch [as 别名]
def go_pi():
	try:
		sys.stderr = open("otherlog.txt", "wa+")
		sys.stdout = open("log.txt", "wa+")
		print "Powering up server..."
		switches = []
		env = Environment(on_switch, on_motion)
		env.start()
		#search until a switch is found
		tries = 0
		print "Searching for switches..."
		while True:
			tries += 1
			names = env.list_switches()
			if len(names) > 0: break
			if tries == 100: 
				print "FAILED to find a switch after 100 tries"
				sys.exit()
		#create a dictionary object wrapper for each found switch
		for switch_name in names:
			s = {NAME : switch_name, SWITCH : None, STATE : OFF, ID : None, THRESH : None, MIN : 0}
			if switch_name == "ymcmb":
				ymcmb = env.get_switch('ymcmb')
				s[SWITCH] = ymcmb
				s[ID] = YMCMB_ID
				s[THRESH] = YMCMB_THRESH
				s[MIN] = YMCMB_MIN
			elif switch_name == "patty":
				paddy = env.get_switch('patty')
				s[SWITCH] = paddy
				s[ID] = PADDY_ID
				s[THRESH] = PADDY_THRESH
			#create a list of all found switches
			switches.append(s)

		run_local_server(switches)
	except:
		pass
开发者ID:mmaduabum,项目名称:Foodie,代码行数:40,代码来源:wemo.py

示例9: toggleLight

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

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

示例11: on_switch

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

# Switch Acquisition
def on_switch(switch):
	print "Switch found!", switch.name
def on_motion(motion):
	print "Motion found!", motion.name
env = Environment(on_switch, on_motion)
env.start()
switches=env.list_switches()

# switchpair matches names to switch obj
switchpair={}
for s in switches:
	if s in devicemap.keys():
		switchpair[s]=env.get_switch(s)
print switchpair

# get ips to look for
ips=[]
for d in db5.find():
	ips.append(d["ip"])

#interval
interval = int(sys.argv[1])

#import applications:
f=os.listdir("apps")
f=[t for t in f if ".py" in t]
apps=[]
for app in f:
开发者ID:nishadg246,项目名称:EnergyAware,代码行数:33,代码来源:main.py

示例12: turn_on

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import get_switch [as 别名]
	  turn_on(sw)
	elif 'set_state_off' in path:
	  turn_off(sw)
	elif 'get_state' in path:
	  self.wfile.write(device_state)

    def log_request(self, code=None, size=None):
        print('Request')

    def log_message(self, format, *args):
        print('Message')


if __name__ == "__main__":
    env = Environment(on_switch)
    try:
        env.start()
    except TypeError:
        pass


    sw = env.get_switch('WeMo Switch')

    try:
        server = HTTPServer(('', 8091), MyHandler)
        print('Started http server')
        server.serve_forever()
    except KeyboardInterrupt:
        print('^C received, shutting down server')
        server.socket.close()
开发者ID:Chiru,项目名称:WeX,代码行数:32,代码来源:wemo_server.py

示例13: Environment

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import get_switch [as 别名]
# Echo client program
import socket
from ouimeaux.environment import Environment

env = Environment()
env.start()

switches = list()

env.discover(seconds=3)

switchesList = env.list_switches()
#switches = list()

for s in switchesList:
    switches.append(env.get_switch(s))

str_switches = ', '.join(switchesList) # to be sent to server



HOST = 'localhost'    # The remote host
PORT = 50010          # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#s.connect((HOST, PORT))
s.bind((HOST, PORT))

print('Ready for Connections')

while 1:
    s.listen(1)
开发者ID:pdiefend,项目名称:BUSERT_Microgrid,代码行数:33,代码来源:27_Server.py

示例14: __init__

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import get_switch [as 别名]
        $ python ./devices/power.py
    '''
    def __init__(self, outlet):
        addr = 'http://' + outlet.replace("wemo://", "") + ":49153/setup.xml"
        self.switch = WemoSwitch(addr)
    def reset(self):
        self.switch.off()
        time.sleep(5)
        self.switch.on()

if __name__ == "__main__":
    print("Gathering info about power outlets...")

    if WemoEnv is not None:
        env = WemoEnv()
        env.start()
        scan_time = 10
        print("Scanning for WeMo switches for %s seconds..." % scan_time)
        env.discover(scan_time)
        if len(env.list_switches()) > 0:
            print("Found the following switches:");
            for switch_name in env.list_switches():
                switch = env.get_switch(switch_name)
                print("%s ip address is %s" % (switch_name, switch.host))
            print("The switches above can be added by ip address"
                    " for example use the")
            print("following to use %s" % switch_name)
            print("\twemo://%s" % switch.host)
        else:
            print("No WeMo switches found")
开发者ID:mtusnio,项目名称:boardfarm,代码行数:32,代码来源:power.py

示例15:

# 需要导入模块: from ouimeaux.environment import Environment [as 别名]
# 或者: from ouimeaux.environment.Environment import get_switch [as 别名]
import serial, urllib,os,datetime
from ouimeaux.environment import Environment
from time import gmtime,strftime
import httplib, urllib
import pyowm
import time

fh=open("log.txt","a")

temp_boost=0.1
env=Environment()
env.start()
boiler=env.get_switch('Boiler')

boiler_state=[]

port = serial.Serial("/dev/ttyACM0", baudrate=9600, timeout = 120)

boiler_off_temp=0
boiler_on_temp=99
porch=[]
landing=[]
garden=[]
battery='x.xx'
print 'starting'
while True:
        error = ''
#    try:    
        try:        
            rcv = port.read(12)
        except:
开发者ID:andythegrouch,项目名称:sketches,代码行数:33,代码来源:house_1_1.py


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