mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Fix config entry unique_id collision in lamarzocco tests (#127484)
This commit is contained in:
parent
49dec1577e
commit
0ae0047246
@ -24,7 +24,7 @@ def mock_config_entry(
|
|||||||
hass: HomeAssistant, mock_lamarzocco: MagicMock
|
hass: HomeAssistant, mock_lamarzocco: MagicMock
|
||||||
) -> MockConfigEntry:
|
) -> MockConfigEntry:
|
||||||
"""Return the default mocked config entry."""
|
"""Return the default mocked config entry."""
|
||||||
entry = MockConfigEntry(
|
return MockConfigEntry(
|
||||||
title="My LaMarzocco",
|
title="My LaMarzocco",
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
version=2,
|
version=2,
|
||||||
@ -37,8 +37,25 @@ def mock_config_entry(
|
|||||||
},
|
},
|
||||||
unique_id=mock_lamarzocco.serial_number,
|
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
|
@pytest.fixture
|
||||||
@ -131,17 +148,6 @@ def mock_lamarzocco(device_fixture: MachineModel) -> Generator[MagicMock]:
|
|||||||
yield lamarzocco
|
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)
|
@pytest.fixture(autouse=True)
|
||||||
def mock_bluetooth(enable_bluetooth: None) -> None:
|
def mock_bluetooth(enable_bluetooth: None) -> None:
|
||||||
"""Auto mock bluetooth."""
|
"""Auto mock bluetooth."""
|
||||||
|
@ -5,7 +5,6 @@ from unittest.mock import MagicMock
|
|||||||
|
|
||||||
from freezegun.api import FrozenDateTimeFactory
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
from lmcloud.exceptions import RequestNotSuccessful
|
from lmcloud.exceptions import RequestNotSuccessful
|
||||||
import pytest
|
|
||||||
from syrupy import SnapshotAssertion
|
from syrupy import SnapshotAssertion
|
||||||
|
|
||||||
from homeassistant.const import STATE_UNAVAILABLE
|
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")
|
assert entry == snapshot(name=f"{serial_number}_{binary_sensor}-entry")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("remove_local_connection")
|
|
||||||
async def test_brew_active_does_not_exists(
|
async def test_brew_active_does_not_exists(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_lamarzocco: MagicMock,
|
mock_lamarzocco: MagicMock,
|
||||||
mock_config_entry: MockConfigEntry,
|
mock_config_entry_no_local_connection: MockConfigEntry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the La Marzocco currently_making_coffee doesn't exist if host not set."""
|
"""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")
|
state = hass.states.get(f"sensor.{mock_lamarzocco.serial_number}_brewing_active")
|
||||||
assert state is None
|
assert state is None
|
||||||
|
|
||||||
|
@ -47,15 +47,14 @@ async def test_sensors(
|
|||||||
assert entry == snapshot(name=f"{serial_number}_{sensor}-entry")
|
assert entry == snapshot(name=f"{serial_number}_{sensor}-entry")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("remove_local_connection")
|
|
||||||
async def test_shot_timer_not_exists(
|
async def test_shot_timer_not_exists(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_lamarzocco: MagicMock,
|
mock_lamarzocco: MagicMock,
|
||||||
mock_config_entry: MockConfigEntry,
|
mock_config_entry_no_local_connection: MockConfigEntry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the La Marzocco shot timer doesn't exist if host not set."""
|
"""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")
|
state = hass.states.get(f"sensor.{mock_lamarzocco.serial_number}_shot_timer")
|
||||||
assert state is None
|
assert state is None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user