mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 10:59:40 +00:00
Adding test for IOmeter __init__.py (#155006)
This commit is contained in:
@@ -1,13 +1,17 @@
|
|||||||
"""Tests for the AirGradient integration."""
|
"""Tests for the IOmeter integration."""
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from unittest.mock import AsyncMock
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
from freezegun.api import FrozenDateTimeFactory
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
|
from iometer import IOmeterConnectionError
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.components.iometer import async_setup_entry
|
||||||
from homeassistant.components.iometer.const import DOMAIN
|
from homeassistant.components.iometer.const import DOMAIN
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
|
||||||
from . import setup_platform
|
from . import setup_platform
|
||||||
@@ -23,7 +27,8 @@ async def test_new_firmware_version(
|
|||||||
freezer: FrozenDateTimeFactory,
|
freezer: FrozenDateTimeFactory,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test device registry integration."""
|
"""Test device registry integration."""
|
||||||
# await setup_integration(hass, mock_config_entry)
|
assert mock_config_entry.unique_id is not None
|
||||||
|
|
||||||
await setup_platform(hass, mock_config_entry, [Platform.SENSOR])
|
await setup_platform(hass, mock_config_entry, [Platform.SENSOR])
|
||||||
device_entry = device_registry.async_get_device(
|
device_entry = device_registry.async_get_device(
|
||||||
identifiers={(DOMAIN, mock_config_entry.unique_id)}
|
identifiers={(DOMAIN, mock_config_entry.unique_id)}
|
||||||
@@ -42,3 +47,21 @@ async def test_new_firmware_version(
|
|||||||
)
|
)
|
||||||
assert device_entry is not None
|
assert device_entry is not None
|
||||||
assert device_entry.sw_version == "build-62/build-69"
|
assert device_entry.sw_version == "build-62/build-69"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_async_setup_entry_connection_error(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_iometer_client: AsyncMock,
|
||||||
|
mock_config_entry: MockConfigEntry,
|
||||||
|
) -> None:
|
||||||
|
"""Test async_setup_entry raises ConfigEntryNotReady on connection error."""
|
||||||
|
|
||||||
|
mock_config_entry.add_to_hass(hass)
|
||||||
|
mock_iometer_client.get_current_status.side_effect = IOmeterConnectionError(
|
||||||
|
"cannot connect"
|
||||||
|
)
|
||||||
|
|
||||||
|
with pytest.raises(ConfigEntryNotReady):
|
||||||
|
await async_setup_entry(hass, mock_config_entry)
|
||||||
|
|
||||||
|
assert mock_iometer_client.get_current_status.await_count == 1
|
||||||
|
|||||||
Reference in New Issue
Block a user