Skip to content

Commit

Permalink
Remove advanced options section
Browse files Browse the repository at this point in the history
  • Loading branch information
jaminh committed Feb 4, 2025
1 parent fb1a9e3 commit 7812e70
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 55 deletions.
29 changes: 2 additions & 27 deletions homeassistant/components/voip/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from homeassistant.core import callback
from homeassistant.helpers import config_validation as cv

from .const import CONF_SIP_PORT, CONF_SIP_USER, DEFAULT_SIP_USER, DOMAIN
from .const import CONF_SIP_PORT, CONF_SIP_USER, DOMAIN


class VoIPConfigFlow(ConfigFlow, domain=DOMAIN):
Expand Down Expand Up @@ -58,9 +58,6 @@ async def async_step_init(
) -> ConfigFlowResult:
"""Manage the options."""
if user_input is not None:
if "enable_advanced" in user_input:
return await self.async_step_advanced()

return self.async_create_entry(title="", data=user_input)

return self.async_show_form(
Expand All @@ -74,34 +71,12 @@ async def async_step_init(
SIP_PORT,
),
): cv.port,
vol.Optional("enable_advanced"): bool,
}
),
description_placeholders={
"note": "Enable advanced options by checking the box.",
},
)

async def async_step_advanced(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Manage the advanced options."""
if user_input is not None:
return self.async_create_entry(
title="", data={**self.config_entry.options, **user_input}
)

return self.async_show_form(
step_id="advanced",
data_schema=vol.Schema(
{
vol.Optional(
CONF_SIP_USER,
default=self.config_entry.options.get(
CONF_SIP_USER,
DEFAULT_SIP_USER,
),
): str,
): vol.Any(None, cv.string),
}
),
)
2 changes: 0 additions & 2 deletions homeassistant/components/voip/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@
"sleep_ratio": 0.99,
}

DEFAULT_SIP_USER = "HA"

CONF_SIP_PORT = "sip_port"
CONF_SIP_USER = "sip_user"
3 changes: 2 additions & 1 deletion homeassistant/components/voip/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"step": {
"init": {
"data": {
"sip_port": "SIP port"
"sip_port": "SIP port",
"sip_user": "SIP user"
}
}
}
Expand Down
29 changes: 4 additions & 25 deletions tests/components/voip/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async def test_options_flow(hass: HomeAssistant) -> None:
user_input={},
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert config_entry.options == {"sip_port": 5060}
assert config_entry.options == {"sip_port": 5060, "sip_user": None}

# Manual
result = await hass.config_entries.options.async_init(
Expand All @@ -79,36 +79,15 @@ async def test_options_flow(hass: HomeAssistant) -> None:
user_input={"sip_port": 5061},
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert config_entry.options == {"sip_port": 5061}
assert config_entry.options == {"sip_port": 5061, "sip_user": None}

# Manual with advanced options default user
# Manual with user
result = await hass.config_entries.options.async_init(
config_entry.entry_id,
)
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={"sip_port": 5061, "enable_advanced": True},
)
assert result["type"] is FlowResultType.FORM
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={},
user_input={"sip_port": 5061, "sip_user": "HA"},
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert config_entry.options == {"sip_port": 5061, "sip_user": "HA"}

# Manual with advanced options
result = await hass.config_entries.options.async_init(
config_entry.entry_id,
)
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={"sip_port": 5061, "enable_advanced": True},
)
assert result["type"] is FlowResultType.FORM
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={"sip_user": "test"},
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert config_entry.options == {"sip_port": 5061, "sip_user": "test"}

0 comments on commit 7812e70

Please sign in to comment.