subarulink icon indicating copy to clipboard operation
subarulink copied to clipboard

Error when parsing time in controller.py

Open anoopknayak opened this issue 1 year ago • 4 comments

Hi,

I have been running subaru integration in Home assistant but I see the following error in the logs:

Traceback (most recent call last):
  File "/home/homeassistant/.pyenv/versions/3.11.6/lib/python3.11/site-packages/homeassistant/helpers/update_coordinator.py", line 290, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.pyenv/versions/3.11.6/lib/python3.11/site-packages/homeassistant/helpers/update_coordinator.py", line 246, in _async_update_data
    return await self.update_method()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.pyenv/versions/3.11.6/lib/python3.11/site-packages/homeassistant/components/subaru/__init__.py", line 75, in async_update_data
    return await refresh_subaru_data(entry, vehicle_info, controller)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.pyenv/versions/3.11.6/lib/python3.11/site-packages/homeassistant/components/subaru/__init__.py", line 125, in refresh_subaru_data
    await controller.fetch(vin, force=True)
  File "/mnt/dietpi_userdata/homeassistant/deps/lib/python3.11/site-packages/subarulink/controller.py", line 569, in fetch
    result = await self._fetch_status(vin)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/dietpi_userdata/homeassistant/deps/lib/python3.11/site-packages/subarulink/controller.py", line 1070, in _fetch_status
    status = await self._parse_condition(js_resp, vin)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/dietpi_userdata/homeassistant/deps/lib/python3.11/site-packages/subarulink/controller.py", line 1304, in _parse_condition
    keep_data[sc.TIMESTAMP] = datetime.strptime(data[api.API_LAST_UPDATED_DATE], api.API_TIMESTAMP_FMT)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.pyenv/versions/3.11.6/lib/python3.11/_strptime.py", line 568, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.pyenv/versions/3.11.6/lib/python3.11/_strptime.py", line 349, in _strptime
    raise ValueError("time data %r does not match format %r" %
ValueError: time data '2024-02-04T18:53:51.000+0000' does not match format '%Y-%m-%dT%H:%M:%S%z'

I can submit a patch if I get time, but I believe the right fix would be to iterate through all the known time formats obtained from subaru. Wdyt @G-Two?

anoopknayak avatar Feb 07 '24 05:02 anoopknayak

Are you using the latest release?

G-Two avatar Feb 07 '24 14:02 G-Two

There should be a try/except block now using the two known formats returned by the subaru API:

        try:
            keep_data[sc.TIMESTAMP] = datetime.strptime(data[api.API_LAST_UPDATED_DATE], api.API_TIMESTAMP_FMT)
        except ValueError:
            keep_data[sc.TIMESTAMP] = datetime.strptime(data[api.API_LAST_UPDATED_DATE], api.API_TIMESTAMP_FMT_OLD)

G-Two avatar Feb 07 '24 14:02 G-Two

Related https://github.com/G-Two/homeassistant-subaru/issues/101

G-Two avatar Feb 07 '24 14:02 G-Two

Hey @G-Two, sorry for the late reply. This missed my notifications. I need to check with the latest release of Home assistant but as of two weeks ago it wasn't working. I'm using the subaru plugin which comes with HA.

anoopknayak avatar Feb 20 '24 18:02 anoopknayak