diff --git a/homeassistant/components/harmony/config_flow.py b/homeassistant/components/harmony/config_flow.py index 6d5adabe235..e01febbef43 100644 --- a/homeassistant/components/harmony/config_flow.py +++ b/homeassistant/components/harmony/config_flow.py @@ -129,19 +129,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): }, ) - async def async_step_import(self, validated_input): - """Handle import.""" - await self.async_set_unique_id( - validated_input[UNIQUE_ID], raise_on_progress=False - ) - self._abort_if_unique_id_configured() - - # Everything was validated in remote async_setup_platform - # all we do now is create. - return await self._async_create_entry_from_valid_input( - validated_input, validated_input - ) - @staticmethod @callback def async_get_options_flow(config_entry): diff --git a/homeassistant/components/harmony/remote.py b/homeassistant/components/harmony/remote.py index b9205a4befb..8409983789b 100644 --- a/homeassistant/components/harmony/remote.py +++ b/homeassistant/components/harmony/remote.py @@ -12,12 +12,10 @@ from homeassistant.components.remote import ( ATTR_HOLD_SECS, ATTR_NUM_REPEATS, DEFAULT_DELAY_SECS, - PLATFORM_SCHEMA, ) -from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry -from homeassistant.const import ATTR_ENTITY_ID, CONF_HOST, CONF_NAME +from homeassistant.config_entries import ConfigEntry +from homeassistant.const import ATTR_ENTITY_ID from homeassistant.core import HomeAssistant -from homeassistant.exceptions import PlatformNotReady from homeassistant.helpers import entity_platform import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -36,15 +34,8 @@ from .const import ( PREVIOUS_ACTIVE_ACTIVITY, SERVICE_CHANGE_CHANNEL, SERVICE_SYNC, - UNIQUE_ID, ) from .subscriber import HarmonyCallback -from .util import ( - find_best_name_for_remote, - find_matching_config_entries_for_host, - find_unique_id_for_remote, - get_harmony_client_if_available, -) _LOGGER = logging.getLogger(__name__) @@ -53,18 +44,6 @@ PARALLEL_UPDATES = 0 ATTR_CHANNEL = "channel" -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - { - vol.Optional(ATTR_ACTIVITY): cv.string, - vol.Required(CONF_NAME): cv.string, - vol.Optional(ATTR_DELAY_SECS, default=DEFAULT_DELAY_SECS): vol.Coerce(float), - vol.Required(CONF_HOST): cv.string, - # The client ignores port so lets not confuse the user by pretenting we do anything with this - }, - extra=vol.ALLOW_EXTRA, -) - - HARMONY_SYNC_SCHEMA = vol.Schema({vol.Optional(ATTR_ENTITY_ID): cv.entity_ids}) HARMONY_CHANGE_CHANNEL_SCHEMA = vol.Schema( @@ -75,36 +54,6 @@ HARMONY_CHANGE_CHANNEL_SCHEMA = vol.Schema( ) -async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): - """Set up the Harmony platform.""" - - if discovery_info: - # Now handled by ssdp in the config flow - return - - if find_matching_config_entries_for_host(hass, config[CONF_HOST]): - return - - # We do the validation to verify we can connect - # so we can raise PlatformNotReady to force - # a retry so we can avoid a scenario where the config - # entry cannot be created via import because hub - # is not yet ready. - harmony = await get_harmony_client_if_available(config[CONF_HOST]) - if not harmony: - raise PlatformNotReady - - validated_config = config.copy() - validated_config[UNIQUE_ID] = find_unique_id_for_remote(harmony) - validated_config[CONF_NAME] = find_best_name_for_remote(config, harmony) - - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_IMPORT}, data=validated_config - ) - ) - - async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities ): diff --git a/homeassistant/components/harmony/util.py b/homeassistant/components/harmony/util.py index b0a16004065..3f126f22f3c 100644 --- a/homeassistant/components/harmony/util.py +++ b/homeassistant/components/harmony/util.py @@ -2,9 +2,7 @@ import aioharmony.exceptions as harmony_exceptions from aioharmony.harmonyapi import HarmonyAPI -from homeassistant.const import CONF_HOST, CONF_NAME - -from .const import DOMAIN +from homeassistant.const import CONF_NAME def find_unique_id_for_remote(harmony: HarmonyAPI): @@ -41,22 +39,3 @@ async def get_harmony_client_if_available(ip_address: str): await harmony.close() return harmony - - -def find_matching_config_entries_for_host(hass, host): - """Search existing config entries for one matching the host.""" - for entry in hass.config_entries.async_entries(DOMAIN): - if entry.data[CONF_HOST] == host: - return entry - return None - - -def list_names_from_hublist(hub_list): - """Extract the name key value from a hub list of names.""" - if not hub_list: - return [] - return [ - element["name"] - for element in hub_list - if element.get("name") and element.get("id") != -1 - ] diff --git a/tests/components/harmony/test_config_flow.py b/tests/components/harmony/test_config_flow.py index e5d0c6f0570..52ef71fc8bc 100644 --- a/tests/components/harmony/test_config_flow.py +++ b/tests/components/harmony/test_config_flow.py @@ -49,49 +49,6 @@ async def test_user_form(hass): assert len(mock_setup_entry.mock_calls) == 1 -async def test_form_import(hass): - """Test we get the form with import source.""" - await setup.async_setup_component(hass, "persistent_notification", {}) - - harmonyapi = _get_mock_harmonyapi(connect=True) - with patch( - "homeassistant.components.harmony.util.HarmonyAPI", - return_value=harmonyapi, - ), patch( - "homeassistant.components.harmony.async_setup", return_value=True - ) as mock_setup, patch( - "homeassistant.components.harmony.async_setup_entry", - return_value=True, - ) as mock_setup_entry: - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data={ - "host": "1.2.3.4", - "name": "friend", - "activity": "Watch TV", - "delay_secs": 0.9, - "unique_id": "555234534543", - }, - ) - await hass.async_block_till_done() - - assert result["result"].unique_id == "555234534543" - assert result["type"] == "create_entry" - assert result["title"] == "friend" - assert result["data"] == { - "host": "1.2.3.4", - "name": "friend", - "activity": "Watch TV", - "delay_secs": 0.9, - } - # It is not possible to import options at this time - # so they end up in the config entry data and are - # used a fallback when they are not in options - assert len(mock_setup.mock_calls) == 1 - assert len(mock_setup_entry.mock_calls) == 1 - - async def test_form_ssdp(hass): """Test we get the form with ssdp source.""" await setup.async_setup_component(hass, "persistent_notification", {})