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

feat: China support #637

Merged
merged 6 commits into from
May 5, 2023
Merged

feat: China support #637

merged 6 commits into from
May 5, 2023

Conversation

cdnninja
Copy link
Collaborator

@cdnninja cdnninja commented May 2, 2023

Could you test this out @toraidl?

@toraidl
Copy link
Contributor

toraidl commented May 2, 2023

Sure I can test it @cdnninja

@toraidl
Copy link
Contributor

toraidl commented May 4, 2023

Two issues encountered:

  1. Force update failed, falling back to cached: can't subtract offset-naive and offset-aware datetimes
    Traceback (most recent call last):
    File "/config/custom_components/kia_uvo/coordinator.py", line 126, in _async_update_data
    await self.hass.async_add_executor_job(
    File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(self.args, self.kwargs)
    File "/usr/local/lib/python3.10/site-packages/hyundai_kia_connect_api/VehicleManager.py", line 96, in check_and_force_update_vehicles
    f"{DOMAIN} - Time differential in seconds: {(started_at_utc - vehicle.last_updated_at).total_seconds()}" # noqa
    TypeError: can't subtract offset-naive and offset-aware datetimes
    *

  2. Traceback (most recent call last):
    File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 455, in async_add_entities
    await asyncio.gather(*tasks)
    File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 731, in _async_add_entity
    await entity.add_to_platform_finish()
    File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 823, in add_to_platform_finish
    self.async_write_ha_state()
    File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 568, in async_write_ha_state
    self._async_write_ha_state()
    File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 632, in _async_write_ha_state
    state = self._stringify_state(available)
    File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 574, in _stringify_state
    if (state := self.state) is None:
    File "/usr/src/homeassistant/homeassistant/components/sensor/init.py", line 523, in state
    raise ValueError(
    ValueError: Invalid datetime: sensor.di_shi_dai_suo_na_ta_20201103_last_updated_at provides state '2023-05-04 09:49:12.243989', which is missing timezone information

@toraidl
Copy link
Contributor

toraidl commented May 4, 2023

@cdnninja I'm wondering if it's possible to test the hyundai_kia_connect_api locally with kia_uvo custom_componment? By testing locally, I can quickly troubleshoot issues.

@cdnninja
Copy link
Collaborator Author

cdnninja commented May 4, 2023

It's a bit of a pain but can be done. I'll grab the link on instructions when I can.

I suspect the issue is related to line 289 of the api file. All times need a time zone or the comparison will fail to current time. Make sure the value coming from the api has a tz and is being parsed correctly to ensure python recognizes it.

@toraidl
Copy link
Contributor

toraidl commented May 5, 2023

image
It seems like correct?

The function get_last_updated_at(self, value) -> dt.datetime on line 210 returns the datetime format: 2023-05-04 14:47:58+08:00
whereas line 294 vehicle.last_updated_at = dt.datetime.now(self.data_timezone) return format like this: 2023-05-05 09:36:55.362564+08:00

@toraidl
Copy link
Contributor

toraidl commented May 5, 2023

I believe I have identified the problem and have submitted a PR to the API repository.
After testing it locally, it appears the issue has been resolved.
image

@cdnninja
Copy link
Collaborator Author

cdnninja commented May 5, 2023

@toraidl Thanks for all the work on this! I will merge this now.

@cdnninja cdnninja merged commit 64a687d into master May 5, 2023
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

Successfully merging this pull request may close these issues.

2 participants