working examples feature complete
This commit is contained in:
parent
9073d60858
commit
c5c64435cf
4 changed files with 70 additions and 88 deletions
|
@ -10,6 +10,8 @@ allMethods = telldus.TELLSTICK_TURNON | telldus.TELLSTICK_TURNOFF | telldus.TELL
|
||||||
|
|
||||||
for i in xrange(devices):
|
for i in xrange(devices):
|
||||||
deviceid = telldus.tdGetDeviceId(i)
|
deviceid = telldus.tdGetDeviceId(i)
|
||||||
|
|
||||||
|
if deviceid:
|
||||||
name = telldus.tdGetName(deviceid)
|
name = telldus.tdGetName(deviceid)
|
||||||
|
|
||||||
print "%s - %s\n" % (deviceid, name)
|
print "%s - %s\n" % (deviceid, name)
|
||||||
|
@ -27,7 +29,7 @@ for i in xrange(devices):
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
if methods & telldus.TELLSTICK_BELL:
|
if methods & telldus.TELLSTICK_BELL:
|
||||||
echo " * Bell\n"
|
print " * Bell\n"
|
||||||
telldus.tdBell(deviceid)
|
telldus.tdBell(deviceid)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
@ -41,10 +43,5 @@ for i in xrange(devices):
|
||||||
|
|
||||||
telldus.tdClose()
|
telldus.tdClose()
|
||||||
|
|
||||||
import time
|
|
||||||
time.sleep(30)
|
|
||||||
for i in xrange(20):
|
|
||||||
telldus.tdTurnOn(3)
|
|
||||||
telldus.tdTurnOff(3)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,8 @@ import threading
|
||||||
import telldus
|
import telldus
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
telldus.tdInit()
|
telldus.tdInit()
|
||||||
|
|
||||||
|
|
||||||
def turnOn():
|
def turnOn():
|
||||||
print "turning on"
|
print "turning on"
|
||||||
telldus.tdTurnOn(1)
|
telldus.tdTurnOn(1)
|
||||||
|
@ -16,21 +14,25 @@ def turnOff():
|
||||||
|
|
||||||
def callback(deviceId, method, value, callbackId):
|
def callback(deviceId, method, value, callbackId):
|
||||||
print "callback"
|
print "callback"
|
||||||
|
print "DeviceId: %i Method: %i Value: %s" % (deviceId, method, value)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
#function to be called when device event occurs, even for unregistered devices
|
#function to be called when device event occurs, even for unregistered devices
|
||||||
def rawcallback(data, controllerId, callbackId):
|
def rawcallback(data, controllerId, callbackId):
|
||||||
print "raw callback"
|
print "raw callback"
|
||||||
|
print "Data: %s ControllerId: %i" % (data, controllerId)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
#callbackid = telldus.tdRegisterDeviceEvent(callback)
|
callbackid = telldus.tdRegisterDeviceEvent(callback)
|
||||||
rawcallbackid = telldus.tdRegisterRawDeviceEvent(rawcallback)
|
rawcallbackid = telldus.tdRegisterRawDeviceEvent(rawcallback)
|
||||||
|
|
||||||
|
print callbackid, rawcallbackid
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while(1):
|
while(1):
|
||||||
time.sleep(0.5) #don't exit
|
time.sleep(0.5) #don't exit
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print "Exiting"
|
print "Exiting"
|
||||||
#telldus.tdUnregisterCallback(callbackid)
|
telldus.tdUnregisterCallback(callbackid)
|
||||||
telldus.tdUnregisterCallback(rawcallbackid)
|
telldus.tdUnregisterCallback(rawcallbackid)
|
||||||
telldus.tdClose()
|
telldus.tdClose()
|
||||||
|
|
|
@ -2,22 +2,22 @@ import telldus
|
||||||
|
|
||||||
telldus.tdInit()
|
telldus.tdInit()
|
||||||
|
|
||||||
while(1):
|
while True:
|
||||||
result = telldus.tdSensor()
|
result = telldus.tdSensor()
|
||||||
if not result:
|
if not result:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
protocol, model, sensorId = result
|
protocol, model, sensorId, dataTypes = result
|
||||||
print "%s,\t%s,\t%i\n" % (protocol, model, sensorId)
|
print "Protocol: %s,\tModel: %s,\tSensorId: %i\nDataTypes: %i" % (protocol, model, sensorId, dataTypes)
|
||||||
|
|
||||||
# Retrieve the values the sensor supports
|
# Retrieve the values the sensor supports
|
||||||
if (dataTypes & telldus.TELLSTICK_TEMPERATURE):
|
if dataTypes & telldus.TELLSTICK_TEMPERATURE:
|
||||||
result = telldus.tdSensorValue(protocol, model, sensorId, telldus.TELLSTICK_TEMPERATURE)
|
result = telldus.tdSensorValue(protocol, model, sensorId, telldus.TELLSTICK_TEMPERATURE)
|
||||||
if result:
|
if result:
|
||||||
value, timestamp = result
|
value, timestamp = result
|
||||||
print "Temperature:\t%sº\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:
|
||||||
value, timestamp = result
|
value, timestamp = result
|
||||||
|
@ -25,4 +25,4 @@ telldus.tdInit()
|
||||||
|
|
||||||
print "\n"
|
print "\n"
|
||||||
|
|
||||||
tdClose()
|
telldus.tdClose()
|
||||||
|
|
|
@ -31,9 +31,6 @@ estrdup(char *s)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
telldus_tdInit(PyObject *self)
|
telldus_tdInit(PyObject *self)
|
||||||
{
|
{
|
||||||
PyEval_InitThreads();
|
|
||||||
PyEval_ReleaseLock();
|
|
||||||
|
|
||||||
tdInit();
|
tdInit();
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
|
@ -386,7 +383,7 @@ telldus_tdRegisterDeviceEvent(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
DeviceEventCallback = func;
|
DeviceEventCallback = func;
|
||||||
|
|
||||||
tdRegisterDeviceEvent((TDDeviceEvent) &telldus_deviceEventCallback, 0);
|
result = tdRegisterDeviceEvent((TDDeviceEvent) &telldus_deviceEventCallback, 0);
|
||||||
|
|
||||||
return PyLong_FromLong((long) result);
|
return PyLong_FromLong((long) result);
|
||||||
}
|
}
|
||||||
|
@ -552,7 +549,7 @@ telldus_tdUnregisterCallback(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
long id;
|
long id;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "l", &id));
|
if (!PyArg_ParseTuple(args, "l", &id))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return PyLong_FromLong((long) tdUnregisterCallback(id));
|
return PyLong_FromLong((long) tdUnregisterCallback(id));
|
||||||
|
@ -576,7 +573,8 @@ telldus_tdSensor(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return PyLong_FromLong(result);
|
Py_INCREF(Py_None);
|
||||||
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -590,36 +588,21 @@ telldus_tdSensorValue(PyObject *self, PyObject *args)
|
||||||
long dataType = 0;
|
long dataType = 0;
|
||||||
char value[DATA_LENGTH];
|
char value[DATA_LENGTH];
|
||||||
long timestamp = 0;
|
long timestamp = 0;
|
||||||
|
|
||||||
PyObject *floatObj;
|
|
||||||
PyObject *timeTuple;
|
|
||||||
|
|
||||||
long result;
|
long result;
|
||||||
|
|
||||||
PyObject *py_date;
|
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);
|
||||||
|
|
||||||
floatObj = PyFloat_FromDouble(timestamp);
|
|
||||||
timeTuple = Py_BuildValue("(O)", floatObj);
|
|
||||||
Py_DECREF(floatObj);
|
|
||||||
|
|
||||||
py_date = PyDateTime_FromTimestamp(timeTuple);
|
|
||||||
|
|
||||||
Py_DECREF(timeTuple);
|
|
||||||
|
|
||||||
Py_INCREF(py_date);
|
|
||||||
|
|
||||||
if (result == TELLSTICK_SUCCESS)
|
if (result == TELLSTICK_SUCCESS)
|
||||||
{
|
{
|
||||||
return Py_BuildValue("sO", value, py_date);
|
return Py_BuildValue("sl", value, timestamp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return PyLong_FromLong(result);
|
Py_INCREF(Py_None);
|
||||||
|
return Py_None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue