From 0830100df1febbdbff712417bfc905641f0a311c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 17 Sep 2021 21:22:14 -1000 Subject: [PATCH] Do not reload the isy994 on ip change since there is already a reload listener (#54602) --- homeassistant/components/isy994/__init__.py | 7 +-- .../components/isy994/config_flow.py | 3 - homeassistant/components/isy994/const.py | 2 - tests/components/isy994/test_config_flow.py | 60 ++----------------- 4 files changed, 7 insertions(+), 65 deletions(-) diff --git a/homeassistant/components/isy994/__init__.py b/homeassistant/components/isy994/__init__.py index e3d11efd739..02bbea29bdb 100644 --- a/homeassistant/components/isy994/__init__.py +++ b/homeassistant/components/isy994/__init__.py @@ -41,7 +41,6 @@ from .const import ( MANUFACTURER, PLATFORMS, PROGRAM_PLATFORMS, - UNDO_UPDATE_LISTENER, ) from .helpers import _categorize_nodes, _categorize_programs, _categorize_variables from .services import async_setup_services, async_unload_services @@ -218,9 +217,7 @@ async def async_setup_entry( await hass.async_add_executor_job(_start_auto_update) - undo_listener = entry.add_update_listener(_async_update_listener) - - hass_isy_data[UNDO_UPDATE_LISTENER] = undo_listener + entry.async_on_unload(entry.add_update_listener(_async_update_listener)) entry.async_on_unload( hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _stop_auto_update) ) @@ -290,8 +287,6 @@ async def async_unload_entry( await hass.async_add_executor_job(_stop_auto_update) - hass_isy_data[UNDO_UPDATE_LISTENER]() - if unload_ok: hass.data[DOMAIN].pop(entry.entry_id) diff --git a/homeassistant/components/isy994/config_flow.py b/homeassistant/components/isy994/config_flow.py index 58e5238cbee..34c7a40cfc0 100644 --- a/homeassistant/components/isy994/config_flow.py +++ b/homeassistant/components/isy994/config_flow.py @@ -182,9 +182,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): ), }, ) - self.hass.async_create_task( - self.hass.config_entries.async_reload(existing_entry.entry_id) - ) raise data_entry_flow.AbortFlow("already_configured") async def async_step_dhcp(self, discovery_info): diff --git a/homeassistant/components/isy994/const.py b/homeassistant/components/isy994/const.py index b7b2f283a84..8e634006ec2 100644 --- a/homeassistant/components/isy994/const.py +++ b/homeassistant/components/isy994/const.py @@ -183,8 +183,6 @@ TYPE_CATEGORY_X10 = "113." TYPE_EZIO2X4 = "7.3.255." TYPE_INSTEON_MOTION = ("16.1.", "16.22.") -UNDO_UPDATE_LISTENER = "undo_update_listener" - # Used for discovery UDN_UUID_PREFIX = "uuid:" ISY_URL_POSTFIX = "/desc" diff --git a/tests/components/isy994/test_config_flow.py b/tests/components/isy994/test_config_flow.py index 1e96de9ff2f..09e6e26e777 100644 --- a/tests/components/isy994/test_config_flow.py +++ b/tests/components/isy994/test_config_flow.py @@ -383,12 +383,7 @@ async def test_form_ssdp_existing_entry(hass: HomeAssistant): ) entry.add_to_hass(hass) - with patch(PATCH_CONNECTION, return_value=MOCK_CONFIG_RESPONSE), patch( - PATCH_ASYNC_SETUP, return_value=True - ) as mock_setup, patch( - PATCH_ASYNC_SETUP_ENTRY, - return_value=True, - ) as mock_setup_entry: + with patch(PATCH_CONNECTION, return_value=MOCK_CONFIG_RESPONSE): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_SSDP}, @@ -404,9 +399,6 @@ async def test_form_ssdp_existing_entry(hass: HomeAssistant): assert result["reason"] == "already_configured" assert entry.data[CONF_HOST] == f"http://3.3.3.3:80{ISY_URL_POSTFIX}" - assert len(mock_setup.mock_calls) == 1 - assert len(mock_setup_entry.mock_calls) == 1 - async def test_form_ssdp_existing_entry_with_no_port(hass: HomeAssistant): """Test we update the ip of an existing entry from ssdp with no port.""" @@ -418,12 +410,7 @@ async def test_form_ssdp_existing_entry_with_no_port(hass: HomeAssistant): ) entry.add_to_hass(hass) - with patch(PATCH_CONNECTION, return_value=MOCK_CONFIG_RESPONSE), patch( - PATCH_ASYNC_SETUP, return_value=True - ) as mock_setup, patch( - PATCH_ASYNC_SETUP_ENTRY, - return_value=True, - ) as mock_setup_entry: + with patch(PATCH_CONNECTION, return_value=MOCK_CONFIG_RESPONSE): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_SSDP}, @@ -439,9 +426,6 @@ async def test_form_ssdp_existing_entry_with_no_port(hass: HomeAssistant): assert result["reason"] == "already_configured" assert entry.data[CONF_HOST] == f"http://3.3.3.3:80/{ISY_URL_POSTFIX}" - assert len(mock_setup.mock_calls) == 1 - assert len(mock_setup_entry.mock_calls) == 1 - async def test_form_ssdp_existing_entry_with_alternate_port(hass: HomeAssistant): """Test we update the ip of an existing entry from ssdp with an alternate port.""" @@ -453,12 +437,7 @@ async def test_form_ssdp_existing_entry_with_alternate_port(hass: HomeAssistant) ) entry.add_to_hass(hass) - with patch(PATCH_CONNECTION, return_value=MOCK_CONFIG_RESPONSE), patch( - PATCH_ASYNC_SETUP, return_value=True - ) as mock_setup, patch( - PATCH_ASYNC_SETUP_ENTRY, - return_value=True, - ) as mock_setup_entry: + with patch(PATCH_CONNECTION, return_value=MOCK_CONFIG_RESPONSE): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_SSDP}, @@ -474,9 +453,6 @@ async def test_form_ssdp_existing_entry_with_alternate_port(hass: HomeAssistant) assert result["reason"] == "already_configured" assert entry.data[CONF_HOST] == f"http://3.3.3.3:1443/{ISY_URL_POSTFIX}" - assert len(mock_setup.mock_calls) == 1 - assert len(mock_setup_entry.mock_calls) == 1 - async def test_form_ssdp_existing_entry_no_port_https(hass: HomeAssistant): """Test we update the ip of an existing entry from ssdp with no port and https.""" @@ -488,12 +464,7 @@ async def test_form_ssdp_existing_entry_no_port_https(hass: HomeAssistant): ) entry.add_to_hass(hass) - with patch(PATCH_CONNECTION, return_value=MOCK_CONFIG_RESPONSE), patch( - PATCH_ASYNC_SETUP, return_value=True - ) as mock_setup, patch( - PATCH_ASYNC_SETUP_ENTRY, - return_value=True, - ) as mock_setup_entry: + with patch(PATCH_CONNECTION, return_value=MOCK_CONFIG_RESPONSE): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_SSDP}, @@ -509,9 +480,6 @@ async def test_form_ssdp_existing_entry_no_port_https(hass: HomeAssistant): assert result["reason"] == "already_configured" assert entry.data[CONF_HOST] == f"https://3.3.3.3:443/{ISY_URL_POSTFIX}" - assert len(mock_setup.mock_calls) == 1 - assert len(mock_setup_entry.mock_calls) == 1 - async def test_form_dhcp(hass: HomeAssistant): """Test we can setup from dhcp.""" @@ -560,12 +528,7 @@ async def test_form_dhcp_existing_entry(hass: HomeAssistant): ) entry.add_to_hass(hass) - with patch(PATCH_CONNECTION, return_value=MOCK_CONFIG_RESPONSE), patch( - PATCH_ASYNC_SETUP, return_value=True - ) as mock_setup, patch( - PATCH_ASYNC_SETUP_ENTRY, - return_value=True, - ) as mock_setup_entry: + with patch(PATCH_CONNECTION, return_value=MOCK_CONFIG_RESPONSE): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_DHCP}, @@ -581,9 +544,6 @@ async def test_form_dhcp_existing_entry(hass: HomeAssistant): assert result["reason"] == "already_configured" assert entry.data[CONF_HOST] == f"http://1.2.3.4{ISY_URL_POSTFIX}" - assert len(mock_setup.mock_calls) == 1 - assert len(mock_setup_entry.mock_calls) == 1 - async def test_form_dhcp_existing_entry_preserves_port(hass: HomeAssistant): """Test we update the ip of an existing entry from dhcp preserves port.""" @@ -598,12 +558,7 @@ async def test_form_dhcp_existing_entry_preserves_port(hass: HomeAssistant): ) entry.add_to_hass(hass) - with patch(PATCH_CONNECTION, return_value=MOCK_CONFIG_RESPONSE), patch( - PATCH_ASYNC_SETUP, return_value=True - ) as mock_setup, patch( - PATCH_ASYNC_SETUP_ENTRY, - return_value=True, - ) as mock_setup_entry: + with patch(PATCH_CONNECTION, return_value=MOCK_CONFIG_RESPONSE): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_DHCP}, @@ -619,6 +574,3 @@ async def test_form_dhcp_existing_entry_preserves_port(hass: HomeAssistant): assert result["reason"] == "already_configured" assert entry.data[CONF_HOST] == f"http://1.2.3.4:1443{ISY_URL_POSTFIX}" assert entry.data[CONF_USERNAME] == "bob" - - assert len(mock_setup.mock_calls) == 1 - assert len(mock_setup_entry.mock_calls) == 1