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

Adding jupyter notebook with reports on data #126

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Binary file added .vs/evohome-client/v15/.suo
Binary file not shown.
47 changes: 47 additions & 0 deletions evohome-client.pyproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{9c55b0d5-8c60-445f-8e2d-fa7f652756fe}</ProjectGuid>
<ProjectHome />
<StartupFile>evohomeclient2\module1.py</StartupFile>
<SearchPath />
<WorkingDirectory>.</WorkingDirectory>
<OutputPath>.</OutputPath>
<ProjectTypeGuids>{888888a0-9f3d-457c-b088-3a5042f75d52}</ProjectTypeGuids>
<LaunchProvider>Standard Python launcher</LaunchProvider>
<InterpreterId />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'" />
<PropertyGroup Condition="'$(Configuration)' == 'Release'" />
<PropertyGroup>
<VisualStudioVersion Condition=" '$(VisualStudioVersion)' == '' ">10.0</VisualStudioVersion>
</PropertyGroup>
<ItemGroup>
<Content Include="LICENSE.txt" />
<Content Include="requirements-dev.txt" />
<Content Include="requirements.txt" />
<Content Include="tox.ini" />
</ItemGroup>
<ItemGroup>
<Compile Include="docs\source\conf.py" />
<Compile Include="evohomeclient2\controlsystem.py" />
<Compile Include="evohomeclient2\gateway.py" />
<Compile Include="evohomeclient2\hotwater.py" />
<Compile Include="evohomeclient2\location.py" />
<Compile Include="evohomeclient2\tests.py" />
<Compile Include="evohomeclient2\zone.py" />
<Compile Include="evohomeclient2\__init__.py" />
<Compile Include="evohomeclient\tests.py" />
<Compile Include="evohomeclient\__init__.py" />
<Compile Include="setup.py" />
</ItemGroup>
<ItemGroup>
<Folder Include="docs\" />
<Folder Include="docs\source" />
<Folder Include="evohomeclient" />
<Folder Include="evohomeclient2" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
</Project>
27 changes: 27 additions & 0 deletions evohome-client.sln
Original file line number Diff line number Diff line change
@@ -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
51 changes: 51 additions & 0 deletions evohome_client_implementation.py
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 4 additions & 7 deletions evohomeclient2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
from datetime import datetime, timedelta

import time;
import requests

from .location import Location
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down