Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions greenwavereality/greenwavereality.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ def grab_xml(host, token=None):
if not token:
scheme = "http"
token = "1234567890"
url = (
scheme + '://' + host + '/gwr/gop.php?cmd=GWRBatch&data=<gwrcmds><gwrcmd><gcmd>RoomGetCarousel</gcmd><gdata><gip><version>1</version><token>' + token + '</token><fields>name,status</fields></gip></gdata></gwrcmd></gwrcmds>&fmt=xml')
response = requests.get(url, verify=False)
url = '{}://{}/gwr/gop.php?cmd=GWRBatch&data=<gwrcmds><gwrcmd><gcmd>RoomGetCarousel</gcmd><gdata><gip><version>1</version><token>{}</token><fields>name,status</fields></gip></gdata></gwrcmd></gwrcmds>&fmt=xml'.format(scheme, host, token)
response = requests.get(url, timeout=10.0, verify=False)
parsed = xmltodict.parse(response.content, force_list={'room', 'device'})
parsed = parsed['gwrcmds']['gwrcmd']['gdata']['gip']['room']
return parsed
Expand All @@ -27,10 +26,8 @@ def set_brightness(host, did, value, token=None):
if not token:
scheme = "http"
token = "1234567890"
url = (
scheme + '://' + host + '/gwr/gop.php?cmd=DeviceSendCommand&data=<gip><version>1</version><token>' + token + '</token><did>' + did + '</did><value>' + str(
value) + '</value><type>level</type></gip>&fmt=xml')
response = requests.get(url, verify=False)
url = '{}://{}/gwr/gop.php?cmd=DeviceSendCommand&data=<gip><version>1</version><token>{}</token><did>{}</did><value>{}</value><type>level</type></gip>&fmt=xml'.format(scheme, host, token, did, value)
response = requests.get(url, timeout=10.0, verify=False)
if response.status_code == '200':
return True
else:
Expand All @@ -54,9 +51,8 @@ def turn_on(host, did, token=None):
if not token:
scheme = "http"
token = "1234567890"
url = (
scheme + '://' + host + '/gwr/gop.php?cmd=DeviceSendCommand&data=<gip><version>1</version><token>' + token + '</token><did>' + did + '</did><value>1</value></gip>&fmt=xml')
response = requests.get(url, verify=False)
url = '{}://{}/gwr/gop.php?cmd=DeviceSendCommand&data=<gip><version>1</version><token>{}</token><did>{}</did><value>1</value></gip>&fmt=xml'.format(scheme, host, token, did)
response = requests.get(url, timeout=10.0, verify=False)
if response.status_code == '200':
return True
else:
Expand All @@ -71,9 +67,8 @@ def turn_off(host, did, token=None):
if not token:
scheme = "http"
token = "1234567890"
url = (
scheme + '://' + host + '/gwr/gop.php?cmd=DeviceSendCommand&data=<gip><version>1</version><token>' + token + '</token><did>' + did + '</did><value>0</value></gip>&fmt=xml')
response = requests.get(url, verify=False)
url = '{}://{}/gwr/gop.php?cmd=DeviceSendCommand&data=<gip><version>1</version><token>{}</token><did>{}</did><value>0</value></gip>&fmt=xml'.format(scheme, host, token, did)
response = requests.get(url, timeout=10.0, verify=False)
if response.status_code == '200':
return True
else:
Expand All @@ -88,8 +83,8 @@ def check_online(device):
def grab_token(host, email, password):
"""Grab token from gateway. Press sync button before running."""
urllib3.disable_warnings()
url = ('https://' + host + '/gwr/gop.php?cmd=GWRLogin&data=<gip><version>1</version><email>' + str(email) + '</email><password>' + str(password) + '</password></gip>&fmt=xml')
response = requests.get(url, verify=False)
url = 'https://{}/gwr/gop.php?cmd=GWRLogin&data=<gip><version>1</version><email>{}</email><password>{}</password></gip>&fmt=xml'.format(host, email, password)
response = requests.get(url, timeout=10.0, verify=False)
if '<rc>404</rc>' in response.text:
raise PermissionError('Not In Pairing Mode')
parsed = xmltodict.parse(response.content)
Expand Down