mirror of
https://github.com/home-assistant/core.git
synced 2025-05-07 07:29:17 +00:00

* init * init tests * linting * checks * tests, linting * pylint * add tests * switch tests * add water heater tests * change icons * extra args cleanup * moar tests * services tests * remove extra platforms * test for unique id * back to single instance * add diagnostics * remove extra platforms * test for unique id * back to single instance * Add better connection management for Idasen Desk (#102135) * Return 'None' for light attributes when off instead of removing them (#101946) * Bump home-assistant-bluetooth to 1.10.4 (#102268) * Bump orjson to 3.9.9 (#102267) * Bump opower to 0.0.37 (#102265) * Bump Python-Roborock to 0.35.0 (#102275) * Add CodeQL CI Job (#102273) * Remove unused dsmr sensors (#102223) * rebase messed up conftest * more tests for init * add client to coveragerc * add client to coveragerc * next lmcloud version * strict typing * more typing * allow multiple machines * remove unneeded var * Update homeassistant/components/lamarzocco/coordinator.py Co-authored-by: Robert Resch <robert@resch.dev> * Update homeassistant/components/lamarzocco/diagnostics.py Co-authored-by: Robert Resch <robert@resch.dev> * Update homeassistant/components/lamarzocco/__init__.py Co-authored-by: Robert Resch <robert@resch.dev> * PR suggestions * remove base exception * Update manifest.json * update lmcloud * update lmcloud * remove ignore * selection bugfix for machines with space in name * bugfix temps * add options flow * send out full user input * remove options flow * split the tests to avoid timeouts * use selectoptionsdict for selection * removing rccoleman * improve test coverage to 100% * Update config_flow.py Co-authored-by: Robert Resch <robert@resch.dev> * Update config_flow.py Co-authored-by: Robert Resch <robert@resch.dev> * Update config_flow.py Co-authored-by: Robert Resch <robert@resch.dev> * autoselect cloud machine for discovered machine * move default values to 3rd party lib * bring property changes from lmcloud * moving things to lmcloud * move validation to method * move more things to lmcloud * remove unused const * Update homeassistant/components/lamarzocco/coordinator.py Co-authored-by: Robert Resch <robert@resch.dev> * Update homeassistant/components/lamarzocco/coordinator.py Co-authored-by: Robert Resch <robert@resch.dev> * Update homeassistant/components/lamarzocco/__init__.py Co-authored-by: Robert Resch <robert@resch.dev> * Update homeassistant/components/lamarzocco/__init__.py Co-authored-by: Robert Resch <robert@resch.dev> * remove callback from coordinator * remove waterheater, add switch * improvement to background task * next lmcloud * adapt to lib changes * Update homeassistant/components/lamarzocco/strings.json Co-authored-by: Robert Resch <robert@resch.dev> * Update homeassistant/components/lamarzocco/entity.py Co-authored-by: Robert Resch <robert@resch.dev> * Update homeassistant/components/lamarzocco/entity.py Co-authored-by: Robert Resch <robert@resch.dev> * Update homeassistant/components/lamarzocco/switch.py Co-authored-by: Robert Resch <robert@resch.dev> * Update homeassistant/components/lamarzocco/switch.py Co-authored-by: Robert Resch <robert@resch.dev> * Update homeassistant/components/lamarzocco/entity.py Co-authored-by: Robert Resch <robert@resch.dev> * Update homeassistant/components/lamarzocco/strings.json Co-authored-by: Robert Resch <robert@resch.dev> * requested changes * Update homeassistant/components/lamarzocco/switch.py Co-authored-by: Robert Resch <robert@resch.dev> * Update homeassistant/components/lamarzocco/entity.py Co-authored-by: Robert Resch <robert@resch.dev> * Update tests/components/lamarzocco/test_config_flow.py Co-authored-by: Robert Resch <robert@resch.dev> * Update tests/components/lamarzocco/test_config_flow.py Co-authored-by: Robert Resch <robert@resch.dev> * some requested changes * changes * requested changes * move steam boiler to controls * fix: remove entities from GS3MP model + tests * remove dataclass decorator * next lmcloud version * improvements * move reauth to user step * improve config flow * remove asserts in favor of runtimeerrors * undo conftest comment * make duc return none * Update homeassistant/components/lamarzocco/switch.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/lamarzocco/entity.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/lamarzocco/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * remove diagnostics, changes * refine config flow * remove runtimeerrors in favor of asserts * move initialization of lm_client to coordinator * remove things from lmclient * remove lm_client * remove lm_client * bump lm version * correctly set initialized for tests * move exception handling inside init + tests * add test for switch without bluetooth on * bump lmcloud * pass httpx client to LMLocalAPI * add call function to reduce code * switch to snapshot testing * remove bluetooth * bump version * cleanup import * remove unused const * set correct integration_type * correct default selection in CF * reduce unnecessary tests by fixture change * use other json loads helpers * move prebrew/infusion to select entity * bump lmcloud * Update coordinator.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update coordinator.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update coordinator.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update entity.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update entity.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * requested feedback * step description, bump lmcloud * create init integration functino * revert * ruff * remove leftover BT test * make main switch main entity * bump lmcloud * re-add bluetooth * improve * bump firmware (again) * correct test * Update homeassistant/components/lamarzocco/coordinator.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/lamarzocco/entity.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/lamarzocco/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * separate device test * add BT to entites * fix import * docstring * minor * fix rebase * get device from discovered devices * tweak * change tests * switch to dict * switch to options * fix * fix --------- Co-authored-by: Abílio Costa <abmantis@users.noreply.github.com> Co-authored-by: Paul Bottein <paul.bottein@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org> Co-authored-by: tronikos <tronikos@users.noreply.github.com> Co-authored-by: Luke Lashley <conway220@gmail.com> Co-authored-by: Franck Nijhof <git@frenck.dev> Co-authored-by: dupondje <jean-louis@dupond.be> Co-authored-by: Robert Resch <robert@resch.dev> Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
334 lines
9.2 KiB
Python
334 lines
9.2 KiB
Python
"""Tests for the La Marzocco number entities."""
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
from lmcloud.const import KEYS_PER_MODEL, LaMarzoccoModel
|
|
import pytest
|
|
from syrupy import SnapshotAssertion
|
|
|
|
from homeassistant.components.number import (
|
|
ATTR_VALUE,
|
|
DOMAIN as NUMBER_DOMAIN,
|
|
SERVICE_SET_VALUE,
|
|
)
|
|
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
|
|
|
pytestmark = pytest.mark.usefixtures("init_integration")
|
|
|
|
|
|
async def test_coffee_boiler(
|
|
hass: HomeAssistant,
|
|
mock_lamarzocco: MagicMock,
|
|
entity_registry: er.EntityRegistry,
|
|
device_registry: dr.DeviceRegistry,
|
|
snapshot: SnapshotAssertion,
|
|
) -> None:
|
|
"""Test the La Marzocco coffee temperature Number."""
|
|
serial_number = mock_lamarzocco.serial_number
|
|
|
|
state = hass.states.get(f"number.{serial_number}_coffee_target_temperature")
|
|
|
|
assert state
|
|
assert state == snapshot
|
|
|
|
entry = entity_registry.async_get(state.entity_id)
|
|
assert entry
|
|
assert entry.device_id
|
|
assert entry == snapshot
|
|
|
|
device = device_registry.async_get(entry.device_id)
|
|
assert device
|
|
|
|
# service call
|
|
await hass.services.async_call(
|
|
NUMBER_DOMAIN,
|
|
SERVICE_SET_VALUE,
|
|
{
|
|
ATTR_ENTITY_ID: f"number.{serial_number}_coffee_target_temperature",
|
|
ATTR_VALUE: 95,
|
|
},
|
|
blocking=True,
|
|
)
|
|
|
|
assert len(mock_lamarzocco.set_coffee_temp.mock_calls) == 1
|
|
mock_lamarzocco.set_coffee_temp.assert_called_once_with(
|
|
temperature=95, ble_device=None
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"device_fixture", [LaMarzoccoModel.GS3_AV, LaMarzoccoModel.GS3_MP]
|
|
)
|
|
@pytest.mark.parametrize(
|
|
("entity_name", "value", "func_name", "kwargs"),
|
|
[
|
|
(
|
|
"steam_target_temperature",
|
|
131,
|
|
"set_steam_temp",
|
|
{"temperature": 131, "ble_device": None},
|
|
),
|
|
("tea_water_duration", 15, "set_dose_hot_water", {"value": 15}),
|
|
],
|
|
)
|
|
async def test_gs3_exclusive(
|
|
hass: HomeAssistant,
|
|
mock_lamarzocco: MagicMock,
|
|
entity_registry: er.EntityRegistry,
|
|
device_registry: dr.DeviceRegistry,
|
|
snapshot: SnapshotAssertion,
|
|
entity_name: str,
|
|
value: float,
|
|
func_name: str,
|
|
kwargs: dict[str, float],
|
|
) -> None:
|
|
"""Test exclusive entities for GS3 AV/MP."""
|
|
|
|
serial_number = mock_lamarzocco.serial_number
|
|
|
|
func = getattr(mock_lamarzocco, func_name)
|
|
|
|
state = hass.states.get(f"number.{serial_number}_{entity_name}")
|
|
assert state
|
|
assert state == snapshot
|
|
|
|
entry = entity_registry.async_get(state.entity_id)
|
|
assert entry
|
|
assert entry.device_id
|
|
assert entry == snapshot
|
|
|
|
device = device_registry.async_get(entry.device_id)
|
|
assert device
|
|
|
|
# service call
|
|
await hass.services.async_call(
|
|
NUMBER_DOMAIN,
|
|
SERVICE_SET_VALUE,
|
|
{
|
|
ATTR_ENTITY_ID: f"number.{serial_number}_{entity_name}",
|
|
ATTR_VALUE: value,
|
|
},
|
|
blocking=True,
|
|
)
|
|
|
|
assert len(func.mock_calls) == 1
|
|
func.assert_called_once_with(**kwargs)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"device_fixture", [LaMarzoccoModel.LINEA_MICRA, LaMarzoccoModel.LINEA_MINI]
|
|
)
|
|
async def test_gs3_exclusive_none(
|
|
hass: HomeAssistant,
|
|
mock_lamarzocco: MagicMock,
|
|
) -> None:
|
|
"""Ensure GS3 exclusive is None for unsupported models."""
|
|
|
|
ENTITIES = ("steam_target_temperature", "tea_water_duration")
|
|
|
|
serial_number = mock_lamarzocco.serial_number
|
|
for entity in ENTITIES:
|
|
state = hass.states.get(f"number.{serial_number}_{entity}")
|
|
assert state is None
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"device_fixture", [LaMarzoccoModel.LINEA_MICRA, LaMarzoccoModel.LINEA_MINI]
|
|
)
|
|
@pytest.mark.parametrize(
|
|
("entity_name", "value", "kwargs"),
|
|
[
|
|
("prebrew_off_time", 6, {"on_time": 3000, "off_time": 6000, "key": 1}),
|
|
("prebrew_on_time", 6, {"on_time": 6000, "off_time": 5000, "key": 1}),
|
|
("preinfusion_time", 7, {"off_time": 7000, "key": 1}),
|
|
],
|
|
)
|
|
async def test_pre_brew_infusion_numbers(
|
|
hass: HomeAssistant,
|
|
mock_lamarzocco: MagicMock,
|
|
entity_registry: er.EntityRegistry,
|
|
device_registry: dr.DeviceRegistry,
|
|
snapshot: SnapshotAssertion,
|
|
entity_name: str,
|
|
value: float,
|
|
kwargs: dict[str, float],
|
|
) -> None:
|
|
"""Test the La Marzocco prebrew/-infusion sensors."""
|
|
|
|
mock_lamarzocco.current_status["enable_preinfusion"] = True
|
|
|
|
serial_number = mock_lamarzocco.serial_number
|
|
|
|
state = hass.states.get(f"number.{serial_number}_{entity_name}")
|
|
|
|
assert state
|
|
assert state == snapshot
|
|
|
|
entry = entity_registry.async_get(state.entity_id)
|
|
assert entry
|
|
assert entry.device_id
|
|
assert entry == snapshot
|
|
|
|
device = device_registry.async_get(entry.device_id)
|
|
assert device
|
|
|
|
# service call
|
|
await hass.services.async_call(
|
|
NUMBER_DOMAIN,
|
|
SERVICE_SET_VALUE,
|
|
{
|
|
ATTR_ENTITY_ID: f"number.{serial_number}_{entity_name}",
|
|
ATTR_VALUE: value,
|
|
},
|
|
blocking=True,
|
|
)
|
|
|
|
assert len(mock_lamarzocco.configure_prebrew.mock_calls) == 1
|
|
mock_lamarzocco.configure_prebrew.assert_called_once_with(**kwargs)
|
|
|
|
|
|
@pytest.mark.parametrize("device_fixture", [LaMarzoccoModel.GS3_AV])
|
|
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
|
@pytest.mark.parametrize(
|
|
("entity_name", "value", "function_name", "kwargs"),
|
|
[
|
|
(
|
|
"prebrew_off_time",
|
|
6,
|
|
"configure_prebrew",
|
|
{"on_time": 3000, "off_time": 6000},
|
|
),
|
|
(
|
|
"prebrew_on_time",
|
|
6,
|
|
"configure_prebrew",
|
|
{"on_time": 6000, "off_time": 5000},
|
|
),
|
|
("preinfusion_time", 7, "configure_prebrew", {"off_time": 7000}),
|
|
("dose", 6, "set_dose", {"value": 6}),
|
|
],
|
|
)
|
|
async def test_pre_brew_infusion_key_numbers(
|
|
hass: HomeAssistant,
|
|
mock_lamarzocco: MagicMock,
|
|
snapshot: SnapshotAssertion,
|
|
entity_name: str,
|
|
value: float,
|
|
function_name: str,
|
|
kwargs: dict[str, float],
|
|
) -> None:
|
|
"""Test the La Marzocco number sensors for GS3AV model."""
|
|
|
|
mock_lamarzocco.current_status["enable_preinfusion"] = True
|
|
|
|
serial_number = mock_lamarzocco.serial_number
|
|
|
|
func = getattr(mock_lamarzocco, function_name)
|
|
|
|
state = hass.states.get(f"number.{serial_number}_{entity_name}")
|
|
assert state is None
|
|
|
|
for key in range(1, KEYS_PER_MODEL[mock_lamarzocco.model_name] + 1):
|
|
state = hass.states.get(f"number.{serial_number}_{entity_name}_key_{key}")
|
|
assert state
|
|
assert state == snapshot(name=f"{serial_number}_{entity_name}_key_{key}-state")
|
|
|
|
# service call
|
|
await hass.services.async_call(
|
|
NUMBER_DOMAIN,
|
|
SERVICE_SET_VALUE,
|
|
{
|
|
ATTR_ENTITY_ID: f"number.{serial_number}_{entity_name}_key_{key}",
|
|
ATTR_VALUE: value,
|
|
},
|
|
blocking=True,
|
|
)
|
|
|
|
kwargs["key"] = key
|
|
|
|
assert len(func.mock_calls) == key
|
|
func.assert_called_with(**kwargs)
|
|
|
|
|
|
@pytest.mark.parametrize("device_fixture", [LaMarzoccoModel.GS3_AV])
|
|
async def test_disabled_entites(
|
|
hass: HomeAssistant,
|
|
mock_lamarzocco: MagicMock,
|
|
) -> None:
|
|
"""Test the La Marzocco prebrew/-infusion sensors for GS3AV model."""
|
|
|
|
ENTITIES = (
|
|
"prebrew_off_time",
|
|
"prebrew_on_time",
|
|
"preinfusion_time",
|
|
"set_dose",
|
|
)
|
|
|
|
serial_number = mock_lamarzocco.serial_number
|
|
|
|
for entity_name in ENTITIES:
|
|
for key in range(1, KEYS_PER_MODEL[mock_lamarzocco.model_name] + 1):
|
|
state = hass.states.get(f"number.{serial_number}_{entity_name}_key_{key}")
|
|
assert state is None
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"device_fixture",
|
|
[LaMarzoccoModel.GS3_MP, LaMarzoccoModel.LINEA_MICRA, LaMarzoccoModel.LINEA_MINI],
|
|
)
|
|
async def test_not_existing_key_entites(
|
|
hass: HomeAssistant,
|
|
mock_lamarzocco: MagicMock,
|
|
) -> None:
|
|
"""Assert not existing key entities."""
|
|
|
|
serial_number = mock_lamarzocco.serial_number
|
|
|
|
for entity in (
|
|
"prebrew_off_time",
|
|
"prebrew_on_time",
|
|
"preinfusion_time",
|
|
"set_dose",
|
|
):
|
|
for key in range(1, KEYS_PER_MODEL[LaMarzoccoModel.GS3_AV] + 1):
|
|
state = hass.states.get(f"number.{serial_number}_{entity}_key_{key}")
|
|
assert state is None
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"device_fixture",
|
|
[LaMarzoccoModel.GS3_MP],
|
|
)
|
|
async def test_not_existing_entites(
|
|
hass: HomeAssistant,
|
|
mock_lamarzocco: MagicMock,
|
|
) -> None:
|
|
"""Assert not existing entities."""
|
|
|
|
serial_number = mock_lamarzocco.serial_number
|
|
|
|
for entity in (
|
|
"prebrew_off_time",
|
|
"prebrew_on_time",
|
|
"preinfusion_time",
|
|
"set_dose",
|
|
):
|
|
state = hass.states.get(f"number.{serial_number}_{entity}")
|
|
assert state is None
|
|
|
|
|
|
@pytest.mark.parametrize("device_fixture", [LaMarzoccoModel.LINEA_MICRA])
|
|
async def test_not_settable_entites(
|
|
hass: HomeAssistant,
|
|
mock_lamarzocco: MagicMock,
|
|
) -> None:
|
|
"""Assert not settable causes error."""
|
|
|
|
serial_number = mock_lamarzocco.serial_number
|
|
|
|
state = hass.states.get(f"number.{serial_number}_preinfusion_time")
|
|
assert state
|
|
assert state.state == STATE_UNAVAILABLE
|