Skip to content
This repository has been archived by the owner on Jun 7, 2021. It is now read-only.

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Young committed Aug 5, 2017
1 parent 56aec93 commit b2d018f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 54 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name = 'wemo',
packages = ['wemo'],
version = '1.0.0',
version = '1.0.1',
description = 'A Wemo API',
author = 'Evan Young',
url = 'https://github.com/DocCodes/wemo',
Expand Down
105 changes: 52 additions & 53 deletions wemo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,61 +8,60 @@
__credits__ = "Evan Young"

__license__ = "GNU GLPv3"
__version__ = "1.0.0"
__version__ = "1.0.1"
__maintainer__ = "Evan Young"
__status__ = "Development"


class switch:
def __init__(self, ip):
if(self.check(ip) == 0): exit
self.ip = ip
self.port = self.check(ip)
self.full = f'{self.ip}:{self.port}'
self.url = f'http://{self.full}/upnp/control/basicevent1'
self.status = self.get()
def enable(self):
self.set(self, 1)
def disable(self):
self.set(self, 0)
def toggle(self):
self.set(self, int(not(self.get(self))))
def set(self, state):
hd = self.headers('SetBinaryState')
data = self.data('SetBinaryState', f'<BinaryState>{state}</BinaryState>')
post(self.url, headers=hd, data=data)
def get(self):
hd = self.headers('GetBinaryState')
data = self.data('GetBinaryState', '')
rsp = post(self.url, headers=hd, data=data).text
return int(self.tagger(rsp, 'BinaryState'))
def name(self):
hd = self.headers('GetFriendlyName')
data = self.data('GetFriendlyName', '')
rsp = post(self.url, headers=hd, data=data).text
return self.tagger(rsp, 'FriendlyName')
def headers(self, soapa):
hd = {
'accept': '',
'content-type': "text/xml; charset='utf-8'",
'SOAPACTION': f'"urn:Belkin:service:basicevent:1#{soapa}"'
}
return hd
def data(self, tag, val):
data = f'<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:{tag} xmlns:u="urn:Belkin:service:basicevent:1">{val}</u:{tag}></s:Body></s:Envelope>'
return data
def tagger(self, txt, tag):
ln = len(f'<{tag}>')
beg = txt.index(f'<{tag}>')
end = txt.index(f'</{tag}>')
return txt[beg+ln:end]
def check(self, ip):
port = 0
for test in range(49152, 49156):
try:
get(f'http://{ip}:{test}')
except:
pass
else:
port = test
return port
def __init__(self, ip):
if(self.check(ip) == 0): exit
self.ip = ip
self.port = self.check(ip)
self.full = f'{self.ip}:{self.port}'
self.url = f'http://{self.full}/upnp/control/basicevent1'
self.status = self.getStatus()
self.name = self.getName()
def enable(self):
self.setStatus(1)
def disable(self):
self.setStatus(0)
def toggle(self):
self.setStatus(int(not(self.getStatus())))
def setStatus(self, state):
hd = self.xmlHeads('SetBinaryState')
data = self.xmlData('SetBinaryState', f'<BinaryState>{state}</BinaryState>')
post(self.url, headers=hd, data=data)
def getStatus(self):
hd = self.xmlHeads('GetBinaryState')
data = self.xmlData('GetBinaryState', '')
rsp = post(self.url, headers=hd, data=data).text
return int(self.tagger(rsp, 'BinaryState'))
def getName(self):
hd = self.xmlHeads('GetFriendlyName')
data = self.xmlData('GetFriendlyName', '')
rsp = post(self.url, headers=hd, data=data).text
return self.tagger(rsp, 'FriendlyName')
def xmlHeads(self, soapa):
return {'accept': '','content-type': "text/xml; charset='utf-8'",'SOAPACTION': f'"urn:Belkin:service:basicevent:1#{soapa}"'}
def xmlData(self, tag, val):
return f'<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:{tag} xmlns:u="urn:Belkin:service:basicevent:1">{val}</u:{tag}></s:Body></s:Envelope>'
def tagger(self, txt, tag):
ln = len(f'<{tag}>')
beg = txt.index(f'<{tag}>')
end = txt.index(f'</{tag}>')
return txt[beg+ln:end]
def check(self, ip):
port = 0
for test in range(49152, 49156):
try:
get(f'http://{ip}:{test}')
except:
pass
else:
port = test
return port

if __name__ == '__main__':
print("Hello Console!")
bd = switch('192.168.1.72')

0 comments on commit b2d018f

Please sign in to comment.