Fix lutron_caseta setup options (#35974)
This commit is contained in:
1 parent
6dfc362f98
commit
cc369cd461
6 files changed
+57
-23
No files matched your search
@@ -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):
|
||||
|
||||
Reference in new issue
Block a user