Patch Discovery timeout in govee light local (#113692)

This commit is contained in:
Joost Lekkerkerker 2024-03-18 16:49:39 +01:00 committed by GitHub
parent eaf86ee1ea
commit aba5dcb63e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View File

@ -20,6 +20,8 @@ from .const import (
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
DISCOVERY_TIMEOUT = 5
async def _async_has_devices(hass: HomeAssistant) -> bool: async def _async_has_devices(hass: HomeAssistant) -> bool:
"""Return if there are devices that can be discovered.""" """Return if there are devices that can be discovered."""
@ -41,7 +43,7 @@ async def _async_has_devices(hass: HomeAssistant) -> bool:
await controller.start() await controller.start()
try: try:
async with asyncio.timeout(delay=5): async with asyncio.timeout(delay=DISCOVERY_TIMEOUT):
while not controller.devices: while not controller.devices:
await asyncio.sleep(delay=1) await asyncio.sleep(delay=1)
except TimeoutError: except TimeoutError:

View File

@ -1,5 +1,4 @@
"""Test Govee light local config flow.""" """Test Govee light local config flow."""
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
from govee_local_api import GoveeDevice from govee_local_api import GoveeDevice
@ -21,6 +20,9 @@ async def test_creating_entry_has_no_devices(
with patch( with patch(
"homeassistant.components.govee_light_local.config_flow.GoveeController", "homeassistant.components.govee_light_local.config_flow.GoveeController",
return_value=mock_govee_api, return_value=mock_govee_api,
), patch(
"homeassistant.components.govee_light_local.config_flow.DISCOVERY_TIMEOUT",
0,
): ):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": config_entries.SOURCE_USER}