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

Integration initialization fails when internet is not connected #1328

Closed
jondycz opened this issue Mar 10, 2023 · 4 comments
Closed

Integration initialization fails when internet is not connected #1328

jondycz opened this issue Mar 10, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@jondycz
Copy link

jondycz commented Mar 10, 2023

The problem

When internet is disconnected and Home Assistant is restarted or LocalTuya reloaded, devices paired with localtuya will be unavailable.

Environment

  • Localtuya version: v5.1.0
  • Home Assistant Core version: 2023.3.3

Steps to reproduce

  1. Unplug router from WAN
  2. Restart home assistant
  3. See unavailable devices

Provide Home Assistant traceback/logs

Logger: homeassistant.config_entries
Source: custom_components/localtuya/cloud_api.py:98
Integration: LocalTuya integration (documentation, issues)
First occurred: 12:24:01 (1 occurrences)
Last logged: 12:24:01

Error setting up entry localtuya for localtuya
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/connection.py", line 72, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/usr/local/lib/python3.10/socket.py", line 955, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Try again

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 1042, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 358, in connect
    self.sock = conn = self._new_conn()
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0xffff734c7fd0>: Failed to establish a new connection: [Errno -3] Try again

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 489, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openapi.tuyaeu.com', port=443): Max retries exceeded with url: /v1.0/token?grant_type=1 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0xffff734c7fd0>: Failed to establish a new connection: [Errno -3] Try again'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 383, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/config/custom_components/localtuya/__init__.py", line 255, in async_setup_entry
    res = await tuya_api.async_get_access_token()
  File "/config/custom_components/localtuya/cloud_api.py", line 104, in async_get_access_token
    resp = await self.async_make_request("GET", "/v1.0/token?grant_type=1")
  File "/config/custom_components/localtuya/cloud_api.py", line 98, in async_make_request
    resp = await self._hass.async_add_executor_job(func)
  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/requests/api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 565, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openapi.tuyaeu.com', port=443): Max retries exceeded with url: /v1.0/token?grant_type=1 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0xffff734c7fd0>: Failed to establish a new connection: [Errno -3] Try again'))


Logger: custom_components.hacs
Source: custom_components/hacs/repositories/base.py:517
Integration: HACS (documentation, issues)
First occurred: 12:25:42 (1 occurrences)
Last logged: 12:25:42

<Integration rospogrigio/localtuya> Cannot connect to host api.github.com:443 ssl:default [Try again]

Additional information

@jondycz jondycz added the bug Something isn't working label Mar 10, 2023
@sakibiqbal
Copy link

Thanks, @jondycz for reporting this. I have been facing the same issue a couple of times. I am waiting eagerly for the solution, as my involvement here is meant to be run in the offline environment most of the time.

@CodingEmil
Copy link

I am also having this issue. Have you ever figured it out? @jondycz

@Nealium Nealium mentioned this issue Jul 26, 2023
@Nealium
Copy link

Nealium commented Jul 26, 2023

I had this issue at 3am! I couldn't shut off the lights! I thought "well, this defeats the entire purpose!"

If you look at my pull's commits you can hotfix it yourself. It's not a big change at all.
The files are located in config/custom_components/localtuya, you can reach it with the normal File Editor add-on.

Note: you must restart your entire HomeAssitant instance for the code change to take effect.. or, so it seems.

@sabaatworld
Copy link

I'm currently using v5.2.1 and still appear to be having this issue.

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

5 participants