Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when parsing time in controller.py #96

Open
anoopknayak opened this issue Feb 7, 2024 · 4 comments
Open

Error when parsing time in controller.py #96

anoopknayak opened this issue Feb 7, 2024 · 4 comments

Comments

@anoopknayak
Copy link

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?

@G-Two
Copy link
Owner

G-Two commented Feb 7, 2024

Are you using the latest release?

@G-Two
Copy link
Owner

G-Two commented Feb 7, 2024

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
Copy link
Owner

G-Two commented Feb 7, 2024

Related G-Two/homeassistant-subaru#101

@anoopknayak
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants