mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Remove obsolete compatibility code from SamsungTV (#144800)
This commit is contained in:
parent
3e07f6543e
commit
b0fb16d48d
@ -21,26 +21,19 @@ from homeassistant.const import (
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import Event, HomeAssistant, callback
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.helpers.debounce import Debouncer
|
||||
|
||||
from .bridge import (
|
||||
SamsungTVBridge,
|
||||
async_get_device_info,
|
||||
mac_from_device_info,
|
||||
model_requires_encryption,
|
||||
)
|
||||
from .bridge import SamsungTVBridge, mac_from_device_info, model_requires_encryption
|
||||
from .const import (
|
||||
CONF_SESSION_ID,
|
||||
CONF_SSDP_MAIN_TV_AGENT_LOCATION,
|
||||
CONF_SSDP_RENDERING_CONTROL_LOCATION,
|
||||
DOMAIN,
|
||||
ENTRY_RELOAD_COOLDOWN,
|
||||
LEGACY_PORT,
|
||||
LOGGER,
|
||||
METHOD_ENCRYPTED_WEBSOCKET,
|
||||
METHOD_LEGACY,
|
||||
UPNP_SVC_MAIN_TV_AGENT,
|
||||
UPNP_SVC_RENDERING_CONTROL,
|
||||
)
|
||||
@ -180,30 +173,10 @@ async def _async_create_bridge_with_updated_data(
|
||||
"""Create a bridge object and update any missing data in the config entry."""
|
||||
updated_data: dict[str, str | int] = {}
|
||||
host: str = entry.data[CONF_HOST]
|
||||
port: int | None = entry.data.get(CONF_PORT)
|
||||
method: str | None = entry.data.get(CONF_METHOD)
|
||||
method: str = entry.data[CONF_METHOD]
|
||||
load_info_attempted = False
|
||||
info: dict[str, Any] | None = None
|
||||
|
||||
if not port or not method:
|
||||
LOGGER.debug("Attempting to get port or method for %s", host)
|
||||
if method == METHOD_LEGACY:
|
||||
port = LEGACY_PORT
|
||||
else:
|
||||
# When we imported from yaml we didn't setup the method
|
||||
# because we didn't know it
|
||||
_result, port, method, info = await async_get_device_info(hass, host)
|
||||
load_info_attempted = True
|
||||
if not port or not method:
|
||||
raise ConfigEntryNotReady(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="failed_to_determine_connection_method",
|
||||
)
|
||||
|
||||
LOGGER.debug("Updated port to %s and method to %s for %s", port, method, host)
|
||||
updated_data[CONF_PORT] = port
|
||||
updated_data[CONF_METHOD] = method
|
||||
|
||||
bridge = _async_get_device_bridge(hass, {**entry.data, **updated_data})
|
||||
|
||||
mac: str | None = entry.data.get(CONF_MAC)
|
||||
|
@ -1,6 +1,5 @@
|
||||
"""Tests for the Samsung TV Integration."""
|
||||
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
@ -16,8 +15,6 @@ from homeassistant.components.samsungtv.const import (
|
||||
CONF_SSDP_MAIN_TV_AGENT_LOCATION,
|
||||
CONF_SSDP_RENDERING_CONTROL_LOCATION,
|
||||
DOMAIN,
|
||||
LEGACY_PORT,
|
||||
METHOD_LEGACY,
|
||||
METHOD_WEBSOCKET,
|
||||
UPNP_SVC_MAIN_TV_AGENT,
|
||||
UPNP_SVC_RENDERING_CONTROL,
|
||||
@ -53,6 +50,7 @@ MOCK_CONFIG = {
|
||||
CONF_HOST: "fake_host",
|
||||
CONF_NAME: "fake_name",
|
||||
CONF_METHOD: METHOD_WEBSOCKET,
|
||||
CONF_PORT: 8001,
|
||||
}
|
||||
|
||||
|
||||
@ -78,42 +76,6 @@ async def test_setup(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
|
||||
async def test_setup_without_port_device_offline(hass: HomeAssistant) -> None:
|
||||
"""Test import from yaml when the device is offline."""
|
||||
with (
|
||||
patch("homeassistant.components.samsungtv.bridge.Remote", side_effect=OSError),
|
||||
patch(
|
||||
"homeassistant.components.samsungtv.bridge.SamsungTVEncryptedWSAsyncRemote.start_listening",
|
||||
side_effect=OSError,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.samsungtv.bridge.SamsungTVWSAsyncRemote.open",
|
||||
side_effect=OSError,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.samsungtv.bridge.SamsungTVWSBridge.async_device_info",
|
||||
return_value=None,
|
||||
),
|
||||
):
|
||||
await setup_samsungtv_entry(hass, MOCK_CONFIG)
|
||||
|
||||
config_entries_domain = hass.config_entries.async_entries(DOMAIN)
|
||||
assert len(config_entries_domain) == 1
|
||||
assert config_entries_domain[0].state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"remote_websocket", "remote_encrypted_websocket_failing", "rest_api"
|
||||
)
|
||||
async def test_setup_without_port_device_online(hass: HomeAssistant) -> None:
|
||||
"""Test import from yaml when the device is online."""
|
||||
await setup_samsungtv_entry(hass, MOCK_CONFIG)
|
||||
|
||||
config_entries_domain = hass.config_entries.async_entries(DOMAIN)
|
||||
assert len(config_entries_domain) == 1
|
||||
assert config_entries_domain[0].data[CONF_MAC] == "aa:bb:aa:aa:aa:aa"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remote_websocket", "remote_encrypted_websocket_failing")
|
||||
async def test_setup_h_j_model(
|
||||
hass: HomeAssistant, rest_api: Mock, caplog: pytest.LogCaptureFixture
|
||||
@ -182,29 +144,6 @@ async def test_reauth_triggered_encrypted(hass: HomeAssistant) -> None:
|
||||
assert len(flows_in_progress) == 1
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"remote_legacy", "remote_encrypted_websocket_failing", "rest_api_failing"
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"entry_data",
|
||||
[
|
||||
{CONF_HOST: "1.2.3.4"}, # Missing port/method
|
||||
{CONF_HOST: "1.2.3.4", CONF_PORT: LEGACY_PORT}, # Missing method
|
||||
{CONF_HOST: "1.2.3.4", CONF_METHOD: METHOD_LEGACY}, # Missing port
|
||||
],
|
||||
)
|
||||
async def test_update_imported_legacy(
|
||||
hass: HomeAssistant, entry_data: dict[str, Any]
|
||||
) -> None:
|
||||
"""Test updating an imported legacy entry."""
|
||||
await setup_samsungtv_entry(hass, entry_data)
|
||||
|
||||
entries = hass.config_entries.async_entries(DOMAIN)
|
||||
assert len(entries) == 1
|
||||
assert entries[0].data[CONF_METHOD] == METHOD_LEGACY
|
||||
assert entries[0].data[CONF_PORT] == LEGACY_PORT
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remote_websocket", "rest_api")
|
||||
async def test_incorrectly_formatted_mac_fixed(hass: HomeAssistant) -> None:
|
||||
"""Test incorrectly formatted mac is corrected."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user