Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated interface.py #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
22 changes: 19 additions & 3 deletions PyTado/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Tado:
# Instance-wide constant info
headers = {'Referer' : 'https://my.tado.com/'}
api2url = 'https://my.tado.com/api/v2/homes/'
api2urlNoHomes = 'https://my.tado.com/api/v2/'
mobi2url = 'https://my.tado.com/mobile/1.9/'
refresh_token = ''
refresh_at = datetime.datetime.now() + datetime.timedelta(minutes=5)
Expand Down Expand Up @@ -53,7 +54,7 @@ def _mobile_apiCall(self, cmd):
return data

# 'Private' methods for use in class, Tado API V2.
def _apiCall(self, cmd, method="GET", data=None, plain=False):
def _apiCall(self, cmd, method="GET", data=None, plain=False, self_id=True):
# pylint: disable=C0103

self._refresh_token()
Expand All @@ -72,7 +73,11 @@ def _apiCall(self, cmd, method="GET", data=None, plain=False):
_LOGGER.debug("api call: %s: %s, headers %s, data %s",
method, cmd, headers, data)

url = '%s%i/%s' % (self.api2url, self.id, cmd)
if self_id:
url = '%s%i/%s' % (self.api2url, self.id, cmd)
else:
url = '%s%s' % (self.api2urlNoHomes, cmd)

req = urllib.request.Request(url,
headers=headers,
method=method,
Expand Down Expand Up @@ -244,7 +249,18 @@ def resetZoneOverlay(self, zone):
cmd = 'zones/%i/overlay' % zone
data = self._apiCall(cmd, "DELETE", {}, True)
return data


def setOffset(self, device, offset_celsius, self_id=False):
'''set celsius offset for a device'''
cmd = 'devices/%s/temperatureOffset' % device

post_data = {
"celsius": offset_celsius
}

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

def setZoneOverlay(self, zone, overlayMode, setTemp=None, duration=None, deviceType='HEATING', power="ON", mode=None):
"""set current overlay for a zone"""
# pylint: disable=C0103
Expand Down