Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve and fix Airzone config flow #70474

Merged
merged 2 commits into from Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 4 additions & 14 deletions homeassistant/components/airzone/config_flow.py
Expand Up @@ -21,10 +21,8 @@
vol.Required(CONF_PORT, default=DEFAULT_PORT): int,
}
)
SYSTEM_ID_SCHEMA = vol.Schema(
SYSTEM_ID_SCHEMA = CONFIG_SCHEMA.extend(
{
vol.Required(CONF_HOST): str,
vol.Required(CONF_PORT, default=DEFAULT_PORT): int,
vol.Required(CONF_ID, default=1): int,
}
)
Expand All @@ -41,30 +39,22 @@ async def async_step_user(
errors = {}

if user_input is not None:
system_id = user_input.get(CONF_ID, DEFAULT_SYSTEM_ID)

self._async_abort_entries_match(
{
CONF_HOST: user_input[CONF_HOST],
CONF_PORT: user_input[CONF_PORT],
CONF_ID: system_id,
}
)
self._async_abort_entries_match(user_input)

airzone = AirzoneLocalApi(
aiohttp_client.async_get_clientsession(self.hass),
ConnectionOptions(
user_input[CONF_HOST],
user_input[CONF_PORT],
system_id,
user_input.get(CONF_ID, DEFAULT_SYSTEM_ID),
),
)

try:
await airzone.validate()
except InvalidSystem:
data_schema = SYSTEM_ID_SCHEMA
errors["base"] = "invalid_system_id"
errors[CONF_ID] = "invalid_system_id"
except AirzoneError:
errors["base"] = "cannot_connect"
else:
Expand Down
8 changes: 4 additions & 4 deletions tests/components/airzone/test_config_flow.py
Expand Up @@ -16,7 +16,7 @@
from homeassistant.const import CONF_HOST, CONF_ID, CONF_PORT
from homeassistant.core import HomeAssistant

from .util import CONFIG, CONFIG_ID1, CONFIG_NO_ID, HVAC_MOCK
from .util import CONFIG, CONFIG_ID1, HVAC_MOCK

from tests.common import MockConfigEntry

Expand Down Expand Up @@ -46,7 +46,7 @@ async def test_form(hass: HomeAssistant) -> None:
assert result["errors"] == {}

result = await hass.config_entries.flow.async_configure(
result["flow_id"], CONFIG_NO_ID
result["flow_id"], CONFIG
)

await hass.async_block_till_done()
Expand Down Expand Up @@ -81,12 +81,12 @@ async def test_form_invalid_system_id(hass: HomeAssistant) -> None:
side_effect=InvalidMethod,
):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=CONFIG_NO_ID
DOMAIN, context={"source": SOURCE_USER}, data=CONFIG
)

assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == SOURCE_USER
assert result["errors"] == {"base": "invalid_system_id"}
assert result["errors"] == {CONF_ID: "invalid_system_id"}

mock_hvac.return_value = HVAC_MOCK[API_SYSTEMS][0]
mock_hvac.side_effect = None
Expand Down
9 changes: 1 addition & 8 deletions tests/components/airzone/util.py
Expand Up @@ -39,17 +39,10 @@
CONFIG = {
CONF_HOST: "192.168.1.100",
CONF_PORT: 3000,
CONF_ID: 0,
}

CONFIG_NO_ID = {
CONF_HOST: CONFIG[CONF_HOST],
CONF_PORT: CONFIG[CONF_PORT],
}

CONFIG_ID1 = {
CONF_HOST: CONFIG[CONF_HOST],
CONF_PORT: CONFIG[CONF_PORT],
**CONFIG,
CONF_ID: 1,
}

Expand Down