mirror of
https://github.com/home-assistant/core.git
synced 2025-08-05 13:45:12 +02:00
Use show_advanced_options in devolo home control (#35360)
This commit is contained in:
@@ -30,12 +30,17 @@ class DevoloHomeControlFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
self.data_schema = {
|
self.data_schema = {
|
||||||
vol.Required(CONF_USERNAME): str,
|
vol.Required(CONF_USERNAME): str,
|
||||||
vol.Required(CONF_PASSWORD): 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):
|
async def async_step_user(self, user_input=None):
|
||||||
"""Handle a flow initiated by the user."""
|
"""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:
|
if user_input is None:
|
||||||
return self._show_form(user_input)
|
return self._show_form(user_input)
|
||||||
user = user_input[CONF_USERNAME]
|
user = user_input[CONF_USERNAME]
|
||||||
@@ -46,8 +51,12 @@ class DevoloHomeControlFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
mydevolo = Mydevolo()
|
mydevolo = Mydevolo()
|
||||||
mydevolo.user = user
|
mydevolo.user = user
|
||||||
mydevolo.password = password
|
mydevolo.password = password
|
||||||
mydevolo.url = user_input[CONF_MYDEVOLO]
|
if self.show_advanced_options:
|
||||||
mydevolo.mprm = user_input[CONF_HOMECONTROL]
|
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(
|
credentials_valid = await self.hass.async_add_executor_job(
|
||||||
mydevolo.credentials_valid
|
mydevolo.credentials_valid
|
||||||
)
|
)
|
||||||
|
@@ -30,12 +30,7 @@ async def test_form(hass):
|
|||||||
):
|
):
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{
|
{"username": "test-username", "password": "test-password"},
|
||||||
"username": "test-username",
|
|
||||||
"password": "test-password",
|
|
||||||
"home_control_url": "https://homecontrol.mydevolo.com",
|
|
||||||
"mydevolo_url": "https://www.mydevolo.com",
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result2["type"] == "create_entry"
|
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 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{
|
{"username": "test-username", "password": "test-password"},
|
||||||
"username": "test-username",
|
|
||||||
"password": "test-password",
|
|
||||||
"home_control_url": "https://homecontrol.mydevolo.com",
|
|
||||||
"mydevolo_url": "https://www.mydevolo.com",
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["errors"] == {"base": "invalid_credentials"}
|
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(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": SOURCE_USER},
|
context={"source": SOURCE_USER},
|
||||||
data={
|
data={"username": "test-username", "password": "test-password"},
|
||||||
"username": "test-username",
|
|
||||||
"password": "test-password",
|
|
||||||
"home_control_url": "https://homecontrol.mydevolo.com",
|
|
||||||
"mydevolo_url": "https://www.mydevolo.com",
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == "already_configured"
|
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
|
||||||
|
Reference in New Issue
Block a user