spacemanspiff2007 / HABApp

Easy home automation with MQTT and/or openHAB
Apache License 2.0
54 stars 23 forks source link

Fixed in 1.1.2 #405

Closed alfista2600 closed 9 months ago

alfista2600 commented 11 months ago
          Fixed in 1.1.2

Originally posted by @spacemanspiff2007 in https://github.com/spacemanspiff2007/HABApp/issues/395#issuecomment-1596550480

I kinda did an unexpected OH 4.0 upgrade this morning, and built a new docker image based on 1.1.2 using the example but I'm getting this same error. Is there something I need to do differently with docker? Sadly won't have much time to troubleshoot today...

alfista2600 commented 11 months ago

and apologies if I did this wrong... still learning GitHub!

spacemanspiff2007 commented 11 months ago

and apologies if I did this wrong... still learning GitHub!

No worries.

Sadly I can not reproduce the issue. The latest version does parse the datetime without issues. Can you show the error message and the habapp version from the log?

alfista2600 commented 11 months ago

Here are some log entries. I wonder if maybe I didn't take time to reset some localization settings which might play a role?

2023-07-26 10:46:35.503 [INFO ] [HABApp                              ] - HABApp Version 1.1.2
2023-07-26 10:46:35.832 [INFO ] [HABApp.mqtt.connection              ] - Connecting to 192.168.0.215:1883
2023-07-26 10:46:35.836 [INFO ] [HABApp.mqtt.connection              ] - Connection Accepted.
2023-07-26 10:46:36.007 [INFO ] [HABApp.openhab.connection           ] - Verify ssl set to False!
2023-07-26 10:46:36.171 [INFO ] [HABApp.openhab.connection           ] - Connected to OpenHAB version 4.0.0 (Release Build)
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] - Error time data '2023-07-26T06:45:20.047581047-0400' does not match format '%Y-%m-%dT%H:%M:%S.%f%z' in map_items:
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] - File "/usr/local/lib/python3.10/site-packages/HABApp/openhab/map_items.py", line 63 in map_item
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] - --------------------------------------------------------------------------------
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] -      34 | def map_item(name: str, type: str, value: Optional[str],
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] -      35 |              label: Optional[str], tags: FrozenSet[str],
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] -      36 |              groups: FrozenSet[str], metadata: Optional[Dict[str, Dict[str, Any]]]) -> \
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] -      37 |         Optional['HABApp.openhab.items.OpenhabItem']:
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] -       (...)
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] -      59 |                 log.warning(f'Item {name:s} is a UoM item but "unit" is not found in item metadata')
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] -      61 |         cls = _items.get(type)
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] -      62 |         if cls is not None:
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] - -->  63 |             return cls.from_oh(name, value, label=label, tags=tags, groups=groups, metadata=meta)
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] -      65 |         raise ValueError(f'Unknown openHAB type: {type} for {name}')
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] -    ------------------------------------------------------------
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] -      cls = <class 'HABApp.openhab.items.datetime_item.DatetimeItem'>
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] -      _items = {'String': <class 'HABApp.openhab.items.string_item.StringItem'>, 'Number': <class 'HABApp.openhab.items.number_item.NumberItem'>, 'Switch': <class 'HABApp.openhab.items.switch_item.SwitchItem'>, 'Contact': <class 'HABApp.openhab.items.contact_item.ContactItem'>, 'Rollershutter': <class 'HABApp.openhab.items.rollershutter_item.RollershutterItem'>, 'Dimmer': <class 'HABApp.openhab.items.dimmer_item.DimmerItem'>, 'DateTime': <class 'HABApp.openhab.items.datetime_item.DatetimeItem'>, 'Color': <class 'HABApp.openhab.items.color_item.ColorItem'>, 'Image': <class 'HABApp.openhab.items.image_item.ImageItem'>, 'Group': <class 'HABApp.openhab.items.group_item.GroupItem'>, 'Player': <class 'HABApp.openhab.items.string_item.PlayerItem'>, 'Location': <class 'HABApp.openhab.items.tuple_items.LocationItem'>, 'Call': <class 'HABApp.openhab.items.tuple_items.CallItem'>}
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] -      Any = typing.Any
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] -      e = ValueError("time data '2023-07-26T06:45:20.047581047-0400' does not match format '%Y-%m-%dT%H:%M:%S.%f%z'")
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] -      groups = frozenset({'gAuto_LastUpdateReading'})
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] -      label = 'Sensor_Outside_LCTemperature'
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] -      log = <Logger HABApp.openhab.items (INFO)>
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] -      meta = immutables.Map({'widgetOrder': MetaData(value='2', config=immutables.Map({})), 'stateDescription': MetaData(value='string', config=immutables.Map({'pattern': '%1$tA - %1$tI:%1$tM %1$Tp'})), 'listWidget': MetaData(value='widget:list_reading', config=immutables.Map({}))})
2023-07-26 10:46:36.865 [ERROR] [HABApp.openhab.items                ] -      metadata = {'listWidget': {'value': 'widget:list_reading'}, 'widgetOrder': {'value': '2'}, 'stateDescription': {'value': 'string', 'config': {'pattern': '%1$tA - %1$tI:%1$tM %1$Tp'}}}
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      name = 'Sensor_Outside_LCTemperature'
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      str, Any = (<class 'str'>, typing.Any)
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      tags = frozenset({'LastChange'})
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      type = 'DateTime'
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      value = '2023-07-26T06:45:20.047581047-0400'
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      ':' in type = False
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      cls is not None = True
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      metadata is not None = True
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      value is not None = True
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -    ------------------------------------------------------------
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] - 
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] - File "/usr/local/lib/python3.10/site-packages/HABApp/openhab/items/base_item.py", line 43 in from_oh
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] - --------------------------------------------------------------------------------
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      38 | @classmethod
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      39 | def from_oh(cls, name: str, value=None,
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      40 |             label: Optional[str] = None, tags: FrozenSet[str] = frozenset(), groups: FrozenSet[str] = frozenset(),
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      41 |             metadata: Mapping[str, MetaData] = Map()):
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      42 |     if value is not None:
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] - -->  43 |         value = cls._state_from_oh_str(value)
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      44 |     return cls(name, value, label=label, tags=tags, groups=groups, metadata=metadata)
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -    ------------------------------------------------------------
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      cls = <class 'HABApp.openhab.items.datetime_item.DatetimeItem'>
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      frozenset() = frozenset()
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      groups = frozenset({'gAuto_LastUpdateReading'})
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      label = 'Sensor_Outside_LCTemperature'
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      metadata = immutables.Map({'widgetOrder': MetaData(value='2', config=immutables.Map({})), 'stateDescription': MetaData(value='string', config=immutables.Map({'pattern': '%1$tA - %1$tI:%1$tM %1$Tp'})), 'listWidget': MetaData(value='widget:list_reading', config=immutables.Map({}))})
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      name = 'Sensor_Outside_LCTemperature'
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      str, MetaData = (<class 'str'>, <class 'HABApp.openhab.items.base_item.MetaData'>)
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      tags = frozenset({'LastChange'})
2023-07-26 10:46:36.866 [ERROR] [HABApp.openhab.items                ] -      value = '2023-07-26T06:45:20.047581047-0400'
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -      value is not None = True
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -    ------------------------------------------------------------
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] - 
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] - File "/usr/local/lib/python3.10/site-packages/HABApp/openhab/items/datetime_item.py", line 36 in _state_from_oh_str
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] - --------------------------------------------------------------------------------
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -      26 | @staticmethod
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -      27 | def _state_from_oh_str(state: str):
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -      28 |     # see implementation im map_values.py
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -       (...)
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -      33 |         pos_plus = state.find('+')
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -      34 |         if pos_plus - pos_dot > 6:
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -      35 |             state = state[:pos_dot + 7] + state[pos_plus:]
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] - -->  36 |         dt = datetime.strptime(state, '%Y-%m-%dT%H:%M:%S.%f%z')
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -      38 |     # all datetime objs from openHAB have a timezone set so we can't easily compare them
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -      39 |     # --> TypeError: can't compare offset-naive and offset-aware datetime
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -    ------------------------------------------------------------
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -      pos_dot = 19
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -      pos_dot + 7 = 26
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -      pos_plus = -1
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -      pos_plus - pos_dot = -20
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -      PYTHON_311 = False
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -      state = '2023-07-26T06:45:20.047581047-0400'
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -      state[:pos_dot + 7] = '2023-07-26T06:45:20.047581'
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -      state[:pos_dot + 7] + state[pos_plus:] = '2023-07-26T06:45:20.0475810'
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -      state[pos_plus:] = '0'
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -      pos_plus - pos_dot > 6 = False
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] -    ------------------------------------------------------------
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] - 
2023-07-26 10:46:36.867 [ERROR] [HABApp.openhab.items                ] - --------------------------------------------------------------------------------
2023-07-26 10:46:36.868 [ERROR] [HABApp.openhab.items                ] - Traceback (most recent call last):
2023-07-26 10:46:36.868 [ERROR] [HABApp.openhab.items                ] -   File "/usr/local/lib/python3.10/site-packages/HABApp/openhab/map_items.py", line 63, in map_item
2023-07-26 10:46:36.868 [ERROR] [HABApp.openhab.items                ] -     return cls.from_oh(name, value, label=label, tags=tags, groups=groups, metadata=meta)
2023-07-26 10:46:36.868 [ERROR] [HABApp.openhab.items                ] -   File "/usr/local/lib/python3.10/site-packages/HABApp/openhab/items/base_item.py", line 43, in from_oh
2023-07-26 10:46:36.868 [ERROR] [HABApp.openhab.items                ] -     value = cls._state_from_oh_str(value)
2023-07-26 10:46:36.868 [ERROR] [HABApp.openhab.items                ] -   File "/usr/local/lib/python3.10/site-packages/HABApp/openhab/items/datetime_item.py", line 36, in _state_from_oh_str
2023-07-26 10:46:36.868 [ERROR] [HABApp.openhab.items                ] -     dt = datetime.strptime(state, '%Y-%m-%dT%H:%M:%S.%f%z')
2023-07-26 10:46:36.868 [ERROR] [HABApp.openhab.items                ] -   File "/usr/local/lib/python3.10/_strptime.py", line 568, in _strptime_datetime
2023-07-26 10:46:36.868 [ERROR] [HABApp.openhab.items                ] -     tt, fraction, gmtoff_fraction = _strptime(data_string, format)
2023-07-26 10:46:36.868 [ERROR] [HABApp.openhab.items                ] -   File "/usr/local/lib/python3.10/_strptime.py", line 349, in _strptime
2023-07-26 10:46:36.868 [ERROR] [HABApp.openhab.items                ] -     raise ValueError("time data %r does not match format %r" %
2023-07-26 10:46:36.868 [ERROR] [HABApp.openhab.items                ] - ValueError: time data '2023-07-26T06:45:20.047581047-0400' does not match format '%Y-%m-%dT%H:%M:%S.%f%z'
2023-07-26 10:46:36.879 [ERROR] [HABApp.openhab.items                ] - Error time data '2023-07-26T06:44:57.717690583-0400' does not match format '%Y-%m-%dT%H:%M:%S.%f%z' in map_items:
2023-07-26 10:46:36.879 [ERROR] [HABApp.openhab.items                ] - File "/usr/local/lib/python3.10/site-packages/HABApp/openhab/map_items.py", line 63 in map_item
2023-07-26 10:46:36.879 [ERROR] [HABApp.openhab.items                ] - --------------------------------------------------------------------------------
2023-07-26 10:46:36.879 [ERROR] [HABApp.openhab.items                ] -      34 | def map_item(name: str, type: str, value: Optional[str],
2023-07-26 10:46:36.879 [ERROR] [HABApp.openhab.items                ] -      35 |              label: Optional[str], tags: FrozenSet[str],
2023-07-26 10:46:36.879 [ERROR] [HABApp.openhab.items                ] -      36 |              groups: FrozenSet[str], metadata: Optional[Dict[str, Dict[str, Any]]]) -> \
2023-07-26 10:46:36.879 [ERROR] [HABApp.openhab.items                ] -      37 |         Optional['HABApp.openhab.items.OpenhabItem']:
2023-07-26 10:46:36.879 [ERROR] [HABApp.openhab.items                ] -       (...)
2023-07-26 10:46:36.879 [ERROR] [HABApp.openhab.items                ] -      59 |                 log.warning(f'Item {name:s} is a UoM item but "unit" is not found in item metadata')
2023-07-26 10:46:36.879 [ERROR] [HABApp.openhab.items                ] -      61 |         cls = _items.get(type)
2023-07-26 10:46:36.879 [ERROR] [HABApp.openhab.items                ] -      62 |         if cls is not None:
2023-07-26 10:46:36.879 [ERROR] [HABApp.openhab.items                ] - -->  63 |             return cls.from_oh(name, value, label=label, tags=tags, groups=groups, metadata=meta)
2023-07-26 10:46:36.879 [ERROR] [HABApp.openhab.items                ] -      65 |         raise ValueError(f'Unknown openHAB type: {type} for {name}')
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -    ------------------------------------------------------------
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      cls = <class 'HABApp.openhab.items.datetime_item.DatetimeItem'>
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      _items = {'String': <class 'HABApp.openhab.items.string_item.StringItem'>, 'Number': <class 'HABApp.openhab.items.number_item.NumberItem'>, 'Switch': <class 'HABApp.openhab.items.switch_item.SwitchItem'>, 'Contact': <class 'HABApp.openhab.items.contact_item.ContactItem'>, 'Rollershutter': <class 'HABApp.openhab.items.rollershutter_item.RollershutterItem'>, 'Dimmer': <class 'HABApp.openhab.items.dimmer_item.DimmerItem'>, 'DateTime': <class 'HABApp.openhab.items.datetime_item.DatetimeItem'>, 'Color': <class 'HABApp.openhab.items.color_item.ColorItem'>, 'Image': <class 'HABApp.openhab.items.image_item.ImageItem'>, 'Group': <class 'HABApp.openhab.items.group_item.GroupItem'>, 'Player': <class 'HABApp.openhab.items.string_item.PlayerItem'>, 'Location': <class 'HABApp.openhab.items.tuple_items.LocationItem'>, 'Call': <class 'HABApp.openhab.items.tuple_items.CallItem'>}
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      Any = typing.Any
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      e = ValueError("time data '2023-07-26T06:44:57.717690583-0400' does not match format '%Y-%m-%dT%H:%M:%S.%f%z'")
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      groups = frozenset({'gAuto_LastUpdateReading'})
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      label = 'Sensor_Outside_LCLux'
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      log = <Logger HABApp.openhab.items (INFO)>
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      meta = immutables.Map({'widgetOrder': MetaData(value='2', config=immutables.Map({})), 'stateDescription': MetaData(value='string', config=immutables.Map({'pattern': '%1$tA - %1$tI:%1$tM %1$Tp'})), 'listWidget': MetaData(value='widget:list_reading', config=immutables.Map({}))})
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      metadata = {'listWidget': {'value': 'widget:list_reading'}, 'widgetOrder': {'value': '2'}, 'stateDescription': {'value': 'string', 'config': {'pattern': '%1$tA - %1$tI:%1$tM %1$Tp'}}}
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      name = 'Sensor_Outside_LCLux'
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      str, Any = (<class 'str'>, typing.Any)
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      tags = frozenset({'LastChange'})
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      type = 'DateTime'
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      value = '2023-07-26T06:44:57.717690583-0400'
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      ':' in type = False
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      cls is not None = True
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      metadata is not None = True
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      value is not None = True
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -    ------------------------------------------------------------
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] - 
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] - File "/usr/local/lib/python3.10/site-packages/HABApp/openhab/items/base_item.py", line 43 in from_oh
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] - --------------------------------------------------------------------------------
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      38 | @classmethod
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      39 | def from_oh(cls, name: str, value=None,
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      40 |             label: Optional[str] = None, tags: FrozenSet[str] = frozenset(), groups: FrozenSet[str] = frozenset(),
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      41 |             metadata: Mapping[str, MetaData] = Map()):
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      42 |     if value is not None:
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] - -->  43 |         value = cls._state_from_oh_str(value)
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -      44 |     return cls(name, value, label=label, tags=tags, groups=groups, metadata=metadata)
2023-07-26 10:46:36.880 [ERROR] [HABApp.openhab.items                ] -    ------------------------------------------------------------
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      cls = <class 'HABApp.openhab.items.datetime_item.DatetimeItem'>
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      frozenset() = frozenset()
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      groups = frozenset({'gAuto_LastUpdateReading'})
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      label = 'Sensor_Outside_LCLux'
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      metadata = immutables.Map({'widgetOrder': MetaData(value='2', config=immutables.Map({})), 'stateDescription': MetaData(value='string', config=immutables.Map({'pattern': '%1$tA - %1$tI:%1$tM %1$Tp'})), 'listWidget': MetaData(value='widget:list_reading', config=immutables.Map({}))})
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      name = 'Sensor_Outside_LCLux'
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      str, MetaData = (<class 'str'>, <class 'HABApp.openhab.items.base_item.MetaData'>)
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      tags = frozenset({'LastChange'})
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      value = '2023-07-26T06:44:57.717690583-0400'
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      value is not None = True
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -    ------------------------------------------------------------
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] - 
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] - File "/usr/local/lib/python3.10/site-packages/HABApp/openhab/items/datetime_item.py", line 36 in _state_from_oh_str
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] - --------------------------------------------------------------------------------
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      26 | @staticmethod
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      27 | def _state_from_oh_str(state: str):
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      28 |     # see implementation im map_values.py
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -       (...)
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      33 |         pos_plus = state.find('+')
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      34 |         if pos_plus - pos_dot > 6:
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      35 |             state = state[:pos_dot + 7] + state[pos_plus:]
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] - -->  36 |         dt = datetime.strptime(state, '%Y-%m-%dT%H:%M:%S.%f%z')
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      38 |     # all datetime objs from openHAB have a timezone set so we can't easily compare them
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      39 |     # --> TypeError: can't compare offset-naive and offset-aware datetime
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -    ------------------------------------------------------------
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      pos_dot = 19
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      pos_dot + 7 = 26
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      pos_plus = -1
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      pos_plus - pos_dot = -20
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      PYTHON_311 = False
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      state = '2023-07-26T06:44:57.717690583-0400'
2023-07-26 10:46:36.881 [ERROR] [HABApp.openhab.items                ] -      state[:pos_dot + 7] = '2023-07-26T06:44:57.717690'
2023-07-26 10:46:36.882 [ERROR] [HABApp.openhab.items                ] -      state[:pos_dot + 7] + state[pos_plus:] = '2023-07-26T06:44:57.7176900'
2023-07-26 10:46:36.882 [ERROR] [HABApp.openhab.items                ] -      state[pos_plus:] = '0'
2023-07-26 10:46:36.882 [ERROR] [HABApp.openhab.items                ] -      pos_plus - pos_dot > 6 = False
2023-07-26 10:46:36.882 [ERROR] [HABApp.openhab.items                ] -    ------------------------------------------------------------
2023-07-26 10:46:36.882 [ERROR] [HABApp.openhab.items                ] - 
2023-07-26 10:46:36.882 [ERROR] [HABApp.openhab.items                ] - --------------------------------------------------------------------------------
2023-07-26 10:46:36.882 [ERROR] [HABApp.openhab.items                ] - Traceback (most recent call last):
2023-07-26 10:46:36.882 [ERROR] [HABApp.openhab.items                ] -   File "/usr/local/lib/python3.10/site-packages/HABApp/openhab/map_items.py", line 63, in map_item
2023-07-26 10:46:36.882 [ERROR] [HABApp.openhab.items                ] -     return cls.from_oh(name, value, label=label, tags=tags, groups=groups, metadata=meta)
2023-07-26 10:46:36.882 [ERROR] [HABApp.openhab.items                ] -   File "/usr/local/lib/python3.10/site-packages/HABApp/openhab/items/base_item.py", line 43, in from_oh
2023-07-26 10:46:36.882 [ERROR] [HABApp.openhab.items                ] -     value = cls._state_from_oh_str(value)
2023-07-26 10:46:36.882 [ERROR] [HABApp.openhab.items                ] -   File "/usr/local/lib/python3.10/site-packages/HABApp/openhab/items/datetime_item.py", line 36, in _state_from_oh_str
2023-07-26 10:46:36.882 [ERROR] [HABApp.openhab.items                ] -     dt = datetime.strptime(state, '%Y-%m-%dT%H:%M:%S.%f%z')
2023-07-26 10:46:36.882 [ERROR] [HABApp.openhab.items                ] -   File "/usr/local/lib/python3.10/_strptime.py", line 568, in _strptime_datetime
2023-07-26 10:46:36.882 [ERROR] [HABApp.openhab.items                ] -     tt, fraction, gmtoff_fraction = _strptime(data_string, format)
2023-07-26 10:46:36.882 [ERROR] [HABApp.openhab.items                ] -   File "/usr/local/lib/python3.10/_strptime.py", line 349, in _strptime
2023-07-26 10:46:36.882 [ERROR] [HABApp.openhab.items                ] -     raise ValueError("time data %r does not match format %r" %
2023-07-26 10:46:36.882 [ERROR] [HABApp.openhab.items                ] - ValueError: time data '2023-07-26T06:44:57.717690583-0400' does not match format '%Y-%m-%dT%H:%M:%S.%f%z'
2023-07-26 10:46:36.882 [WARN ] [HABApp.openhab.items                ] - Item Control_Apartment_Thermostat_LocalHeatHold is a UoM item but "unit" is not found in item metadata
2023-07-26 10:46:36.894 [ERROR] [HABApp.openhab.items                ] - Error time data '2023-07-26T06:45:20.404246239-0400' does not match format '%Y-%m-%dT%H:%M:%S.%f%z' in map_items:
2023-07-26 10:46:36.894 [ERROR] [HABApp.openhab.items                ] - File "/usr/local/lib/python3.10/site-packages/HABApp/openhab/map_items.py", line 63 in map_item
2023-07-26 10:46:36.894 [ERROR] [HABApp.openhab.items                ] - --------------------------------------------------------------------------------
2023-07-26 10:46:36.894 [ERROR] [HABApp.openhab.items                ] -      34 | def map_item(name: str, type: str, value: Optional[str],
2023-07-26 10:46:36.894 [ERROR] [HABApp.openhab.items                ] -      35 |              label: Optional[str], tags: FrozenSet[str],
2023-07-26 10:46:36.894 [ERROR] [HABApp.openhab.items                ] -      36 |              groups: FrozenSet[str], metadata: Optional[Dict[str, Dict[str, Any]]]) -> \
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      37 |         Optional['HABApp.openhab.items.OpenhabItem']:
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -       (...)
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      59 |                 log.warning(f'Item {name:s} is a UoM item but "unit" is not found in item metadata')
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      61 |         cls = _items.get(type)
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      62 |         if cls is not None:
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] - -->  63 |             return cls.from_oh(name, value, label=label, tags=tags, groups=groups, metadata=meta)
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      65 |         raise ValueError(f'Unknown openHAB type: {type} for {name}')
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -    ------------------------------------------------------------
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      cls = <class 'HABApp.openhab.items.datetime_item.DatetimeItem'>
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      _items = {'String': <class 'HABApp.openhab.items.string_item.StringItem'>, 'Number': <class 'HABApp.openhab.items.number_item.NumberItem'>, 'Switch': <class 'HABApp.openhab.items.switch_item.SwitchItem'>, 'Contact': <class 'HABApp.openhab.items.contact_item.ContactItem'>, 'Rollershutter': <class 'HABApp.openhab.items.rollershutter_item.RollershutterItem'>, 'Dimmer': <class 'HABApp.openhab.items.dimmer_item.DimmerItem'>, 'DateTime': <class 'HABApp.openhab.items.datetime_item.DatetimeItem'>, 'Color': <class 'HABApp.openhab.items.color_item.ColorItem'>, 'Image': <class 'HABApp.openhab.items.image_item.ImageItem'>, 'Group': <class 'HABApp.openhab.items.group_item.GroupItem'>, 'Player': <class 'HABApp.openhab.items.string_item.PlayerItem'>, 'Location': <class 'HABApp.openhab.items.tuple_items.LocationItem'>, 'Call': <class 'HABApp.openhab.items.tuple_items.CallItem'>}
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      Any = typing.Any
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      e = ValueError("time data '2023-07-26T06:45:20.404246239-0400' does not match format '%Y-%m-%dT%H:%M:%S.%f%z'")
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      groups = frozenset({'gAuto_LastUpdateReading'})
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      label = 'Back Hallway Temp'
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      log = <Logger HABApp.openhab.items (INFO)>
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      meta = immutables.Map({'widgetOrder': MetaData(value='2', config=immutables.Map({})), 'stateDescription': MetaData(value='string', config=immutables.Map({'pattern': '%1$tA - %1$tI:%1$tM %1$Tp'})), 'listWidget': MetaData(value='widget:list_reading', config=immutables.Map({}))})
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      metadata = {'listWidget': {'value': 'widget:list_reading'}, 'widgetOrder': {'value': '2'}, 'stateDescription': {'value': 'string', 'config': {'pattern': '%1$tA - %1$tI:%1$tM %1$Tp'}}}
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      name = 'Sensor_BackHallway_LCTemperature'
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      str, Any = (<class 'str'>, typing.Any)
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      tags = frozenset({'LastChange'})
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      type = 'DateTime'
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      value = '2023-07-26T06:45:20.404246239-0400'
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      ':' in type = False
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      cls is not None = True
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      metadata is not None = True
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -      value is not None = True
2023-07-26 10:46:36.895 [ERROR] [HABApp.openhab.items                ] -    ------------------------------------------------------------
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] - 
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] - File "/usr/local/lib/python3.10/site-packages/HABApp/openhab/items/base_item.py", line 43 in from_oh
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] - --------------------------------------------------------------------------------
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -      38 | @classmethod
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -      39 | def from_oh(cls, name: str, value=None,
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -      40 |             label: Optional[str] = None, tags: FrozenSet[str] = frozenset(), groups: FrozenSet[str] = frozenset(),
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -      41 |             metadata: Mapping[str, MetaData] = Map()):
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -      42 |     if value is not None:
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] - -->  43 |         value = cls._state_from_oh_str(value)
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -      44 |     return cls(name, value, label=label, tags=tags, groups=groups, metadata=metadata)
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -    ------------------------------------------------------------
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -      cls = <class 'HABApp.openhab.items.datetime_item.DatetimeItem'>
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -      frozenset() = frozenset()
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -      groups = frozenset({'gAuto_LastUpdateReading'})
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -      label = 'Back Hallway Temp'
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -      metadata = immutables.Map({'widgetOrder': MetaData(value='2', config=immutables.Map({})), 'stateDescription': MetaData(value='string', config=immutables.Map({'pattern': '%1$tA - %1$tI:%1$tM %1$Tp'})), 'listWidget': MetaData(value='widget:list_reading', config=immutables.Map({}))})
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -      name = 'Sensor_BackHallway_LCTemperature'
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -      str, MetaData = (<class 'str'>, <class 'HABApp.openhab.items.base_item.MetaData'>)
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -      tags = frozenset({'LastChange'})
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -      value = '2023-07-26T06:45:20.404246239-0400'
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -      value is not None = True
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -    ------------------------------------------------------------
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] - 
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] - File "/usr/local/lib/python3.10/site-packages/HABApp/openhab/items/datetime_item.py", line 36 in _state_from_oh_str
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] - --------------------------------------------------------------------------------
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -      26 | @staticmethod
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -      27 | def _state_from_oh_str(state: str):
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -      28 |     # see implementation im map_values.py
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -       (...)
2023-07-26 10:46:36.896 [ERROR] [HABApp.openhab.items                ] -      33 |         pos_plus = state.find('+')
2023-07-26 10:46:36.897 [ERROR] [HABApp.openhab.items                ] -      34 |         if pos_plus - pos_dot > 6:
2023-07-26 10:46:36.897 [ERROR] [HABApp.openhab.items                ] -      35 |             state = state[:pos_dot + 7] + state[pos_plus:]
2023-07-26 10:46:36.897 [ERROR] [HABApp.openhab.items                ] - -->  36 |         dt = datetime.strptime(state, '%Y-%m-%dT%H:%M:%S.%f%z')
2023-07-26 10:46:36.897 [ERROR] [HABApp.openhab.items                ] -      38 |     # all datetime objs from openHAB have a timezone set so we can't easily compare them
2023-07-26 10:46:36.897 [ERROR] [HABApp.openhab.items                ] -      39 |     # --> TypeError: can't compare offset-naive and offset-aware datetime
2023-07-26 10:46:36.897 [ERROR] [HABApp.openhab.items                ] -    ------------------------------------------------------------
2023-07-26 10:46:36.897 [ERROR] [HABApp.openhab.items                ] -      pos_dot = 19
2023-07-26 10:46:36.897 [ERROR] [HABApp.openhab.items                ] -      pos_dot + 7 = 26
2023-07-26 10:46:36.897 [ERROR] [HABApp.openhab.items                ] -      pos_plus = -1
2023-07-26 10:46:36.897 [ERROR] [HABApp.openhab.items                ] -      pos_plus - pos_dot = -20
2023-07-26 10:46:36.897 [ERROR] [HABApp.openhab.items                ] -      PYTHON_311 = False
2023-07-26 10:46:36.897 [ERROR] [HABApp.openhab.items                ] -      state = '2023-07-26T06:45:20.404246239-0400'
2023-07-26 10:46:36.897 [ERROR] [HABApp.openhab.items                ] -      state[:pos_dot + 7] = '2023-07-26T06:45:20.404246'
2023-07-26 10:46:36.897 [ERROR] [HABApp.openhab.items                ] -      state[:pos_dot + 7] + state[pos_plus:] = '2023-07-26T06:45:20.4042460'
2023-07-26 10:46:36.897 [ERROR] [HABApp.openhab.items                ] -      state[pos_plus:] = '0'
2023-07-26 10:46:36.897 [ERROR] [HABApp.openhab.items                ] -      pos_plus - pos_dot > 6 = False
2023-07-26 10:46:36.897 [ERROR] [HABApp.openhab.items                ] -    ------------------------------------------------------------
spacemanspiff2007 commented 11 months ago

