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

Function PythonEventsProcessPython

main/EventsPythonModule.cpp:361–649  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

359 }
360
361 void PythonEventsProcessPython(const std::string& reason, const std::string& filename, const std::string& PyString,
362 const uint64_t DeviceID, std::map<uint64_t, CEventSystem::_tDeviceStatus> deviceStates,
363 std::map<uint64_t, CEventSystem::_tUserVariable> userVariables, int intSunRise, int intSunSet)
364 {
365 if (!m_ModuleInitialized)
366 {
367 return;
368 }
369
370 if (!Py_IsInitialized())
371 {
372 _log.Log(LOG_ERROR, "EventSystem: Python not Initialized");
373 return;
374 }
375
376 if (m_PyInterpreter)
377 PyEval_RestoreThread(m_PyInterpreter);
378
379 PyBorrowedRef pModule = PythonEventsGetModule();
380 if (pModule)
381 {
382 PyBorrowedRef pModuleDict = PyModule_GetDict(pModule);
383 if (!pModuleDict)
384 {
385 _log.Log(LOG_ERROR, "Python EventSystem: Failed to open module dictionary.");
386 PyEval_SaveThread();
387 return;
388 }
389
390 if (!Py_None)
391 {
392 PyNewRef local_dict = PyDict_New();
393 PyNewRef pCode = Py_CompileString("# Eval will return 'None'\n", "<domoticz>", Py_file_input);
394 if (pCode)
395 {
396 PyNewRef pEval = PyEval_EvalCode(pCode, pModuleDict, local_dict);
397 Py_None = pEval;
398 Py_INCREF(Py_None);
399 }
400 }
401
402
403 PyNewRef pStrVal = PyUnicode_FromString(deviceStates[DeviceID].deviceName.c_str());
404 if (PyDict_SetItemString(pModuleDict, "changed_device_name", pStrVal) == -1)
405 {
406 _log.Log(LOG_ERROR, "Python EventSystem: Failed to set changed_device_name.");
407 return;
408 }
409
410 PyNewRef pDeviceDict = PyDict_New();
411 if (PyDict_SetItemString(pModuleDict, "Devices", pDeviceDict) == -1)
412 {
413 _log.Log(LOG_ERROR, "Python EventSystem: Failed to add Device dictionary.");
414 PyEval_SaveThread();
415 return;
416 }
417
418 for (auto it_type = deviceStates.begin(); it_type != deviceStates.end(); ++it_type)

Callers 1

EvaluatePythonMethod · 0.85

Calls 13

PythonEventsGetModuleFunction · 0.85
mytimeFunction · 0.85
localtime_rFunction · 0.85
LogPythonExceptionFunction · 0.85
c_strMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
lengthMethod · 0.80
IsDictMethod · 0.80
LogMethod · 0.45
is_openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected