Skip to content

Commit

Permalink
Force IPv4 when getting location information (#104363)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Nov 23, 2023
1 parent ada0578 commit 2febc9c
Showing 1 changed file with 5 additions and 4 deletions.
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

0 comments on commit 2febc9c

Please sign in to comment.