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

Exception in error handling in charge port controls #30

Closed
3 tasks done
zzarne opened this issue Feb 13, 2024 · 4 comments
Closed
3 tasks done

Exception in error handling in charge port controls #30

zzarne opened this issue Feb 13, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@zzarne
Copy link
Contributor

zzarne commented Feb 13, 2024

Checklist

  • I have filled out the issue template to the best of my ability.
  • This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • This issue is not a duplicate issue of any previous issues..

Describe the issue

This may be an issue in the fleet api library. When an error is returned, the response is not JSON but text. The variable "result" then is of type string instead of dict, resulting in exceptions. Probably affects more entities like trunk or maybe all error handling.

With the reproduction steps, the error is "car could not execute command: already closed". Showing an error here is fine as the entity's state is still changing. The issue is that not the above error message is shown to the user, but "[...]string indices must be integers, not 'str'".

Reproduction steps

  1. Click open charge port
  2. Quickly(!) click close charge port

Debug logs

2024-02-13 14:01:23.595 DEBUG (MainThread) [tesla_fleet_api] Sending request to api/1/vehicles/VVVVVVVVVVVVVVVVV/command/charge_port_door_open
2024-02-13 14:01:25.695 DEBUG (MainThread) [tesla_fleet_api] Response Status: 200
2024-02-13 14:01:25.695 DEBUG (MainThread) [tesla_fleet_api] Response JSON: {'response': {'result': True, 'reason': ''}}
2024-02-13 14:01:25.696 DEBUG (MainThread) [custom_components.teslemetry] Command result: {'response': {'result': True, 'reason': ''}}

2024-02-13 14:01:26.045 DEBUG (MainThread) [tesla_fleet_api] Sending request to api/1/vehicles/VVVVVVVVVVVVVVVVV/command/charge_port_door_close
2024-02-13 14:01:26.564 DEBUG (MainThread) [tesla_fleet_api] Response Status: 200
2024-02-13 14:01:26.564 DEBUG (MainThread) [tesla_fleet_api] Response Text: {"response":{"result":false,"string":"car could not execute command: already closed"},"error":"","error_description":""}

2024-02-13 14:01:26.565 DEBUG (MainThread) [custom_components.teslemetry] Command result: {"response":{"result":false,"string":"car could not execute command: already closed"},"error":"","error_description":""}

2024-02-13 14:01:26.565 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [CCCCCCCCCCCCCCC] string indices must be integers, not 'str'
Traceback (most recent call last):
  File "/home/hass/.local/lib/python3.12/site-packages/homeassistant/components/websocket_api/commands.py", line 240, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hass/.local/lib/python3.12/site-packages/homeassistant/core.py", line 2279, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/home/hass/.local/lib/python3.12/site-packages/homeassistant/core.py", line 2316, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hass/.local/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 892, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hass/.local/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 962, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/home/hass/.homeassistant/custom_components/teslemetry/cover.py", line 124, in async_close_cover
    await self.handle_command(self.api.charge_port_door_close())
  File "/home/hass/.homeassistant/custom_components/teslemetry/entity.py", line 138, in handle_command
    if not result["response"]["result"]:
           ~~~~~~^^^^^^^^^^^^
TypeError: string indices must be integers, not 'str'

2024-02-13 14:01:30.617 DEBUG (MainThread) [tesla_fleet_api] Sending request to api/1/vehicles/VVVVVVVVVVVVVVVVV/command/charge_port_door_close
2024-02-13 14:01:31.139 DEBUG (MainThread) [tesla_fleet_api] Response Status: 200
2024-02-13 14:01:31.140 DEBUG (MainThread) [tesla_fleet_api] Response JSON: {'response': {'result': True, 'reason': ''}}
2024-02-13 14:01:31.140 DEBUG (MainThread) [custom_components.teslemetry] Command result: {'response': {'result': True, 'reason': ''}}
@zzarne zzarne mentioned this issue Feb 13, 2024
3 tasks
@Bre77
Copy link
Contributor

Bre77 commented Feb 13, 2024

Ok I can see the issue here... Unfortunately it looks to be Tesla's fault, but I should be able to address it.

@Bre77
Copy link
Contributor

Bre77 commented Feb 13, 2024

Alright, I think all of your issues are related to the Tesla Command Proxy, as it does not have the same types of responses as the Fleet API directly. I'll have to add some custom code for this server side.

@Bre77 Bre77 added the bug Something isn't working label Feb 13, 2024
@Bre77 Bre77 self-assigned this Feb 13, 2024
@Bre77
Copy link
Contributor

Bre77 commented Feb 13, 2024

A backend change was pushed to fix this in theory, please test and let me know.

@zzarne
Copy link
Contributor Author

zzarne commented Feb 14, 2024

Lovelace now alerts me with "[...]cover/close_cover. Validation error: already closed", as it should. I say it's fixed.

@zzarne zzarne closed this as completed May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants