diff --git a/changelog.md b/changelog.md index 136ca729..ce2ed008 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,7 @@ # Version 2024.4.10 (2024-04-21) - Add wait_for_callback to collector +- Wait for target value in wait_for_state_change_or_timeout # Version 2024.4.9 (2024-04-20) diff --git a/hahomematic/client/__init__.py b/hahomematic/client/__init__.py index 8f4a3135..343af937 100644 --- a/hahomematic/client/__init__.py +++ b/hahomematic/client/__init__.py @@ -11,7 +11,7 @@ from hahomematic import central as hmcu from hahomematic.caches.dynamic import CommandCache, PingPongCache from hahomematic.client.xml_rpc import XmlRpcProxy -from hahomematic.config import CALLBACK_WARN_INTERVAL, RECONNECT_WAIT +from hahomematic.config import CALLBACK_WARN_INTERVAL, RECONNECT_WAIT, WAIT_FOR_CALLBACK from hahomematic.const import ( DATETIME_FORMAT_MILLIS, DEFAULT_CUSTOM_ID, @@ -429,7 +429,7 @@ async def _set_value( channel_address: str, parameter: str, value: Any, - wait_for_callback: bool, + wait_for_callback: int | None, rx_mode: str | None = None, ) -> set[ENTITY_KEY]: """Set single value on paramset VALUES.""" @@ -443,12 +443,17 @@ async def _set_value( entity_keys = self._last_value_send_cache.add_set_value( channel_address=channel_address, parameter=parameter, value=value ) - if wait_for_callback and ( + if wait_for_callback is not None and ( device := self.central.get_device( address=get_device_address(address=channel_address) ) ): - await wait_for_state_change_or_timeout(device=device, entity_keys=entity_keys) + await wait_for_state_change_or_timeout( + device=device, + entity_keys=entity_keys, + values={parameter: value}, + wait_for_callback=wait_for_callback, + ) return entity_keys # noqa: TRY300 except BaseHomematicException as ex: _LOGGER.warning( @@ -467,7 +472,7 @@ async def set_value( paramset_key: str, parameter: str, value: Any, - wait_for_callback: bool = False, + wait_for_callback: int | None = WAIT_FOR_CALLBACK, rx_mode: str | None = None, ) -> set[ENTITY_KEY]: """Set single value on paramset VALUES.""" @@ -517,7 +522,7 @@ async def put_paramset( channel_address: str, paramset_key: str, values: dict[str, Any], - wait_for_callback: bool = False, + wait_for_callback: int | None = WAIT_FOR_CALLBACK, rx_mode: str | None = None, ) -> set[ENTITY_KEY]: """ @@ -534,14 +539,21 @@ async def put_paramset( await self._proxy.putParamset(channel_address, paramset_key, values) # store the send value in the last_value_send_cache entity_keys = self._last_value_send_cache.add_put_paramset( - channel_address=channel_address, paramset_key=paramset_key, values=values + channel_address=channel_address, + paramset_key=paramset_key, + values=values, ) - if wait_for_callback and ( + if wait_for_callback is not None and ( device := self.central.get_device( address=get_device_address(address=channel_address) ) ): - await wait_for_state_change_or_timeout(device=device, entity_keys=entity_keys) + await wait_for_state_change_or_timeout( + device=device, + entity_keys=entity_keys, + values=values, + wait_for_callback=wait_for_callback, + ) return entity_keys # noqa: TRY300 except BaseHomematicException as ex: _LOGGER.warning( @@ -1120,41 +1132,72 @@ def get_client(interface_id: str) -> Client | None: return None +@measure_execution_time async def wait_for_state_change_or_timeout( - device: HmDevice, entity_keys: set[ENTITY_KEY], timeout: float = 30.0 + device: HmDevice, entity_keys: set[ENTITY_KEY], values: dict[str, Any], wait_for_callback: int ) -> None: """Wait for an entity to change state.""" waits = [ _track_single_entity_state_change_or_timeout( - device=device, entity_key=entity_key, timeout=timeout + device=device, + entity_key=entity_key, + value=values.get(entity_key[1]), + wait_for_callback=wait_for_callback, ) for entity_key in entity_keys ] await asyncio.gather(*waits) +@measure_execution_time async def _track_single_entity_state_change_or_timeout( - device: HmDevice, entity_key: ENTITY_KEY, timeout: float + device: HmDevice, entity_key: ENTITY_KEY, value: Any, wait_for_callback: int ) -> None: """Wait for an entity to change state.""" ev = asyncio.Event() def _async_event_changed(*args: Any, **kwargs: Any) -> None: - ev.set() - _LOGGER.debug("Changed event %s", entity_key) + if entity: + _LOGGER.debug( + "TRACK_SINGLE_ENTITY_STATE_CHANGE_OR_TIMEOUT: Received event %s with value %s", + entity_key, + entity.value, + ) + if _isclose(value, entity.value): + _LOGGER.debug( + "TRACK_SINGLE_ENTITY_STATE_CHANGE_OR_TIMEOUT: Finished event %s with value %s", + entity_key, + entity.value, + ) + ev.set() channel_address, parameter = entity_key if entity := device.get_generic_entity(channel_address=channel_address, parameter=parameter): if not entity.supports_events: + _LOGGER.debug( + "TRACK_SINGLE_ENTITY_STATE_CHANGE_OR_TIMEOUT: Entity supports no events %s", + entity_key, + ) return unsub = entity.register_entity_updated_callback( entity_updated_callback=_async_event_changed, custom_id=DEFAULT_CUSTOM_ID ) try: - async with asyncio.timeout(timeout): + async with asyncio.timeout(wait_for_callback): await ev.wait() except TimeoutError: - pass + _LOGGER.debug( + "TRACK_SINGLE_ENTITY_STATE_CHANGE_OR_TIMEOUT: Timeout waiting for event %s with value %s", + entity_key, + entity.value, + ) finally: unsub() + + +def _isclose(value1: Any, value2: Any) -> bool: + """Check if the both values are close to each other.""" + if isinstance(value1, float): + return bool(round(value1, 2) == round(value2, 2)) + return bool(value1 == value2) diff --git a/hahomematic/config.py b/hahomematic/config.py index e23a1ade..ee6aa759 100644 --- a/hahomematic/config.py +++ b/hahomematic/config.py @@ -10,6 +10,7 @@ DEFAULT_PING_PONG_MISMATCH_COUNT_TTL, DEFAULT_RECONNECT_WAIT, DEFAULT_TIMEOUT, + DEFAULT_WAIT_FOR_CALLBACK, ) CALLBACK_WARN_INTERVAL = DEFAULT_CONNECTION_CHECKER_INTERVAL * 40 @@ -20,3 +21,4 @@ PING_PONG_MISMATCH_COUNT_TTL = DEFAULT_PING_PONG_MISMATCH_COUNT_TTL RECONNECT_WAIT = DEFAULT_RECONNECT_WAIT TIMEOUT = DEFAULT_TIMEOUT +WAIT_FOR_CALLBACK = DEFAULT_WAIT_FOR_CALLBACK diff --git a/hahomematic/const.py b/hahomematic/const.py index 0d02dded..91e2924a 100644 --- a/hahomematic/const.py +++ b/hahomematic/const.py @@ -19,6 +19,7 @@ DEFAULT_TIMEOUT: Final = 60 # default timeout for a connection DEFAULT_TLS: Final = False DEFAULT_VERIFY_TLS: Final = False +DEFAULT_WAIT_FOR_CALLBACK: Final[int | None] = None REGA_SCRIPT_FETCH_ALL_DEVICE_DATA: Final = "fetch_all_device_data.fn" REGA_SCRIPT_GET_SERIAL: Final = "get_serial.fn" diff --git a/hahomematic/performance.py b/hahomematic/performance.py index 810fce6c..e9554e1b 100644 --- a/hahomematic/performance.py +++ b/hahomematic/performance.py @@ -28,11 +28,12 @@ async def async_wrapper(*args: Any, **kwargs: Any) -> Any: finally: if is_enabled: delta = (datetime.now() - start).total_seconds() + arg = str(args[0]) if len(args) > 0 else "" _LOGGER.info( "Execution of %s took %ss (%s)", func.__name__, delta, - str(args[0]), + arg, ) @wraps(func) diff --git a/hahomematic/platforms/entity.py b/hahomematic/platforms/entity.py index 130c3109..43a6cda3 100644 --- a/hahomematic/platforms/entity.py +++ b/hahomematic/platforms/entity.py @@ -14,6 +14,7 @@ from hahomematic import central as hmcu, client as hmcl, support as hms from hahomematic.async_support import loop_check +from hahomematic.config import WAIT_FOR_CALLBACK from hahomematic.const import ( CALLBACK_TYPE, DEFAULT_CUSTOM_ID, @@ -797,7 +798,7 @@ def add_entity( self._paramsets[collector_order][entity.channel_address] = {} self._paramsets[collector_order][entity.channel_address][entity.parameter] = value - async def send_data(self, wait_for_callback: bool) -> bool: + async def send_data(self, wait_for_callback: int | None) -> bool: """Send data to backend.""" for paramset_no in dict(sorted(self._paramsets.items())).values(): for channel_address, paramset in paramset_no.items(): @@ -821,7 +822,9 @@ async def send_data(self, wait_for_callback: bool) -> bool: return True -def bind_collector(wait_for_callback: bool = False) -> Callable: +def bind_collector( + wait_for_callback: int | None = WAIT_FOR_CALLBACK, +) -> Callable: """Decorate function to automatically add collector if not set.""" def decorator_bind_collector(func: _CallableT) -> _CallableT: @@ -843,7 +846,9 @@ async def wrapper_collector(*args: Any, **kwargs: Any) -> Any: collector = CallParameterCollector(device=args[0].device) kwargs[_COLLECTOR_ARGUMENT_NAME] = collector return_value = await func(*args, **kwargs) - await collector.send_data(wait_for_callback=wait_for_callback) + await collector.send_data( + wait_for_callback=wait_for_callback, + ) return return_value return wrapper_collector # type: ignore[return-value] diff --git a/hahomematic_support/client_local.py b/hahomematic_support/client_local.py index 1e2100d3..a9299fe5 100644 --- a/hahomematic_support/client_local.py +++ b/hahomematic_support/client_local.py @@ -11,6 +11,7 @@ import orjson from hahomematic.client import _LOGGER, Client, _ClientConfig +from hahomematic.config import WAIT_FOR_CALLBACK from hahomematic.const import ( DEFAULT_ENCODING, ENTITY_KEY, @@ -196,7 +197,7 @@ async def set_value( paramset_key: str, parameter: str, value: Any, - wait_for_callback: bool = False, + wait_for_callback: int | None = WAIT_FOR_CALLBACK, rx_mode: str | None = None, ) -> set[ENTITY_KEY]: """Set single value on paramset VALUES.""" @@ -250,7 +251,7 @@ async def put_paramset( channel_address: str, paramset_key: str, values: Any, - wait_for_callback: bool = False, + wait_for_callback: int | None = WAIT_FOR_CALLBACK, rx_mode: str | None = None, ) -> set[ENTITY_KEY]: """ diff --git a/tests/test_climate.py b/tests/test_climate.py index 8e6b8628..c52251a5 100644 --- a/tests/test_climate.py +++ b/tests/test_climate.py @@ -9,6 +9,7 @@ from freezegun import freeze_time import pytest +from hahomematic.config import WAIT_FOR_CALLBACK from hahomematic.const import EntityUsage, ParamsetKey from hahomematic.platforms.custom.climate import ( CeIpThermostat, @@ -62,7 +63,7 @@ async def test_cesimplerfthermostat(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="SETPOINT", value=12.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert mock_client.method_calls[-2] == last_call assert climate.target_temperature == 12.0 @@ -119,7 +120,7 @@ async def test_cerfthermostat(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="SET_TEMPERATURE", value=12.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert climate.target_temperature == 12.0 @@ -135,7 +136,7 @@ async def test_cerfthermostat(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="MANU_MODE", value=12.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU0000050:4", "CONTROL_MODE", ModeHmIP.MANU.value) assert climate.hvac_mode == HvacMode.HEAT @@ -145,7 +146,7 @@ async def test_cerfthermostat(factory: helper.Factory) -> None: channel_address="VCU0000050:4", paramset_key="VALUES", values={"MANU_MODE": 12.0, "SET_TEMPERATURE": 4.5}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert climate.hvac_mode == HvacMode.OFF @@ -157,7 +158,7 @@ async def test_cerfthermostat(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="AUTO_MODE", value=True, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU0000050:4", "CONTROL_MODE", 0) await central.event(const.INTERFACE_ID, "VCU0000050:4", "SET_TEMPERATURE", 24.0) @@ -176,7 +177,7 @@ async def test_cerfthermostat(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="BOOST_MODE", value=True, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU0000050:4", "CONTROL_MODE", 3) assert climate.preset_mode == PresetMode.BOOST @@ -188,7 +189,7 @@ async def test_cerfthermostat(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="COMFORT_MODE", value=True, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await climate.set_preset_mode(PresetMode.ECO) assert mock_client.method_calls[-1] == call.set_value( @@ -196,7 +197,7 @@ async def test_cerfthermostat(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LOWERING_MODE", value=True, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU0000050:4", "CONTROL_MODE", 3) @@ -268,7 +269,7 @@ async def test_ceipthermostat(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="SET_POINT_TEMPERATURE", value=12.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert climate.target_temperature == 12.0 @@ -285,7 +286,7 @@ async def test_ceipthermostat(factory: helper.Factory) -> None: channel_address="VCU1769958:1", paramset_key="VALUES", values={"CONTROL_MODE": 1, "SET_POINT_TEMPERATURE": 4.5}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert climate.hvac_mode == HvacMode.OFF assert climate.hvac_action == HvacAction.OFF @@ -295,7 +296,7 @@ async def test_ceipthermostat(factory: helper.Factory) -> None: channel_address="VCU1769958:1", paramset_key="VALUES", values={"CONTROL_MODE": 1, "SET_POINT_TEMPERATURE": 5.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU1769958:1", "SET_POINT_MODE", ModeHmIP.MANU.value) assert climate.hvac_mode == HvacMode.HEAT @@ -311,7 +312,7 @@ async def test_ceipthermostat(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="BOOST_MODE", value=True, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU1769958:1", "BOOST_MODE", 1) assert climate.preset_mode == PresetMode.BOOST @@ -321,7 +322,7 @@ async def test_ceipthermostat(factory: helper.Factory) -> None: channel_address="VCU1769958:1", paramset_key="VALUES", values={"BOOST_MODE": False, "CONTROL_MODE": 0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU1769958:1", "SET_POINT_MODE", ModeHmIP.AUTO.value) await central.event(const.INTERFACE_ID, "VCU1769958:1", "BOOST_MODE", 1) @@ -342,7 +343,7 @@ async def test_ceipthermostat(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="BOOST_MODE", value=False, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU1769958:1", "SET_POINT_MODE", ModeHmIP.AWAY.value) assert climate.preset_mode == PresetMode.AWAY @@ -354,7 +355,7 @@ async def test_ceipthermostat(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="ACTIVE_PROFILE", value=1, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert climate.preset_mode == PresetMode.WEEK_PROGRAM_1 diff --git a/tests/test_cover.py b/tests/test_cover.py index 6180d105..cfd89073 100644 --- a/tests/test_cover.py +++ b/tests/test_cover.py @@ -7,6 +7,7 @@ import pytest +from hahomematic.config import WAIT_FOR_CALLBACK from hahomematic.const import EntityUsage from hahomematic.platforms.custom.cover import ( _CLOSED_LEVEL, @@ -53,7 +54,7 @@ async def test_cecover(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=0.81, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert cover.current_position == 81 assert cover.is_closed is False @@ -63,7 +64,7 @@ async def test_cecover(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=1.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert cover.current_position == 100 await cover.close() @@ -72,7 +73,7 @@ async def test_cecover(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=_CLOSED_LEVEL, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert cover.current_position == 0 @@ -121,7 +122,7 @@ async def test_ceipblind_dr(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="COMBINED_PARAMETER", value="L2=0,L=81", - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) # test unconfirmed values @@ -142,7 +143,7 @@ async def test_ceipblind_dr(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="COMBINED_PARAMETER", value="L2=100,L=100", - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert cover._e_level.unconfirmed_last_value_send == 1.0 assert cover._e_level_2.unconfirmed_last_value_send == 1.0 @@ -160,7 +161,7 @@ async def test_ceipblind_dr(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="COMBINED_PARAMETER", value="L2=0,L=0", - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU7807849:1", "LEVEL", _CLOSED_LEVEL) assert cover.is_opening is None @@ -193,7 +194,7 @@ async def test_cewindowdrive(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=0.81, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert cover.current_position == 81 assert cover.is_closed is False @@ -204,7 +205,7 @@ async def test_cewindowdrive(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=_OPEN_LEVEL, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert cover.current_position == 100 await cover.close() @@ -213,7 +214,7 @@ async def test_cewindowdrive(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=_WD_CLOSED_LEVEL, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert cover.current_position == 0 assert cover._channel_level == _WD_CLOSED_LEVEL @@ -245,7 +246,7 @@ async def test_ceblind(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL_COMBINED", value="0xa2,0x00", - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU0000145:1", "LEVEL", 0.81) assert cover.current_position == 81 @@ -257,7 +258,7 @@ async def test_ceblind(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL_COMBINED", value="0xc8,0x00", - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU0000145:1", "LEVEL", _OPEN_LEVEL) assert cover.current_position == 100 @@ -269,7 +270,7 @@ async def test_ceblind(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL_COMBINED", value="0x00,0x00", - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU0000145:1", "LEVEL", _CLOSED_LEVEL) assert cover.current_position == 0 @@ -281,7 +282,7 @@ async def test_ceblind(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL_COMBINED", value="0x00,0xc8", - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU0000145:1", "LEVEL_SLATS", _OPEN_LEVEL) assert cover.current_position == 0 @@ -293,7 +294,7 @@ async def test_ceblind(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL_COMBINED", value="0x00,0x5a", - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU0000145:1", "LEVEL_SLATS", 0.45) assert cover.current_position == 0 @@ -305,7 +306,7 @@ async def test_ceblind(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL_COMBINED", value="0x00,0x00", - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU0000145:1", "LEVEL_SLATS", _CLOSED_LEVEL) assert cover.current_position == 0 @@ -317,7 +318,7 @@ async def test_ceblind(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL_COMBINED", value="0x14,0x28", - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU0000145:1", "LEVEL", 0.1) await central.event(const.INTERFACE_ID, "VCU0000145:1", "LEVEL_SLATS", 0.2) @@ -330,7 +331,7 @@ async def test_ceblind(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="STOP", value=True, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await cover.stop_tilt() assert mock_client.method_calls[-1] == call.set_value( @@ -338,7 +339,7 @@ async def test_ceblind(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="STOP", value=True, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await cover.open_tilt() @@ -376,7 +377,7 @@ async def test_ceipblind(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="COMBINED_PARAMETER", value="L2=0,L=81", - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU1223813:4", "LEVEL", 0.81) assert cover.current_position == 81 @@ -388,7 +389,7 @@ async def test_ceipblind(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="COMBINED_PARAMETER", value="L2=100,L=100", - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU1223813:4", "LEVEL_2", 1.0) await central.event(const.INTERFACE_ID, "VCU1223813:4", "LEVEL", 1.0) @@ -401,7 +402,7 @@ async def test_ceipblind(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="COMBINED_PARAMETER", value="L2=0,L=0", - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU1223813:4", "LEVEL_2", 0.0) await central.event(const.INTERFACE_ID, "VCU1223813:4", "LEVEL", 0.0) @@ -414,7 +415,7 @@ async def test_ceipblind(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="COMBINED_PARAMETER", value="L2=100,L=0", - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU1223813:4", "LEVEL_2", 1.0) assert cover.current_position == 0 @@ -426,7 +427,7 @@ async def test_ceipblind(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="COMBINED_PARAMETER", value="L2=45,L=0", - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU1223813:4", "LEVEL_2", 0.45) assert cover.current_position == 0 @@ -438,7 +439,7 @@ async def test_ceipblind(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="COMBINED_PARAMETER", value="L2=0,L=0", - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU1223813:4", "LEVEL_2", 0.0) await central.event(const.INTERFACE_ID, "VCU1223813:4", "LEVEL", 0.0) @@ -451,7 +452,7 @@ async def test_ceipblind(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="COMBINED_PARAMETER", value="L2=20,L=10", - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU1223813:4", "LEVEL", 0.1) await central.event(const.INTERFACE_ID, "VCU1223813:4", "LEVEL_2", 0.2) @@ -490,7 +491,7 @@ async def test_ceipblind(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="STOP", value=True, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) @@ -508,7 +509,7 @@ async def test_ceipblind_hdm(factory: helper.Factory) -> None: channel_address="VCU3560967:1", paramset_key="VALUES", values={"LEVEL_2": 0.0, "LEVEL": 0.81}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU3560967:1", "LEVEL", 0.81) assert cover.current_position == 81 @@ -519,7 +520,7 @@ async def test_ceipblind_hdm(factory: helper.Factory) -> None: channel_address="VCU3560967:1", paramset_key="VALUES", values={"LEVEL_2": 1.0, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU3560967:1", "LEVEL_2", 1.0) await central.event(const.INTERFACE_ID, "VCU3560967:1", "LEVEL", 1.0) @@ -531,7 +532,7 @@ async def test_ceipblind_hdm(factory: helper.Factory) -> None: channel_address="VCU3560967:1", paramset_key="VALUES", values={"LEVEL_2": 0.0, "LEVEL": 0.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU3560967:1", "LEVEL_2", 0.0) await central.event(const.INTERFACE_ID, "VCU3560967:1", "LEVEL", 0.0) @@ -543,7 +544,7 @@ async def test_ceipblind_hdm(factory: helper.Factory) -> None: channel_address="VCU3560967:1", paramset_key="VALUES", values={"LEVEL_2": 1.0, "LEVEL": 0.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU3560967:1", "LEVEL_2", 1.0) assert cover.current_position == 0 @@ -554,7 +555,7 @@ async def test_ceipblind_hdm(factory: helper.Factory) -> None: channel_address="VCU3560967:1", paramset_key="VALUES", values={"LEVEL_2": 0.45, "LEVEL": 0.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU3560967:1", "LEVEL_2", 0.45) assert cover.current_position == 0 @@ -565,7 +566,7 @@ async def test_ceipblind_hdm(factory: helper.Factory) -> None: channel_address="VCU3560967:1", paramset_key="VALUES", values={"LEVEL_2": 0.0, "LEVEL": 0.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU3560967:1", "LEVEL_2", 0.0) await central.event(const.INTERFACE_ID, "VCU3560967:1", "LEVEL", 0.0) @@ -577,7 +578,7 @@ async def test_ceipblind_hdm(factory: helper.Factory) -> None: channel_address="VCU3560967:1", paramset_key="VALUES", values={"LEVEL_2": 0.2, "LEVEL": 0.1}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU3560967:1", "LEVEL", 0.1) await central.event(const.INTERFACE_ID, "VCU3560967:1", "LEVEL_2", 0.2) @@ -600,7 +601,7 @@ async def test_ceipblind_hdm(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="STOP", value=True, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) @@ -618,7 +619,7 @@ async def test_cegarageho(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="DOOR_COMMAND", value=1, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU3574044:1", "DOOR_STATE", 1) assert cover.current_position == 100 @@ -628,7 +629,7 @@ async def test_cegarageho(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="DOOR_COMMAND", value=3, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU3574044:1", "DOOR_STATE", 0) assert cover.current_position == 0 @@ -639,7 +640,7 @@ async def test_cegarageho(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="DOOR_COMMAND", value=4, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU3574044:1", "DOOR_STATE", 2) assert cover.current_position == 10 @@ -650,7 +651,7 @@ async def test_cegarageho(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="DOOR_COMMAND", value=3, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU3574044:1", "DOOR_STATE", 0) assert cover.current_position == 0 @@ -661,7 +662,7 @@ async def test_cegarageho(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="DOOR_COMMAND", value=1, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await cover.stop() assert mock_client.method_calls[-1] == call.set_value( @@ -669,7 +670,7 @@ async def test_cegarageho(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="DOOR_COMMAND", value=2, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU3574044:1", "DOOR_STATE", 1) @@ -721,7 +722,7 @@ async def test_cegaragetm(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="DOOR_COMMAND", value=1, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU6166407:1", "DOOR_STATE", 1) assert cover.current_position == 100 @@ -731,7 +732,7 @@ async def test_cegaragetm(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="DOOR_COMMAND", value=3, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU6166407:1", "DOOR_STATE", 0) assert cover.current_position == 0 @@ -742,7 +743,7 @@ async def test_cegaragetm(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="DOOR_COMMAND", value=4, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU6166407:1", "DOOR_STATE", 2) assert cover.current_position == 10 @@ -753,7 +754,7 @@ async def test_cegaragetm(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="DOOR_COMMAND", value=3, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU6166407:1", "DOOR_STATE", 0) assert cover.current_position == 0 @@ -764,7 +765,7 @@ async def test_cegaragetm(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="DOOR_COMMAND", value=1, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await cover.stop() assert mock_client.method_calls[-1] == call.set_value( @@ -772,7 +773,7 @@ async def test_cegaragetm(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="DOOR_COMMAND", value=2, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU6166407:1", "DOOR_STATE", 1) diff --git a/tests/test_light.py b/tests/test_light.py index b07031b1..a0384224 100644 --- a/tests/test_light.py +++ b/tests/test_light.py @@ -7,6 +7,7 @@ import pytest +from hahomematic.config import WAIT_FOR_CALLBACK from hahomematic.const import EntityUsage, ParamsetKey from hahomematic.platforms.custom.light import ( CeColorDimmer, @@ -60,7 +61,7 @@ async def test_cedimmer(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=1.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 255 assert light.brightness_pct == 100 @@ -70,7 +71,7 @@ async def test_cedimmer(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=0.10980392156862745, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 28 assert light.brightness_pct == 10 @@ -85,14 +86,14 @@ async def test_cedimmer(factory: helper.Factory) -> None: channel_address="VCU1399816:4", paramset_key="VALUES", values={"LEVEL": 0.10980392156862745, "RAMP_TIME": 6.0, "ON_TIME": 5.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await light.turn_on(on_time=5.0) assert mock_client.method_calls[-2] == call.put_paramset( channel_address="VCU1399816:4", paramset_key="VALUES", values={"ON_TIME": 5.0, "LEVEL": 0.10980392156862745}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await light.turn_off(ramp_time=6.0) @@ -100,7 +101,7 @@ async def test_cedimmer(factory: helper.Factory) -> None: channel_address="VCU1399816:4", paramset_key="VALUES", values={"RAMP_TIME": 6.0, "LEVEL": 0.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 0 await light.turn_on() @@ -111,7 +112,7 @@ async def test_cedimmer(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=0.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await light.turn_off() @@ -121,7 +122,7 @@ async def test_cedimmer(factory: helper.Factory) -> None: channel_address="VCU1399816:4", paramset_key="VALUES", values={"ON_TIME": 0.5, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await light.turn_on() @@ -168,7 +169,7 @@ async def test_cecolordimmereffect(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=1.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 255 await light.turn_on(brightness=28) @@ -177,7 +178,7 @@ async def test_cecolordimmereffect(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=0.10980392156862745, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 28 await light.turn_off() @@ -186,7 +187,7 @@ async def test_cecolordimmereffect(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=0.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 0 @@ -197,14 +198,14 @@ async def test_cecolordimmereffect(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="COLOR", value=25, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert mock_client.method_calls[-2] == call.set_value( channel_address="VCU3747418:1", paramset_key="VALUES", parameter="LEVEL", value=1.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.hs_color == (45.0, 100) @@ -214,14 +215,14 @@ async def test_cecolordimmereffect(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="COLOR", value=0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert mock_client.method_calls[-2] == call.set_value( channel_address="VCU3747418:1", paramset_key="VALUES", parameter="LEVEL", value=1.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.hs_color == (0.0, 100.0) @@ -232,14 +233,14 @@ async def test_cecolordimmereffect(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=1.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert mock_client.method_calls[-2] == call.set_value( channel_address="VCU3747418:3", paramset_key="VALUES", parameter="PROGRAM", value=1, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.effect == "Slow color change" @@ -265,14 +266,14 @@ async def test_cecolordimmereffect(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=0.10980392156862745, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert mock_client.method_calls[-2] == call.set_value( channel_address="VCU3747418:3", paramset_key="VALUES", parameter="PROGRAM", value=1, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) @@ -300,7 +301,7 @@ async def test_cecolortempdimmer(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=1.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 255 await light.turn_on(brightness=28) @@ -309,7 +310,7 @@ async def test_cecolortempdimmer(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=0.10980392156862745, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 28 await light.turn_off() @@ -318,7 +319,7 @@ async def test_cecolortempdimmer(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=0.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 0 @@ -329,14 +330,14 @@ async def test_cecolortempdimmer(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=0.1930835734870317, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert mock_client.method_calls[-2] == call.set_value( channel_address="VCU0000115:1", paramset_key="VALUES", parameter="LEVEL", value=1.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.color_temp == 433 @@ -379,7 +380,7 @@ async def test_ceipfixedcolorlight(factory: helper.Factory) -> None: channel_address="VCU3716619:8", paramset_key="VALUES", values={"COLOR": 7, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 255 await light.turn_on(brightness=28) @@ -388,7 +389,7 @@ async def test_ceipfixedcolorlight(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=0.10980392156862745, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 28 await light.turn_off() @@ -397,7 +398,7 @@ async def test_ceipfixedcolorlight(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=0.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 0 assert light.color_name == FixedColor.WHITE @@ -407,7 +408,7 @@ async def test_ceipfixedcolorlight(factory: helper.Factory) -> None: channel_address="VCU3716619:8", paramset_key="VALUES", values={"COLOR": 4, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.color_name == FixedColor.RED @@ -416,7 +417,7 @@ async def test_ceipfixedcolorlight(factory: helper.Factory) -> None: channel_address="VCU3716619:8", paramset_key="VALUES", values={"COLOR": 7, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.color_name == FixedColor.WHITE @@ -425,7 +426,7 @@ async def test_ceipfixedcolorlight(factory: helper.Factory) -> None: channel_address="VCU3716619:8", paramset_key="VALUES", values={"COLOR": 6, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.color_name == FixedColor.YELLOW @@ -434,7 +435,7 @@ async def test_ceipfixedcolorlight(factory: helper.Factory) -> None: channel_address="VCU3716619:8", paramset_key="VALUES", values={"COLOR": 2, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.color_name == FixedColor.GREEN @@ -443,7 +444,7 @@ async def test_ceipfixedcolorlight(factory: helper.Factory) -> None: channel_address="VCU3716619:8", paramset_key="VALUES", values={"COLOR": 3, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.color_name == FixedColor.TURQUOISE @@ -452,7 +453,7 @@ async def test_ceipfixedcolorlight(factory: helper.Factory) -> None: channel_address="VCU3716619:8", paramset_key="VALUES", values={"COLOR": 1, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.color_name == FixedColor.BLUE @@ -461,7 +462,7 @@ async def test_ceipfixedcolorlight(factory: helper.Factory) -> None: channel_address="VCU3716619:8", paramset_key="VALUES", values={"COLOR": 5, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.color_name == FixedColor.PURPLE @@ -479,7 +480,7 @@ async def test_ceipfixedcolorlight(factory: helper.Factory) -> None: channel_address="VCU3716619:8", paramset_key="VALUES", values={"DURATION_VALUE": 18, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await light.turn_off() @@ -489,7 +490,7 @@ async def test_ceipfixedcolorlight(factory: helper.Factory) -> None: channel_address="VCU3716619:8", paramset_key="VALUES", values={"DURATION_UNIT": 1, "DURATION_VALUE": 283, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await light.turn_off() @@ -499,14 +500,14 @@ async def test_ceipfixedcolorlight(factory: helper.Factory) -> None: channel_address="VCU3716619:8", paramset_key="VALUES", values={"DURATION_UNIT": 2, "DURATION_VALUE": 277, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await light.turn_on(ramp_time=18) assert mock_client.method_calls[-2] == call.put_paramset( channel_address="VCU3716619:8", paramset_key="VALUES", values={"RAMP_TIME_VALUE": 18, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await light.turn_on(ramp_time=17000) @@ -514,7 +515,7 @@ async def test_ceipfixedcolorlight(factory: helper.Factory) -> None: channel_address="VCU3716619:8", paramset_key="VALUES", values={"RAMP_TIME_UNIT": 1, "RAMP_TIME_VALUE": 283, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await light.turn_on(ramp_time=1000000) @@ -522,7 +523,7 @@ async def test_ceipfixedcolorlight(factory: helper.Factory) -> None: channel_address="VCU3716619:8", paramset_key="VALUES", values={"RAMP_TIME_UNIT": 2, "RAMP_TIME_VALUE": 277, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await light.turn_on() @@ -572,7 +573,7 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: channel_address="VCU4704397:8", paramset_key="VALUES", values={"COLOR_BEHAVIOUR": 1, "COLOR": 7, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 255 assert light.color_name == FixedColor.WHITE @@ -582,7 +583,7 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: channel_address="VCU4704397:8", paramset_key="VALUES", values={"COLOR_BEHAVIOUR": 1, "LEVEL": 0.39215686274509803}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 100 assert light.color_name == FixedColor.WHITE @@ -594,7 +595,7 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=0.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 0 assert light.color_name == FixedColor.WHITE @@ -605,7 +606,7 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: channel_address="VCU4704397:8", paramset_key="VALUES", values={"COLOR_BEHAVIOUR": 1, "COLOR": 4, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 255 assert light.color_name == FixedColor.RED @@ -616,7 +617,7 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: channel_address="VCU4704397:8", paramset_key="VALUES", values={"COLOR_BEHAVIOUR": 1, "COLOR": 7, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 255 assert light.color_name == FixedColor.WHITE @@ -627,7 +628,7 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: channel_address="VCU4704397:8", paramset_key="VALUES", values={"COLOR_BEHAVIOUR": 1, "COLOR": 6, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 255 assert light.color_name == FixedColor.YELLOW @@ -638,7 +639,7 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: channel_address="VCU4704397:8", paramset_key="VALUES", values={"COLOR_BEHAVIOUR": 1, "COLOR": 2, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 255 assert light.color_name == FixedColor.GREEN @@ -649,7 +650,7 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: channel_address="VCU4704397:8", paramset_key="VALUES", values={"COLOR_BEHAVIOUR": 1, "COLOR": 3, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 255 assert light.color_name == FixedColor.TURQUOISE @@ -660,7 +661,7 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: channel_address="VCU4704397:8", paramset_key="VALUES", values={"COLOR_BEHAVIOUR": 1, "COLOR": 1, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 255 assert light.color_name == FixedColor.BLUE @@ -671,7 +672,7 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: channel_address="VCU4704397:8", paramset_key="VALUES", values={"COLOR_BEHAVIOUR": 1, "COLOR": 5, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 255 assert light.color_name == FixedColor.PURPLE @@ -687,7 +688,7 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: channel_address="VCU4704397:8", paramset_key="VALUES", values={"COLOR_BEHAVIOUR": 1, "LEVEL": 0.39215686274509803}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 100 assert light.color_name == FixedColor.PURPLE @@ -698,7 +699,7 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: channel_address="VCU4704397:8", paramset_key="VALUES", values={"COLOR_BEHAVIOUR": 1, "LEVEL": 0.12941176470588237}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 33 assert light.color_name == FixedColor.PURPLE @@ -709,7 +710,7 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: channel_address="VCU4704397:8", paramset_key="VALUES", values={"COLOR_BEHAVIOUR": 6, "LEVEL": 0.12941176470588237}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 33 assert light.color_name == FixedColor.PURPLE @@ -720,7 +721,7 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: channel_address="VCU4704397:8", paramset_key="VALUES", values={"COLOR_BEHAVIOUR": 6, "LEVEL": 0.25882352941176473}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 66 assert light.color_name == FixedColor.PURPLE @@ -734,7 +735,7 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: channel_address="VCU4704397:8", paramset_key="VALUES", values={"COLOR_BEHAVIOUR": 6, "DURATION_VALUE": 18, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await light.turn_off() @@ -744,7 +745,7 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: channel_address="VCU4704397:8", paramset_key="VALUES", values={"COLOR_BEHAVIOUR": 6, "DURATION_UNIT": 1, "DURATION_VALUE": 283, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await light.turn_off() @@ -754,14 +755,14 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: channel_address="VCU4704397:8", paramset_key="VALUES", values={"COLOR_BEHAVIOUR": 6, "DURATION_UNIT": 2, "DURATION_VALUE": 277, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await light.turn_on(ramp_time=18) assert mock_client.method_calls[-3] == call.put_paramset( channel_address="VCU4704397:8", paramset_key="VALUES", values={"COLOR_BEHAVIOUR": 6, "RAMP_TIME_VALUE": 18, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await light.turn_on(ramp_time=17000) @@ -769,7 +770,7 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: channel_address="VCU4704397:8", paramset_key="VALUES", values={"COLOR_BEHAVIOUR": 6, "RAMP_TIME_UNIT": 1, "RAMP_TIME_VALUE": 283, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await light.turn_on(ramp_time=1000000) @@ -777,7 +778,7 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: channel_address="VCU4704397:8", paramset_key="VALUES", values={"COLOR_BEHAVIOUR": 6, "RAMP_TIME_UNIT": 2, "RAMP_TIME_VALUE": 277, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await light.turn_on() @@ -796,7 +797,7 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: channel_address="VCU4704397:8", paramset_key="VALUES", values={"COLOR_BEHAVIOUR": 2, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await light.turn_on(brightness=28) @@ -805,7 +806,7 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: channel_address="VCU4704397:8", paramset_key="VALUES", values={"COLOR_BEHAVIOUR": 6, "LEVEL": 0.10980392156862745}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) @@ -856,7 +857,7 @@ async def test_ceiprgbwlight(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=1.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 255 await light.turn_on(brightness=28) @@ -865,7 +866,7 @@ async def test_ceiprgbwlight(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=0.10980392156862745, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 28 await light.turn_off() @@ -874,7 +875,7 @@ async def test_ceiprgbwlight(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=0.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 0 @@ -884,7 +885,7 @@ async def test_ceiprgbwlight(factory: helper.Factory) -> None: channel_address="VCU5629873:1", paramset_key="VALUES", values={"COLOR_TEMPERATURE": 3333, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.color_temp == 300 @@ -904,7 +905,7 @@ async def test_ceiprgbwlight(factory: helper.Factory) -> None: channel_address="VCU5629873:1", paramset_key="VALUES", values={"HUE": 44, "SATURATION": 0.693, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.hs_color == (44, 69.3) @@ -913,7 +914,7 @@ async def test_ceiprgbwlight(factory: helper.Factory) -> None: channel_address="VCU5629873:1", paramset_key="VALUES", values={"HUE": 0, "SATURATION": 0.5, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.hs_color == (0.0, 50.0) @@ -922,7 +923,7 @@ async def test_ceiprgbwlight(factory: helper.Factory) -> None: channel_address="VCU5629873:1", paramset_key="VALUES", values={"EFFECT": 1, "LEVEL": 1.0}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await light.turn_on(hs_color=(44, 66), ramp_time=5) @@ -936,7 +937,7 @@ async def test_ceiprgbwlight(factory: helper.Factory) -> None: "RAMP_TIME_VALUE": 5, "LEVEL": 1.0, }, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) @@ -964,7 +965,7 @@ async def test_cecolordimmer(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=1.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 255 await light.turn_on(brightness=28) @@ -973,7 +974,7 @@ async def test_cecolordimmer(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=0.10980392156862745, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 28 await light.turn_off() @@ -982,7 +983,7 @@ async def test_cecolordimmer(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LEVEL", value=0.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.brightness == 0 @@ -993,14 +994,14 @@ async def test_cecolordimmer(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="COLOR", value=25, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert mock_client.method_calls[-2] == call.set_value( channel_address="VCU9973336:13", paramset_key="VALUES", parameter="LEVEL", value=1.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.hs_color == (45.0, 100) @@ -1010,14 +1011,14 @@ async def test_cecolordimmer(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="COLOR", value=0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert mock_client.method_calls[-2] == call.set_value( channel_address="VCU9973336:13", paramset_key="VALUES", parameter="LEVEL", value=1.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.hs_color == (0.0, 100.0) await light.turn_on(hs_color=(0, 1)) @@ -1026,14 +1027,14 @@ async def test_cecolordimmer(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="COLOR", value=200, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert mock_client.method_calls[-2] == call.set_value( channel_address="VCU9973336:13", paramset_key="VALUES", parameter="LEVEL", value=1.0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert light.hs_color == (0.0, 0.0) await central.event(const.INTERFACE_ID, "VCU9973336:15", "COLOR", 201) diff --git a/tests/test_lock.py b/tests/test_lock.py index a2e2305e..43ea083b 100644 --- a/tests/test_lock.py +++ b/tests/test_lock.py @@ -7,6 +7,7 @@ import pytest +from hahomematic.config import WAIT_FOR_CALLBACK from hahomematic.const import EntityUsage from hahomematic.platforms.custom.lock import CeIpLock, CeRfLock @@ -34,7 +35,7 @@ async def test_cerflock(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="STATE", value=True, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert lock.is_locked is False await lock.lock() @@ -43,7 +44,7 @@ async def test_cerflock(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="STATE", value=False, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert lock.is_locked is True await lock.open() @@ -52,7 +53,7 @@ async def test_cerflock(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="OPEN", value=True, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert lock.is_locking is None @@ -93,7 +94,7 @@ async def test_ceiplock(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LOCK_TARGET_LEVEL", value=0, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU9724704:1", "LOCK_STATE", 1) assert lock.is_locked is True @@ -103,7 +104,7 @@ async def test_ceiplock(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LOCK_TARGET_LEVEL", value=1, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await central.event(const.INTERFACE_ID, "VCU9724704:1", "LOCK_STATE", 2) assert lock.is_locked is False @@ -113,7 +114,7 @@ async def test_ceiplock(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="LOCK_TARGET_LEVEL", value=2, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert lock.is_locking is None diff --git a/tests/test_siren.py b/tests/test_siren.py index 5dfeaaec..9d2db406 100644 --- a/tests/test_siren.py +++ b/tests/test_siren.py @@ -7,6 +7,7 @@ import pytest +from hahomematic.config import WAIT_FOR_CALLBACK from hahomematic.const import EntityUsage from hahomematic.platforms.custom.siren import CeIpSiren, CeIpSirenSmoke @@ -51,7 +52,7 @@ async def test_ceipsiren(factory: helper.Factory) -> None: "DURATION_UNIT": 0, "DURATION_VALUE": 30, }, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await siren.turn_on( @@ -68,7 +69,7 @@ async def test_ceipsiren(factory: helper.Factory) -> None: "DURATION_UNIT": 0, "DURATION_VALUE": 30, }, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) with pytest.raises(ValueError): @@ -95,7 +96,7 @@ async def test_ceipsiren(factory: helper.Factory) -> None: "DURATION_UNIT": 0, "DURATION_VALUE": 0, }, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await siren.turn_off() diff --git a/tests/test_switch.py b/tests/test_switch.py index 8b71f367..267455ab 100644 --- a/tests/test_switch.py +++ b/tests/test_switch.py @@ -7,6 +7,7 @@ import pytest +from hahomematic.config import WAIT_FOR_CALLBACK from hahomematic.const import EntityUsage from hahomematic.platforms.custom.switch import CeSwitch from hahomematic.platforms.generic.switch import HmSwitch @@ -37,7 +38,7 @@ async def test_ceswitch(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="STATE", value=True, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert switch.value is True await switch.turn_off() @@ -46,7 +47,7 @@ async def test_ceswitch(factory: helper.Factory) -> None: paramset_key="VALUES", parameter="STATE", value=False, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert switch.value is False await switch.turn_on(on_time=60) @@ -54,7 +55,7 @@ async def test_ceswitch(factory: helper.Factory) -> None: channel_address="VCU2128127:4", paramset_key="VALUES", values={"ON_TIME": 60.0, "STATE": True}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) assert switch.value is True @@ -65,7 +66,7 @@ async def test_ceswitch(factory: helper.Factory) -> None: channel_address="VCU2128127:4", paramset_key="VALUES", values={"ON_TIME": 35.4, "STATE": True}, - wait_for_callback=False, + wait_for_callback=WAIT_FOR_CALLBACK, ) await switch.turn_on()