From 7308912b391ad9feeea05bd97a7e782f3d1b32a1 Mon Sep 17 00:00:00 2001 From: "Mr. Bubbles" Date: Mon, 5 Aug 2024 08:43:29 +0200 Subject: [PATCH] Catch exception in coordinator setup of IronOS integration (#123079) --- .../components/iron_os/coordinator.py | 6 ++++- tests/components/iron_os/test_init.py | 26 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/components/iron_os/test_init.py diff --git a/homeassistant/components/iron_os/coordinator.py b/homeassistant/components/iron_os/coordinator.py index e8424478d865cd..aefb14b689ba1e 100644 --- a/homeassistant/components/iron_os/coordinator.py +++ b/homeassistant/components/iron_os/coordinator.py @@ -46,4 +46,8 @@ async def _async_update_data(self) -> LiveDataResponse: async def _async_setup(self) -> None: """Set up the coordinator.""" - self.device_info = await self.device.get_device_info() + try: + self.device_info = await self.device.get_device_info() + + except CommunicationError as e: + raise UpdateFailed("Cannot connect to device") from e diff --git a/tests/components/iron_os/test_init.py b/tests/components/iron_os/test_init.py new file mode 100644 index 00000000000000..fb0a782ea36ab1 --- /dev/null +++ b/tests/components/iron_os/test_init.py @@ -0,0 +1,26 @@ +"""Test init of IronOS integration.""" + +from unittest.mock import AsyncMock + +from pynecil import CommunicationError +import pytest + +from homeassistant.config_entries import ConfigEntryState +from homeassistant.core import HomeAssistant + +from tests.common import MockConfigEntry + + +@pytest.mark.usefixtures("ble_device") +async def test_setup_config_entry_not_ready( + hass: HomeAssistant, + config_entry: MockConfigEntry, + mock_pynecil: AsyncMock, +) -> None: + """Test config entry not ready.""" + mock_pynecil.get_device_info.side_effect = CommunicationError + config_entry.add_to_hass(hass) + await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() + + assert config_entry.state is ConfigEntryState.SETUP_RETRY