Skip to content

Commit

Permalink
manual encoding of mytado response
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfgang Malgadey committed Dec 31, 2016
1 parent 92e871b commit 9e0b966
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions PyTado/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import json


class Tado:
"""Interacts with a Tado thermostat via public API.
Example usage: t = Tado('me@somewhere.com', 'mypasswd')
Expand All @@ -20,15 +21,17 @@ def _mobile_apiCall(self, cmd):
url = '%s%s' % (self.mobi2url, cmd)
req = urllib.request.Request(url, headers=self.headers)
response = self.opener.open(req)
data = json.loads(response.read())
str_response = response.read().decode('utf-8')
data = json.loads(str_response)
return data

# 'Private' methods for use in class, Tado API V2.
def _apiCall(self, cmd):
url = '%s%i/%s' % (self.api2url, self.id, cmd)
req = urllib.request.Request(url, headers=self.headers)
response = self.opener.open(req)
data = json.loads(response.read())
str_response = response.read().decode('utf-8')
data = json.loads(str_response)
return data

def _setOAuthHeader(self, data):
Expand All @@ -48,7 +51,8 @@ def _loginV2(self, username, password):
headers={'Content-Type': 'application/json', 'Referer' : 'https://my.tado.com/'})

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

# Public interface
Expand All @@ -57,7 +61,8 @@ def getMe(self):
url = 'https://my.tado.com/api/v2/me'
req = urllib.request.Request(url, headers=self.headers)
response = self.opener.open(req)
data = json.loads(response.read())
str_response = response.read().decode('utf-8')
data = json.loads(str_response)
return data

def getDevices(self):
Expand Down

0 comments on commit 9e0b966

Please sign in to comment.