diff --git a/.coveragerc b/.coveragerc index 03c1f9f088e..7f0f519133f 100644 --- a/.coveragerc +++ b/.coveragerc @@ -440,7 +440,13 @@ omit = homeassistant/components/luftdaten/* homeassistant/components/lupusec/* homeassistant/components/lutron/* - homeassistant/components/lutron_caseta/* + homeassistant/components/lutron_caseta/__init__.py + homeassistant/components/lutron_caseta/binary_sensor.py + homeassistant/components/lutron_caseta/cover.py + homeassistant/components/lutron_caseta/fan.py + homeassistant/components/lutron_caseta/light.py + homeassistant/components/lutron_caseta/scene.py + homeassistant/components/lutron_caseta/switch.py homeassistant/components/lw12wifi/light.py homeassistant/components/lyft/sensor.py homeassistant/components/magicseaweed/sensor.py diff --git a/homeassistant/components/lutron_caseta/__init__.py b/homeassistant/components/lutron_caseta/__init__.py index 59fd81e650e..ff7ec61ecc8 100644 --- a/homeassistant/components/lutron_caseta/__init__.py +++ b/homeassistant/components/lutron_caseta/__init__.py @@ -39,11 +39,7 @@ LUTRON_CASETA_COMPONENTS = ["light", "switch", "cover", "scene", "fan", "binary_ async def async_setup(hass, base_config): """Set up the Lutron component.""" - bridge_configs = base_config.get(DOMAIN) - - if not bridge_configs: - return True - + bridge_configs = base_config[DOMAIN] hass.data.setdefault(DOMAIN, {}) for config in bridge_configs: diff --git a/homeassistant/components/lutron_caseta/config_flow.py b/homeassistant/components/lutron_caseta/config_flow.py index 45a7f10fbf0..3a5a4a151a1 100644 --- a/homeassistant/components/lutron_caseta/config_flow.py +++ b/homeassistant/components/lutron_caseta/config_flow.py @@ -94,11 +94,6 @@ class LutronCasetaFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): await bridge.close() return True - except (KeyError, ValueError): - _LOGGER.error( - "Error while checking connectivity to bridge %s", self.data[CONF_HOST], - ) - return False except Exception: # pylint: disable=broad-except _LOGGER.exception( "Unknown exception while checking connectivity to bridge %s", diff --git a/homeassistant/components/lutron_caseta/manifest.json b/homeassistant/components/lutron_caseta/manifest.json index 7b55dfd9c87..34fc326425c 100644 --- a/homeassistant/components/lutron_caseta/manifest.json +++ b/homeassistant/components/lutron_caseta/manifest.json @@ -2,7 +2,10 @@ "domain": "lutron_caseta", "name": "Lutron Caséta", "documentation": "https://www.home-assistant.io/integrations/lutron_caseta", - "requirements": ["pylutron-caseta==0.6.1"], - "codeowners": ["@swails"], - "config_flow": true -} \ No newline at end of file + "requirements": [ + "pylutron-caseta==0.6.1" + ], + "codeowners": [ + "@swails" + ] +} diff --git a/homeassistant/generated/config_flows.py b/homeassistant/generated/config_flows.py index 2918f09d626..208ea3ef07f 100644 --- a/homeassistant/generated/config_flows.py +++ b/homeassistant/generated/config_flows.py @@ -85,7 +85,6 @@ FLOWS = [ "locative", "logi_circle", "luftdaten", - "lutron_caseta", "mailgun", "melcloud", "met", diff --git a/tests/components/lutron_caseta/test_config_flow.py b/tests/components/lutron_caseta/test_config_flow.py index a528e223e44..fc9c5fe279d 100644 --- a/tests/components/lutron_caseta/test_config_flow.py +++ b/tests/components/lutron_caseta/test_config_flow.py @@ -1,5 +1,4 @@ """Test the Lutron Caseta config flow.""" -from asynctest import patch from pylutron_caseta.smartbridge import Smartbridge from homeassistant import config_entries, data_entry_flow @@ -14,6 +13,7 @@ from homeassistant.components.lutron_caseta.const import ( ) from homeassistant.const import CONF_HOST +from tests.async_mock import AsyncMock, patch from tests.common import MockConfigEntry @@ -51,7 +51,11 @@ async def test_bridge_import_flow(hass): with patch( "homeassistant.components.lutron_caseta.async_setup_entry", return_value=True, - ) as mock_setup_entry, patch.object(Smartbridge, "create_tls") as create_tls: + ) as mock_setup_entry, patch( + "homeassistant.components.lutron_caseta.async_setup", return_value=True + ), patch.object( + Smartbridge, "create_tls" + ) as create_tls: create_tls.return_value = MockBridge(can_connect=True) result = await hass.config_entries.flow.async_init( @@ -77,9 +81,7 @@ async def test_bridge_cannot_connect(hass): CONF_CA_CERTS: "", } - with patch( - "homeassistant.components.lutron_caseta.async_setup_entry", return_value=True, - ) as mock_setup_entry, patch.object(Smartbridge, "create_tls") as create_tls: + with patch.object(Smartbridge, "create_tls") as create_tls: create_tls.return_value = MockBridge(can_connect=False) result = await hass.config_entries.flow.async_init( @@ -91,8 +93,41 @@ async def test_bridge_cannot_connect(hass): assert result["type"] == "form" assert result["step_id"] == STEP_IMPORT_FAILED assert result["errors"] == {"base": ERROR_CANNOT_CONNECT} - # validate setup_entry was not called - assert len(mock_setup_entry.mock_calls) == 0 + + result = await hass.config_entries.flow.async_configure(result["flow_id"], {}) + + assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT + assert result["reason"] == CasetaConfigFlow.ABORT_REASON_CANNOT_CONNECT + + +async def test_bridge_cannot_connect_unknown_error(hass): + """Test checking for connection and encountering an unknown error.""" + + entry_mock_data = { + CONF_HOST: "", + CONF_KEYFILE: "", + CONF_CERTFILE: "", + CONF_CA_CERTS: "", + } + + with patch.object(Smartbridge, "create_tls") as create_tls: + mock_bridge = MockBridge() + mock_bridge.connect = AsyncMock(side_effect=Exception()) + create_tls.return_value = mock_bridge + result = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": config_entries.SOURCE_IMPORT}, + data=entry_mock_data, + ) + + assert result["type"] == "form" + assert result["step_id"] == STEP_IMPORT_FAILED + assert result["errors"] == {"base": ERROR_CANNOT_CONNECT} + + result = await hass.config_entries.flow.async_configure(result["flow_id"], {}) + + assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT + assert result["reason"] == CasetaConfigFlow.ABORT_REASON_CANNOT_CONNECT async def test_duplicate_bridge_import(hass):