Closed Rick-Jongbloed closed 5 years ago
Can you post your entire core.date.to_python_datetime
method please. Use triple ticks instead on singles like this:
```python
Code goes here
Sorry... my bad. In #95, there was a place where the getID() method needed to be changed to getId()...
... and I mistakenly changed it here to match, thinking it was a typo, without looking at the JavaDoc first...
Change L110 back to using getID() to correct this. I'll add a PR.
https://docs.oracle.com/javase/8/docs/api/java/time/ZoneId.html#getId-- https://docs.oracle.com/javase/8/docs/api/java/util/TimeZone.html#getID--
@ricadelic, let me know if this was the correct fix for your issue! To help with troubleshooting in the future, use the rule decorator and you'll get a traceback. Another option would be to use the core.log.log_traceback decorator on your class. Or use a try/except (this is what I used)...
from core.log import logging, LOG_PREFIX
log = logging.getLogger(LOG_PREFIX + ".TEST")
from core.date import to_python_datetime
try:
log.warn("[{}], [{}]".format(items.Virtual_DateTime_1, to_python_datetime(items.Virtual_DateTime_1)))
except Exception as e:
import traceback
log.error("Exception: [{}]: [{}]".format(e, traceback.format_exc()))
2019-05-30 11:17:08.326 [ERROR] [jsr223.jython.TEST] - Exception: ['sun.util.calendar.ZoneInfo' object has no attribute 'getId']: [Traceback (most recent call last):
File "<script>", line 50, in <module>
File "/opt/openhab2/conf/automation/lib/python/core/date.py", line 146, in to_python_datetime
value_zoneddatetime = to_java_zoneddatetime(value)
File "/opt/openhab2/conf/automation/lib/python/core/date.py", line 119, in to_java_zoneddatetime
return to_java_zoneddatetime(value.calendar)
File "/opt/openhab2/conf/automation/lib/python/core/date.py", line 110, in to_java_zoneddatetime
return ZonedDateTime.ofInstant(value.toInstant(), ZoneId.of(value.getTimeZone().getId()))
AttributeError: 'sun.util.calendar.ZoneInfo' object has no attribute 'getId'
]
Well that's what I get for trying to diag this on phone over breakfast. I thought this was working last time I looked
The fix works. The stacktrace on the @Rule decorator as well. Thanks! Now onto the next error that occurs haha
Describe the bug When converting a datetime value (2019-06-04T09:00:00.000+0200) to a python datetime a stack trace is logged and the python date is not returned.
To Reproduce Steps to reproduce the behavior:
Expected behavior A python datetime object should be returned
Troubleshooting info
I believe the error occurs on this line
return ZonedDateTime.ofInstant(value.toInstant(), ZoneId.of(value.getTimeZone().getId()))
i tried to isolate is and it seems like the error is in the partvalue.getTimeZone().getId()
doesn't work aslogging.info(str(value.getTimeZone().getId())
doesn't work either.the value of garbage_retrieval_datetime is 2019-06-04T09:00:00.000+0200 and it's type is <type 'org.eclipse.smarthome.core.library.types.DateTimeType'>
My script
Environment (please complete the following information):
Additional context Stack trace