Fix LG ThinQ failing to set up during a temporary network outage (#179901)

This commit is contained in:
Marco
2026-08-23 12:33:01 -04:00
committed by GitHub
parent ee8b7874bc
commit 7e1ffafc59
2 changed files with 43 additions and 3 deletions
@@ -4,6 +4,7 @@ import asyncio
from dataclasses import dataclass, field
import logging
from aiohttp import ClientError
from thinqconnect import ThinQApi, ThinQAPIException
from thinqconnect.integration import async_get_ha_bridge_list
@@ -93,6 +94,11 @@ async def async_setup_coordinators(
bridge_list = await async_get_ha_bridge_list(thinq_api)
except ThinQAPIException as exc:
raise ConfigEntryNotReady(exc.message) from exc
except (ClientError, TimeoutError) as exc:
raise ConfigEntryNotReady(
translation_domain=DOMAIN,
translation_key="connection_error",
) from exc
if not bridge_list:
_LOGGER.warning("No devices registered with the correct profile")
@@ -144,6 +150,11 @@ async def async_setup_mqtt(
translation_key="failed_to_connect_mqtt",
translation_placeholders={"error": str(exc)},
) from exc
except (ClientError, TimeoutError) as exc:
raise ConfigEntryNotReady(
translation_domain=DOMAIN,
translation_key="connection_error",
) from exc
if not result:
_LOGGER.error("Failed to set up mqtt connection")
+32 -3
View File
@@ -2,7 +2,9 @@
from unittest.mock import AsyncMock, patch
from aiohttp import ClientError
import pytest
from thinqconnect import ThinQAPIException
from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant
@@ -32,14 +34,17 @@ async def test_load_unload_entry(
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
@pytest.mark.parametrize("exception", [AttributeError(), TypeError(), ValueError()])
async def test_config_not_ready(
@pytest.mark.parametrize(
"exception",
[AttributeError(), TypeError(), ValueError(), ClientError(), TimeoutError()],
)
async def test_config_not_ready_mqtt(
hass: HomeAssistant,
mock_thinq_api: AsyncMock,
mock_config_entry: MockConfigEntry,
exception: Exception,
) -> None:
"""Test for setup failure exception occurred."""
"""Test for setup failure exception occurred during MQTT setup."""
with patch(
"homeassistant.components.lg_thinq.ThinQMQTT.async_connect",
side_effect=exception,
@@ -47,3 +52,27 @@ async def test_config_not_ready(
await setup_integration(hass, mock_config_entry)
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
@pytest.mark.parametrize(
"exception",
[
ThinQAPIException(code="1309", message="Not allowed api call", headers={}),
ClientError(),
TimeoutError(),
],
)
async def test_config_not_ready_bridge_list(
hass: HomeAssistant,
mock_thinq_api: AsyncMock,
mock_config_entry: MockConfigEntry,
exception: Exception,
) -> None:
"""Test for setup failure exception occurred during coordinator setup."""
with patch(
"homeassistant.components.lg_thinq.async_get_ha_bridge_list",
side_effect=exception,
):
await setup_integration(hass, mock_config_entry)
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY