carohauta / oma-helen-ha-integration

Home Assistant integration for Oma Helen data
MIT License
37 stars 7 forks source link

Restarting home assistant breaks the integration #8

Closed davenojd closed 8 months ago

davenojd commented 1 year ago

Hei!

When I initially set this up it works fine, however if I reboot home assistant I get an error in the log to check my credentials, however if I log into oma helen portal myself before rebooting home assistant it works fine, am I missing something here or is this actually a bug? My home assistant instance gets rebooted semi often and I'll likely forget I need to log in to the portal, so I'd like to avoid that if possible 😅

Home Assistant 2023.7.2 Supervisor 2023.07.1 Operating System 10.3 Frontend 20230705.1 - latest

carohauta commented 1 year ago

Hi! Could you provide the full error message and stack trace? Does the integration recover on its own and fetch the data on the next update (after 3 hours)? It logs in every time it fetches data because the login token is valid only for one hour.

I suspect that it could be a timeout issue. I have encountered it sometimes during development when it is required to log in several times within a short timeframe.

davenojd commented 1 year ago

Okay, thanks after looking at the log it does indeed seem to be a timeout, I haven't seen it recover after this, but I will keep an eye on it to see if it might


Source: /usr/local/lib/python3.11/site-packages/helenservice/helen_session.py:29
First occurred: 12:04:13 (4 occurrences)
Last logged: 21:04:13

Login to Oma Helen failed. Check your credentials!
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
                       ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 1042, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.11/site-packages/urllib3/connection.py", line 456, in connect
    cert = self.sock.getpeercert()
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/ssl.py", line 1158, in getpeercert
    self._check_connected()
  File "/usr/local/lib/python3.11/ssl.py", line 1123, in _check_connected
    self.getpeername()
OSError: [Errno 107] Socket not connected

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/urllib3/util/retry.py", line 550, in increment
    raise six.reraise(type(error), error, _stacktrace)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/urllib3/packages/six.py", line 769, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
                       ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 1042, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.11/site-packages/urllib3/connection.py", line 456, in connect
    cert = self.sock.getpeercert()
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/ssl.py", line 1158, in getpeercert
    self._check_connected()
  File "/usr/local/lib/python3.11/ssl.py", line 1123, in _check_connected
    self.getpeername()
urllib3.exceptions.ProtocolError: ('Connection aborted.', OSError(107, 'Socket not connected'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/helenservice/helen_session.py", line 26, in login
    login_response = self._send_login_request(username, password)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/helenservice/helen_session.py", line 95, in _send_login_request
    authorization_response = self._make_url_request(
                             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/helenservice/helen_session.py", line 72, in _make_url_request
    response = self._session.send(prepared_request, timeout=HTTP_READ_TIMEOUT)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/requests/adapters.py", line 501, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', OSError(107, 'Socket not connected'))
davenojd commented 1 year ago

I had a chance to observe it yesterday/today, it timed out at 22:31 yesterday and continued to timeout every 3 hours after that. I just restarted home assistant now after manually logging into oma helen, to try and get yesterday's data in, which has worked. I don't know python at all so I can't really debug it further but would love to have this integration running if you have any thoughts/ideas that could help

carohauta commented 1 year ago

This seems to be a different exception and not the timeout one I have encountered. 107, 'Socket not connected' implies that the connection was never made and/or the client tried to read from a closed socket. This would normally be something network related but the fact that it works sometimes complicates things a bit.

I need to test it out with the same HA versions you have in use and try to figure it out.

carohauta commented 8 months ago

Could not reproduce with the most recent 2024 HA version