diff --git a/.vs/evohome-client/v15/.suo b/.vs/evohome-client/v15/.suo new file mode 100644 index 0000000..99c9cc3 Binary files /dev/null and b/.vs/evohome-client/v15/.suo differ diff --git a/evohome-client.pyproj b/evohome-client.pyproj new file mode 100644 index 0000000..eb6cf2a --- /dev/null +++ b/evohome-client.pyproj @@ -0,0 +1,47 @@ + + + + Debug + 2.0 + {9c55b0d5-8c60-445f-8e2d-fa7f652756fe} + + evohomeclient2\module1.py + + . + . + {888888a0-9f3d-457c-b088-3a5042f75d52} + Standard Python launcher + + + + + + 10.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/evohome-client.sln b/evohome-client.sln new file mode 100644 index 0000000..8588c0c --- /dev/null +++ b/evohome-client.sln @@ -0,0 +1,27 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27428.2015 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "evohome-client", "evohome-client.pyproj", "{9C55B0D5-8C60-445F-8E2D-FA7F652756FE}" +EndProject +Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "evohome-client-implementation", "..\evohome-client-implementation\evohome-client-implementation.pyproj", "{E403C845-8122-4415-8ABD-CCE816286913}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9C55B0D5-8C60-445F-8E2D-FA7F652756FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9C55B0D5-8C60-445F-8E2D-FA7F652756FE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E403C845-8122-4415-8ABD-CCE816286913}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E403C845-8122-4415-8ABD-CCE816286913}.Release|Any CPU.ActiveCfg = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {91C12F89-56E9-4574-9B07-0E6DDAB3B7B3} + EndGlobalSection +EndGlobal diff --git a/evohome_client_implementation.py b/evohome_client_implementation.py new file mode 100644 index 0000000..744589d --- /dev/null +++ b/evohome_client_implementation.py @@ -0,0 +1,51 @@ +from evohomeclient2 import EvohomeClient; +import pyodbc; +from datetime import datetime; +import time; +import configparser; + +config = configparser.ConfigParser() + +config.read("config.ini") + +databasename = config.get('DB', 'dbname'); +server = config.get('DB', 'dbserver'); +driver = config.get('DB', 'dbdriver'); + +username = config.get('evohome', 'username'); +password = config.get('evohome', 'password'); + +CONNECTION_STRING = 'DRIVER=' + driver + '; SERVER=' + server + '; DATABASE=' + databasename + '; Trusted_Connection=yes'; + +def insert_zones(thermostat, id, name, temp, setpoint): + cursor = connection.cursor(); + sSQL = ''' + INSERT INTO + dbo.Zones (uid, timestamp, thermostat, id, [name], temp, setpoint) + VALUES (NEWID(), CURRENT_TIMESTAMP, \'''' + thermostat + '''\', \'''' + id + '''\', \'''' + name + '''\', \'''' + str(temp) + '''\', \'''' + str(setpoint) + '''\') + ''' + + cursor.execute(sSQL); + + print('id: ' + id + ' inserted') + + cursor.commit(); + +# Infinite loop every 5 minutes, send temperatures to sql +while True: + connection = pyodbc.connect(CONNECTION_STRING); + + try: + client = EvohomeClient(username, password, debug=True) + + for device in client.temperatures(): + print(device) + insert_zones(thermostat=device['thermostat'], id=device['id'], name=device['name'], temp=device['temp'], setpoint=device['setpoint']) + + connection.close(); + except: + print("Error when connecting to internet"); + connection.close(); + + print ("Going to sleep for 2 minutes") + time.sleep(120) \ No newline at end of file diff --git a/evohomeclient2/__init__.py b/evohomeclient2/__init__.py index 92d76b8..4b0015f 100644 --- a/evohomeclient2/__init__.py +++ b/evohomeclient2/__init__.py @@ -5,6 +5,7 @@ import logging from datetime import datetime, timedelta +import time; import requests from .location import Location @@ -180,7 +181,7 @@ def _obtain_access_token(self, credentials): if response.text: # if there is a message, then raise with it msg = msg + ", hint: " + response.text - raise AuthenticationError(msg) + #raise AuthenticationError(msg) try: # the access token _should_ be valid... # this may cause a ValueError @@ -194,14 +195,10 @@ def _obtain_access_token(self, credentials): self.refresh_token = response_json["refresh_token"] except KeyError: - raise AuthenticationError( - "Unable to obtain an Access Token, hint: " + response_json - ) + print("AuthenticationError - Unable to obtain an Access Token, hint: " + response_json) except ValueError: - raise AuthenticationError( - "Unable to obtain an Access Token, hint: " + response.text - ) + print("AuthenticationError - Unable to obtain an Access Token, hint: " + response.text) def _get_location(self, location): if location is None: