Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions homeassistant/components/lutron_caseta/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@
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:
Expand Down
5 changes: 0 additions & 5 deletions homeassistant/components/lutron_caseta/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ async def async_validate_connectable_bridge_config(self):

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",
Expand Down
11 changes: 7 additions & 4 deletions homeassistant/components/lutron_caseta/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
1 change: 0 additions & 1 deletion homeassistant/generated/config_flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
"locative",
"logi_circle",
"luftdaten",
"lutron_caseta",
"mailgun",
"melcloud",
"met",
Expand Down
49 changes: 42 additions & 7 deletions tests/components/lutron_caseta/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,6 +13,7 @@
)
from homeassistant.const import CONF_HOST

from tests.async_mock import AsyncMock, patch
from tests.common import MockConfigEntry


Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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):
Expand Down