hass-core/tests/components/lifx/conftest.py
Avi Miller 0e63a4c091
Fix lifx service call interference (#77770)
* Fix #77735 by restoring the wait to let state settle

Signed-off-by: Avi Miller <me@dje.li>

* Skip the asyncio.sleep during testing

Signed-off-by: Avi Miller <me@dje.li>

* Patch out asyncio.sleep for lifx tests

Signed-off-by: Avi Miller <me@dje.li>

* Patch out a constant instead of overriding asyncio.sleep directly

Signed-off-by: Avi Miller <me@dje.li>

Signed-off-by: Avi Miller <me@dje.li>
2022-09-04 17:51:57 +02:00

56 lines
1.4 KiB
Python

"""Tests for the lifx integration."""
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from tests.common import mock_device_registry, mock_registry
@pytest.fixture
def mock_effect_conductor():
"""Mock the effect conductor."""
class MockConductor:
def __init__(self, *args, **kwargs) -> None:
"""Mock the conductor."""
self.start = AsyncMock()
self.stop = AsyncMock()
def effect(self, bulb):
"""Mock effect."""
return MagicMock()
mock_conductor = MockConductor()
with patch(
"homeassistant.components.lifx.manager.aiolifx_effects.Conductor",
return_value=mock_conductor,
):
yield mock_conductor
@pytest.fixture(autouse=True)
def lifx_mock_get_source_ip(mock_get_source_ip):
"""Mock network util's async_get_source_ip."""
@pytest.fixture(autouse=True)
def lifx_mock_async_get_ipv4_broadcast_addresses():
"""Mock network util's async_get_ipv4_broadcast_addresses."""
with patch(
"homeassistant.components.network.async_get_ipv4_broadcast_addresses",
return_value=["255.255.255.255"],
):
yield
@pytest.fixture(name="device_reg")
def device_reg_fixture(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture(name="entity_reg")
def entity_reg_fixture(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)