Use show_advanced_options in devolo home control (#35360)

This commit is contained in:
Markus Bong
2020-06-03 02:52:36 +02:00
committed by GitHub
parent a5d520b603
commit e94228fddf
2 changed files with 60 additions and 22 deletions

View File

@@ -30,12 +30,17 @@ class DevoloHomeControlFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
self.data_schema = {
vol.Required(CONF_USERNAME): str,
vol.Required(CONF_PASSWORD): str,
vol.Required(CONF_MYDEVOLO, default=DEFAULT_MYDEVOLO): str,
vol.Required(CONF_HOMECONTROL, default=DEFAULT_MPRM): str,
}
async def async_step_user(self, user_input=None):
"""Handle a flow initiated by the user."""
if self.show_advanced_options:
self.data_schema = {
vol.Required(CONF_USERNAME): str,
vol.Required(CONF_PASSWORD): str,
vol.Required(CONF_MYDEVOLO): str,
vol.Required(CONF_HOMECONTROL): str,
}
if user_input is None:
return self._show_form(user_input)
user = user_input[CONF_USERNAME]
@@ -46,8 +51,12 @@ class DevoloHomeControlFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
mydevolo = Mydevolo()
mydevolo.user = user
mydevolo.password = password
mydevolo.url = user_input[CONF_MYDEVOLO]
mydevolo.mprm = user_input[CONF_HOMECONTROL]
if self.show_advanced_options:
mydevolo.url = user_input[CONF_MYDEVOLO]
mydevolo.mprm = user_input[CONF_HOMECONTROL]
else:
mydevolo.url = DEFAULT_MYDEVOLO
mydevolo.mprm = DEFAULT_MPRM
credentials_valid = await self.hass.async_add_executor_job(
mydevolo.credentials_valid
)

View File

@@ -30,12 +30,7 @@ async def test_form(hass):
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
"username": "test-username",
"password": "test-password",
"home_control_url": "https://homecontrol.mydevolo.com",
"mydevolo_url": "https://www.mydevolo.com",
},
{"username": "test-username", "password": "test-password"},
)
assert result2["type"] == "create_entry"
@@ -67,12 +62,7 @@ async def test_form_invalid_credentials(hass):
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
"username": "test-username",
"password": "test-password",
"home_control_url": "https://homecontrol.mydevolo.com",
"mydevolo_url": "https://www.mydevolo.com",
},
{"username": "test-username", "password": "test-password"},
)
assert result["errors"] == {"base": "invalid_credentials"}
@@ -91,12 +81,51 @@ async def test_form_already_configured(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_USER},
data={
"username": "test-username",
"password": "test-password",
"home_control_url": "https://homecontrol.mydevolo.com",
"mydevolo_url": "https://www.mydevolo.com",
},
data={"username": "test-username", "password": "test-password"},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "already_configured"
async def test_form_advanced_options(hass):
"""Test if we get the advanced options if user has enabled it."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": "user", "show_advanced_options": True}
)
assert result["type"] == "form"
assert result["errors"] == {}
with patch(
"homeassistant.components.devolo_home_control.async_setup", return_value=True,
) as mock_setup, patch(
"homeassistant.components.devolo_home_control.async_setup_entry",
return_value=True,
) as mock_setup_entry, patch(
"homeassistant.components.devolo_home_control.config_flow.Mydevolo.credentials_valid",
return_value=True,
), patch(
"homeassistant.components.devolo_home_control.config_flow.Mydevolo.get_gateway_ids",
return_value=["123456"],
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
"username": "test-username",
"password": "test-password",
"home_control_url": "https://test_url.test",
"mydevolo_url": "https://test_mydevolo_url.test",
},
)
assert result2["type"] == "create_entry"
assert result2["title"] == "devolo Home Control"
assert result2["data"] == {
"username": "test-username",
"password": "test-password",
"home_control_url": "https://test_url.test",
"mydevolo_url": "https://test_mydevolo_url.test",
}
await hass.async_block_till_done()
assert len(mock_setup.mock_calls) == 1
assert len(mock_setup_entry.mock_calls) == 1