Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
Support for history data added
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-fursov committed Sep 8, 2014
1 parent f146166 commit 198b45b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tellprox/tellstick.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from tasensor import *
import bottle_helpers as bh
import tellcore.telldus as td
import MySQLdb
import MySQLdb.cursors

def map_response(cmdresp, id = '', method = ''):
if (cmdresp == TELLSTICK_SUCCESS):
Expand Down Expand Up @@ -188,6 +190,10 @@ def __init__(self, api, config, version):
'fn' : self.sensor_info,
'inputs': { 'name': 'id', 'type': 'int', 'description': '' }
},
'history': {
'fn' : self.sensor_history,
'inputs': { 'name': 'id', 'type': 'int', 'description': '' }
},
'setignore': {
'fn' : self.sensor_setignore,
'inputs': [
Expand Down Expand Up @@ -346,6 +352,21 @@ def sensor_info(self, func, id):
if not sensor: return map_response("Sensor " + "\"" + str(id) + "\" not found!")
return self.sensor_to_dict(sensor, True)

def sensor_history(self, func, id):
#sensor = self.get_sensor(id)
#if not sensor: return map_response("Sensor " + "\"" + str(id) + "\" not found!")
#return self.sensor_to_dict(sensor, True)
db = MySQLdb.connect(db = 'ha', user = 'ha', passwd = 'ha', cursorclass = MySQLdb.cursors.DictCursor)
cursor = db.cursor()
query = "SELECT `temperature`, `humidity`, `timestamp` FROM `sensordata` WHERE `sensor_id`='" + str(id) + "' ORDER BY `timestamp` ASC"
numOfEntries = cursor.execute(query)
allEntries = cursor.fetchall()
outDict = {}
outDict['id'] = id
outDict['data'] = allEntries
return outDict


@dec_response
def sensor_setignore(self, func, id, ignore):
sensor = self.get_sensor(id)
Expand Down Expand Up @@ -429,6 +450,8 @@ def device_to_dict(self, device, methods_supported, info):

return dict



def sensor_to_dict(self, sensor, info):
# Set default value in case we get back nothing
lastUpdated = -1
Expand Down

0 comments on commit 198b45b

Please sign in to comment.