mirror of
https://github.com/home-assistant/core.git
synced 2026-09-25 17:04:04 -04:00
Let LG ThinQ unload when the network is down (#180610)
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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()],
|
||||
|
||||
Reference in New Issue
Block a user