Fix config entry unique_id collision in lamarzocco tests (#127484)

This commit is contained in:
Erik Montnemery 2024-10-03 21:39:39 +02:00 committed by GitHub
parent 49dec1577e
commit 0ae0047246
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 21 deletions

View File

@ -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."""

View File

@ -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

View File

@ -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