Skip to content

Instantly share code, notes, and snippets.

@matbor
Last active December 28, 2015 22:59
Show Gist options
  • Save matbor/7575954 to your computer and use it in GitHub Desktop.
Save matbor/7575954 to your computer and use it in GitHub Desktop.
testing wemo ouimeaux script to get the state of my belkin wemo device
from ouimeaux.environment import Environment
def on_switch(switch):
print ('******** Switch found:', switch.name)
def on_change(value):
print('******** light has changed state and has been switched!')
env = Environment(switch_callback=on_switch, with_cache=False)
env.start()
env.discover(3)
lounge = env.get_switch('Lounge room lamp')
lounge.register_listener(on_change)
env.wait()
@matbor
Copy link
Author

matbor commented Nov 21, 2013

update.... just upgraded to 0.5.1 and it seems to of fixed my problem and is detecting the switch changes now ;)

but now it is coming up with this error....

'********  Switch found:', 'Lounge room lamp'

192.168.4.109 - - [2013-11-22 10:10:31] "NOTIFY / HTTP/1.1" 200 161 0.013892
<socket fileno=7 sock=192.168.4.20:8989>: Invalid HTTP method: '\n'
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/gevent/greenlet.py", line 328, in run
    result = self._run(*self.args, **self.kwargs)
  File "/usr/local/lib/python2.7/dist-packages/gevent/pywsgi.py", line 654, in handle
    handler.handle()
  File "/usr/local/lib/python2.7/dist-packages/gevent/pywsgi.py", line 190, in handle
    self.socket.sendall(response_body)
  File "/usr/local/lib/python2.7/dist-packages/gevent/socket.py", line 458, in sendall
    data_sent += self.send(_get_memory(data, data_sent), flags)
  File "/usr/local/lib/python2.7/dist-packages/gevent/socket.py", line 435, in send
    return sock.send(data, flags)
error: [Errno 32] Broken pipe
<Greenlet at 0x25c8440: <bound method WSGIServer.handle of <WSGIServer at 0x25bdcb0 fileno=6 address=0.0.0.0:8989>>(<socket at 0x262dd70 fileno=[Errno 9] Bad file des, ('192.168.4.109', 3322))> failed with error

192.168.4.109 - - [2013-11-22 10:10:31] "NOTIFY / HTTP/1.1" 200 161 0.002756
<socket fileno=8 sock=192.168.4.20:8989 peer=192.168.4.109:3323>: Invalid HTTP method: '\n'
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/gevent/greenlet.py", line 328, in run
    result = self._run(*self.args, **self.kwargs)
  File "/usr/local/lib/python2.7/dist-packages/gevent/pywsgi.py", line 654, in handle
    handler.handle()
  File "/usr/local/lib/python2.7/dist-packages/gevent/pywsgi.py", line 190, in handle
    self.socket.sendall(response_body)
  File "/usr/local/lib/python2.7/dist-packages/gevent/socket.py", line 458, in sendall
    data_sent += self.send(_get_memory(data, data_sent), flags)
  File "/usr/local/lib/python2.7/dist-packages/gevent/socket.py", line 435, in send
    return sock.send(data, flags)
error: [Errno 32] Broken pipe
<Greenlet at 0x25c8710: <bound method WSGIServer.handle of <WSGIServer at 0x25bdcb0 fileno=6 address=0.0.0.0:8989>>(<socket at 0x262d8f0 fileno=[Errno 9] Bad file des, ('192.168.4.109', 3323))> failed with error

192.168.4.109 - - [2013-11-22 10:10:31] "NOTIFY / HTTP/1.1" 200 161 0.002753
<socket fileno=7 sock=192.168.4.20:8989 peer=192.168.4.109:3324>: Invalid HTTP method: '\n'
192.168.4.109 - - [2013-11-22 10:10:31] "" 400 0 0.002173

'********  light has changed state and has been switched!

192.168.4.109 - - [2013-11-22 10:10:44] "NOTIFY / HTTP/1.1" 200 161 0.015749
<socket fileno=7 sock=192.168.4.20:8989 peer=192.168.4.109:3325>: Invalid HTTP method: '\n'
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/gevent/greenlet.py", line 328, in run
    result = self._run(*self.args, **self.kwargs)
  File "/usr/local/lib/python2.7/dist-packages/gevent/pywsgi.py", line 654, in handle
    handler.handle()
  File "/usr/local/lib/python2.7/dist-packages/gevent/pywsgi.py", line 190, in handle
    self.socket.sendall(response_body)
  File "/usr/local/lib/python2.7/dist-packages/gevent/socket.py", line 458, in sendall
    data_sent += self.send(_get_memory(data, data_sent), flags)
  File "/usr/local/lib/python2.7/dist-packages/gevent/socket.py", line 435, in send
    return sock.send(data, flags)
error: [Errno 32] Broken pipe
<Greenlet at 0x25ceb20: <bound method WSGIServer.handle of <WSGIServer at 0x25bdcb0 fileno=6 address=0.0.0.0:8989>>(<socket at 0x262d4d0 fileno=[Errno 9] Bad file des, ('192.168.4.109', 3325))> failed with error


@matbor
Copy link
Author

matbor commented Nov 24, 2013

Above was fixed in new release of library,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment