mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Add full test coverage for Comelit coordinator (#141321)
* Add full test coverage for Comelit coordinator * add common const * apply review comment
This commit is contained in:
parent
7bcba2b639
commit
d7de8c5f68
@ -9,3 +9,5 @@ _LOGGER = logging.getLogger(__package__)
|
|||||||
DOMAIN = "comelit"
|
DOMAIN = "comelit"
|
||||||
DEFAULT_PORT = 80
|
DEFAULT_PORT = 80
|
||||||
DEVICE_TYPE_LIST = [BRIDGE, VEDO]
|
DEVICE_TYPE_LIST = [BRIDGE, VEDO]
|
||||||
|
|
||||||
|
SCAN_INTERVAL = 5
|
||||||
|
@ -22,7 +22,7 @@ from homeassistant.exceptions import ConfigEntryAuthFailed
|
|||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
from .const import _LOGGER, DOMAIN
|
from .const import _LOGGER, DOMAIN, SCAN_INTERVAL
|
||||||
|
|
||||||
type ComelitConfigEntry = ConfigEntry[ComelitBaseCoordinator]
|
type ComelitConfigEntry = ConfigEntry[ComelitBaseCoordinator]
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ class ComelitBaseCoordinator(DataUpdateCoordinator[T]):
|
|||||||
logger=_LOGGER,
|
logger=_LOGGER,
|
||||||
config_entry=entry,
|
config_entry=entry,
|
||||||
name=f"{DOMAIN}-{host}-coordinator",
|
name=f"{DOMAIN}-{host}-coordinator",
|
||||||
update_interval=timedelta(seconds=5),
|
update_interval=timedelta(seconds=SCAN_INTERVAL),
|
||||||
)
|
)
|
||||||
device_registry = dr.async_get(self.hass)
|
device_registry = dr.async_get(self.hass)
|
||||||
device_registry.async_get_or_create(
|
device_registry.async_get_or_create(
|
||||||
|
49
tests/components/comelit/test_coordinator.py
Normal file
49
tests/components/comelit/test_coordinator.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
"""Tests for Comelit SimpleHome coordinator."""
|
||||||
|
|
||||||
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
|
from aiocomelit.exceptions import CannotAuthenticate, CannotConnect, CannotRetrieveData
|
||||||
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.components.comelit.const import SCAN_INTERVAL
|
||||||
|
from homeassistant.const import STATE_OFF, STATE_UNAVAILABLE
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from . import setup_integration
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"side_effect",
|
||||||
|
[
|
||||||
|
CannotConnect,
|
||||||
|
CannotRetrieveData,
|
||||||
|
CannotAuthenticate,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_coordinator_data_update_fails(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
freezer: FrozenDateTimeFactory,
|
||||||
|
mock_serial_bridge: AsyncMock,
|
||||||
|
mock_serial_bridge_config_entry: MockConfigEntry,
|
||||||
|
side_effect: Exception,
|
||||||
|
) -> None:
|
||||||
|
"""Test coordinator data update exceptions."""
|
||||||
|
|
||||||
|
entity_id = "light.light0"
|
||||||
|
|
||||||
|
await setup_integration(hass, mock_serial_bridge_config_entry)
|
||||||
|
|
||||||
|
assert (state := hass.states.get(entity_id))
|
||||||
|
assert state.state == STATE_OFF
|
||||||
|
|
||||||
|
mock_serial_bridge.login.side_effect = side_effect
|
||||||
|
|
||||||
|
freezer.tick(SCAN_INTERVAL)
|
||||||
|
async_fire_time_changed(hass)
|
||||||
|
await hass.async_block_till_done(wait_background_tasks=True)
|
||||||
|
|
||||||
|
assert (state := hass.states.get(entity_id))
|
||||||
|
assert state.state == STATE_UNAVAILABLE
|
Loading…
x
Reference in New Issue
Block a user