widewing / ha-toyota-na

Home Assistant integration for Toyota Motor (North America) connected services
69 stars 12 forks source link

error fetching vehicle data #67

Open ch604 opened 5 months ago

ch604 commented 5 months ago

I was able to successfully log into the toyota service with the new updates to the authentication flow! No more workarounds! But, after connecting, I get the following error output when the app attempts to initialize:

2024-03-28 03:38:01.823 ERROR (MainThread) [custom_components.toyota_na] Error fetching data
Traceback (most recent call last):
File "/config/custom_components/toyota_na/__init__.py", line 104, in update_vehicles_status
raw_vehicles = await get_vehicles(client)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/toyota_na/vehicle/vehicle.py", line 36, in get_vehicles
await vehicle.update()
File "/usr/local/lib/python3.12/site-packages/toyota_na/vehicle/vehicle_generations/seventeen_cy_plus.py", line 77, in update
vehicle_status = await self._client.get_vehicle_status(self._vin)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/toyota_na/client.py", line 67, in get_vehicle_status
return await self.get_vehicle_status_17cyplus(vin)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/toyota_na/client.py", line 80, in get_vehicle_status_17cyplus
return await self.api_get("v1/global/remote/status", {"VIN": vin})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/toyota_na/client.py", line 41, in api_get
return await self.api_request("GET", endpoint, header_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/toyota_na/client.py", line 31, in api_request
resp.raise_for_status()
File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1060, in raise_for_status
raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 504, message='Gateway Timeout', url=URL('https://oneapi.telematicsct.com/v1/global/remote/status')

For kicks, I modified the toyota_na python package inside my hass docker container as described in #52 and generated a new set of tokens. when i poll using these tokens for get_user_vehicle_list, all info arrives normally:

...
    "fuelType": "B",
    "fleetInd": null,
    "svlStatus": false,
    "displayModelDescription": "2022 Toyota RAV4 HYBRID",
...
ch604 commented 5 months ago

i checked into the toyota_na code a bit and found that the app likely DID find my vehicle, but failed to get its status:

$:/usr/local/lib/python3.12/site-packages/toyota_na# python -m toyota_na.app get_user_vehicle_list | grep generation
/usr/local/lib/python3.12/site-packages/toyota_na/app.py:127: DeprecationWarning: There is no current event loop
  loop = asyncio.get_event_loop()
    "generation": "17CYPLUS",

this generation feeds into client.py:

async def get_vehicle_status_17cyplus(self, vin):                     
    return await self.api_get("v1/global/remote/status", {"VIN": vin})

even running this directly times out:

$:/usr/local/lib/python3.12/site-packages/toyota_na# python -m toyota_na.app get_vehicle_status XXXXXXXXXXX
...
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 504, message='Gateway Timeout', url=URL('https://oneapi.telematicsct.com/v1/global/remote/status')

so it sounds like another unfortunate double upstream issue of the undocumented toyota api. several documented calls work fine from command line, others do not.