Skip to content
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

Force IPv4 when getting location information #104363

Merged
merged 1 commit into from Nov 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions homeassistant/components/cloudflare/__init__.py
Expand Up @@ -4,8 +4,8 @@
import asyncio
from datetime import timedelta
import logging
import socket

from aiohttp import ClientSession
import pycfdns

from homeassistant.config_entries import ConfigEntry
Expand Down Expand Up @@ -51,7 +51,7 @@ async def update_records(now):
"""Set up recurring update."""
try:
await _async_update_cloudflare(
session, client, dns_zone, entry.data[CONF_RECORDS]
hass, client, dns_zone, entry.data[CONF_RECORDS]
)
except (
pycfdns.AuthenticationException,
Expand All @@ -63,7 +63,7 @@ async def update_records_service(call: ServiceCall) -> None:
"""Set up service for manual trigger."""
try:
await _async_update_cloudflare(
session, client, dns_zone, entry.data[CONF_RECORDS]
hass, client, dns_zone, entry.data[CONF_RECORDS]
)
except (
pycfdns.AuthenticationException,
Expand Down Expand Up @@ -92,7 +92,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:


async def _async_update_cloudflare(
session: ClientSession,
hass: HomeAssistant,
client: pycfdns.Client,
dns_zone: pycfdns.ZoneModel,
target_records: list[str],
Expand All @@ -102,6 +102,7 @@ async def _async_update_cloudflare(
records = await client.list_dns_records(zone_id=dns_zone["id"], type="A")
_LOGGER.debug("Records: %s", records)

session = async_get_clientsession(hass, family=socket.AF_INET)
location_info = await async_detect_location_info(session)

if not location_info or not is_ipv4_address(location_info.ip):
Expand Down