planbnet / livisi_unofficial

Unofficial fork of the home assistant livisi integration without dependencies on the abandoned aiolivisi lib
Apache License 2.0
36 stars 5 forks source link

Server disconnected #19

Closed DanielHabenicht closed 1 year ago

DanielHabenicht commented 1 year ago

System Health details

System Information

version core-2023.8.2
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.11.4
os_name Linux
os_version 6.1.21-v8
arch aarch64
timezone Europe/Berlin
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 4937 Installed Version | 1.32.1 Stage | running Available Repositories | 1339 Downloaded Repositories | 4
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Home Assistant OS 10.4 -- | -- update_channel | stable supervisor_version | supervisor-2023.08.1 agent_version | 1.5.1 docker_version | 23.0.6 disk_total | 116.7 GB disk_used | 19.5 GB healthy | true supported | true board | rpi4-64 supervisor_api | ok version_api | ok installed_addons | Let's Encrypt (4.12.9), NGINX Home Assistant SSL proxy (3.5.0), File editor (5.6.0), Terminal & SSH (9.7.1), Home Assistant Google Drive Backup (0.111.1), Mosquitto broker (6.2.1), deCONZ (6.20.0), AppDaemon (0.13.4), Studio Code Server (5.10.1), InfluxDB (4.7.0), ESPHome (2023.8.2), Grafana (9.0.3), MQTT Explorer (browser-1.0.1)
Dashboards dashboards | 2 -- | -- resources | 0 views | 1 mode | storage
Recorder oldest_recorder_run | August 19, 2023 at 02:03 -- | -- current_recorder_run | August 28, 2023 at 04:03 estimated_db_size | 241.11 MiB database_engine | sqlite database_version | 3.41.2

Checklist

Describe the issue

For me, the integration fails to initialize because the server (Zentrale 1.Generation, Version 1.914 - 3.1.1088.0). Seems to disconnect on the second request.

I already tried to debug but wanted to ask if you already encountered the same problem, or if you can reproduce it?

While debugging it is showing me that the second request is failing:

  1. http://192.168.178.141:8080/auth/token works
  2. http://192.168.178.141:8080/status does not

Interestingly, if I have some debug points enabled and there is some time between the requests it is more likely to not break up. However, it does not seem to be a time-related problem as the custom script I wrote to find out if it is timing-related works just fine (without any wait between the API calls).

The official integration also works fine.

Reproduction steps

  1. Install Integration according to readme.
  2. Try to log in with the proper credentials.

Debug logs

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 148, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 181, in post
    return await super().post(request, flow_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper
    result = await method(view, request, data, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 296, in async_configure
    result = await self._async_handle_step(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 392, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/livisi/config_flow.py", line 59, in async_step_user
    controller_info = await self.aio_livisi.async_get_controller()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/livisi/aiolivisi.py", line 143, in async_get_controller
    return await self.async_get_controller_status()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/livisi/aiolivisi.py", line 147, in async_get_controller_status
    shc_info = await self.async_send_authorized_request("get", url="status")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/livisi/aiolivisi.py", line 83, in async_send_authorized_request
    return await self.async_send_request(method, path, payload, self._auth_headers)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/livisi/aiolivisi.py", line 116, in async_send_request
    response = await self.__async_send_request(method, url, payload, headers)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/livisi/aiolivisi.py", line 130, in __async_send_request
    async with self._web_session.request(
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 1141, in __aenter__
    self._resp = await self._coro
                 ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 560, in _request
    await resp.start(conn)
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 899, in start
    message, payload = await protocol.read()  # type: ignore[union-attr]
                       ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/streams.py", line 616, in read
    await self._waiter
aiohttp.client_exceptions.ServerDisconnectedError: Server disconnected


### Diagnostics dump

_No response_
DanielHabenicht commented 1 year ago

Not getting further with debugging I compared your library with the official one and it seems like they have a try...catch statement to retry a failed request once and it seems like it is really needed: image

planbnet commented 1 year ago

Well, I removed this to fix the problem with reauthentification. At least now I know why it was in there. I can only guess that this is required for the v1 shc but breaks for v2.