fix: Fix CI/CD issues and enhance integration
Some checks failed
Integration Testing / Integration Tests (2024.12.0, 3.11) (push) Failing after 22s
Integration Testing / Integration Tests (2024.12.0, 3.12) (push) Failing after 21s
Integration Testing / Integration Tests (2024.12.0, 3.13) (push) Failing after 1m32s
Integration Testing / Integration Tests (2025.9.4, 3.11) (push) Failing after 15s
Integration Testing / Integration Tests (2025.9.4, 3.12) (push) Failing after 20s
Integration Testing / Integration Tests (2025.9.4, 3.13) (push) Failing after 20s
Some checks failed
Integration Testing / Integration Tests (2024.12.0, 3.11) (push) Failing after 22s
Integration Testing / Integration Tests (2024.12.0, 3.12) (push) Failing after 21s
Integration Testing / Integration Tests (2024.12.0, 3.13) (push) Failing after 1m32s
Integration Testing / Integration Tests (2025.9.4, 3.11) (push) Failing after 15s
Integration Testing / Integration Tests (2025.9.4, 3.12) (push) Failing after 20s
Integration Testing / Integration Tests (2025.9.4, 3.13) (push) Failing after 20s
Signed-off-by: Rafal Zielinski <sq4ind@gmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""Config flow for AdGuard Control Hub integration."""
|
||||
import asyncio
|
||||
import logging
|
||||
import re
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
import voluptuous as vol
|
||||
@@ -10,7 +11,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
from .api import AdGuardHomeAPI, AdGuardConnectionError, AdGuardAuthError
|
||||
from .api import AdGuardHomeAPI, AdGuardConnectionError, AdGuardAuthError, AdGuardTimeoutError
|
||||
from .const import (
|
||||
CONF_SSL,
|
||||
CONF_VERIFY_SSL,
|
||||
@@ -32,16 +33,33 @@ STEP_USER_DATA_SCHEMA = vol.Schema({
|
||||
})
|
||||
|
||||
|
||||
async def validate_input(hass, data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Validate the user input allows us to connect."""
|
||||
host = data[CONF_HOST].strip()
|
||||
def validate_host(host: str) -> str:
|
||||
"""Validate and clean host input."""
|
||||
host = host.strip()
|
||||
if not host:
|
||||
raise InvalidHost("Host cannot be empty")
|
||||
|
||||
# Remove protocol if present
|
||||
if host.startswith(("http://", "https://")):
|
||||
host = host.split("://", 1)[1]
|
||||
data[CONF_HOST] = host
|
||||
|
||||
# Remove path if present
|
||||
if "/" in host:
|
||||
host = host.split("/", 1)[0]
|
||||
|
||||
return host
|
||||
|
||||
|
||||
async def validate_input(hass, data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Validate the user input allows us to connect."""
|
||||
# Validate and clean host
|
||||
try:
|
||||
host = validate_host(data[CONF_HOST])
|
||||
data[CONF_HOST] = host
|
||||
except InvalidHost:
|
||||
raise
|
||||
|
||||
# Validate port
|
||||
port = data[CONF_PORT]
|
||||
if not (1 <= port <= 65535):
|
||||
raise InvalidPort("Port must be between 1 and 65535")
|
||||
@@ -54,6 +72,7 @@ async def validate_input(hass, data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
username=data.get(CONF_USERNAME),
|
||||
password=data.get(CONF_PASSWORD),
|
||||
ssl=data.get(CONF_SSL, False),
|
||||
verify_ssl=data.get(CONF_VERIFY_SSL, True),
|
||||
session=session,
|
||||
timeout=10,
|
||||
)
|
||||
@@ -72,6 +91,7 @@ async def validate_input(hass, data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"host": host,
|
||||
}
|
||||
except Exception:
|
||||
# If we can't get status but connection works, still proceed
|
||||
return {
|
||||
"title": f"AdGuard Control Hub ({host})",
|
||||
"version": "unknown",
|
||||
@@ -80,6 +100,8 @@ async def validate_input(hass, data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
|
||||
except AdGuardAuthError as err:
|
||||
raise InvalidAuth from err
|
||||
except AdGuardTimeoutError as err:
|
||||
raise Timeout from err
|
||||
except AdGuardConnectionError as err:
|
||||
if "timeout" in str(err).lower():
|
||||
raise Timeout from err
|
||||
@@ -87,6 +109,7 @@ async def validate_input(hass, data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
except asyncio.TimeoutError as err:
|
||||
raise Timeout from err
|
||||
except Exception as err:
|
||||
_LOGGER.exception("Unexpected error during validation")
|
||||
raise CannotConnect from err
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user