From aef24a807e72a3548dfbd594a8108c0ee52b5c56 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 13 May 2021 22:33:18 -0700 Subject: [PATCH] Yeelight: Do not log errors when cannot connect (#50592) --- homeassistant/components/yeelight/config_flow.py | 6 +++++- tests/components/yeelight/test_config_flow.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/yeelight/config_flow.py b/homeassistant/components/yeelight/config_flow.py index d6902abcf5a..0b0fe0d96c1 100644 --- a/homeassistant/components/yeelight/config_flow.py +++ b/homeassistant/components/yeelight/config_flow.py @@ -61,7 +61,11 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): if progress.get("context", {}).get(CONF_HOST) == self._discovered_ip: return self.async_abort(reason="already_in_progress") - self._discovered_model = await self._async_try_connect(self._discovered_ip) + try: + self._discovered_model = await self._async_try_connect(self._discovered_ip) + except CannotConnect: + return self.async_abort(reason="cannot_connect") + if not self.unique_id: return self.async_abort(reason="cannot_connect") diff --git a/tests/components/yeelight/test_config_flow.py b/tests/components/yeelight/test_config_flow.py index 8cc49c9799a..dd5ae85e89e 100644 --- a/tests/components/yeelight/test_config_flow.py +++ b/tests/components/yeelight/test_config_flow.py @@ -19,6 +19,7 @@ from homeassistant.components.yeelight import ( DOMAIN, NIGHTLIGHT_SWITCH_TYPE_LIGHT, ) +from homeassistant.components.yeelight.config_flow import CannotConnect from homeassistant.const import CONF_DEVICE, CONF_HOST, CONF_ID, CONF_NAME from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import RESULT_TYPE_ABORT, RESULT_TYPE_FORM @@ -323,6 +324,15 @@ async def test_discovered_by_homekit_and_dhcp(hass): assert result3["type"] == RESULT_TYPE_ABORT assert result3["reason"] == "already_in_progress" + with patch(f"{MODULE_CONFIG_FLOW}.yeelight.Bulb", side_effect=CannotConnect): + result3 = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": config_entries.SOURCE_DHCP}, + data={"ip": "1.2.3.5", "macaddress": "00:00:00:00:00:01"}, + ) + assert result3["type"] == RESULT_TYPE_ABORT + assert result3["reason"] == "cannot_connect" + @pytest.mark.parametrize( "source, data",