Remove config entry import from lg_netcast (#128179)

pull/128182/head
G Johansson 2024-10-11 18:20:50 +02:00 committed by GitHub
parent 6a12a24d73
commit 39e63aee0c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 3 additions and 163 deletions

View File

@ -18,10 +18,9 @@ from homeassistant.const import (
CONF_MODEL,
CONF_NAME,
)
from homeassistant.core import CALLBACK_TYPE, DOMAIN as HOMEASSISTANT_DOMAIN, callback
from homeassistant.core import CALLBACK_TYPE, callback
from homeassistant.data_entry_flow import AbortFlow
from homeassistant.helpers.event import async_track_time_interval
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.util.network import is_host_valid
from .const import DEFAULT_NAME, DOMAIN
@ -68,56 +67,6 @@ class LGNetCast(config_entries.ConfigFlow, domain=DOMAIN):
errors=errors,
)
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Import configuration from yaml."""
self.device_config = {
CONF_HOST: import_data[CONF_HOST],
CONF_NAME: import_data[CONF_NAME],
}
def _create_issue():
async_create_issue(
self.hass,
HOMEASSISTANT_DOMAIN,
f"deprecated_yaml_{DOMAIN}",
breaks_in_ha_version="2024.11.0",
is_fixable=False,
issue_domain=DOMAIN,
severity=IssueSeverity.WARNING,
translation_key="deprecated_yaml",
translation_placeholders={
"domain": DOMAIN,
"integration_title": "LG Netcast",
},
)
try:
result: ConfigFlowResult = await self.async_step_authorize(import_data)
except AbortFlow as err:
if err.reason != "already_configured":
async_create_issue(
self.hass,
DOMAIN,
"deprecated_yaml_import_issue_{err.reason}",
breaks_in_ha_version="2024.11.0",
is_fixable=False,
issue_domain=DOMAIN,
severity=IssueSeverity.WARNING,
translation_key=f"deprecated_yaml_import_issue_{err.reason}",
translation_placeholders={
"domain": DOMAIN,
"integration_title": "LG Netcast",
"error_type": err.reason,
},
)
else:
_create_issue()
raise
_create_issue()
return result
async def async_discover_client(self):
"""Handle Discovery step."""
self.create_client()

View File

@ -7,26 +7,20 @@ from typing import TYPE_CHECKING, Any
from pylgnetcast import LG_COMMAND, LgNetCastClient, LgNetCastError
from requests import RequestException
import voluptuous as vol
from homeassistant.components.media_player import (
PLATFORM_SCHEMA as MEDIA_PLAYER_PLATFORM_SCHEMA,
MediaPlayerDeviceClass,
MediaPlayerEntity,
MediaPlayerEntityFeature,
MediaPlayerState,
MediaType,
)
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_HOST, CONF_MODEL, CONF_NAME
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.exceptions import PlatformNotReady
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.trigger import PluggableAction
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from .const import ATTR_MANUFACTURER, DOMAIN
from .triggers.turn_on import async_get_turn_on_trigger
@ -49,15 +43,6 @@ SUPPORT_LGTV = (
| MediaPlayerEntityFeature.STOP
)
PLATFORM_SCHEMA = MEDIA_PLAYER_PLATFORM_SCHEMA.extend(
{
vol.Optional(CONF_ON_ACTION): cv.SCRIPT_SCHEMA,
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_ACCESS_TOKEN): vol.All(cv.string, vol.Length(max=6)),
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
}
)
async def async_setup_entry(
hass: HomeAssistant,
@ -79,27 +64,6 @@ async def async_setup_entry(
async_add_entities([LgTVDevice(client, name, model, unique_id=unique_id)])
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the LG TV platform."""
host = config.get(CONF_HOST)
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data=config
)
if (
result.get("type") == FlowResultType.ABORT
and result.get("reason") == "cannot_connect"
):
raise PlatformNotReady(f"Connection error while connecting to {host}")
class LgTVDevice(MediaPlayerEntity):
"""Representation of a LG TV."""

View File

@ -5,7 +5,7 @@ from unittest.mock import DEFAULT, patch
from homeassistant import data_entry_flow
from homeassistant.components.lg_netcast.const import DOMAIN
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import (
CONF_ACCESS_TOKEN,
CONF_HOST,
@ -24,8 +24,6 @@ from . import (
_patch_lg_netcast,
)
from tests.common import MockConfigEntry
async def test_show_form(hass: HomeAssistant) -> None:
"""Test that the form is served with no input."""
@ -146,77 +144,6 @@ async def test_invalid_session_id(hass: HomeAssistant) -> None:
assert result2["errors"]["base"] == "cannot_connect"
async def test_import(hass: HomeAssistant) -> None:
"""Test that the import works."""
with _patch_lg_netcast():
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={
CONF_HOST: IP_ADDRESS,
CONF_ACCESS_TOKEN: FAKE_PIN,
CONF_NAME: MODEL_NAME,
},
)
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
assert result["result"].unique_id == UNIQUE_ID
assert result["data"] == {
CONF_HOST: IP_ADDRESS,
CONF_ACCESS_TOKEN: FAKE_PIN,
CONF_NAME: MODEL_NAME,
CONF_MODEL: MODEL_NAME,
CONF_ID: UNIQUE_ID,
}
async def test_import_not_online(hass: HomeAssistant) -> None:
"""Test that the import works."""
with _patch_lg_netcast(fail_connection=True):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={
CONF_HOST: IP_ADDRESS,
CONF_ACCESS_TOKEN: FAKE_PIN,
CONF_NAME: MODEL_NAME,
},
)
assert result["type"] == data_entry_flow.FlowResultType.ABORT
assert result["reason"] == "cannot_connect"
async def test_import_duplicate_error(hass: HomeAssistant) -> None:
"""Test that errors are shown when duplicates are added during import."""
config_entry = MockConfigEntry(
domain=DOMAIN,
unique_id=UNIQUE_ID,
data={
CONF_HOST: IP_ADDRESS,
CONF_ACCESS_TOKEN: FAKE_PIN,
CONF_NAME: MODEL_NAME,
CONF_ID: UNIQUE_ID,
},
)
config_entry.add_to_hass(hass)
with _patch_lg_netcast():
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={
CONF_HOST: IP_ADDRESS,
CONF_ACCESS_TOKEN: FAKE_PIN,
CONF_NAME: MODEL_NAME,
CONF_ID: UNIQUE_ID,
},
)
assert result["type"] == data_entry_flow.FlowResultType.ABORT
assert result["reason"] == "already_configured"
async def test_display_access_token_aborted(hass: HomeAssistant) -> None:
"""Test Access token display is cancelled."""