Catch exception in coordinator setup of IronOS integration (#123079)

This commit is contained in:
Mr. Bubbles 2024-08-05 08:43:29 +02:00 committed by GitHub
parent 4d103c1fc2
commit 7308912b39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 1 deletions

View File

@ -46,4 +46,8 @@ class IronOSCoordinator(DataUpdateCoordinator[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

View File

@ -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