Let LG ThinQ unload when the network is down (#180610)

This commit is contained in:
Franck Nijhof
2026-08-31 08:50:54 +00:00
parent 52d5247e92
commit 85565226e1
2 changed files with 38 additions and 1 deletions
+3 -1
View File
@@ -6,6 +6,7 @@ import json
import logging
from typing import Any
from aiohttp import ClientError
from thinqconnect import (
DeviceType,
ThinQApi,
@@ -58,7 +59,8 @@ class ThinQMQTT:
if self.client is not None:
try:
await self.client.async_disconnect()
except ThinQAPIException, TypeError, ValueError:
except ThinQAPIException, TypeError, ValueError, ClientError, TimeoutError:
# Saying goodbye is a courtesy, never a reason to fail the unload
_LOGGER.exception("Failed to disconnect")
def _get_failed_device_count(
+35
View File
@@ -34,6 +34,41 @@ async def test_load_unload_entry(
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
@pytest.mark.parametrize(
"exception",
[
ThinQAPIException(code="1309", message="Not allowed api call", headers={}),
TypeError(),
ValueError(),
ClientError(),
TimeoutError(),
],
)
async def test_unload_entry_with_failing_disconnect(
hass: HomeAssistant,
mock_thinq_api: AsyncMock,
mock_config_entry: MockConfigEntry,
exception: Exception,
) -> None:
"""Test the entry unloads even when telling LG we are leaving fails."""
with patch(
"homeassistant.components.lg_thinq.ThinQMQTT.async_connect",
return_value=True,
):
await setup_integration(hass, mock_config_entry)
assert mock_config_entry.state is ConfigEntryState.LOADED
mqtt_client = mock_config_entry.runtime_data.mqtt_client
mqtt_client.client = AsyncMock()
mqtt_client.client.async_disconnect.side_effect = exception
assert await hass.config_entries.async_unload(mock_config_entry.entry_id)
await hass.async_block_till_done()
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
@pytest.mark.parametrize(
"exception",
[AttributeError(), TypeError(), ValueError(), ClientError(), TimeoutError()],