mirror of
https://github.com/home-assistant/core.git
synced 2025-11-08 18:39:30 +00:00
Support specifying Airzone System ID (#69751)
This commit is contained in:
committed by
GitHub
parent
00621617c2
commit
c76b21e24e
@@ -4,17 +4,30 @@ from __future__ import annotations
|
||||
from typing import Any
|
||||
|
||||
from aioairzone.common import ConnectionOptions
|
||||
from aioairzone.exceptions import InvalidHost
|
||||
from aioairzone.exceptions import AirzoneError, InvalidSystem
|
||||
from aioairzone.localapi import AirzoneLocalApi
|
||||
from aiohttp.client_exceptions import ClientConnectorError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||
from homeassistant.const import CONF_HOST, CONF_ID, CONF_PORT
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.helpers import aiohttp_client
|
||||
|
||||
from .const import DEFAULT_LOCAL_API_PORT, DOMAIN
|
||||
from .const import DEFAULT_LOCAL_API_PORT, DEFAULT_SYSTEM_ID, DOMAIN
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_HOST): str,
|
||||
vol.Required(CONF_PORT, default=DEFAULT_LOCAL_API_PORT): int,
|
||||
}
|
||||
)
|
||||
SYSTEM_ID_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_HOST): str,
|
||||
vol.Required(CONF_PORT, default=DEFAULT_LOCAL_API_PORT): int,
|
||||
vol.Required(CONF_ID, default=1): int,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
@@ -24,13 +37,17 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> FlowResult:
|
||||
"""Handle the initial step."""
|
||||
data_schema = CONFIG_SCHEMA
|
||||
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,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -39,12 +56,16 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
ConnectionOptions(
|
||||
user_input[CONF_HOST],
|
||||
user_input[CONF_PORT],
|
||||
system_id,
|
||||
),
|
||||
)
|
||||
|
||||
try:
|
||||
await airzone.validate_airzone()
|
||||
except (ClientConnectorError, InvalidHost):
|
||||
except InvalidSystem:
|
||||
data_schema = SYSTEM_ID_SCHEMA
|
||||
errors["base"] = "invalid_system_id"
|
||||
except AirzoneError:
|
||||
errors["base"] = "cannot_connect"
|
||||
else:
|
||||
title = f"Airzone {user_input[CONF_HOST]}:{user_input[CONF_PORT]}"
|
||||
@@ -52,11 +73,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="user",
|
||||
data_schema=vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_HOST): str,
|
||||
vol.Required(CONF_PORT, default=DEFAULT_LOCAL_API_PORT): int,
|
||||
}
|
||||
),
|
||||
data_schema=data_schema,
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user