Fix lifx tests opening sockets (#156460)

This commit is contained in:
Erik Montnemery
2025-11-12 20:51:54 +01:00
committed by GitHub
parent 4159e483ee
commit 26bb301cc0
2 changed files with 20 additions and 7 deletions

View File

@@ -1,9 +1,10 @@
"""Tests for the lifx integration config flow."""
from collections.abc import Generator
from ipaddress import ip_address
import socket
from typing import Any
from unittest.mock import patch
from unittest.mock import AsyncMock, patch
import pytest
@@ -44,6 +45,15 @@ from . import (
from tests.common import MockConfigEntry
@pytest.fixture(autouse=True)
def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.lifx.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
async def test_discovery(hass: HomeAssistant) -> None:
"""Test setting up discovery."""
with _patch_discovery(), _patch_config_flow_try_connect():
@@ -591,6 +601,7 @@ async def test_refuse_relays(hass: HomeAssistant) -> None:
assert result2["errors"] == {"base": "cannot_connect"}
@pytest.mark.parametrize("mock_setup_entry", [None]) # Disable the autouse fixture
async def test_suggested_area(
hass: HomeAssistant,
area_registry: ar.AreaRegistry,

View File

@@ -1619,9 +1619,10 @@ async def test_transitions_brightness_only(hass: HomeAssistant) -> None:
bulb.get_color.reset_mock()
# Ensure we force an update after the transition
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=5))
await hass.async_block_till_done()
assert len(bulb.get_color.calls) == 2
with _patch_discovery(device=bulb):
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=5))
await hass.async_block_till_done()
assert len(bulb.get_color.calls) == 2
async def test_transitions_color_bulb(hass: HomeAssistant) -> None:
@@ -1714,9 +1715,10 @@ async def test_transitions_color_bulb(hass: HomeAssistant) -> None:
bulb.get_color.reset_mock()
# Ensure we force an update after the transition
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=5))
await hass.async_block_till_done()
assert len(bulb.get_color.calls) == 2
with _patch_discovery(device=bulb):
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=5))
await hass.async_block_till_done()
assert len(bulb.get_color.calls) == 2
bulb.set_power.reset_mock()
bulb.set_color.reset_mock()