Skip to content

Commit

Permalink
Remove platform yaml Frontier Silicon (#93552)
Browse files Browse the repository at this point in the history
  • Loading branch information
gjohansson-ST committed May 26, 2023
1 parent d852ba8 commit 3633062
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 210 deletions.
38 changes: 1 addition & 37 deletions homeassistant/components/frontier_silicon/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

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 (
Expand Down Expand Up @@ -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:
Expand Down
52 changes: 2 additions & 50 deletions homeassistant/components/frontier_silicon/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,73 +10,25 @@
NotImplementedException as FSNotImplementedException,
PlayState,
)
import voluptuous as vol

from homeassistant.components.media_player import (
PLATFORM_SCHEMA,
BrowseError,
BrowseMedia,
MediaPlayerEntity,
MediaPlayerEntityFeature,
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,
Expand Down
6 changes: 0 additions & 6 deletions homeassistant/components/frontier_silicon/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
}
118 changes: 1 addition & 117 deletions tests/components/frontier_silicon/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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

Expand All @@ -37,122 +37,6 @@
)


@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)],
Expand Down

0 comments on commit 3633062

Please sign in to comment.