mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Fix dns resolver error in dnsip config flow validation (#145735)
Fix dns resolver error in dnsip
This commit is contained in:
parent
2cf2613dbd
commit
719dd09eb3
@ -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] = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user