Remove platform yaml Frontier Silicon (#93552)

This commit is contained in:
G Johansson 2023-05-26 08:24:08 +02:00 committed by GitHub
parent d852ba8b09
commit 3633062024
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 4 additions and 210 deletions

View File

@ -16,7 +16,7 @@ import voluptuous as vol
from homeassistant import config_entries
from homeassistant.components import ssdp
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT
from homeassistant.const import CONF_HOST, CONF_PORT
from homeassistant.data_entry_flow import FlowResult
from .const import (
@ -61,42 +61,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
_webfsapi_url: str
_reauth_entry: config_entries.ConfigEntry | None = None # Only used in reauth flows
async def async_step_import(self, import_info: dict[str, Any]) -> FlowResult:
"""Handle the import of legacy configuration.yaml entries."""
device_url = f"http://{import_info[CONF_HOST]}:{import_info[CONF_PORT]}/device"
try:
webfsapi_url = await AFSAPI.get_webfsapi_endpoint(device_url)
except FSConnectionError:
return self.async_abort(reason="cannot_connect")
except Exception as exception: # pylint: disable=broad-except
_LOGGER.exception(exception)
return self.async_abort(reason="unknown")
afsapi = AFSAPI(webfsapi_url, import_info[CONF_PIN])
try:
unique_id = await afsapi.get_radio_id()
except NotImplementedException:
unique_id = None # Not all radios have this call implemented
except FSConnectionError:
return self.async_abort(reason="cannot_connect")
except InvalidPinException:
return self.async_abort(reason="invalid_auth")
except Exception as exception: # pylint: disable=broad-except
_LOGGER.exception(exception)
return self.async_abort(reason="unknown")
await self.async_set_unique_id(unique_id, raise_on_progress=False)
self._abort_if_unique_id_configured()
return self.async_create_entry(
title=import_info[CONF_NAME] or "Radio",
data={
CONF_WEBFSAPI_URL: webfsapi_url,
CONF_PIN: import_info[CONF_PIN],
},
)
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:

View File

@ -10,10 +10,8 @@ from afsapi import (
NotImplementedException as FSNotImplementedException,
PlayState,
)
import voluptuous as vol
from homeassistant.components.media_player import (
PLATFORM_SCHEMA,
BrowseError,
BrowseMedia,
MediaPlayerEntity,
@ -21,62 +19,16 @@ from homeassistant.components.media_player import (
MediaPlayerState,
MediaType,
)
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_PORT
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers import issue_registry as ir
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from .browse_media import browse_node, browse_top_level
from .const import CONF_PIN, DEFAULT_PIN, DEFAULT_PORT, DOMAIN, MEDIA_CONTENT_ID_PRESET
from .const import DOMAIN, MEDIA_CONTENT_ID_PRESET
_LOGGER = logging.getLogger(__name__)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
vol.Optional(CONF_PASSWORD, default=DEFAULT_PIN): cv.string,
vol.Optional(CONF_NAME): cv.string,
}
)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the Frontier Silicon platform.
YAML is deprecated, and imported automatically.
"""
ir.async_create_issue(
hass,
DOMAIN,
"remove_yaml",
breaks_in_ha_version="2023.6.0",
is_fixable=False,
severity=ir.IssueSeverity.WARNING,
translation_key="removed_yaml",
)
await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={
CONF_NAME: config.get(CONF_NAME),
CONF_HOST: config.get(CONF_HOST),
CONF_PORT: config.get(CONF_PORT, DEFAULT_PORT),
CONF_PIN: config.get(CONF_PASSWORD, DEFAULT_PIN),
},
)
async def async_setup_entry(
hass: HomeAssistant,

View File

@ -30,11 +30,5 @@
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"unknown": "[%key:common::config_flow::error::unknown%]"
}
},
"issues": {
"removed_yaml": {
"title": "The Frontier Silicon YAML configuration has been removed",
"description": "Configuring Frontier Silicon using YAML has been removed.\n\nYour existing YAML configuration is not used by Home Assistant.\n\nRemove the YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue."
}
}
}

View File

@ -11,7 +11,7 @@ from homeassistant.components.frontier_silicon.const import (
DEFAULT_PIN,
DOMAIN,
)
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PIN, CONF_PORT
from homeassistant.const import CONF_HOST, CONF_PIN, CONF_PORT
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@ -37,122 +37,6 @@ INVALID_MOCK_DISCOVERY = ssdp.SsdpServiceInfo(
)
@pytest.mark.parametrize(
("radio_id_return_value", "radio_id_side_effect"),
[("mock_radio_id", None), (None, NotImplementedException)],
)
async def test_import_success(
hass: HomeAssistant,
radio_id_return_value: str | None,
radio_id_side_effect: Exception | None,
) -> None:
"""Test successful import."""
with patch(
"homeassistant.components.frontier_silicon.config_flow.AFSAPI.get_radio_id",
return_value=radio_id_return_value,
side_effect=radio_id_side_effect,
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data={
CONF_HOST: "1.1.1.1",
CONF_PORT: 80,
CONF_PIN: "1234",
CONF_NAME: "Test name",
},
)
assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["title"] == "Test name"
assert result["data"] == {
CONF_WEBFSAPI_URL: "http://1.1.1.1:80/webfsapi",
CONF_PIN: "1234",
}
@pytest.mark.parametrize(
("webfsapi_endpoint_error", "result_reason"),
[
(ConnectionError, "cannot_connect"),
(ValueError, "unknown"),
],
)
async def test_import_webfsapi_endpoint_failures(
hass: HomeAssistant, webfsapi_endpoint_error: Exception, result_reason: str
) -> None:
"""Test various failure of get_webfsapi_endpoint."""
with patch(
"homeassistant.components.frontier_silicon.config_flow.AFSAPI.get_webfsapi_endpoint",
side_effect=webfsapi_endpoint_error,
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data={
CONF_HOST: "1.1.1.1",
CONF_PORT: 80,
CONF_PIN: "1234",
CONF_NAME: "Test name",
},
)
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == result_reason
@pytest.mark.parametrize(
("radio_id_error", "result_reason"),
[
(ConnectionError, "cannot_connect"),
(InvalidPinException, "invalid_auth"),
(ValueError, "unknown"),
],
)
async def test_import_radio_id_failures(
hass: HomeAssistant, radio_id_error: Exception, result_reason: str
) -> None:
"""Test various failure of get_radio_id."""
with patch(
"homeassistant.components.frontier_silicon.config_flow.AFSAPI.get_radio_id",
side_effect=radio_id_error,
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data={
CONF_HOST: "1.1.1.1",
CONF_PORT: 80,
CONF_PIN: "1234",
CONF_NAME: "Test name",
},
)
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == result_reason
async def test_import_already_exists(
hass: HomeAssistant, config_entry: MockConfigEntry
) -> None:
"""Test import of device which already exists."""
config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data={
CONF_HOST: "1.1.1.1",
CONF_PORT: 80,
CONF_PIN: "1234",
CONF_NAME: "Test name",
},
)
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "already_configured"
@pytest.mark.parametrize(
("radio_id_return_value", "radio_id_side_effect"),
[("mock_radio_id", None), (None, NotImplementedException)],