home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.68k stars 30.81k forks source link

Linkplay, cannot set up Wiim Pro Plus - `AttributeError: '_io.TextIOWrapper' object has no attribute 'delete'` #126904

Closed ireun closed 1 month ago

ireun commented 1 month ago

The problem

image Look at stack trace

What version of Home Assistant Core has the issue?

core-2024.9.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

linkplay

Link to integration documentation on our website

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

Diagnostics information

Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/discovery_flow.py", line 108, in _async_start
    await gather_with_limited_concurrency(FLOW_INIT_LIMIT, *init_coros)
  File "/usr/src/homeassistant/homeassistant/util/async_.py", line 114, in gather_with_limited_concurrency
    return await gather(
           ^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/async_.py", line 112, in sem_task
    return await task
           ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1296, in async_init
    flow, result = await self._async_init(flow_id, handler, context, data)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1331, in _async_init
    result = await self._async_handle_step(flow, flow.init_step, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 516, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/linkplay/config_flow.py", line 34, in async_step_zeroconf
    session: ClientSession = await async_get_client_session(self.hass)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/linkplay/utils.py", line 61, in async_get_client_session
    clientsession: ClientSession = await async_create_unverified_client_session()
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/linkplay/utils.py", line 200, in async_create_unverified_client_session
    context: ssl.SSLContext = await async_create_unverified_context()
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/linkplay/utils.py", line 147, in async_create_unverified_context
    async with aiofiles.tempfile.NamedTemporaryFile(
  File "/usr/local/lib/python3.12/site-packages/aiofiles/base.py", line 78, in __aenter__
    self._obj = await self._coro
                ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiofiles/tempfile/__init__.py", line 177, in _temporary_file
    result.delete = f.delete
                    ^^^^^^^^
  File "/usr/local/lib/python3.12/tempfile.py", line 494, in __getattr__
    a = getattr(file, name)
        ^^^^^^^^^^^^^^^^^^^
AttributeError: '_io.TextIOWrapper' object has no attribute 'delete'

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 month ago

Hey there @velleman, mind taking a look at this issue as it has been labeled with an integration (linkplay) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `linkplay` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign linkplay` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


linkplay documentation linkplay source (message by IssueLinks)

sin7ek commented 1 month ago

In addition, I have the same experience with my WiiM Ultra. It says: 'Unable to connect'.

image

silamon commented 1 month ago

It points to aiofiles in the stacktrace, which somehow doesn't run the latest version of that dependency in your setup. It may be a custom integration that is causing this. Could you find out which version is running in your setup?

sin7ek commented 1 month ago

My HA also auto detects my WiiM after upgrading to 2024.9.3 (Core).

silamon commented 1 month ago

Do you have the same issue as the other person?

rdzakson commented 1 month ago

I am experiencing the same issue. Devices are on the network. Adding by IP causes this error. Devices is "pingable" from within HOAS terminal and IPs are static. Devices otherwise work perfectly (e.g spotify, linkplay app, etc) and are recognised as DLNA renderers.

I have no additional related integrations, although I have tried them, then removed. If there are any leftovers - how to identify them? Officially there is absolutely nothing in integrations / addons / HACS.

Core: 2024.10.1 Supervisor: 2024.09.1 Operating System: 13.1

Logger: aiohttp.server
Source: /usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py:448
First occurred: 11:47:55 (1 occurrences)
Last logged: 11:47:55

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 477, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 559, in _handle
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/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 92, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 210, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 85, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 81, in with_admin
    return await func(self, request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 222, in post
    return await super().post(request, flow_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 74, in wrapper
    return await method(view, request, data, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 370, in async_configure
    result = await self._async_configure(flow_id, user_input)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 417, in _async_configure
    result = await self._async_handle_step(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 520, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/linkplay/config_flow.py", line 80, in async_step_user
    session: ClientSession = await async_get_client_session(self.hass)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/linkplay/utils.py", line 61, in async_get_client_session
    clientsession: ClientSession = await async_create_unverified_client_session()
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/linkplay/utils.py", line 200, in async_create_unverified_client_session
    context: ssl.SSLContext = await async_create_unverified_context()
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/linkplay/utils.py", line 147, in async_create_unverified_context
    async with aiofiles.tempfile.NamedTemporaryFile(
  File "/usr/local/lib/python3.12/site-packages/aiofiles/base.py", line 78, in __aenter__
    self._obj = await self._coro
                ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiofiles/tempfile/__init__.py", line 177, in _temporary_file
    result.delete = f.delete
                    ^^^^^^^^
  File "/usr/local/lib/python3.12/tempfile.py", line 494, in __getattr__
    a = getattr(file, name)
        ^^^^^^^^^^^^^^^^^^^
AttributeError: '_io.TextIOWrapper' object has no attribute 'delete'
ireun commented 1 month ago

Could you find out which version is running in your setup?

homeassistant:/config# pip freeze | grep aiofiles
aiofiles==24.1.0

seems to be the newest one.. Hmm could it be that it didn't worked because I've disabled the "DLNA integration" ?

rdzakson commented 1 month ago
~ # ha core info
arch: amd64
audio_input: null
audio_output: null
backups_exclude_database: false
boot: true
image: ghcr.io/home-assistant/qemux86-64-homeassistant
ip_address: 172.30.32.1
machine: qemux86-64
port: 8123
ssl: false
update_available: false
version: 2024.10.1
version_latest: 2024.10.1
watchdog: true

~ # docker ps
CONTAINER ID   IMAGE                                                       COMMAND               CREATED          STATUS                  PORTS                                   NAMES
a4dd0dadba6a   ghcr.io/hassio-addons/ssh/amd64:19.0.0                      "/init"               51 minutes ago   Up 51 minutes                                                   addon_a0d7b954_ssh
7564fe80ff1a   homeassistant/amd64-addon-samba:12.3.2                      "/init"               26 hours ago     Up 26 hours (healthy)                                           addon_core_samba
ec98849b328d   ghcr.io/hassio-addons/grafana/amd64:10.1.1                  "/init"               26 hours ago     Up 26 hours (healthy)                                           addon_a0d7b954_grafana
85c97fdcbd78   ghcr.io/hassio-addons/tailscale/amd64:0.22.1                "/init"               26 hours ago     Up 26 hours                                                     addon_a0d7b954_tailscale
661a3d33b5d9   ghcr.io/hassio-addons/vscode/amd64:5.17.0                   "/init"               26 hours ago     Up 26 hours (healthy)                                           addon_a0d7b954_vscode
1a3ad8e7832c   ghcr.io/home-assistant/amd64-hassio-multicast:2024.03.0     "/init"               26 hours ago     Up 26 hours                                                     hassio_multicast
69ff98f3ad3a   ghcr.io/home-assistant/amd64-hassio-audio:2023.12.0         "/init"               26 hours ago     Up 26 hours                                                     hassio_audio
4d0b1aa67810   ghcr.io/home-assistant/amd64-hassio-dns:2024.04.0           "/init"               26 hours ago     Up 26 hours                                                     hassio_dns
c59fd275c5bc   ghcr.io/home-assistant/amd64-hassio-cli:2024.09.0           "/init"               26 hours ago     Up 26 hours                                                     hassio_cli
3d37ca219864   ghcr.io/home-assistant/qemux86-64-homeassistant:2024.10.1   "/init"               36 hours ago     Up 26 hours                                                     homeassistant
51a89a06a203   ghcr.io/home-assistant/amd64-hassio-supervisor:latest       "/init"               3 weeks ago      Up 26 hours                                                     hassio_supervisor
b2095f17dbab   ghcr.io/home-assistant/amd64-hassio-observer:2023.06.0      "/usr/bin/observer"   4 weeks ago      Up 26 hours             0.0.0.0:4357->80/tcp, :::4357->80/tcp   hassio_observer

~ # docker exec -it 3d37ca219864 /bin/bash
homeassistant:/config# ls /usr/local/lib/python3.12/site-packages/aiofiles*
/usr/local/lib/python3.12/site-packages/aiofiles:
__init__.py  __pycache__  base.py      os.py        ospath.py    tempfile     threadpool

/usr/local/lib/python3.12/site-packages/aiofiles-0.8.0.dist-info:
INSTALLER  LICENSE    METADATA   RECORD     REQUESTED  WHEEL

homeassistant:/config# pip freeze | grep aiofiles
aiofiles==0.8.0
silamon commented 1 month ago

Version v24.1.0 is the latest one. I see you've already upgrade Home Assistant since the initial post, have you retried adding?

Version v0.8.0 is outdated. I'm still not sure what or how that is being caused to happen.

ireun commented 1 month ago

I have removed all unused custom integrations, than I've updated HA, and enabled DLNA integration, LinkPlay seems to be working now

rdzakson commented 1 month ago

@silamon sorry, I'm not sure who are you replying to. It seems @ireun issue is gone. I'm aware I am piggibacking on existing bur report instead of logging a new one, but I thought it's better this way :) So I added as much info as possible. My issue is still there. Not sure how can I update anything more if my version is of core is the latest, but the aiofiles are old (0.0.8), and I don't see this dependency explicitly listed anywhere (I may be wrong, I'm not familiar with this project). Not sure if this library is version is indeed the reason for this bug. Any advice appreciated.

silamon commented 1 month ago

I've went through a lot of old issues and found one custom integration (https://github.com/UI-Lovelace-Minimalist/UI) forcing that dependency to exactly v0.8.0. You've already mentioned you don't have any custom integrations installed, but I can suggest to double check just to be sure. If you run docker exec -it 3d37ca219864 /bin/bash again and then check folder contents of /config/custom_components, it should be empty. Honestly, I think you can do pip install aiofiles==24.1.0 and it may be solved as well in your installation, but I'm not sure about that.

I'm getting diagnostics added to the integration to help getting issues like this faster solved.

ireun commented 1 month ago

custom integration (https://github.com/UI-Lovelace-Minimalist/UI)

^^^ I can tell you that this custom integration was one of integrations that I have uninstalled, after that it seems that LinkPlay integration finally worked.

rdzakson commented 1 month ago

Ha! "I have no additional related integrations, although I have tried them, then removed." is what I said, but I do have this very integration. I would never think it may be related! Perfect find! Thank you. Let me get rid of it now!

rdzakson commented 1 month ago

OK, removed, rebuilding code (can't update), as the restart didn't solve the problem after removal. Finger crossed. Yes, I do wonder how dependency resolution works here and if it could be better enforced, especially on the core.

rdzakson commented 1 month ago

Reporting success after rebuild! Thank you!

ireun commented 1 month ago

I will close this issue now.

For future reference: The issue was that I had UI-Lovelace-Minimalist custom integration installed though HACS, try uninstalling it :)

silamon commented 1 month ago

I've opened a PR to add it to the package constraints. Thank you both for digging into your installation to find the root cause.