Skip to content

Commit

Permalink
Catch exception in coordinator setup of IronOS integration (home-assi…
Browse files Browse the repository at this point in the history
  • Loading branch information
tr4nt0r authored Aug 5, 2024
1 parent 4d103c1 commit 7308912
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion homeassistant/components/iron_os/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 26 additions & 0 deletions tests/components/iron_os/test_init.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7308912

Please sign in to comment.