I am trying to convert the Devices[UnitID].LastUpdate to a datetime object, so i can compare with another timestamp (which has the format of a unix timestamp). The timestamp has the string format "YYYY-MM-DD HH:MM", so i think i have to convert using the datetime.strptime function. but this one gives me " 'onStart' failed 'TypeError':''NoneType' object is not callable'."
i thought something something was wrong with the code i wrote, so to test i created a test.py script with a code example from the official python docs:
Code: Select all
import datetime
datetimeObj = datetime.datetime.strptime('2018-09-11 15:11:45', '%Y-%m-%d %H:%M:%S')
print(datetimeObj)
print(type(datetimeObj))Code: Select all
2018-09-11 15:11:45
<type 'datetime.datetime'>
" 'onStart' failed 'TypeError':''NoneType' object is not callable'." on the datetime.datetime.strptime line
if i change datetime.datetime.strptime() to datetime.datetime.fromtimestamp() or datetime.datetime.now() the error is gone again…
what am i missing here? and how can i get datetime.datetime.striptime() to work in a python plugin?
UPDATE:
I found the cause and a workaround.
The issue is not my lack of programming skills (pfjew…) , but a bug in python (https://bugs.python.org/issue27400). and i checked: This Py_Finalize is called a lot in the domoticz code, causing this bug to occur. Fortunately the workaround is also in that link:
instead of
Code: Select all
datetimeObj = datetime.datetime.strptime(string, format)Code: Select all
datetimeObj = datetime.datetime.fromtimestamp(time.mktime(time.strptime(string, format)))