Skip to content

[pull] dev from home-assistant:dev #781

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions homeassistant/components/dnsip/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from datetime import timedelta
from ipaddress import IPv4Address, IPv6Address
import logging
from typing import Literal

import aiodns
from aiodns.error import DNSError
Expand Down Expand Up @@ -34,7 +35,7 @@
SCAN_INTERVAL = timedelta(seconds=120)


def sort_ips(ips: list, querytype: str) -> list:
def sort_ips(ips: list, querytype: Literal["A", "AAAA"]) -> list:
"""Join IPs into a single string."""

if querytype == "AAAA":
Expand Down Expand Up @@ -89,7 +90,7 @@ def __init__(
self.hostname = hostname
self.resolver = aiodns.DNSResolver(tcp_port=port, udp_port=port)
self.resolver.nameservers = [resolver]
self.querytype = "AAAA" if ipv6 else "A"
self.querytype: Literal["A", "AAAA"] = "AAAA" if ipv6 else "A"
self._retries = DEFAULT_RETRIES
self._attr_extra_state_attributes = {
"resolver": resolver,
Expand All @@ -106,7 +107,7 @@ def __init__(
async def async_update(self) -> None:
"""Get the current DNS IP address for hostname."""
try:
response = await self.resolver.query(self.hostname, self.querytype) # type: ignore[call-overload]
response = await self.resolver.query(self.hostname, self.querytype)
except DNSError as err:
_LOGGER.warning("Exception while resolving host: %s", err)
response = None
Expand Down