Advertisement
Guest User

Untitled

a guest
Mar 1st, 2014
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import urllib2
  3. import urllib
  4.  
  5. class Pymoticz:
  6. def __init__(self):
  7. self.host='192.168.1.4:8080'
  8.  
  9. def _request(self, url):
  10. urllib2.urlopen(url)
  11.  
  12. def turn_on(self, _id):
  13. url='http://%s/json.htm?type=command&param=switchlight&idx=%s&switchcmd=On' % (self.host, _id)
  14. self._request(url)
  15.  
  16. def turn_off(self, _id):
  17. url='http://%s/json.htm?type=command&param=switchlight&idx=%s&switchcmd=Off&level=0' % (self.host, _id)
  18. self._request(url)
  19.  
  20. def dim(self, _id, level):
  21. f = urllib.urlencode({ 'type' : 'command', 'param' : 'switchlight' , 'idx' : _id , 'switchcmd' : 'Set Level' , 'level' : level })
  22. url='http://%s/json.htm?' % (self.host) + f
  23. self._request(url)
  24.  
  25. if __name__ == '__main__':
  26. p=None
  27. p=Pymoticz()
  28. p.dim(2,16)
  29. p.dim(3,16)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement