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.32k stars 30.62k forks source link

Upnp errors in SamsungTV integration #69980

Closed figorr closed 2 years ago

figorr commented 2 years ago

The problem

Several warnings and errors are shown in the log regarding to the Samsung integration when the Samsung TV is turned on.

What version of Home Assistant Core has the issue?

2022.4.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

Samsung Smart TV

Link to integration documentation on our website

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

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Error:

Logger: homeassistant.helpers.entity
Source: components/samsungtv/media_player.py:234 
First occurred: 15:08:00 (50 occurrences) 
Last logged: 15:16:10

Update for media_player.samsung_tv_salon fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/async_upnp_client/aiohttp.py", line 174, in _async_http_request
    async with self._session.request(
  File "/usr/local/lib/python3.9/site-packages/aiohttp/client.py", line 1138, in __aenter__
    self._resp = await self._coro
  File "/usr/local/lib/python3.9/site-packages/aiohttp/client.py", line 559, in _request
    await resp.start(conn)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 898, in start
    message, payload = await protocol.read()  # type: ignore[union-attr]
  File "/usr/local/lib/python3.9/site-packages/aiohttp/streams.py", line 616, in read
    await self._waiter
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/async_upnp_client/aiohttp.py", line 190, in _async_http_request
    resp_body_text = await response.text()
  File "/usr/local/lib/python3.9/site-packages/async_timeout/__init__.py", line 129, in __aexit__
    self._do_exit(exc_type)
  File "/usr/local/lib/python3.9/site-packages/async_timeout/__init__.py", line 212, in _do_exit
    raise asyncio.TimeoutError
asyncio.exceptions.TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 514, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 742, in async_device_update
    raise exc
  File "/usr/src/homeassistant/homeassistant/components/samsungtv/media_player.py", line 234, in async_update
    await asyncio.gather(*startup_tasks)
  File "/usr/local/lib/python3.9/site-packages/async_upnp_client/profiles/profile.py", line 355, in async_subscribe_services
    new_sid, timeout = await self._event_handler.async_subscribe(
  File "/usr/local/lib/python3.9/site-packages/async_upnp_client/event_handler.py", line 195, in async_subscribe
    response_status, response_headers, _ = await self._requester.async_http_request(
  File "/usr/local/lib/python3.9/site-packages/async_upnp_client/aiohttp.py", line 140, in async_http_request
    return await self._async_http_request(method, url, headers, body)
  File "/usr/local/lib/python3.9/site-packages/async_upnp_client/aiohttp.py", line 192, in _async_http_request
    raise UpnpConnectionTimeoutError(str(err)) from err
async_upnp_client.exceptions.UpnpConnectionTimeoutError: ('', None)

Warning:

Logger: async_upnp_client.profiles.profile
Source: /usr/local/lib/python3.9/site-packages/async_upnp_client/profiles/profile.py:363 
First occurred: 15:08:00 (50 occurrences) 
Last logged: 15:16:10

Failed subscribing to service: UpnpConnectionTimeoutError('', None)

Additional information

No response

probot-home-assistant[bot] commented 2 years ago

Hey there @chemelli74, @epenet, mind taking a look at this issue as it has been labeled with an integration (samsungtv) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)


samsungtv documentation samsungtv source (message by IssueLinks)

epenet commented 2 years ago

I wonder if maybe the TV starts responding (STATE = ON) before it's Upnp functionnality is ready.

Could you please enable logging, restart and provide full logs?

logger:
    default: info
    logs:
        homeassistant.components.samsungtv: debug
        samsungtvws: debug
figorr commented 2 years ago

Thank you for your quick answer.

Before seeing your answer I restarted the Samsung Smart TV integration and all the warnings & errors suddenly stopped.

Then I saw your answer and I applied the changes in the logger and restarted Home Assistant. No errors & warnings are being shown after the restart. I turned off the Samsung TV and then turned on it again ... but no errors are being shown.

The full log from the file "home-assistant.log" after the restart is:

home-assistant.log

epenet commented 2 years ago

If the error message is not present, then we need to wait for the message to re-appear, and then you can post the new log file.

figorr commented 2 years ago

The errors appeared again.

Here is the log.

home-assistant.log

epenet commented 2 years ago

Thanks, could you please add your diagnostics for the TV?

It seems strange that Upnp is failing, as it should only get enabled if a UPNP url was added to the integration.

I have created a PR #69984 but maybe there is a bigger root cause that still needs investigating.

figorr commented 2 years ago

Do you mean the diagnostics created by the integration?

This is the file.

config_entry-samsungtv-5b39d3e98a9004e014e6c544522dd065.json.txt

epenet commented 2 years ago

Thanks.

So it seems that Upnp was detected previously, but for some reason your TV is now rejecting the connection.

{
        "ssdp_rendering_control_location": "http://192.168.2.64:7676/smp_14_",
        "ssdp_main_tv_agent_location": "http://192.168.2.64:7676/smp_2_"
}

I have no idea why, but in any case it shouldn't be blocking the update so the PR is still valid.

figorr commented 2 years ago

No idea why it is rejecting the connection. The errors started to appear with the 2022.4,2 update. No errors with the 2022.4.1

I have a multimedia card and I can see the entity is shown as offline (Samsung TV SALON, multimedia card is grey). But the TV is ON.

If I press the ON button nothing happens. The TV is still offline ("Apagado").

Pictures 01 & 02

SAMSUNG_01

SAMSUNG_02

If I restart the SAMSUNG integration ... then the multimedia card is blue again and the entity is being shown as Online. And no more errors appeared in the log. I thing the restart of the integration it is shown at line 5465 of the log home-assistant.log

Pictures 03 & 04

SAMSUNG_03

SAMSUNG_04

Log file:

home-assistant.log