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
26 changes: 12 additions & 14 deletions PyTado/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import logging
import json
import datetime
import urllib.request
import urllib.parse
import urllib.error
import urllib2
import urllib

from http.cookiejar import CookieJar

Expand Down Expand Up @@ -41,7 +40,7 @@ def _mobile_apiCall(self, cmd):
cmd)

url = '%s%s' % (self.mobi2url, cmd)
req = urllib.request.Request(url, headers=self.headers)
req = urllib2.urlopen(url, headers=self.headers)
response = self.opener.open(req)
str_response = response.read().decode('utf-8')

Expand Down Expand Up @@ -73,9 +72,8 @@ def _apiCall(self, cmd, method="GET", data=None, plain=False):
method, cmd, headers, data)

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

response = self.opener.open(req)
Expand Down Expand Up @@ -119,9 +117,9 @@ def _refresh_token(self):
'scope' : 'home.user',
'refresh_token' : self.refresh_token}
# pylint: disable=R0204
data = urllib.parse.urlencode(data)
data = urllib.urlencode(data)
url = url + '?' + data
req = urllib.request.Request(url, data=json.dumps({}).encode('utf8'), method='POST',
req = urllib2.urlopen(url, data=json.dumps({}).encode('utf8'), method='POST',
headers={'Content-Type': 'application/json',
'Referer' : 'https://my.tado.com/'})

Expand All @@ -145,9 +143,9 @@ def _loginV2(self, username, password):
'scope' : 'home.user',
'username' : username}
# pylint: disable=R0204
data = urllib.parse.urlencode(data)
data = urllib.urlencode(data)
url = url + '?' + data
req = urllib.request.Request(url, data=json.dumps({}).encode('utf8'), method='POST',
req = urllib2.Request(url, data=json.dumps({}).encode('utf8'), #method='POST',
headers={'Content-Type': 'application/json',
'Referer' : 'https://my.tado.com/'})

Expand All @@ -167,7 +165,7 @@ def getMe(self):
# pylint: disable=C0103

url = 'https://my.tado.com/api/v2/me'
req = urllib.request.Request(url, headers=self.headers)
req = urllib2.Request(url, headers=self.headers)
response = self.opener.open(req)
str_response = response.read().decode('utf-8')
data = json.loads(str_response)
Expand Down Expand Up @@ -286,8 +284,8 @@ def __init__(self, username, password):
# pylint: disable=C0103
cj = CookieJar()

self.opener = urllib.request.build_opener(
urllib.request.HTTPCookieProcessor(cj),
urllib.request.HTTPSHandler())
self.opener = urllib2.build_opener(
urllib2.HTTPCookieProcessor(cj),
urllib2.HTTPSHandler())
self._loginV2(username, password)
self.id = self.getMe()['homes'][0]['id']