return a datetime on success

This commit is contained in:
Øyvind Saltvik 2012-08-10 21:00:40 +02:00
parent c5c64435cf
commit 5cfd91717f
2 changed files with 16 additions and 3 deletions

View file

@ -16,7 +16,7 @@ while True:
if result:
value, timestamp = result
print "Temperature:\t%sC\t(%s)\n" % (value, str(timestamp))
if dataTypes & telldus.TELLSTICK_HUMIDITY:
result = telldus.tdSensorValue(protocol, model, sensorId, telldus.TELLSTICK_HUMIDITY)
if result:

View file

@ -590,14 +590,27 @@ telldus_tdSensorValue(PyObject *self, PyObject *args)
long timestamp = 0;
long result;
PyObject *floatObj = NULL;
PyObject *timeTuple = NULL;
PyObject *dateTime = NULL;
if (!PyArg_ParseTuple(args, "ssll", &protocol, &model, &sensorId, &dataType))
return NULL;
result = tdSensorValue(protocol, model, sensorId, dataType, &value, DATA_LENGTH, &timestamp);
if (result == TELLSTICK_SUCCESS)
{
return Py_BuildValue("sl", value, timestamp);
floatObj = PyFloat_FromDouble((double) timestamp);
timeTuple = Py_BuildValue("(O)", floatObj);
dateTime = PyDateTime_FromTimestamp(timeTuple);
Py_DECREF(floatObj);
Py_DECREF(timeTuple);
return Py_BuildValue("sO", value, dateTime);
}
else
{