1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Shelly: set confirm only (#47608)

This commit is contained in:
Paulus Schoutsen
2021-03-09 04:13:43 -08:00
committed by GitHub
parent 8e58c3aa7b
commit 34b9e6f6fc
2 changed files with 31 additions and 118 deletions

View File

@@ -338,6 +338,13 @@ async def test_zeroconf(hass):
with patch(
"aioshelly.get_info",
return_value={"mac": "test-mac", "type": "SHSW-1", "auth": False},
), patch(
"aioshelly.Device.create",
new=AsyncMock(
return_value=Mock(
settings=MOCK_SETTINGS,
)
),
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
@@ -352,14 +359,8 @@ async def test_zeroconf(hass):
if flow["flow_id"] == result["flow_id"]
)
assert context["title_placeholders"]["name"] == "shelly1pm-12345"
assert context["confirm_only"] is True
with patch(
"aioshelly.Device.create",
new=AsyncMock(
return_value=Mock(
settings=MOCK_SETTINGS,
)
),
), patch(
"homeassistant.components.shelly.async_setup", return_value=True
) as mock_setup, patch(
"homeassistant.components.shelly.async_setup_entry",
@@ -479,69 +480,6 @@ async def test_zeroconf_sleeping_device_error(hass, error):
assert result["reason"] == "cannot_connect"
@pytest.mark.parametrize(
"error", [(asyncio.TimeoutError, "cannot_connect"), (ValueError, "unknown")]
)
async def test_zeroconf_confirm_error(hass, error):
"""Test we get the form."""
exc, base_error = error
await setup.async_setup_component(hass, "persistent_notification", {})
with patch(
"aioshelly.get_info",
return_value={"mac": "test-mac", "type": "SHSW-1", "auth": False},
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
data=DISCOVERY_INFO,
context={"source": config_entries.SOURCE_ZEROCONF},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["errors"] == {}
with patch(
"aioshelly.Device.create",
new=AsyncMock(side_effect=exc),
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{},
)
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result2["errors"] == {"base": base_error}
async def test_zeroconf_confirm_auth_error(hass):
"""Test we get credentials form after an auth error when confirming discovery."""
await setup.async_setup_component(hass, "persistent_notification", {})
with patch(
"aioshelly.get_info",
return_value={"mac": "test-mac", "type": "SHSW-1", "auth": False},
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
data=DISCOVERY_INFO,
context={"source": config_entries.SOURCE_ZEROCONF},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["errors"] == {}
with patch(
"aioshelly.Device.create",
new=AsyncMock(side_effect=aioshelly.AuthRequired),
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{},
)
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result2["step_id"] == "credentials"
assert result2["errors"] == {}
async def test_zeroconf_already_configured(hass):
"""Test we get the form."""
await setup.async_setup_component(hass, "persistent_notification", {})
@@ -607,13 +545,6 @@ async def test_zeroconf_require_auth(hass):
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["errors"] == {}
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{},
)
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result2["errors"] == {}
with patch(
"aioshelly.Device.create",
new=AsyncMock(
@@ -627,15 +558,15 @@ async def test_zeroconf_require_auth(hass):
"homeassistant.components.shelly.async_setup_entry",
return_value=True,
) as mock_setup_entry:
result3 = await hass.config_entries.flow.async_configure(
result2["flow_id"],
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{"username": "test username", "password": "test password"},
)
await hass.async_block_till_done()
assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result3["title"] == "Test name"
assert result3["data"] == {
assert result2["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result2["title"] == "Test name"
assert result2["data"] == {
"host": "1.1.1.1",
"model": "SHSW-1",
"sleep_period": 0,