Skip to content

Commit a3d7601

Browse files
authored
Adding test for IOmeter __init__.py (home-assistant#155006)
1 parent 6e194ad commit a3d7601

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

tests/components/iometer/test_init.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
"""Tests for the AirGradient integration."""
1+
"""Tests for the IOmeter integration."""
22

33
from datetime import timedelta
44
from unittest.mock import AsyncMock
55

66
from freezegun.api import FrozenDateTimeFactory
7+
from iometer import IOmeterConnectionError
8+
import pytest
79

10+
from homeassistant.components.iometer import async_setup_entry
811
from homeassistant.components.iometer.const import DOMAIN
912
from homeassistant.const import Platform
1013
from homeassistant.core import HomeAssistant
14+
from homeassistant.exceptions import ConfigEntryNotReady
1115
from homeassistant.helpers import device_registry as dr
1216

1317
from . import setup_platform
@@ -23,7 +27,8 @@ async def test_new_firmware_version(
2327
freezer: FrozenDateTimeFactory,
2428
) -> None:
2529
"""Test device registry integration."""
26-
# await setup_integration(hass, mock_config_entry)
30+
assert mock_config_entry.unique_id is not None
31+
2732
await setup_platform(hass, mock_config_entry, [Platform.SENSOR])
2833
device_entry = device_registry.async_get_device(
2934
identifiers={(DOMAIN, mock_config_entry.unique_id)}
@@ -42,3 +47,21 @@ async def test_new_firmware_version(
4247
)
4348
assert device_entry is not None
4449
assert device_entry.sw_version == "build-62/build-69"
50+
51+
52+
async def test_async_setup_entry_connection_error(
53+
hass: HomeAssistant,
54+
mock_iometer_client: AsyncMock,
55+
mock_config_entry: MockConfigEntry,
56+
) -> None:
57+
"""Test async_setup_entry raises ConfigEntryNotReady on connection error."""
58+
59+
mock_config_entry.add_to_hass(hass)
60+
mock_iometer_client.get_current_status.side_effect = IOmeterConnectionError(
61+
"cannot connect"
62+
)
63+
64+
with pytest.raises(ConfigEntryNotReady):
65+
await async_setup_entry(hass, mock_config_entry)
66+
67+
assert mock_iometer_client.get_current_status.await_count == 1

0 commit comments

Comments
 (0)