Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import urllib2
- import urllib
- class Pymoticz:
- def __init__(self):
- self.host='192.168.1.4:8080'
- def _request(self, url):
- urllib2.urlopen(url)
- def turn_on(self, _id):
- url='http://%s/json.htm?type=command¶m=switchlight&idx=%s&switchcmd=On' % (self.host, _id)
- self._request(url)
- def turn_off(self, _id):
- url='http://%s/json.htm?type=command¶m=switchlight&idx=%s&switchcmd=Off&level=0' % (self.host, _id)
- self._request(url)
- def dim(self, _id, level):
- f = urllib.urlencode({ 'type' : 'command', 'param' : 'switchlight' , 'idx' : _id , 'switchcmd' : 'Set Level' , 'level' : level })
- url='http://%s/json.htm?' % (self.host) + f
- self._request(url)
- if __name__ == '__main__':
- p=None
- p=Pymoticz()
- p.dim(2,16)
- p.dim(3,16)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement