Skip to content

Commit

Permalink
added overlay functionality
Browse files Browse the repository at this point in the history
* setZoneOverlay and resetZoneOverlay to change set Temperature
  • Loading branch information
Wolfgang Malgadey committed Jan 4, 2017
1 parent edd0a84 commit f61c964
Showing 1 changed file with 59 additions and 2 deletions.
61 changes: 59 additions & 2 deletions PyTado/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,28 @@ def _mobile_apiCall(self, cmd):
return data

# 'Private' methods for use in class, Tado API V2.
def _apiCall(self, cmd):
def _apiCall(self, cmd, method="GET", data=None):
self._refreshToken()

headers = self.headers

if data is not None:
headers['Content-Type'] = 'application/json;charset=UTF-8'
headers['Mime-Type'] = 'application/json;charset=UTF-8'
data=json.dumps(data).encode('utf8')

url = '%s%i/%s' % (self.api2url, self.id, cmd)
req = urllib.request.Request(url, headers=self.headers)
req = urllib.request.Request(url,
headers=headers,
method=method,
data=data)

response = self.opener.open(req)
str_response = response.read().decode('utf-8')

if str_response is None or str_response == "":
return

data = json.loads(str_response)
return data

Expand Down Expand Up @@ -72,6 +87,9 @@ def _refreshToken(self):
return response

def _loginV2(self, username, password):
headers = self.headers
headers['Content-Type'] = 'application/json'

url='https://my.tado.com/oauth/token'
data = { 'client_id' : 'tado-webapp',
'grant_type' : 'password',
Expand Down Expand Up @@ -148,6 +166,45 @@ def getAppUsersRelativePositions(self):
data = self._mobile_apiCall(cmd)
return data

def resetZoneOverlay(self, zone):
"""Delete current overlay"""
cmd = 'zones/%i/overlay' % zone
data = self._apiCall(cmd, "DELETE", {})
return data

def setZoneOverlay(self, zone, overlayMode, setTemp=None, duration=None):
"""set current overlay for a zone"""
cmd = 'zones/%i/overlay' % zone

postData = { "setting" : {}, "termination" : {} }

if setTemp is None:
postData["setting"] = {
"type":"HEATING",
"power":"OFF"
}
else:
postData["setting"] = {
"type":"HEATING",
"power":"ON",
"temperature":{
"celsius": setTemp
}
}

postData["termination"] = {
"type":overlayMode
#{"type":"TIMER","durationInSeconds":900}
#{"type":"MANUAL"}
#{"type":"TADO_MODE"}
}

if duration is not None:
postData["termination"]["durationInSeconds"] = duration

data = self._apiCall(cmd, "PUT", postData)
return data

# Ctor
def __init__(self, username, password):
"""Performs login and save session cookie."""
Expand Down

0 comments on commit f61c964

Please sign in to comment.