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

@ -590,6 +590,11 @@ 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;
@ -597,7 +602,15 @@ telldus_tdSensorValue(PyObject *self, PyObject *args)
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
{