diff --git a/README.md b/README.md new file mode 100644 index 0000000..5f4734d --- /dev/null +++ b/README.md @@ -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). diff --git a/radiotstat/__init__.py b/radiotstat/__init__.py new file mode 100644 index 0000000..7391493 --- /dev/null +++ b/radiotstat/__init__.py @@ -0,0 +1,3 @@ +#!/usr/bin/env python + +from tstat import * diff --git a/API.py b/radiotstat/api.py similarity index 93% rename from API.py rename to radiotstat/api.py index 9190e9c..1a46dde 100644 --- a/API.py +++ b/radiotstat/api.py @@ -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 @@ -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", @@ -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 + diff --git a/TStat.py b/radiotstat/tstat.py old mode 100755 new mode 100644 similarity index 98% rename from TStat.py rename to radiotstat/tstat.py index 1e620a1..28be87c --- a/TStat.py +++ b/radiotstat/tstat.py @@ -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: @@ -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): @@ -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: @@ -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 @@ -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) diff --git a/TStatGcal.py b/radiotstat/tstat_gcal.py similarity index 99% rename from TStatGcal.py rename to radiotstat/tstat_gcal.py index 7c1440e..98ac7bd 100644 --- a/TStatGcal.py +++ b/radiotstat/tstat_gcal.py @@ -29,7 +29,7 @@ VERSION = 1.0 -# TStatGcal.py +# tstat_gcal.py # Script to pull commands from Google Calendar and update thermostat. # # Requirements: @@ -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): diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..cceb2c4 --- /dev/null +++ b/setup.py @@ -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='pjennings-tstat@pjennings.net', + url='https://github.com/pjennings/Python-TStat', + packages=['radiotstat'], + )