return a datetime on success
This commit is contained in:
parent
c5c64435cf
commit
5cfd91717f
2 changed files with 16 additions and 3 deletions
|
@ -16,7 +16,7 @@ while True:
|
||||||
if result:
|
if result:
|
||||||
value, timestamp = result
|
value, timestamp = result
|
||||||
print "Temperature:\t%sC\t(%s)\n" % (value, str(timestamp))
|
print "Temperature:\t%sC\t(%s)\n" % (value, str(timestamp))
|
||||||
|
|
||||||
if dataTypes & telldus.TELLSTICK_HUMIDITY:
|
if dataTypes & telldus.TELLSTICK_HUMIDITY:
|
||||||
result = telldus.tdSensorValue(protocol, model, sensorId, telldus.TELLSTICK_HUMIDITY)
|
result = telldus.tdSensorValue(protocol, model, sensorId, telldus.TELLSTICK_HUMIDITY)
|
||||||
if result:
|
if result:
|
||||||
|
|
|
@ -590,14 +590,27 @@ telldus_tdSensorValue(PyObject *self, PyObject *args)
|
||||||
long timestamp = 0;
|
long timestamp = 0;
|
||||||
long result;
|
long result;
|
||||||
|
|
||||||
|
PyObject *floatObj = NULL;
|
||||||
|
PyObject *timeTuple = NULL;
|
||||||
|
PyObject *dateTime = NULL;
|
||||||
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "ssll", &protocol, &model, &sensorId, &dataType))
|
if (!PyArg_ParseTuple(args, "ssll", &protocol, &model, &sensorId, &dataType))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
result = tdSensorValue(protocol, model, sensorId, dataType, &value, DATA_LENGTH, ×tamp);
|
result = tdSensorValue(protocol, model, sensorId, dataType, &value, DATA_LENGTH, ×tamp);
|
||||||
|
|
||||||
if (result == TELLSTICK_SUCCESS)
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue