Fix lutron_caseta setup options (#35974)

pull/36985/head
Martin Hjelmare 2020-05-22 23:01:48 +02:00 committed by GitHub
parent 6dfc362f98
commit cc369cd461
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 57 additions and 23 deletions

View File

@ -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

View File

@ -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:

View File

@ -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",

View File

@ -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
}
"requirements": [
"pylutron-caseta==0.6.1"
],
"codeowners": [
"@swails"
]
}

View File

@ -85,7 +85,6 @@ FLOWS = [
"locative",
"logi_circle",
"luftdaten",
"lutron_caseta",
"mailgun",
"melcloud",
"met",

View File

@ -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):