Add more param getter functions to the python api
This commit is contained in:
parent
be68d925be
commit
e7a5cf854b
@ -97,7 +97,7 @@ static PyObject * PyThingActionInfo_paramValue(PyThingActionInfo* self, PyObject
|
|||||||
for (int i = 0; i < PyTuple_Size(self->pyParams); i++) {
|
for (int i = 0; i < PyTuple_Size(self->pyParams); i++) {
|
||||||
PyParam *pyParam = reinterpret_cast<PyParam*>(PyTuple_GetItem(self->pyParams, i));
|
PyParam *pyParam = reinterpret_cast<PyParam*>(PyTuple_GetItem(self->pyParams, i));
|
||||||
// We're intentionally converting both ids to QUuid here in order to be more flexible with different UUID notations
|
// We're intentionally converting both ids to QUuid here in order to be more flexible with different UUID notations
|
||||||
ParamTypeId ptid = StateTypeId(PyUnicode_AsUTF8AndSize(pyParam->pyParamTypeId, nullptr));
|
ParamTypeId ptid = ParamTypeId(PyUnicode_AsUTF8AndSize(pyParam->pyParamTypeId, nullptr));
|
||||||
if (ptid == paramTypeId) {
|
if (ptid == paramTypeId) {
|
||||||
Py_INCREF(pyParam->pyValue);
|
Py_INCREF(pyParam->pyValue);
|
||||||
return pyParam->pyValue;
|
return pyParam->pyValue;
|
||||||
@ -105,7 +105,7 @@ static PyObject * PyThingActionInfo_paramValue(PyThingActionInfo* self, PyObject
|
|||||||
}
|
}
|
||||||
qCWarning(dcPythonIntegrations()) << "No such ParamTypeId in action params" << paramTypeId;
|
qCWarning(dcPythonIntegrations()) << "No such ParamTypeId in action params" << paramTypeId;
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
};
|
}
|
||||||
|
|
||||||
static PyMemberDef PyThingActionInfo_members[] = {
|
static PyMemberDef PyThingActionInfo_members[] = {
|
||||||
{"thing", T_OBJECT_EX, offsetof(PyThingActionInfo, pyThing), 0, "Thing this action is for"},
|
{"thing", T_OBJECT_EX, offsetof(PyThingActionInfo, pyThing), 0, "Thing this action is for"},
|
||||||
|
|||||||
@ -69,6 +69,27 @@ static void PyThingDiscoveryInfo_dealloc(PyThingDiscoveryInfo * self)
|
|||||||
Py_TYPE(self)->tp_free(self);
|
Py_TYPE(self)->tp_free(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject * PyThingDiscoveryInfo_paramValue(PyThingDiscoveryInfo* self, PyObject* args) {
|
||||||
|
char *paramTypeIdStr = nullptr;
|
||||||
|
if (!PyArg_ParseTuple(args, "s", ¶mTypeIdStr)) {
|
||||||
|
PyErr_SetString(PyExc_TypeError, "Invalid arguments in paramValue call. Expected: paramValue(paramTypeId)");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
ParamTypeId paramTypeId = ParamTypeId(paramTypeIdStr);
|
||||||
|
for (int i = 0; i < PyTuple_Size(self->pyParams); i++) {
|
||||||
|
PyParam *pyParam = reinterpret_cast<PyParam*>(PyTuple_GetItem(self->pyParams, i));
|
||||||
|
// We're intentionally converting both ids to QUuid here in order to be more flexible with different UUID notations
|
||||||
|
ParamTypeId ptid = ParamTypeId(PyUnicode_AsUTF8AndSize(pyParam->pyParamTypeId, nullptr));
|
||||||
|
if (ptid == paramTypeId) {
|
||||||
|
Py_INCREF(pyParam->pyValue);
|
||||||
|
return pyParam->pyValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qCWarning(dcPythonIntegrations()) << "No such ParamTypeId in discovery params" << paramTypeId;
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject * PyThingDiscoveryInfo_finish(PyThingDiscoveryInfo* self, PyObject* args)
|
static PyObject * PyThingDiscoveryInfo_finish(PyThingDiscoveryInfo* self, PyObject* args)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
@ -142,6 +163,7 @@ static PyMemberDef PyThingDiscoveryInfo_members[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static PyMethodDef PyThingDiscoveryInfo_methods[] = {
|
static PyMethodDef PyThingDiscoveryInfo_methods[] = {
|
||||||
|
{ "paramValue", (PyCFunction)PyThingDiscoveryInfo_paramValue, METH_VARARGS, "Get a discovery param value"},
|
||||||
{ "addDescriptor", (PyCFunction)PyThingDiscoveryInfo_addDescriptor, METH_VARARGS, "Add a new descriptor to the discovery" },
|
{ "addDescriptor", (PyCFunction)PyThingDiscoveryInfo_addDescriptor, METH_VARARGS, "Add a new descriptor to the discovery" },
|
||||||
{ "finish", (PyCFunction)PyThingDiscoveryInfo_finish, METH_VARARGS, "Finish a discovery" },
|
{ "finish", (PyCFunction)PyThingDiscoveryInfo_finish, METH_VARARGS, "Finish a discovery" },
|
||||||
{nullptr, nullptr, 0, nullptr} // sentinel
|
{nullptr, nullptr, 0, nullptr} // sentinel
|
||||||
|
|||||||
@ -89,6 +89,27 @@ static void PyThingPairingInfo_dealloc(PyThingPairingInfo * self)
|
|||||||
Py_TYPE(self)->tp_free(self);
|
Py_TYPE(self)->tp_free(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject * PyThingPairingInfo_paramValue(PyThingPairingInfo* self, PyObject* args) {
|
||||||
|
char *paramTypeIdStr = nullptr;
|
||||||
|
if (!PyArg_ParseTuple(args, "s", ¶mTypeIdStr)) {
|
||||||
|
PyErr_SetString(PyExc_TypeError, "Invalid arguments in paramValue call. Expected: paramValue(paramTypeId)");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
ParamTypeId paramTypeId = ParamTypeId(paramTypeIdStr);
|
||||||
|
for (int i = 0; i < PyTuple_Size(self->pyParams); i++) {
|
||||||
|
PyParam *pyParam = reinterpret_cast<PyParam*>(PyTuple_GetItem(self->pyParams, i));
|
||||||
|
// We're intentionally converting both ids to QUuid here in order to be more flexible with different UUID notations
|
||||||
|
ParamTypeId ptid = ParamTypeId(PyUnicode_AsUTF8AndSize(pyParam->pyParamTypeId, nullptr));
|
||||||
|
if (ptid == paramTypeId) {
|
||||||
|
Py_INCREF(pyParam->pyValue);
|
||||||
|
return pyParam->pyValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qCWarning(dcPythonIntegrations()) << "No such ParamTypeId in thing params" << paramTypeId;
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject * PyThingPairingInfo_finish(PyThingPairingInfo* self, PyObject* args)
|
static PyObject * PyThingPairingInfo_finish(PyThingPairingInfo* self, PyObject* args)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
@ -113,6 +134,7 @@ static PyObject * PyThingPairingInfo_finish(PyThingPairingInfo* self, PyObject*
|
|||||||
}
|
}
|
||||||
|
|
||||||
static PyMethodDef PyThingPairingInfo_methods[] = {
|
static PyMethodDef PyThingPairingInfo_methods[] = {
|
||||||
|
{ "paramValue", (PyCFunction)PyThingPairingInfo_paramValue, METH_VARARGS, "Get a param value for the thing to be paired"},
|
||||||
{ "finish", (PyCFunction)PyThingPairingInfo_finish, METH_VARARGS, "Finish a discovery" },
|
{ "finish", (PyCFunction)PyThingPairingInfo_finish, METH_VARARGS, "Finish a discovery" },
|
||||||
{nullptr, nullptr, 0, nullptr} // sentinel
|
{nullptr, nullptr, 0, nullptr} // sentinel
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user