Cleanup lamarzocco tests (#134383)

This commit is contained in:
Josef Zweck 2025-01-01 13:00:14 +01:00 committed by GitHub
parent 809629c0e2
commit 7ab2d2e07a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 242 additions and 173 deletions

View File

@ -1,19 +1,5 @@
# serializer version: 1 # serializer version: 1
# name: test_binary_sensors[GS012345_backflush_active-binary_sensor] # name: test_binary_sensors[binary_sensor.gs012345_backflush_active-entry]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'running',
'friendly_name': 'GS012345 Backflush active',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.gs012345_backflush_active',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_binary_sensors[GS012345_backflush_active-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({
}), }),
@ -46,21 +32,21 @@
'unit_of_measurement': None, 'unit_of_measurement': None,
}) })
# --- # ---
# name: test_binary_sensors[GS012345_brewing_active-binary_sensor] # name: test_binary_sensors[binary_sensor.gs012345_backflush_active-state]
StateSnapshot({ StateSnapshot({
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({
'device_class': 'running', 'device_class': 'running',
'friendly_name': 'GS012345 Brewing active', 'friendly_name': 'GS012345 Backflush active',
}), }),
'context': <ANY>, 'context': <ANY>,
'entity_id': 'binary_sensor.gs012345_brewing_active', 'entity_id': 'binary_sensor.gs012345_backflush_active',
'last_changed': <ANY>, 'last_changed': <ANY>,
'last_reported': <ANY>, 'last_reported': <ANY>,
'last_updated': <ANY>, 'last_updated': <ANY>,
'state': 'off', 'state': 'off',
}) })
# --- # ---
# name: test_binary_sensors[GS012345_brewing_active-entry] # name: test_binary_sensors[binary_sensor.gs012345_brewing_active-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({
}), }),
@ -93,21 +79,21 @@
'unit_of_measurement': None, 'unit_of_measurement': None,
}) })
# --- # ---
# name: test_binary_sensors[GS012345_water_tank_empty-binary_sensor] # name: test_binary_sensors[binary_sensor.gs012345_brewing_active-state]
StateSnapshot({ StateSnapshot({
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({
'device_class': 'problem', 'device_class': 'running',
'friendly_name': 'GS012345 Water tank empty', 'friendly_name': 'GS012345 Brewing active',
}), }),
'context': <ANY>, 'context': <ANY>,
'entity_id': 'binary_sensor.gs012345_water_tank_empty', 'entity_id': 'binary_sensor.gs012345_brewing_active',
'last_changed': <ANY>, 'last_changed': <ANY>,
'last_reported': <ANY>, 'last_reported': <ANY>,
'last_updated': <ANY>, 'last_updated': <ANY>,
'state': 'off', 'state': 'off',
}) })
# --- # ---
# name: test_binary_sensors[GS012345_water_tank_empty-entry] # name: test_binary_sensors[binary_sensor.gs012345_water_tank_empty-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({
}), }),
@ -140,6 +126,20 @@
'unit_of_measurement': None, 'unit_of_measurement': None,
}) })
# --- # ---
# name: test_binary_sensors[binary_sensor.gs012345_water_tank_empty-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'problem',
'friendly_name': 'GS012345 Water tank empty',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.gs012345_water_tank_empty',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_scale_connectivity[Linea Mini] # name: test_scale_connectivity[Linea Mini]
StateSnapshot({ StateSnapshot({
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({

View File

@ -50,7 +50,7 @@
'unit_of_measurement': '%', 'unit_of_measurement': '%',
}) })
# --- # ---
# name: test_sensors[GS012345_current_coffee_temperature-entry] # name: test_sensors[sensor.gs012345_current_coffee_temperature-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({
}), }),
@ -88,7 +88,7 @@
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>, 'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>,
}) })
# --- # ---
# name: test_sensors[GS012345_current_coffee_temperature-sensor] # name: test_sensors[sensor.gs012345_current_coffee_temperature-state]
StateSnapshot({ StateSnapshot({
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({
'device_class': 'temperature', 'device_class': 'temperature',
@ -104,7 +104,7 @@
'state': '96.5', 'state': '96.5',
}) })
# --- # ---
# name: test_sensors[GS012345_current_steam_temperature-entry] # name: test_sensors[sensor.gs012345_current_steam_temperature-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({
}), }),
@ -142,7 +142,7 @@
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>, 'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>,
}) })
# --- # ---
# name: test_sensors[GS012345_current_steam_temperature-sensor] # name: test_sensors[sensor.gs012345_current_steam_temperature-state]
StateSnapshot({ StateSnapshot({
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({
'device_class': 'temperature', 'device_class': 'temperature',
@ -158,7 +158,7 @@
'state': '123.800003051758', 'state': '123.800003051758',
}) })
# --- # ---
# name: test_sensors[GS012345_shot_timer-entry] # name: test_sensors[sensor.gs012345_shot_timer-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({
}), }),
@ -193,7 +193,7 @@
'unit_of_measurement': <UnitOfTime.SECONDS: 's'>, 'unit_of_measurement': <UnitOfTime.SECONDS: 's'>,
}) })
# --- # ---
# name: test_sensors[GS012345_shot_timer-sensor] # name: test_sensors[sensor.gs012345_shot_timer-state]
StateSnapshot({ StateSnapshot({
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({
'device_class': 'duration', 'device_class': 'duration',
@ -209,7 +209,7 @@
'state': '0', 'state': '0',
}) })
# --- # ---
# name: test_sensors[GS012345_total_coffees_made-entry] # name: test_sensors[sensor.gs012345_total_coffees_made-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({
}), }),
@ -244,7 +244,7 @@
'unit_of_measurement': 'drinks', 'unit_of_measurement': 'drinks',
}) })
# --- # ---
# name: test_sensors[GS012345_total_coffees_made-sensor] # name: test_sensors[sensor.gs012345_total_coffees_made-state]
StateSnapshot({ StateSnapshot({
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({
'friendly_name': 'GS012345 Total coffees made', 'friendly_name': 'GS012345 Total coffees made',
@ -259,7 +259,7 @@
'state': '1047', 'state': '1047',
}) })
# --- # ---
# name: test_sensors[GS012345_total_flushes_made-entry] # name: test_sensors[sensor.gs012345_total_flushes_made-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({
}), }),
@ -294,7 +294,7 @@
'unit_of_measurement': 'drinks', 'unit_of_measurement': 'drinks',
}) })
# --- # ---
# name: test_sensors[GS012345_total_flushes_made-sensor] # name: test_sensors[sensor.gs012345_total_flushes_made-state]
StateSnapshot({ StateSnapshot({
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({
'friendly_name': 'GS012345 Total flushes made', 'friendly_name': 'GS012345 Total flushes made',

View File

@ -91,20 +91,7 @@
'state': 'on', 'state': 'on',
}) })
# --- # ---
# name: test_switches[-set_power-kwargs0] # name: test_switches[switch.gs012345-entry]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'GS012345',
}),
'context': <ANY>,
'entity_id': 'switch.gs012345',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---
# name: test_switches[-set_power-kwargs0].1
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({
}), }),
@ -137,20 +124,112 @@
'unit_of_measurement': None, 'unit_of_measurement': None,
}) })
# --- # ---
# name: test_switches[_smart_standby_enabled-set_smart_standby-kwargs2] # name: test_switches[switch.gs012345-state]
StateSnapshot({ StateSnapshot({
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({
'friendly_name': 'GS012345 Smart standby enabled', 'friendly_name': 'GS012345',
}), }),
'context': <ANY>, 'context': <ANY>,
'entity_id': 'switch.gs012345_smart_standby_enabled', 'entity_id': 'switch.gs012345',
'last_changed': <ANY>, 'last_changed': <ANY>,
'last_reported': <ANY>, 'last_reported': <ANY>,
'last_updated': <ANY>, 'last_updated': <ANY>,
'state': 'on', 'state': 'on',
}) })
# --- # ---
# name: test_switches[_smart_standby_enabled-set_smart_standby-kwargs2].1 # name: test_switches[switch.gs012345_auto_on_off_axfz5bj-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'switch',
'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'switch.gs012345_auto_on_off_axfz5bj',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Auto on/off (aXFz5bJ)',
'platform': 'lamarzocco',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'auto_on_off',
'unique_id': 'GS012345_auto_on_off_aXFz5bJ',
'unit_of_measurement': None,
})
# ---
# name: test_switches[switch.gs012345_auto_on_off_axfz5bj-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'GS012345 Auto on/off (aXFz5bJ)',
}),
'context': <ANY>,
'entity_id': 'switch.gs012345_auto_on_off_axfz5bj',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---
# name: test_switches[switch.gs012345_auto_on_off_os2oswx-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'switch',
'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'switch.gs012345_auto_on_off_os2oswx',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Auto on/off (Os2OswX)',
'platform': 'lamarzocco',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'auto_on_off',
'unique_id': 'GS012345_auto_on_off_Os2OswX',
'unit_of_measurement': None,
})
# ---
# name: test_switches[switch.gs012345_auto_on_off_os2oswx-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'GS012345 Auto on/off (Os2OswX)',
}),
'context': <ANY>,
'entity_id': 'switch.gs012345_auto_on_off_os2oswx',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---
# name: test_switches[switch.gs012345_smart_standby_enabled-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({
}), }),
@ -183,20 +262,20 @@
'unit_of_measurement': None, 'unit_of_measurement': None,
}) })
# --- # ---
# name: test_switches[_steam_boiler-set_steam-kwargs1] # name: test_switches[switch.gs012345_smart_standby_enabled-state]
StateSnapshot({ StateSnapshot({
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({
'friendly_name': 'GS012345 Steam boiler', 'friendly_name': 'GS012345 Smart standby enabled',
}), }),
'context': <ANY>, 'context': <ANY>,
'entity_id': 'switch.gs012345_steam_boiler', 'entity_id': 'switch.gs012345_smart_standby_enabled',
'last_changed': <ANY>, 'last_changed': <ANY>,
'last_reported': <ANY>, 'last_reported': <ANY>,
'last_updated': <ANY>, 'last_updated': <ANY>,
'state': 'on', 'state': 'on',
}) })
# --- # ---
# name: test_switches[_steam_boiler-set_steam-kwargs1].1 # name: test_switches[switch.gs012345_steam_boiler-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({
}), }),
@ -229,3 +308,16 @@
'unit_of_measurement': None, 'unit_of_measurement': None,
}) })
# --- # ---
# name: test_switches[switch.gs012345_steam_boiler-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'GS012345 Steam boiler',
}),
'context': <ANY>,
'entity_id': 'switch.gs012345_steam_boiler',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---

View File

@ -1,31 +1,5 @@
# serializer version: 1 # serializer version: 1
# name: test_update_entites[gateway_firmware-gateway] # name: test_update[update.gs012345_gateway_firmware-entry]
StateSnapshot({
'attributes': ReadOnlyDict({
'auto_update': False,
'device_class': 'firmware',
'display_precision': 0,
'entity_picture': 'https://brands.home-assistant.io/_/lamarzocco/icon.png',
'friendly_name': 'GS012345 Gateway firmware',
'in_progress': False,
'installed_version': 'v3.1-rc4',
'latest_version': 'v3.5-rc3',
'release_summary': None,
'release_url': 'https://support-iot.lamarzocco.com/firmware-updates/',
'skipped_version': None,
'supported_features': <UpdateEntityFeature: 1>,
'title': None,
'update_percentage': None,
}),
'context': <ANY>,
'entity_id': 'update.gs012345_gateway_firmware',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---
# name: test_update_entites[gateway_firmware-gateway].1
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({
}), }),
@ -58,17 +32,17 @@
'unit_of_measurement': None, 'unit_of_measurement': None,
}) })
# --- # ---
# name: test_update_entites[machine_firmware-machine] # name: test_update[update.gs012345_gateway_firmware-state]
StateSnapshot({ StateSnapshot({
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({
'auto_update': False, 'auto_update': False,
'device_class': 'firmware', 'device_class': 'firmware',
'display_precision': 0, 'display_precision': 0,
'entity_picture': 'https://brands.home-assistant.io/_/lamarzocco/icon.png', 'entity_picture': 'https://brands.home-assistant.io/_/lamarzocco/icon.png',
'friendly_name': 'GS012345 Machine firmware', 'friendly_name': 'GS012345 Gateway firmware',
'in_progress': False, 'in_progress': False,
'installed_version': '1.40', 'installed_version': 'v3.1-rc4',
'latest_version': '1.55', 'latest_version': 'v3.5-rc3',
'release_summary': None, 'release_summary': None,
'release_url': 'https://support-iot.lamarzocco.com/firmware-updates/', 'release_url': 'https://support-iot.lamarzocco.com/firmware-updates/',
'skipped_version': None, 'skipped_version': None,
@ -77,14 +51,14 @@
'update_percentage': None, 'update_percentage': None,
}), }),
'context': <ANY>, 'context': <ANY>,
'entity_id': 'update.gs012345_machine_firmware', 'entity_id': 'update.gs012345_gateway_firmware',
'last_changed': <ANY>, 'last_changed': <ANY>,
'last_reported': <ANY>, 'last_reported': <ANY>,
'last_updated': <ANY>, 'last_updated': <ANY>,
'state': 'on', 'state': 'on',
}) })
# --- # ---
# name: test_update_entites[machine_firmware-machine].1 # name: test_update[update.gs012345_machine_firmware-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({
}), }),
@ -117,3 +91,29 @@
'unit_of_measurement': None, 'unit_of_measurement': None,
}) })
# --- # ---
# name: test_update[update.gs012345_machine_firmware-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'auto_update': False,
'device_class': 'firmware',
'display_precision': 0,
'entity_picture': 'https://brands.home-assistant.io/_/lamarzocco/icon.png',
'friendly_name': 'GS012345 Machine firmware',
'in_progress': False,
'installed_version': '1.40',
'latest_version': '1.55',
'release_summary': None,
'release_url': 'https://support-iot.lamarzocco.com/firmware-updates/',
'skipped_version': None,
'supported_features': <UpdateEntityFeature: 1>,
'title': None,
'update_percentage': None,
}),
'context': <ANY>,
'entity_id': 'update.gs012345_machine_firmware',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---

View File

@ -1,7 +1,7 @@
"""Tests for La Marzocco binary sensors.""" """Tests for La Marzocco binary sensors."""
from datetime import timedelta from datetime import timedelta
from unittest.mock import MagicMock from unittest.mock import MagicMock, patch
from freezegun.api import FrozenDateTimeFactory from freezegun.api import FrozenDateTimeFactory
from pylamarzocco.const import MachineModel from pylamarzocco.const import MachineModel
@ -10,19 +10,13 @@ from pylamarzocco.models import LaMarzoccoScale
import pytest import pytest
from syrupy import SnapshotAssertion from syrupy import SnapshotAssertion
from homeassistant.const import STATE_UNAVAILABLE from homeassistant.const import STATE_UNAVAILABLE, Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
from . import async_init_integration from . import async_init_integration
from tests.common import MockConfigEntry, async_fire_time_changed from tests.common import MockConfigEntry, async_fire_time_changed, snapshot_platform
BINARY_SENSORS = (
"brewing_active",
"backflush_active",
"water_tank_empty",
)
async def test_binary_sensors( async def test_binary_sensors(
@ -34,19 +28,11 @@ async def test_binary_sensors(
) -> None: ) -> None:
"""Test the La Marzocco binary sensors.""" """Test the La Marzocco binary sensors."""
await async_init_integration(hass, mock_config_entry) with patch(
"homeassistant.components.lamarzocco.PLATFORMS", [Platform.BINARY_SENSOR]
serial_number = mock_lamarzocco.serial_number ):
await async_init_integration(hass, mock_config_entry)
for binary_sensor in BINARY_SENSORS: await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
state = hass.states.get(f"binary_sensor.{serial_number}_{binary_sensor}")
assert state
assert state == snapshot(name=f"{serial_number}_{binary_sensor}-binary_sensor")
entry = entity_registry.async_get(state.entity_id)
assert entry
assert entry.device_id
assert entry == snapshot(name=f"{serial_number}_{binary_sensor}-entry")
async def test_brew_active_does_not_exists( async def test_brew_active_does_not_exists(

View File

@ -38,9 +38,7 @@ async def test_load_unload_config_entry(
mock_lamarzocco: MagicMock, mock_lamarzocco: MagicMock,
) -> None: ) -> None:
"""Test loading and unloading the integration.""" """Test loading and unloading the integration."""
mock_config_entry.add_to_hass(hass) await async_init_integration(hass, mock_config_entry)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
assert mock_config_entry.state is ConfigEntryState.LOADED assert mock_config_entry.state is ConfigEntryState.LOADED
@ -58,9 +56,7 @@ async def test_config_entry_not_ready(
"""Test the La Marzocco configuration entry not ready.""" """Test the La Marzocco configuration entry not ready."""
mock_lamarzocco.get_config.side_effect = RequestNotSuccessful("") mock_lamarzocco.get_config.side_effect = RequestNotSuccessful("")
mock_config_entry.add_to_hass(hass) await async_init_integration(hass, mock_config_entry)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
assert len(mock_lamarzocco.get_config.mock_calls) == 1 assert len(mock_lamarzocco.get_config.mock_calls) == 1
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
@ -73,9 +69,7 @@ async def test_invalid_auth(
) -> None: ) -> None:
"""Test auth error during setup.""" """Test auth error during setup."""
mock_lamarzocco.get_config.side_effect = AuthFail("") mock_lamarzocco.get_config.side_effect = AuthFail("")
mock_config_entry.add_to_hass(hass) await async_init_integration(hass, mock_config_entry)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR
assert len(mock_lamarzocco.get_config.mock_calls) == 1 assert len(mock_lamarzocco.get_config.mock_calls) == 1

View File

@ -30,6 +30,8 @@ from . import async_init_integration
from tests.common import MockConfigEntry, async_fire_time_changed from tests.common import MockConfigEntry, async_fire_time_changed
pytest.mark.usefixtures("init_integration")
@pytest.mark.usefixtures("init_integration") @pytest.mark.usefixtures("init_integration")
@pytest.mark.parametrize("device_fixture", [MachineModel.LINEA_MICRA]) @pytest.mark.parametrize("device_fixture", [MachineModel.LINEA_MICRA])
@ -66,9 +68,6 @@ async def test_steam_boiler_level(
mock_lamarzocco.set_steam_level.assert_called_once_with(level=SteamLevel.LEVEL_2) mock_lamarzocco.set_steam_level.assert_called_once_with(level=SteamLevel.LEVEL_2)
pytest.mark.usefixtures("init_integration")
@pytest.mark.parametrize( @pytest.mark.parametrize(
"device_fixture", "device_fixture",
[MachineModel.GS3_AV, MachineModel.GS3_MP, MachineModel.LINEA_MINI], [MachineModel.GS3_AV, MachineModel.GS3_MP, MachineModel.LINEA_MINI],

View File

@ -1,7 +1,7 @@
"""Tests for La Marzocco sensors.""" """Tests for La Marzocco sensors."""
from datetime import timedelta from datetime import timedelta
from unittest.mock import MagicMock from unittest.mock import MagicMock, patch
from freezegun.api import FrozenDateTimeFactory from freezegun.api import FrozenDateTimeFactory
from pylamarzocco.const import MachineModel from pylamarzocco.const import MachineModel
@ -9,21 +9,13 @@ from pylamarzocco.models import LaMarzoccoScale
import pytest import pytest
from syrupy import SnapshotAssertion from syrupy import SnapshotAssertion
from homeassistant.const import STATE_UNAVAILABLE from homeassistant.const import STATE_UNAVAILABLE, Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
from . import async_init_integration from . import async_init_integration
from tests.common import MockConfigEntry, async_fire_time_changed from tests.common import MockConfigEntry, async_fire_time_changed, snapshot_platform
SENSORS = (
"total_coffees_made",
"total_flushes_made",
"shot_timer",
"current_coffee_temperature",
"current_steam_temperature",
)
async def test_sensors( async def test_sensors(
@ -35,19 +27,9 @@ async def test_sensors(
) -> None: ) -> None:
"""Test the La Marzocco sensors.""" """Test the La Marzocco sensors."""
serial_number = mock_lamarzocco.serial_number with patch("homeassistant.components.lamarzocco.PLATFORMS", [Platform.SENSOR]):
await async_init_integration(hass, mock_config_entry)
await async_init_integration(hass, mock_config_entry) await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
for sensor in SENSORS:
state = hass.states.get(f"sensor.{serial_number}_{sensor}")
assert state
assert state == snapshot(name=f"{serial_number}_{sensor}-sensor")
entry = entity_registry.async_get(state.entity_id)
assert entry
assert entry.device_id
assert entry == snapshot(name=f"{serial_number}_{sensor}-entry")
async def test_shot_timer_not_exists( async def test_shot_timer_not_exists(
@ -102,6 +84,7 @@ async def test_scale_battery(
await async_init_integration(hass, mock_config_entry) await async_init_integration(hass, mock_config_entry)
state = hass.states.get("sensor.lmz_123a45_battery") state = hass.states.get("sensor.lmz_123a45_battery")
assert state
assert state == snapshot assert state == snapshot
entry = entity_registry.async_get(state.entity_id) entry = entity_registry.async_get(state.entity_id)

View File

@ -1,7 +1,7 @@
"""Tests for La Marzocco switches.""" """Tests for La Marzocco switches."""
from typing import Any from typing import Any
from unittest.mock import MagicMock from unittest.mock import MagicMock, patch
from pylamarzocco.exceptions import RequestNotSuccessful from pylamarzocco.exceptions import RequestNotSuccessful
import pytest import pytest
@ -12,14 +12,27 @@ from homeassistant.components.switch import (
SERVICE_TURN_OFF, SERVICE_TURN_OFF,
SERVICE_TURN_ON, SERVICE_TURN_ON,
) )
from homeassistant.const import ATTR_ENTITY_ID from homeassistant.const import ATTR_ENTITY_ID, Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
from . import WAKE_UP_SLEEP_ENTRY_IDS, async_init_integration from . import WAKE_UP_SLEEP_ENTRY_IDS, async_init_integration
from tests.common import MockConfigEntry from tests.common import MockConfigEntry, snapshot_platform
async def test_switches(
hass: HomeAssistant,
mock_lamarzocco: MagicMock,
mock_config_entry: MockConfigEntry,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
) -> None:
"""Test the La Marzocco switches."""
with patch("homeassistant.components.lamarzocco.PLATFORMS", [Platform.SWITCH]):
await async_init_integration(hass, mock_config_entry)
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -38,12 +51,10 @@ from tests.common import MockConfigEntry
), ),
], ],
) )
async def test_switches( async def test_switches_actions(
hass: HomeAssistant, hass: HomeAssistant,
mock_lamarzocco: MagicMock, mock_lamarzocco: MagicMock,
mock_config_entry: MockConfigEntry, mock_config_entry: MockConfigEntry,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
entity_name: str, entity_name: str,
method_name: str, method_name: str,
kwargs: dict[str, Any], kwargs: dict[str, Any],
@ -55,14 +66,6 @@ async def test_switches(
control_fn = getattr(mock_lamarzocco, method_name) control_fn = getattr(mock_lamarzocco, method_name)
state = hass.states.get(f"switch.{serial_number}{entity_name}")
assert state
assert state == snapshot
entry = entity_registry.async_get(state.entity_id)
assert entry
assert entry == snapshot
await hass.services.async_call( await hass.services.async_call(
SWITCH_DOMAIN, SWITCH_DOMAIN,
SERVICE_TURN_OFF, SERVICE_TURN_OFF,

View File

@ -1,6 +1,6 @@
"""Tests for the La Marzocco Update Entities.""" """Tests for the La Marzocco Update Entities."""
from unittest.mock import MagicMock from unittest.mock import MagicMock, patch
from pylamarzocco.const import FirmwareType from pylamarzocco.const import FirmwareType
from pylamarzocco.exceptions import RequestNotSuccessful from pylamarzocco.exceptions import RequestNotSuccessful
@ -8,12 +8,27 @@ import pytest
from syrupy import SnapshotAssertion from syrupy import SnapshotAssertion
from homeassistant.components.update import DOMAIN as UPDATE_DOMAIN, SERVICE_INSTALL from homeassistant.components.update import DOMAIN as UPDATE_DOMAIN, SERVICE_INSTALL
from homeassistant.const import ATTR_ENTITY_ID from homeassistant.const import ATTR_ENTITY_ID, Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
pytestmark = pytest.mark.usefixtures("init_integration") from . import async_init_integration
from tests.common import MockConfigEntry, snapshot_platform
async def test_update(
hass: HomeAssistant,
mock_lamarzocco: MagicMock,
mock_config_entry: MockConfigEntry,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
) -> None:
"""Test the La Marzocco updates."""
with patch("homeassistant.components.lamarzocco.PLATFORMS", [Platform.UPDATE]):
await async_init_integration(hass, mock_config_entry)
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -26,8 +41,7 @@ pytestmark = pytest.mark.usefixtures("init_integration")
async def test_update_entites( async def test_update_entites(
hass: HomeAssistant, hass: HomeAssistant,
mock_lamarzocco: MagicMock, mock_lamarzocco: MagicMock,
entity_registry: er.EntityRegistry, mock_config_entry: MockConfigEntry,
snapshot: SnapshotAssertion,
entity_name: str, entity_name: str,
component: FirmwareType, component: FirmwareType,
) -> None: ) -> None:
@ -35,13 +49,7 @@ async def test_update_entites(
serial_number = mock_lamarzocco.serial_number serial_number = mock_lamarzocco.serial_number
state = hass.states.get(f"update.{serial_number}_{entity_name}") await async_init_integration(hass, mock_config_entry)
assert state
assert state == snapshot
entry = entity_registry.async_get(state.entity_id)
assert entry
assert entry == snapshot
await hass.services.async_call( await hass.services.async_call(
UPDATE_DOMAIN, UPDATE_DOMAIN,
@ -65,10 +73,14 @@ async def test_update_entites(
async def test_update_error( async def test_update_error(
hass: HomeAssistant, hass: HomeAssistant,
mock_lamarzocco: MagicMock, mock_lamarzocco: MagicMock,
mock_config_entry: MockConfigEntry,
attr: str, attr: str,
value: bool | Exception, value: bool | Exception,
) -> None: ) -> None:
"""Test error during update.""" """Test error during update."""
await async_init_integration(hass, mock_config_entry)
state = hass.states.get(f"update.{mock_lamarzocco.serial_number}_machine_firmware") state = hass.states.get(f"update.{mock_lamarzocco.serial_number}_machine_firmware")
assert state assert state