From fd24baa1f6bfaab7cc7f14a5faa1ce71a6c3bff4 Mon Sep 17 00:00:00 2001 From: Shay Levy Date: Wed, 16 Dec 2020 22:28:59 +0200 Subject: [PATCH] Fix Shelly devices missing properties field (#44279) --- .../components/shelly/config_flow.py | 8 +---- tests/components/shelly/test_config_flow.py | 30 +------------------ 2 files changed, 2 insertions(+), 36 deletions(-) diff --git a/homeassistant/components/shelly/config_flow.py b/homeassistant/components/shelly/config_flow.py index 40ac452a9da..261c1898ca9 100644 --- a/homeassistant/components/shelly/config_flow.py +++ b/homeassistant/components/shelly/config_flow.py @@ -27,12 +27,6 @@ HOST_SCHEMA = vol.Schema({vol.Required(CONF_HOST): str}) HTTP_CONNECT_ERRORS = (asyncio.TimeoutError, aiohttp.ClientError) -def _remove_prefix(shelly_str): - if shelly_str.startswith("shellyswitch"): - return shelly_str[6:] - return shelly_str - - async def validate_input(hass: core.HomeAssistant, host, data): """Validate the user input allows us to connect. @@ -159,7 +153,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): self.host = zeroconf_info["host"] # pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167 self.context["title_placeholders"] = { - "name": _remove_prefix(zeroconf_info["properties"]["id"]) + "name": zeroconf_info.get("name", "").split(".")[0] } return await self.async_step_confirm_discovery() diff --git a/tests/components/shelly/test_config_flow.py b/tests/components/shelly/test_config_flow.py index 75ac015b83b..71c971757c1 100644 --- a/tests/components/shelly/test_config_flow.py +++ b/tests/components/shelly/test_config_flow.py @@ -20,11 +20,6 @@ DISCOVERY_INFO = { "name": "shelly1pm-12345", "properties": {"id": "shelly1pm-12345"}, } -SWITCH25_DISCOVERY_INFO = { - "host": "1.1.1.1", - "name": "shellyswitch25-12345", - "properties": {"id": "shellyswitch25-12345"}, -} async def test_form(hass): @@ -67,7 +62,7 @@ async def test_form(hass): assert len(mock_setup_entry.mock_calls) == 1 -async def test_title_without_name_and_prefix(hass): +async def test_title_without_name(hass): """Test we set the title to the hostname when the device doesn't have a name.""" await setup.async_setup_component(hass, "persistent_notification", {}) result = await hass.config_entries.flow.async_init( @@ -360,29 +355,6 @@ async def test_zeroconf(hass): assert len(mock_setup_entry.mock_calls) == 1 -async def test_zeroconf_with_switch_prefix(hass): - """Test we get remove shelly from the prefix.""" - await setup.async_setup_component(hass, "persistent_notification", {}) - - with patch( - "aioshelly.get_info", - return_value={"mac": "test-mac", "type": "SHSW-1", "auth": False}, - ): - result = await hass.config_entries.flow.async_init( - DOMAIN, - data=SWITCH25_DISCOVERY_INFO, - context={"source": config_entries.SOURCE_ZEROCONF}, - ) - assert result["type"] == "form" - assert result["errors"] == {} - context = next( - flow["context"] - for flow in hass.config_entries.flow.async_progress() - if flow["flow_id"] == result["flow_id"] - ) - assert context["title_placeholders"]["name"] == "switch25-12345" - - @pytest.mark.parametrize( "error", [(asyncio.TimeoutError, "cannot_connect"), (ValueError, "unknown")] )