Skip to content

Get vehicle_name from vehicle_state or set to VIN or ID when not available#599

Merged
ngardiner merged 1 commit intongardiner:mainfrom
RichieB2B:vehicle-name
Jan 9, 2025
Merged

Get vehicle_name from vehicle_state or set to VIN or ID when not available#599
ngardiner merged 1 commit intongardiner:mainfrom
RichieB2B:vehicle-name

Conversation

@RichieB2B
Copy link
Copy Markdown

I restarted TWCManager this morging and noticed these errors:

2024-12-27 22:24:57,318 - ⛽ Manager  20 BackgroundError: Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/TWCManager/Vehicle/TeslaAPI.py", line 1507, in update_vehicle_data
    (result, response) = self.get_car_api(url)
  File "/usr/local/lib/python3.9/dist-packages/TWCManager/Vehicle/TeslaAPI.py", line 1415, in get_car_api
    if checkReady and not self.ready():
  File "/usr/local/lib/python3.9/dist-packages/TWCManager/Vehicle/TeslaAPI.py", line 1394, in ready
    self.name + " not ready because it wasn't woken in the last 2 minutes.",
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

It seems in the Fleet API response for /api/1/vehicles display_name is now defined as null.

I made the code more robust so that self.name always is a string and it updates to the vehicle_name from vehicle_state when present.

@MikeBishop
Copy link
Copy Markdown
Collaborator

This looks like good improvement over #597. Yes, please.

@MikeBishop
Copy link
Copy Markdown
Collaborator

One thing that this doesn't completely fix -- not a blocker, but perhaps future work -- is that the display name appears to be collected from vehicle_data after the cached MQTT data has already come in, meaning that the correlation between MQTT data and vehicle remains broken. (Unless the vehicle's name actually changes, anyway.)

I think any fix here relies on noticing when a vehicle's name "changes":

  • We could simply restart the MQTT connection, expecting to get the current data delivered again and match the vehicle at that point. More annoying the more vehicles you have, though.
  • MQTT Fixes from Abstract #571 includes saving the MQTT data from unmatched vehicles and applying it once the display_name is known. We could re-match whenever an API vehicle's name "changes."

The second is a better long-term solution, but depends on being ready to merge the other MQTT work.

@RichieB2B
Copy link
Copy Markdown
Author

I think you are referring to MQTT data received from TeslaMate and db2d104 ? I don't use TeslaMate myself so I can't test this. I agree that acting on the change of vehicle_name is the way to fix it.

@ngardiner
Copy link
Copy Markdown
Owner

Agreed, let's merge this to avoid the exception, then follow up with MQTT vehicle name change logic - my preference would be to merge your MQTT fixes @MikeBishop and leverage that for vehicle name change support

@ngardiner ngardiner merged commit ce9e2f1 into ngardiner:main Jan 9, 2025
@RichieB2B RichieB2B deleted the vehicle-name branch January 9, 2025 12:12
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.

3 participants