MCPcopy Create free account
hub / github.com/domoticz/domoticz / CUnitEx_update

Function CUnitEx_update

hardware/plugins/PythonObjectEx.cpp:720–1002  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

718 }
719
720 PyObject *CUnitEx_update(CUnitEx *self, PyObject *args, PyObject *kwds)
721 {
722 module_state *pModState = CPlugin::FindModule();
723 if (!pModState)
724 {
725 _log.Log(LOG_ERROR, "(%s) Unable to obtain module state.", __func__);
726 Py_RETURN_NONE;
727 }
728
729 if (pModState->pPlugin)
730 {
731 char *TypeName = nullptr;
732 int bWriteLog = false;
733 int bUpdateProperties = false;
734 int bUpdateOptions = false;
735 int bSuppressTriggers = false;
736
737 static char *kwlist[] = { "log", "typename", "updateproperties", "updateoptions", "suppresstriggers", nullptr };
738
739 // Try to extract parameters needed to update device settings
740 if (!PyArg_ParseTupleAndNormalizedKeywords(args, kwds, "|psppp", kwlist, &bWriteLog, &TypeName, &bUpdateProperties, &bUpdateOptions, &bSuppressTriggers))
741 {
742 pModState->pPlugin->Log(LOG_ERROR, "(%s) Failed to parse parameters: 'Log' and/or 'TypeName' and/or 'UpdateProperties' and/or 'UpdateOptions' and/or 'SuppressTriggers' expected. Note: Parameter names are case-insensitive.", __func__);
743 pModState->pPlugin->LogPythonException(__func__);
744 Py_RETURN_NONE;
745 }
746
747 if (!(CDeviceEx*)self->Parent)
748 {
749 _log.Log(LOG_ERROR, "(%s) Unit is not associated with a Device.", __func__);
750 Py_RETURN_NONE;
751 }
752 CDeviceEx *pDevice = (CDeviceEx *)self->Parent;
753 std::string sDeviceID = PyBorrowedRef(pDevice->DeviceID);
754 std::string sID = std::to_string(self->ID);
755
756 // Build representations of changeable fields (these may not be of the right type so be defensive)
757 std::string sName = PyBorrowedRef(self->Name);
758 std::string sDescription = PyBorrowedRef(self->Description);
759 std::string sValue = PyBorrowedRef(self->sValue);
760 std::string sColor = PyBorrowedRef(self->Color);
761 sColor = _tColor(sColor).toJSONString();
762 int nValue = self->nValue;
763 int iImage = self->Image;
764 int iBatteryLevel = self->BatteryLevel;
765 int iSignalLevel = self->SignalLevel;
766 int iUsed = self->Used;
767 int iType = self->Type;
768 int iSubType = self->SubType;
769 int iSwitchType = self->SwitchType;
770 PyBorrowedRef pOptionsDict = self->Options;
771 PyObject *OptionsTypeName = PyDict_New();
772 if (OptionsTypeName == nullptr)
773 {
774 pModState->pPlugin->Log(LOG_ERROR, "(%s) Create dict failed.", __func__);
775 pModState->pPlugin->LogPythonException(__func__);
776 Py_RETURN_NONE;
777 }

Callers

nothing calls this directly

Calls 15

PyBorrowedRefClass · 0.85
_tColorClass · 0.85
maptypenameFunction · 0.85
TimeToStringFunction · 0.85
CUnitEx_refreshFunction · 0.85
IsLightOrSwitchFunction · 0.85
LogPythonExceptionMethod · 0.80
toJSONStringMethod · 0.80
IsDictMethod · 0.80
safe_queryMethod · 0.80
c_strMethod · 0.80

Tested by

no test coverage detected