core: Unable to add Tesla integration

The problem

When trying to add the new, fixed, Tesla integration I get: “Unknown error occurred”. I have removed the old Tesla integration and restarted HA, but still the same error.

What is version of Home Assistant Core has the issue?

core-2021.2.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

tesla

Link to integration documentation on our website

https://www.home-assistant.io/integrations/tesla/

Example YAML snippet

# Put your YAML below this line

Anything in the logs that might be useful for us?

# Put your logs below this line
Logger: aiohttp.server
Source: components/tesla/config_flow.py:157
First occurred: 3:31:47 PM (2 occurrences)
Last logged: 3:39:29 PM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
    resp = await self._request_handler(request)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py", line 499, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_middlewares.py", line 118, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 56, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 18, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 72, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 127, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 129, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 169, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 60, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 106, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 155, in async_configure
    result = await self._async_handle_step(flow, cur_step["step_id"], user_input)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 213, in _async_handle_step
    result: Dict = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/tesla/config_flow.py", line 57, in async_step_user
    info = await validate_input(self.hass, user_input)
  File "/usr/src/homeassistant/homeassistant/components/tesla/config_flow.py", line 157, in validate_input
    (config[CONF_TOKEN], config[CONF_ACCESS_TOKEN]) = await controller.connect(
  File "/usr/local/lib/python3.8/site-packages/teslajsonpy/controller.py", line 268, in connect
    cars = await self.get_vehicles()
  File "/usr/local/lib/python3.8/site-packages/backoff/_async.py", line 133, in retry
    ret = await target(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/teslajsonpy/controller.py", line 357, in get_vehicles
    return (await self.__connection.get("vehicles"))["response"]
  File "/usr/local/lib/python3.8/site-packages/teslajsonpy/connection.py", line 78, in get
    return await self.post(command, "get", None)
  File "/usr/local/lib/python3.8/site-packages/teslajsonpy/connection.py", line 96, in post
    self.code = await self.get_authorization_code(
  File "/usr/local/lib/python3.8/site-packages/teslajsonpy/connection.py", line 372, in get_authorization_code
    code_url = URL(resp.history[-1].url)
IndexError: tuple index out of range

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 9
  • Comments: 45 (8 by maintainers)

Most upvoted comments

FFS. You don’t need to comment in order to follow. And we know everyone has the same problem. I don’t need to receive an email every time someone realizes their integration doesn’t work.

Comments are for contributions to a solution. If you don’t have any new debug info. Use the subscribe button and the reaction emojis.

Custom component is out. I may have to change the name since it conflicts with core.

Use HACS to install. If you’re replacing core, you will need to remove your existing core integration and add the custom component. This will force a new login using the new method.

If you’re using my Alexa Media Player component, make sure you’ve signed in recently to AMP as the login will be broken in AMP until the next release.

I have a potential fix for MFA that needs testing by advanced users in the linked PR. If you cannot figure out how to apply it yourself safely, please consider waiting till it’s released. I will be fixing any bugs discovered but not to be too harsh, I won’t be responding to questions on how to apply it.

Yes, MFA is unsupported. Feel free to update the documentation to indicate that. I’m working on a separate fix but it may not arrive for a while.

The workaround others have been using is creating a separate account for HA to use itself without MFA. I’ll probably put in a short term fix to make it an appropriate error message.

There are 2 issues. One affects all auth and has been integrated into 2021.5 (https://github.com/home-assistant/core/pull/49939). The other affects only MFA and it looks like that won’t be integrated because of the web scraping. So, if you aren’t using MFA, things should be fixed with this month’s release.

AFAIK the workaround for authentication will not be accepted in HA Core. See https://github.com/home-assistant/core/pull/46558#issuecomment-822858608 So unless Tesla offers a public API will full support for 3rd party applications, you’ll need to keep using the custom component.

I rolled back to 2021.4.3 from 2021.4.6 via snapshot restore and the issue went away. Going to hang here for a bit.

I have a separate Tesla account I use for HA and 2fa is not enabled. My config has been solid since early January.

EDIT…take that back. It worked for a few minutes and then stopped working.

yeah I’m running CORE 2021.2.3 and the integration stopped working w/o any updates

+1 Core 2021.4.5 seeing this issue as well

Correct, we just merged in #49939 which will allow regular logins without MFA. However, MFA will not work unless you go to the custom component until someone implements it. I do not plan on doing that.

Is this going to be fixed in core as well? Or do we need to migrate to the custom component?

Custom component is out. I may have to change the name since it conflicts with core. Use HACS to install. If you’re replacing core, you will need to remove your existing core integration and add the custom component. This will force a new login using the new method. If you’re using my Alexa Media Player component, make sure you’ve signed in recently to AMP as the login will be broken in AMP until the next release.

Does it work with MFA also?

/Nicklas

Yes! Just set it up. Works like a charm.

Same problem overhere, will follow this thread for a solution

Yes, I am using 2FA. Maybe there should be a warning that the integration doesn’t work if you utilize 2FA.

I had the same issue after the .3 patch - disabled 2fA on my Tesla account and was able to add the integration no problem. fwiw and fyi.