diff --git a/homeassistant/components/risco/__init__.py b/homeassistant/components/risco/__init__.py index e95b3016139de43c9cdd9b619c2ef8dd646d2936..179ddd5cad64fdb6c3bd4cf32da1fe78e3554374 100644 --- a/homeassistant/components/risco/__init__.py +++ b/homeassistant/components/risco/__init__.py @@ -154,6 +154,10 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: + if is_local(entry): + local_data: LocalData = hass.data[DOMAIN][entry.entry_id] + await local_data.system.disconnect() + hass.data[DOMAIN].pop(entry.entry_id) return unload_ok diff --git a/homeassistant/components/risco/config_flow.py b/homeassistant/components/risco/config_flow.py index 1befe6263479b813aff4b5217122a059f6b4611b..5e1cdb75b5a9776d70531c063caad01f5ed9502c 100644 --- a/homeassistant/components/risco/config_flow.py +++ b/homeassistant/components/risco/config_flow.py @@ -1,7 +1,6 @@ """Config flow for Risco integration.""" from __future__ import annotations -import asyncio from collections.abc import Mapping import logging @@ -32,7 +31,6 @@ from .const import ( DEFAULT_OPTIONS, DOMAIN, RISCO_STATES, - SLEEP_INTERVAL, TYPE_LOCAL, ) @@ -150,9 +148,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): await self.async_set_unique_id(info["title"]) self._abort_if_unique_id_configured() - # Risco can hang if we don't wait before creating a new connection - await asyncio.sleep(SLEEP_INTERVAL) - return self.async_create_entry( title=info["title"], data={**user_input, **{CONF_TYPE: TYPE_LOCAL}} ) diff --git a/homeassistant/components/risco/const.py b/homeassistant/components/risco/const.py index f4ac170d3c7e29b0f5bcb40b5e17ed1593424a81..9f0e71701c65b915c8e2c8cfa56c595681fea100 100644 --- a/homeassistant/components/risco/const.py +++ b/homeassistant/components/risco/const.py @@ -46,5 +46,3 @@ DEFAULT_OPTIONS = { CONF_RISCO_STATES_TO_HA: DEFAULT_RISCO_STATES_TO_HA, CONF_HA_STATES_TO_RISCO: DEFAULT_HA_STATES_TO_RISCO, } - -SLEEP_INTERVAL = 1 diff --git a/homeassistant/components/risco/manifest.json b/homeassistant/components/risco/manifest.json index 38035e22c62319a185c30f63fa1b813f697196a3..9703b5775bc425138dc35700c55a3270e2aefc82 100644 --- a/homeassistant/components/risco/manifest.json +++ b/homeassistant/components/risco/manifest.json @@ -3,7 +3,7 @@ "name": "Risco", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/risco", - "requirements": ["pyrisco==0.5.3"], + "requirements": ["pyrisco==0.5.4"], "codeowners": ["@OnFreund"], "quality_scale": "platinum", "iot_class": "local_push", diff --git a/requirements_all.txt b/requirements_all.txt index 3e778246ec236e001a46418e85a3f188579c66fa..3fa89f3898efc3a1ba1f7e3e9703e77dd5b63034 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1814,7 +1814,7 @@ pyrecswitch==1.0.2 pyrepetierng==0.1.0 # homeassistant.components.risco -pyrisco==0.5.3 +pyrisco==0.5.4 # homeassistant.components.rituals_perfume_genie pyrituals==0.0.6 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 5e1c1b44334f6963ecae0a581865b6cb50800cd9..e9bbc312652b3b86c21646c425a5163b95ecd917 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1270,7 +1270,7 @@ pyps4-2ndscreen==1.3.1 pyqwikswitch==0.93 # homeassistant.components.risco -pyrisco==0.5.3 +pyrisco==0.5.4 # homeassistant.components.rituals_perfume_genie pyrituals==0.0.6 diff --git a/tests/components/risco/test_alarm_control_panel.py b/tests/components/risco/test_alarm_control_panel.py index 0014e712ab1cbd81826603c7b02a3e91b29f03cb..1625e78ece690513717186450b9143ac09ce11ae 100644 --- a/tests/components/risco/test_alarm_control_panel.py +++ b/tests/components/risco/test_alarm_control_panel.py @@ -479,6 +479,9 @@ async def test_local_setup(hass, two_part_local_alarm, setup_risco_local): device = registry.async_get_device({(DOMAIN, TEST_SITE_UUID + "_1_local")}) assert device is not None assert device.manufacturer == "Risco" + with patch("homeassistant.components.risco.RiscoLocal.disconnect") as mock_close: + await hass.config_entries.async_unload(setup_risco_local.entry_id) + mock_close.assert_awaited_once() async def _check_local_state( diff --git a/tests/components/risco/test_config_flow.py b/tests/components/risco/test_config_flow.py index a39a724d7b94bf2a58556e6e12f98f612f34db14..396aad8015dd4e550624afcc2ba8f597250a27a0 100644 --- a/tests/components/risco/test_config_flow.py +++ b/tests/components/risco/test_config_flow.py @@ -72,9 +72,6 @@ async def test_cloud_form(hass): ), patch( "homeassistant.components.risco.config_flow.RiscoCloud.close" ) as mock_close, patch( - "homeassistant.components.risco.config_flow.SLEEP_INTERVAL", - 0, - ), patch( "homeassistant.components.risco.async_setup_entry", return_value=True, ) as mock_setup_entry: @@ -168,9 +165,6 @@ async def test_local_form(hass): ), patch( "homeassistant.components.risco.config_flow.RiscoLocal.disconnect" ) as mock_close, patch( - "homeassistant.components.risco.config_flow.SLEEP_INTERVAL", - 0, - ), patch( "homeassistant.components.risco.async_setup_entry", return_value=True, ) as mock_setup_entry: