diff --git a/tests/components/freedompro/conftest.py b/tests/components/freedompro/conftest.py index c43887fa487..36070c1a0d5 100644 --- a/tests/components/freedompro/conftest.py +++ b/tests/components/freedompro/conftest.py @@ -9,6 +9,22 @@ from tests.common import MockConfigEntry from tests.components.freedompro.const import DEVICES, DEVICES_STATE +@pytest.fixture(autouse=True) +def mock_freedompro(): + """Mock freedompro get_list and get_states.""" + with patch( + "homeassistant.components.freedompro.get_list", + return_value={ + "state": True, + "devices": DEVICES, + }, + ), patch( + "homeassistant.components.freedompro.get_states", + return_value=DEVICES_STATE, + ): + yield + + @pytest.fixture async def init_integration(hass) -> MockConfigEntry: """Set up the Freedompro integration in Home Assistant.""" @@ -21,19 +37,9 @@ async def init_integration(hass) -> MockConfigEntry: }, ) - with patch( - "homeassistant.components.freedompro.get_list", - return_value={ - "state": True, - "devices": DEVICES, - }, - ), patch( - "homeassistant.components.freedompro.get_states", - return_value=DEVICES_STATE, - ): - entry.add_to_hass(hass) - await hass.config_entries.async_setup(entry.entry_id) - await hass.async_block_till_done() + entry.add_to_hass(hass) + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() return entry diff --git a/tests/components/freedompro/test_config_flow.py b/tests/components/freedompro/test_config_flow.py index f44cbd232ad..42dc0674d07 100644 --- a/tests/components/freedompro/test_config_flow.py +++ b/tests/components/freedompro/test_config_flow.py @@ -26,7 +26,7 @@ async def test_show_form(hass): async def test_invalid_auth(hass): """Test that errors are shown when API key is invalid.""" with patch( - "homeassistant.components.freedompro.config_flow.list", + "homeassistant.components.freedompro.config_flow.get_list", return_value={ "state": False, "code": -201, diff --git a/tests/components/freedompro/test_light.py b/tests/components/freedompro/test_light.py index 09a945ada03..b23ebf85676 100644 --- a/tests/components/freedompro/test_light.py +++ b/tests/components/freedompro/test_light.py @@ -1,4 +1,8 @@ """Tests for the Freedompro light.""" +from unittest.mock import patch + +import pytest + from homeassistant.components.light import ( ATTR_BRIGHTNESS, ATTR_HS_COLOR, @@ -9,6 +13,13 @@ from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, STATE_OFF, STA from homeassistant.helpers import entity_registry as er +@pytest.fixture(autouse=True) +def mock_freedompro_put_state(): + """Mock freedompro put_state.""" + with patch("homeassistant.components.freedompro.light.put_state"): + yield + + async def test_light_get_state(hass, init_integration): """Test states of the light.""" init_integration