Switching your docker base image to python 3.11 should fix the issue. Otherwise I have a fix prepared in the next version.

alfista2600 commented 11 months ago

Ok! Thanks. Wouldn't have come up with that on my own - much appreciated. Now let's see if I've learned enough about Docker to make this happen.

spacemanspiff2007 commented 11 months ago

You can just copy/paste the dockerfile from the develop branch into your local folder

NickWaterton commented 10 months ago

I just upgraded to the latest github version (master) - not sure if this is v 1.1.2, and also upgraded to Openhab 4.0.

I'm having the same problems with datetimes not being parsed correctly (python 3.10).

Logs:

2023-08-11 14:52:19,085[                    HABApp]ERROR|   process_exception:      openhab_type = 'DateTime'
2023-08-11 14:52:19,085[                    HABApp]ERROR|   process_exception:      openhab_type == 'UnDef' or openhab_value == 'NULL' = False
2023-08-11 14:52:19,085[                    HABApp]ERROR|   process_exception:      openhab_value = '2023-08-11T14:52:18.842929707-0400'
2023-08-11 14:52:19,085[                    HABApp]ERROR|   process_exception:      openhab_value[:pos_dot + 7] = '2023-08-11T14:52:18.842929'
2023-08-11 14:52:19,086[                    HABApp]ERROR|   process_exception:      openhab_value[:pos_dot + 7] + openhab_value[pos_plus:] = '2023-08-11T14:52:18.8429290'
2023-08-11 14:52:19,086[                    HABApp]ERROR|   process_exception:      openhab_value[pos_plus:] = '0'
2023-08-11 14:52:19,086[                    HABApp]ERROR|   process_exception:      pos_dot = 19
2023-08-11 14:52:19,086[                    HABApp]ERROR|   process_exception:      pos_dot + 7 = 26
2023-08-11 14:52:19,086[                    HABApp]ERROR|   process_exception:      pos_plus = -1
2023-08-11 14:52:19,087[                    HABApp]ERROR|   process_exception:      pos_plus - pos_dot = -20
2023-08-11 14:52:19,087[                    HABApp]ERROR|   process_exception:      PYTHON_311 = False
2023-08-11 14:52:19,087[                    HABApp]ERROR|   process_exception:      openhab_type == "DateTime" = True
2023-08-11 14:52:19,087[                    HABApp]ERROR|   process_exception:      openhab_type == "Decimal" = False
2023-08-11 14:52:19,088[                    HABApp]ERROR|   process_exception:      openhab_type == "HSB" = False
2023-08-11 14:52:19,088[                    HABApp]ERROR|   process_exception:      openhab_type == "Number" = False
2023-08-11 14:52:19,088[                    HABApp]ERROR|   process_exception:      openhab_type == "String" = False
2023-08-11 14:52:19,088[                    HABApp]ERROR|   process_exception:      openhab_type == 'OnOff' = False
2023-08-11 14:52:19,089[                    HABApp]ERROR|   process_exception:      openhab_type == 'OpenClosed' = False
2023-08-11 14:52:19,089[                    HABApp]ERROR|   process_exception:      openhab_type == 'Percent' = False
2023-08-11 14:52:19,089[                    HABApp]ERROR|   process_exception:      openhab_type == 'Point' = False
2023-08-11 14:52:19,089[                    HABApp]ERROR|   process_exception:      openhab_type == 'Quantity' = False
2023-08-11 14:52:19,089[                    HABApp]ERROR|   process_exception:      openhab_type == 'Raw' = False
2023-08-11 14:52:19,090[                    HABApp]ERROR|   process_exception:      openhab_type == 'UnDef' = False
2023-08-11 14:52:19,090[                    HABApp]ERROR|   process_exception:      openhab_type == 'UpDown' = False
2023-08-11 14:52:19,090[                    HABApp]ERROR|   process_exception:      openhab_value == 'NULL' = False
2023-08-11 14:52:19,090[                    HABApp]ERROR|   process_exception:      pos_plus - pos_dot > 6 = False
2023-08-11 14:52:19,091[                    HABApp]ERROR|   process_exception:    ------------------------------------------------------------
2023-08-11 14:52:19,091[                    HABApp]ERROR|   process_exception:
2023-08-11 14:52:19,091[                    HABApp]ERROR|   process_exception: --------------------------------------------------------------------------------
2023-08-11 14:52:19,091[                    HABApp]ERROR|   process_exception: Traceback (most recent call last):
2023-08-11 14:52:19,092[                    HABApp]ERROR|   process_exception:   File "/home/nick/Scripts/HABApp/src/HABApp/openhab/connection_handler/sse_handler.py", line 32, in on_sse_event
2023-08-11 14:52:19,092[                    HABApp]ERROR|   process_exception:     event = get_event(event_dict)
2023-08-11 14:52:19,092[                    HABApp]ERROR|   process_exception:   File "/home/nick/Scripts/HABApp/src/HABApp/openhab/map_events.py", line 44, in get_event
2023-08-11 14:52:19,092[                    HABApp]ERROR|   process_exception:     return _events[event_type].from_dict(topic, payload)
2023-08-11 14:52:19,092[                    HABApp]ERROR|   process_exception:   File "/home/nick/Scripts/HABApp/src/HABApp/openhab/events/item_events.py", line 238, in from_dict
2023-08-11 14:52:19,093[                    HABApp]ERROR|   process_exception:     map_openhab_values(payload['type'], payload['value']),
2023-08-11 14:52:19,093[                    HABApp]ERROR|   process_exception:   File "/home/nick/Scripts/HABApp/src/HABApp/openhab/map_values.py", line 40, in map_openhab_values
2023-08-11 14:52:19,093[                    HABApp]ERROR|   process_exception:     dt = datetime.strptime(openhab_value, '%Y-%m-%dT%H:%M:%S.%f%z')
2023-08-11 14:52:19,093[                    HABApp]ERROR|   process_exception:   File "/usr/lib/python3.10/_strptime.py", line 568, in _strptime_datetime
2023-08-11 14:52:19,094[                    HABApp]ERROR|   process_exception:     tt, fraction, gmtoff_fraction = _strptime(data_string, format)
2023-08-11 14:52:19,094[                    HABApp]ERROR|   process_exception:   File "/usr/lib/python3.10/_strptime.py", line 349, in _strptime
2023-08-11 14:52:19,094[                    HABApp]ERROR|   process_exception:     raise ValueError("time data %r does not match format %r" %
2023-08-11 14:52:19,094[                    HABApp]ERROR|   process_exception: ValueError: time data '2023-08-11T14:52:18.842929707-0400' does not match format '%Y-%m-%dT%H:%M:%S.%f%z'
2023-08-11 14:52:19,145[                    HABApp]ERROR|   process_exception: Error time data '2023-08-11T14:52:19.103874820-0400' does not match format '%Y-%m-%dT%H:%M:%S.%f%z' in on_sse_event:

This is caused by the microseconds value in the OH string having nine digits instead of the six that datetime.strptime() expects - ie the %f field is only expecting 6 digits, but gets 9.

This is because in src/HABApp/openhab/map_values.py the nanosecond conversion routine only searches for a '+' symbol, but I am GMT -0400 - and the - symbol is not considered.

if openhab_type == "DateTime":
        # see implementation im datetime_item.py
        if PYTHON_311:
            dt = datetime.fromisoformat(openhab_value)
        else:
            pos_dot = openhab_value.find('.')
            pos_plus = openhab_value.find('+')
            if pos_plus - pos_dot > 6:
                openhab_value = openhab_value[:pos_dot + 7] + openhab_value[pos_plus:]
            dt = datetime.strptime(openhab_value, '%Y-%m-%dT%H:%M:%S.%f%z')

        # all datetimes from openHAB have a timezone set, so we can't easily compare them
        # --> TypeError: can't compare offset-naive and offset-aware datetimes
        dt = dt.astimezone(tz=None)   # Changes datetime object so it uses system timezone
        dt = dt.replace(tzinfo=None)  # Removes timezone awareness
        return dt

ie line 37 pos_plus = openhab_value.find('+') returns -1 if your timezone is negative from UTC.

It is hard to find the - timezone indicator, as the string itself contains - characters.

I'll try to find a workaround.

spacemanspiff2007 commented 10 months ago

The most easy way would be switching to python 3.11. Or use this file from the dev branch.

NickWaterton commented 10 months ago

I'll look, but it's not "easy" to switch to python 3.11.

NickWaterton commented 10 months ago

Ok,

fixed it by adding:

if pos_plus == -1:
    pos_plus = openhab_value.rfind('-')

You should fix this in the master branch, not everyone has python 3.11, and a lot of people live west of UTC.

spacemanspiff2007 commented 9 months ago

Fixed with the 23.09.0