Force IPv4 when getting location information (#104363)

This commit is contained in:
Joakim Sørensen 2023-11-23 09:13:00 +01:00 committed by GitHub
parent ada0578f3a
commit 2febc9c4b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,8 +4,8 @@ from __future__ import annotations
import asyncio import asyncio
from datetime import timedelta from datetime import timedelta
import logging import logging
import socket
from aiohttp import ClientSession
import pycfdns import pycfdns
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
@ -51,7 +51,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up recurring update.""" """Set up recurring update."""
try: try:
await _async_update_cloudflare( await _async_update_cloudflare(
session, client, dns_zone, entry.data[CONF_RECORDS] hass, client, dns_zone, entry.data[CONF_RECORDS]
) )
except ( except (
pycfdns.AuthenticationException, pycfdns.AuthenticationException,
@ -63,7 +63,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up service for manual trigger.""" """Set up service for manual trigger."""
try: try:
await _async_update_cloudflare( await _async_update_cloudflare(
session, client, dns_zone, entry.data[CONF_RECORDS] hass, client, dns_zone, entry.data[CONF_RECORDS]
) )
except ( except (
pycfdns.AuthenticationException, pycfdns.AuthenticationException,
@ -92,7 +92,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def _async_update_cloudflare( async def _async_update_cloudflare(
session: ClientSession, hass: HomeAssistant,
client: pycfdns.Client, client: pycfdns.Client,
dns_zone: pycfdns.ZoneModel, dns_zone: pycfdns.ZoneModel,
target_records: list[str], target_records: list[str],
@ -102,6 +102,7 @@ async def _async_update_cloudflare(
records = await client.list_dns_records(zone_id=dns_zone["id"], type="A") records = await client.list_dns_records(zone_id=dns_zone["id"], type="A")
_LOGGER.debug("Records: %s", records) _LOGGER.debug("Records: %s", records)
session = async_get_clientsession(hass, family=socket.AF_INET)
location_info = await async_detect_location_info(session) location_info = await async_detect_location_info(session)
if not location_info or not is_ipv4_address(location_info.ip): if not location_info or not is_ipv4_address(location_info.ip):