Fix dns resolver error in dnsip config flow validation (#145735)

Fix dns resolver error in dnsip
This commit is contained in:
G Johansson 2025-05-27 22:17:34 +02:00 committed by Bram Kragten
parent cd133cbbe3
commit 61823ec7e2

View File

@ -4,7 +4,7 @@ from __future__ import annotations
import asyncio import asyncio
import contextlib import contextlib
from typing import Any from typing import Any, Literal
import aiodns import aiodns
from aiodns.error import DNSError from aiodns.error import DNSError
@ -62,16 +62,16 @@ async def async_validate_hostname(
"""Validate hostname.""" """Validate hostname."""
async def async_check( async def async_check(
hostname: str, resolver: str, qtype: str, port: int = 53 hostname: str, resolver: str, qtype: Literal["A", "AAAA"], port: int = 53
) -> bool: ) -> bool:
"""Return if able to resolve hostname.""" """Return if able to resolve hostname."""
result = False result: bool = False
with contextlib.suppress(DNSError): with contextlib.suppress(DNSError):
result = bool( _resolver = aiodns.DNSResolver(
await aiodns.DNSResolver( # type: ignore[call-overload] nameservers=[resolver], udp_port=port, tcp_port=port
nameservers=[resolver], udp_port=port, tcp_port=port
).query(hostname, qtype)
) )
result = bool(await _resolver.query(hostname, qtype))
return result return result
result: dict[str, bool] = {} result: dict[str, bool] = {}