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

Just my 2 cents #6

Open
wants to merge 9 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
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Python-TStat
Python interface for Radio Thermostat wifi-enabled thermostats.

#Usage:
t = TStat('1.2.3.4') Where 1.2.3.4 is your thermostat's IP address

t.getCurrentTemp() Returns current temperature as a float

t.setHeatPoint(68.0) Sets target temperature for heating to 68.0

...

A simple cache based on retrieved URL and time of retrieval is included.
If you call TStat.getFanMode(), /tstat will be retrieved and the value
for fmode will be return. If you then call t.getTState(), a cached
value will already exist and tstate will be returned from that.

You can change the time for cache expiration by calling

t.setCacheExpiry(timeInSeconds).
3 changes: 3 additions & 0 deletions radiotstat/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python

from tstat import *
26 changes: 17 additions & 9 deletions API.py → radiotstat/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
#THE POSSIBILITY OF SUCH DAMAGE.

# API.py
# api.py
# API definitions for Radio Thermostat wifi-enabled thermostats.

# This file allows multiple APIs to be defined for different versions of the
Expand Down Expand Up @@ -95,7 +95,8 @@ def has_key(self, key):
}

class API_CT50v109(API):
models = ['CT50 V1.09']
#since there is only one model defined lets allow all basic models to work
models = ['CT50 V1.09','CT30','CT50','CT80']
successStrings = [
"Tstat Command Processed",
"Cloud updates have been suspended till reboot",
Expand Down Expand Up @@ -195,12 +196,19 @@ class API_CT50v109(API):
#'eventlog': #TODO
}

class API_CT30v192(API_CT50v109):
models = ['CT30 V1.92']

APIs = [API_CT50v109, API_CT30v192]
APIs = [API_CT50v109]

def getAPI(model):
for api in APIs:
if model in api.models:
return api()
try:
for api in APIs:
if model in api.models:
return api()
else:
for m in api.models:
if model.startswith(m):
return api()
#fall thru
print 'Unsupported thermostat: ' + model
except:
print 'Unsupported thermostat: ' + model

12 changes: 8 additions & 4 deletions TStat.py → radiotstat/tstat.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
#THE POSSIBILITY OF SUCH DAMAGE.

# TStat.py
# tstat.py
# Python interface for Radio Thermostat wifi-enabled thermostats.

# Usage:
Expand Down Expand Up @@ -66,7 +66,7 @@
from json import loads
from json import dumps

from API import *
from api import *

class CacheEntry:
def __init__(self, location, data):
Expand All @@ -86,7 +86,7 @@ def __init__(self, address, cacheExpiry=5, api=None, logger=None, logLevel=None)
if logLevel is None:
logLevel = logging.WARNING
logging.basicConfig(level=logLevel)
self.logger = logging.getLogger('TStat')
self.logger = logging.getLogger(__name__)
else:
self.logger = logger
if api is None:
Expand Down Expand Up @@ -176,7 +176,8 @@ def _get(self, key, raw=False):

l = self.logger
l.debug("Requested: %s" % key)

if not self.api:
raise Exception("No API")
# Check for valid request
if not self.api.has_key(key):
#TODO: Error processing
Expand Down Expand Up @@ -408,6 +409,9 @@ def main():
addr = discover()

t = TStat(addr, api=API_CT50v109())
if len(sys.argv) == 1:
print "Usage: " + sys.argv[0] + " command(s)"
print "Example: " + sys.argv[0] + " getCurrentTemp"
for cmd in sys.argv[1:]:
result = eval("t.%s(raw=True)" % cmd)
#print "%s: %s" % (cmd, result)
Expand Down
4 changes: 2 additions & 2 deletions TStatGcal.py → radiotstat/tstat_gcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

VERSION = 1.0

# TStatGcal.py
# tstat_gcal.py
# Script to pull commands from Google Calendar and update thermostat.
#
# Requirements:
Expand Down Expand Up @@ -251,7 +251,7 @@ def main(tstatAddr, commandMap=None, username=None, password=None, calName="Ther
periodCommands = {}
for day in range(0,7):
if not periodCommands.has_key(day):
periodCommands[day] = []
periodCommands[day] = []
for p in PERIODS:

if periods.has_key(p):
Expand Down
12 changes: 12 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python

from distutils.core import setup

setup(name='radiotstat',
version='1.0',
description='Python interface for Radio Thermostat wifi-enabled thermostats.',
author='Paul Jennings',
author_email='[email protected]',
url='https://github.com/pjennings/Python-TStat',
packages=['radiotstat'],
)