mirror of
https://github.com/home-assistant/core.git
synced 2025-08-09 15:45:08 +02:00
Handle ConnectionClosed in SamsungTV try_connect (#68125)
* Handle ConnectionClosed in SamsungTV try_connect * Add tests * Add quotes around the error message Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
@@ -374,6 +374,15 @@ class SamsungTVWSBridge(SamsungTVBridge):
|
|||||||
self.token = remote.token
|
self.token = remote.token
|
||||||
LOGGER.debug("Working config: %s", config)
|
LOGGER.debug("Working config: %s", config)
|
||||||
return RESULT_SUCCESS
|
return RESULT_SUCCESS
|
||||||
|
except ConnectionClosedError as err:
|
||||||
|
LOGGER.info(
|
||||||
|
"Working but unsupported config: %s, error: '%s'; this may "
|
||||||
|
"be an indication that access to the TV has been denied. Please "
|
||||||
|
"check the Device Connection Manager on your TV",
|
||||||
|
config,
|
||||||
|
err,
|
||||||
|
)
|
||||||
|
result = RESULT_NOT_SUPPORTED
|
||||||
except WebSocketException as err:
|
except WebSocketException as err:
|
||||||
LOGGER.debug(
|
LOGGER.debug(
|
||||||
"Working but unsupported config: %s, error: %s", config, err
|
"Working but unsupported config: %s, error: %s", config, err
|
||||||
|
@@ -6,7 +6,12 @@ import pytest
|
|||||||
from samsungctl.exceptions import AccessDenied, UnhandledResponse
|
from samsungctl.exceptions import AccessDenied, UnhandledResponse
|
||||||
from samsungtvws.async_remote import SamsungTVWSAsyncRemote
|
from samsungtvws.async_remote import SamsungTVWSAsyncRemote
|
||||||
from samsungtvws.exceptions import ConnectionFailure, HttpApiError
|
from samsungtvws.exceptions import ConnectionFailure, HttpApiError
|
||||||
from websockets.exceptions import WebSocketException, WebSocketProtocolError
|
from websockets import frames
|
||||||
|
from websockets.exceptions import (
|
||||||
|
ConnectionClosedError,
|
||||||
|
WebSocketException,
|
||||||
|
WebSocketProtocolError,
|
||||||
|
)
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components import dhcp, ssdp, zeroconf
|
from homeassistant.components import dhcp, ssdp, zeroconf
|
||||||
@@ -283,6 +288,26 @@ async def test_user_websocket_not_supported(hass: HomeAssistant) -> None:
|
|||||||
assert result["reason"] == RESULT_NOT_SUPPORTED
|
assert result["reason"] == RESULT_NOT_SUPPORTED
|
||||||
|
|
||||||
|
|
||||||
|
async def test_user_websocket_access_denied(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
|
"""Test starting a flow by user for not supported device."""
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.samsungtv.bridge.Remote",
|
||||||
|
side_effect=OSError("Boom"),
|
||||||
|
), patch(
|
||||||
|
"homeassistant.components.samsungtv.bridge.SamsungTVWSAsyncRemote.open",
|
||||||
|
side_effect=ConnectionClosedError(rcvd=None, sent=frames.Close(1002, "")),
|
||||||
|
):
|
||||||
|
# websocket device not supported
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_USER_DATA
|
||||||
|
)
|
||||||
|
assert result["type"] == "abort"
|
||||||
|
assert result["reason"] == RESULT_NOT_SUPPORTED
|
||||||
|
assert "Please check the Device Connection Manager on your TV" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
async def test_user_not_successful(hass: HomeAssistant) -> None:
|
async def test_user_not_successful(hass: HomeAssistant) -> None:
|
||||||
"""Test starting a flow by user but no connection found."""
|
"""Test starting a flow by user but no connection found."""
|
||||||
with patch(
|
with patch(
|
||||||
|
Reference in New Issue
Block a user