From ece7ec6a3879f6e7329a325e0f8e0589fb839352 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 24 Oct 2023 23:08:41 -0500 Subject: [PATCH] Disable IPV6 in the august integration (#98003) --- homeassistant/components/august/__init__.py | 8 +++---- .../components/august/config_flow.py | 7 ++---- homeassistant/components/august/util.py | 24 +++++++++++++++++++ 3 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 homeassistant/components/august/util.py diff --git a/homeassistant/components/august/__init__.py b/homeassistant/components/august/__init__.py index 408d6e0be7e..c1eb21b6827 100644 --- a/homeassistant/components/august/__init__.py +++ b/homeassistant/components/august/__init__.py @@ -25,13 +25,14 @@ from homeassistant.exceptions import ( ConfigEntryNotReady, HomeAssistantError, ) -from homeassistant.helpers import aiohttp_client, device_registry as dr, discovery_flow +from homeassistant.helpers import device_registry as dr, discovery_flow from .activity import ActivityStream from .const import CONF_BRAND, DOMAIN, MIN_TIME_BETWEEN_DETAIL_UPDATES, PLATFORMS from .exceptions import CannotConnect, InvalidAuth, RequireValidation from .gateway import AugustGateway from .subscriber import AugustSubscriberMixin +from .util import async_create_august_clientsession _LOGGER = logging.getLogger(__name__) @@ -46,10 +47,7 @@ YALEXS_BLE_DOMAIN = "yalexs_ble" async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up August from a config entry.""" - # Create an aiohttp session instead of using the default one since the - # default one is likely to trigger august's WAF if another integration - # is also using Cloudflare - session = aiohttp_client.async_create_clientsession(hass) + session = async_create_august_clientsession(hass) august_gateway = AugustGateway(hass, session) try: diff --git a/homeassistant/components/august/config_flow.py b/homeassistant/components/august/config_flow.py index 670d1608421..0028db55415 100644 --- a/homeassistant/components/august/config_flow.py +++ b/homeassistant/components/august/config_flow.py @@ -13,7 +13,6 @@ from homeassistant import config_entries from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.core import callback from homeassistant.data_entry_flow import FlowResult -from homeassistant.helpers import aiohttp_client from .const import ( CONF_ACCESS_TOKEN_CACHE_FILE, @@ -26,6 +25,7 @@ from .const import ( ) from .exceptions import CannotConnect, InvalidAuth, RequireValidation from .gateway import AugustGateway +from .util import async_create_august_clientsession _LOGGER = logging.getLogger(__name__) @@ -159,10 +159,7 @@ class AugustConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): """Set up the gateway.""" if self._august_gateway is not None: return self._august_gateway - # Create an aiohttp session instead of using the default one since the - # default one is likely to trigger august's WAF if another integration - # is also using Cloudflare - self._aiohttp_session = aiohttp_client.async_create_clientsession(self.hass) + self._aiohttp_session = async_create_august_clientsession(self.hass) self._august_gateway = AugustGateway(self.hass, self._aiohttp_session) return self._august_gateway diff --git a/homeassistant/components/august/util.py b/homeassistant/components/august/util.py new file mode 100644 index 00000000000..9703fdc6fcd --- /dev/null +++ b/homeassistant/components/august/util.py @@ -0,0 +1,24 @@ +"""August util functions.""" + +import socket + +import aiohttp + +from homeassistant.core import HomeAssistant, callback +from homeassistant.helpers import aiohttp_client + + +@callback +def async_create_august_clientsession(hass: HomeAssistant) -> aiohttp.ClientSession: + """Create an aiohttp session for the august integration.""" + # Create an aiohttp session instead of using the default one since the + # default one is likely to trigger august's WAF if another integration + # is also using Cloudflare + # + # The family is set to AF_INET because IPv6 keeps coming up as an issue + # see https://github.com/home-assistant/core/issues/97146 + # + # When https://github.com/aio-libs/aiohttp/issues/4451 is implemented + # we can allow IPv6 again + # + return aiohttp_client.async_create_clientsession(hass, family=socket.AF_INET)