From b35b4e8bfd54d97cefaddd9a4e6b9b91e7567ac7 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Benecke Date: Tue, 19 Mar 2024 18:24:36 +0100 Subject: [PATCH] Do not patch `asyncio.timeout` in govee light local test (#113819) --- homeassistant/components/govee_light_local/__init__.py | 4 ++-- homeassistant/components/govee_light_local/config_flow.py | 3 +-- homeassistant/components/govee_light_local/const.py | 1 + tests/components/govee_light_local/test_light.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/govee_light_local/__init__.py b/homeassistant/components/govee_light_local/__init__.py index 5a791b9e3d1..d2537fb5c9b 100644 --- a/homeassistant/components/govee_light_local/__init__.py +++ b/homeassistant/components/govee_light_local/__init__.py @@ -9,7 +9,7 @@ from homeassistant.const import Platform from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady -from .const import DOMAIN +from .const import DISCOVERY_TIMEOUT, DOMAIN from .coordinator import GoveeLocalApiCoordinator PLATFORMS: list[Platform] = [Platform.LIGHT] @@ -26,7 +26,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: await coordinator.async_config_entry_first_refresh() try: - async with asyncio.timeout(delay=5): + async with asyncio.timeout(delay=DISCOVERY_TIMEOUT): while not coordinator.devices: await asyncio.sleep(delay=1) except TimeoutError as ex: diff --git a/homeassistant/components/govee_light_local/config_flow.py b/homeassistant/components/govee_light_local/config_flow.py index bcf9886f6b4..d31bfed0579 100644 --- a/homeassistant/components/govee_light_local/config_flow.py +++ b/homeassistant/components/govee_light_local/config_flow.py @@ -15,13 +15,12 @@ from .const import ( CONF_LISTENING_PORT_DEFAULT, CONF_MULTICAST_ADDRESS_DEFAULT, CONF_TARGET_PORT_DEFAULT, + DISCOVERY_TIMEOUT, DOMAIN, ) _LOGGER = logging.getLogger(__name__) -DISCOVERY_TIMEOUT = 5 - async def _async_has_devices(hass: HomeAssistant) -> bool: """Return if there are devices that can be discovered.""" diff --git a/homeassistant/components/govee_light_local/const.py b/homeassistant/components/govee_light_local/const.py index d9410c9c05e..a90a1ff1ff1 100644 --- a/homeassistant/components/govee_light_local/const.py +++ b/homeassistant/components/govee_light_local/const.py @@ -11,3 +11,4 @@ CONF_LISTENING_PORT_DEFAULT = 4002 CONF_DISCOVERY_INTERVAL_DEFAULT = 60 SCAN_INTERVAL = timedelta(seconds=30) +DISCOVERY_TIMEOUT = 5 diff --git a/tests/components/govee_light_local/test_light.py b/tests/components/govee_light_local/test_light.py index 66f471df267..3bc9da77fe5 100644 --- a/tests/components/govee_light_local/test_light.py +++ b/tests/components/govee_light_local/test_light.py @@ -131,8 +131,8 @@ async def test_light_setup_retry( entry.add_to_hass(hass) with patch( - "homeassistant.components.govee_light_local.asyncio.timeout", - side_effect=TimeoutError, + "homeassistant.components.govee_light_local.DISCOVERY_TIMEOUT", + 0, ): await hass.config_entries.async_setup(entry.entry_id) assert entry.state is ConfigEntryState.SETUP_RETRY