Skip to content

Commit

Permalink
Fix config entry unique_id collision in lamarzocco tests (#127484)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery authored Oct 3, 2024
1 parent 49dec15 commit 0ae0047
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
34 changes: 20 additions & 14 deletions tests/components/lamarzocco/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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."""
Expand Down
6 changes: 2 additions & 4 deletions tests/components/lamarzocco/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from freezegun.api import FrozenDateTimeFactory
from lmcloud.exceptions import RequestNotSuccessful
import pytest
from syrupy import SnapshotAssertion

from homeassistant.const import STATE_UNAVAILABLE
Expand Down Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions tests/components/lamarzocco/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 0ae0047

Please sign in to comment.