diff --git a/homeassistant/components/elkm1/__init__.py b/homeassistant/components/elkm1/__init__.py index 04a26f2822b..6791c2ec1bb 100644 --- a/homeassistant/components/elkm1/__init__.py +++ b/homeassistant/components/elkm1/__init__.py @@ -279,9 +279,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: keypad.add_callback(_element_changed) try: - if not await async_wait_for_elk_to_sync( - elk, LOGIN_TIMEOUT, SYNC_TIMEOUT, bool(conf[CONF_USERNAME]) - ): + if not await async_wait_for_elk_to_sync(elk, LOGIN_TIMEOUT, SYNC_TIMEOUT): return False except asyncio.TimeoutError as exc: raise ConfigEntryNotReady(f"Timed out connecting to {conf[CONF_HOST]}") from exc @@ -334,7 +332,6 @@ async def async_wait_for_elk_to_sync( elk: elkm1.Elk, login_timeout: int, sync_timeout: int, - password_auth: bool, ) -> bool: """Wait until the elk has finished sync. Can fail login or timeout.""" @@ -354,18 +351,23 @@ async def async_wait_for_elk_to_sync( login_event.set() sync_event.set() + def first_response(*args, **kwargs): + _LOGGER.debug("ElkM1 received first response (VN)") + login_event.set() + def sync_complete(): sync_event.set() success = True elk.add_handler("login", login_status) + # VN is the first command sent for panel, when we get + # it back we now we are logged in either with or without a password + elk.add_handler("VN", first_response) elk.add_handler("sync_complete", sync_complete) - events = [] - if password_auth: - events.append(("login", login_event, login_timeout)) - events.append(("sync_complete", sync_event, sync_timeout)) - - for name, event, timeout in events: + for name, event, timeout in ( + ("login", login_event, login_timeout), + ("sync_complete", sync_event, sync_timeout), + ): _LOGGER.debug("Waiting for %s event for %s seconds", name, timeout) try: async with async_timeout.timeout(timeout): diff --git a/homeassistant/components/elkm1/config_flow.py b/homeassistant/components/elkm1/config_flow.py index a21cf186005..96f9fd5d078 100644 --- a/homeassistant/components/elkm1/config_flow.py +++ b/homeassistant/components/elkm1/config_flow.py @@ -81,9 +81,7 @@ async def validate_input(data: dict[str, str], mac: str | None) -> dict[str, str ) elk.connect() - if not await async_wait_for_elk_to_sync( - elk, LOGIN_TIMEOUT, VALIDATE_TIMEOUT, bool(userid) - ): + if not await async_wait_for_elk_to_sync(elk, LOGIN_TIMEOUT, VALIDATE_TIMEOUT): raise InvalidAuth short_mac = _short_mac(mac) if mac else None