From 0ae0047246b815f721a33f448ac7c5a5f7132418 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Thu, 3 Oct 2024 21:39:39 +0200 Subject: [PATCH] Fix config entry unique_id collision in lamarzocco tests (#127484) --- tests/components/lamarzocco/conftest.py | 34 +++++++++++-------- .../lamarzocco/test_binary_sensor.py | 6 ++-- tests/components/lamarzocco/test_sensor.py | 5 ++- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/tests/components/lamarzocco/conftest.py b/tests/components/lamarzocco/conftest.py index 1a4fbbd4a0c..2520433e86a 100644 --- a/tests/components/lamarzocco/conftest.py +++ b/tests/components/lamarzocco/conftest.py @@ -24,7 +24,7 @@ def mock_config_entry( hass: HomeAssistant, mock_lamarzocco: MagicMock ) -> MockConfigEntry: """Return the default mocked config entry.""" - entry = MockConfigEntry( + return MockConfigEntry( title="My LaMarzocco", domain=DOMAIN, version=2, @@ -37,8 +37,25 @@ def mock_config_entry( }, unique_id=mock_lamarzocco.serial_number, ) - entry.add_to_hass(hass) - return entry + + +@pytest.fixture +def mock_config_entry_no_local_connection( + hass: HomeAssistant, mock_lamarzocco: MagicMock +) -> MockConfigEntry: + """Return the default mocked config entry.""" + return MockConfigEntry( + title="My LaMarzocco", + domain=DOMAIN, + version=2, + data=USER_INPUT + | { + CONF_MODEL: mock_lamarzocco.model, + CONF_TOKEN: "token", + CONF_NAME: "GS3", + }, + unique_id=mock_lamarzocco.serial_number, + ) @pytest.fixture @@ -131,17 +148,6 @@ def mock_lamarzocco(device_fixture: MachineModel) -> Generator[MagicMock]: yield lamarzocco -@pytest.fixture -def remove_local_connection( - hass: HomeAssistant, mock_config_entry: MockConfigEntry -) -> MockConfigEntry: - """Remove the local connection.""" - data = mock_config_entry.data.copy() - del data[CONF_HOST] - hass.config_entries.async_update_entry(mock_config_entry, data=data) - return mock_config_entry - - @pytest.fixture(autouse=True) def mock_bluetooth(enable_bluetooth: None) -> None: """Auto mock bluetooth.""" diff --git a/tests/components/lamarzocco/test_binary_sensor.py b/tests/components/lamarzocco/test_binary_sensor.py index d363b96ca21..120d825c804 100644 --- a/tests/components/lamarzocco/test_binary_sensor.py +++ b/tests/components/lamarzocco/test_binary_sensor.py @@ -5,7 +5,6 @@ from unittest.mock import MagicMock from freezegun.api import FrozenDateTimeFactory from lmcloud.exceptions import RequestNotSuccessful -import pytest from syrupy import SnapshotAssertion from homeassistant.const import STATE_UNAVAILABLE @@ -47,15 +46,14 @@ async def test_binary_sensors( assert entry == snapshot(name=f"{serial_number}_{binary_sensor}-entry") -@pytest.mark.usefixtures("remove_local_connection") async def test_brew_active_does_not_exists( hass: HomeAssistant, mock_lamarzocco: MagicMock, - mock_config_entry: MockConfigEntry, + mock_config_entry_no_local_connection: MockConfigEntry, ) -> None: """Test the La Marzocco currently_making_coffee doesn't exist if host not set.""" - await async_init_integration(hass, mock_config_entry) + await async_init_integration(hass, mock_config_entry_no_local_connection) state = hass.states.get(f"sensor.{mock_lamarzocco.serial_number}_brewing_active") assert state is None diff --git a/tests/components/lamarzocco/test_sensor.py b/tests/components/lamarzocco/test_sensor.py index 1ce56724fa3..760dcffd28f 100644 --- a/tests/components/lamarzocco/test_sensor.py +++ b/tests/components/lamarzocco/test_sensor.py @@ -47,15 +47,14 @@ async def test_sensors( assert entry == snapshot(name=f"{serial_number}_{sensor}-entry") -@pytest.mark.usefixtures("remove_local_connection") async def test_shot_timer_not_exists( hass: HomeAssistant, mock_lamarzocco: MagicMock, - mock_config_entry: MockConfigEntry, + mock_config_entry_no_local_connection: MockConfigEntry, ) -> None: """Test the La Marzocco shot timer doesn't exist if host not set.""" - await async_init_integration(hass, mock_config_entry) + await async_init_integration(hass, mock_config_entry_no_local_connection) state = hass.states.get(f"sensor.{mock_lamarzocco.serial_number}_shot_timer") assert state is None