Cleanup webOS TV YAML import leftovers (#85957)

This commit is contained in:
Shay Levy 2023-01-15 20:07:15 +02:00 committed by GitHub
parent 3cb56211f8
commit 03d9d30eca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 51 deletions

View File

@ -90,10 +90,7 @@ class FlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
self.context["title_placeholders"] = {"name": self._name} self.context["title_placeholders"] = {"name": self._name}
errors = {} errors = {}
if ( if user_input is not None:
self.context["source"] == config_entries.SOURCE_IMPORT
or user_input is not None
):
try: try:
client = await async_control_connect(self._host, None) client = await async_control_connect(self._host, None)
except WebOsTvPairError: except WebOsTvPairError:

View File

@ -4,7 +4,6 @@ from unittest.mock import AsyncMock, Mock, patch
import pytest import pytest
from homeassistant.components.webostv.const import LIVE_TV_APP_ID from homeassistant.components.webostv.const import LIVE_TV_APP_ID
from homeassistant.helpers import entity_registry
from .const import CHANNEL_1, CHANNEL_2, CLIENT_KEY, FAKE_UUID, MOCK_APPS, MOCK_INPUTS from .const import CHANNEL_1, CHANNEL_2, CLIENT_KEY, FAKE_UUID, MOCK_APPS, MOCK_INPUTS
@ -48,28 +47,3 @@ def client_fixture():
client.mock_state_update = AsyncMock(side_effect=mock_state_update_callback) client.mock_state_update = AsyncMock(side_effect=mock_state_update_callback)
yield client yield client
@pytest.fixture(name="client_entity_removed")
def client_entity_removed_fixture(hass):
"""Patch of client library, entity removed waiting for connect."""
with patch(
"homeassistant.components.webostv.WebOsClient", autospec=True
) as mock_client_class:
client = mock_client_class.return_value
client.hello_info = {"deviceUUID": FAKE_UUID}
client.connected = False
def mock_is_connected():
return client.connected
client.is_connected = Mock(side_effect=mock_is_connected)
async def mock_connected():
ent_reg = entity_registry.async_get(hass)
ent_reg.async_remove("media_player.webostv_some_secret")
client.connected = True
client.connect = AsyncMock(side_effect=mock_connected)
yield client

View File

@ -7,8 +7,6 @@ TV_NAME = "fake_webos"
ENTITY_ID = f"{MP_DOMAIN}.{TV_NAME}" ENTITY_ID = f"{MP_DOMAIN}.{TV_NAME}"
HOST = "1.2.3.4" HOST = "1.2.3.4"
CLIENT_KEY = "some-secret" CLIENT_KEY = "some-secret"
MOCK_CLIENT_KEYS = {HOST: CLIENT_KEY}
MOCK_JSON = '{"1.2.3.4": "some-secret"}'
CHANNEL_1 = { CHANNEL_1 = {
"channelNumber": "1", "channelNumber": "1",

View File

@ -9,25 +9,15 @@ from homeassistant import config_entries
from homeassistant.components import ssdp from homeassistant.components import ssdp
from homeassistant.components.webostv.const import CONF_SOURCES, DOMAIN, LIVE_TV_APP_ID from homeassistant.components.webostv.const import CONF_SOURCES, DOMAIN, LIVE_TV_APP_ID
from homeassistant.config_entries import SOURCE_SSDP from homeassistant.config_entries import SOURCE_SSDP
from homeassistant.const import ( from homeassistant.const import CONF_HOST, CONF_NAME, CONF_SOURCE
CONF_CLIENT_SECRET,
CONF_HOST,
CONF_ICON,
CONF_NAME,
CONF_SOURCE,
CONF_UNIQUE_ID,
)
from homeassistant.data_entry_flow import FlowResultType from homeassistant.data_entry_flow import FlowResultType
from . import setup_webostv from . import setup_webostv
from .const import CLIENT_KEY, FAKE_UUID, HOST, MOCK_APPS, MOCK_INPUTS, TV_NAME from .const import FAKE_UUID, HOST, MOCK_APPS, MOCK_INPUTS, TV_NAME
MOCK_YAML_CONFIG = { MOCK_USER_CONFIG = {
CONF_HOST: HOST, CONF_HOST: HOST,
CONF_NAME: TV_NAME, CONF_NAME: TV_NAME,
CONF_ICON: "mdi:test",
CONF_CLIENT_SECRET: CLIENT_KEY,
CONF_UNIQUE_ID: FAKE_UUID,
} }
MOCK_DISCOVERY_INFO = ssdp.SsdpServiceInfo( MOCK_DISCOVERY_INFO = ssdp.SsdpServiceInfo(
@ -57,7 +47,7 @@ async def test_form(hass, client):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={CONF_SOURCE: config_entries.SOURCE_USER}, context={CONF_SOURCE: config_entries.SOURCE_USER},
data=MOCK_YAML_CONFIG, data=MOCK_USER_CONFIG,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -67,7 +57,7 @@ async def test_form(hass, client):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={CONF_SOURCE: config_entries.SOURCE_USER}, context={CONF_SOURCE: config_entries.SOURCE_USER},
data=MOCK_YAML_CONFIG, data=MOCK_USER_CONFIG,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -141,7 +131,7 @@ async def test_form_cannot_connect(hass, client):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={CONF_SOURCE: config_entries.SOURCE_USER}, context={CONF_SOURCE: config_entries.SOURCE_USER},
data=MOCK_YAML_CONFIG, data=MOCK_USER_CONFIG,
) )
client.connect = Mock(side_effect=ConnectionRefusedError()) client.connect = Mock(side_effect=ConnectionRefusedError())
@ -159,7 +149,7 @@ async def test_form_pairexception(hass, client):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={CONF_SOURCE: config_entries.SOURCE_USER}, context={CONF_SOURCE: config_entries.SOURCE_USER},
data=MOCK_YAML_CONFIG, data=MOCK_USER_CONFIG,
) )
client.connect = Mock(side_effect=WebOsTvPairError("error")) client.connect = Mock(side_effect=WebOsTvPairError("error"))
@ -180,7 +170,7 @@ async def test_entry_already_configured(hass, client):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={CONF_SOURCE: config_entries.SOURCE_USER}, context={CONF_SOURCE: config_entries.SOURCE_USER},
data=MOCK_YAML_CONFIG, data=MOCK_USER_CONFIG,
) )
assert result["type"] == FlowResultType.ABORT assert result["type"] == FlowResultType.ABORT
@ -208,7 +198,7 @@ async def test_ssdp_in_progress(hass, client):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={CONF_SOURCE: config_entries.SOURCE_USER}, context={CONF_SOURCE: config_entries.SOURCE_USER},
data=MOCK_YAML_CONFIG, data=MOCK_USER_CONFIG,
) )
await hass.async_block_till_done() await hass.async_block_till_done()