| 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) |
no test coverage detected