diff --git a/changelog.md b/changelog.md index 48802e0f..1cdb5fb3 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,7 @@ +# Version 2023.9.0 (2023-09-03) + +- Refactor cover api + # Version 2023.8.14 (2023-08-30) - Reduce visibility of local constants diff --git a/hahomematic/platforms/custom/cover.py b/hahomematic/platforms/custom/cover.py index 987d22b3..1270b8bb 100644 --- a/hahomematic/platforms/custom/cover.py +++ b/hahomematic/platforms/custom/cover.py @@ -106,12 +106,15 @@ def current_position(self) -> int: @bind_collector async def set_position( - self, position: float, collector: CallParameterCollector | None = None + self, + position: float | None = None, + tilt_position: float | None = None, + collector: CallParameterCollector | None = None, ) -> None: """Move the cover to a specific position.""" if not self.is_state_change(position=position): return - level = min(100.0, max(0.0, position)) / 100.0 + level = min(100.0, max(0.0, position)) / 100.0 if position is not None else None await self._set_level(level=level, collector=collector) async def _set_level( @@ -244,27 +247,19 @@ def current_tilt_position(self) -> int: return int(self._channel_tilt_level * 100) @bind_collector - async def set_tilt_position( - self, tilt_position: float, collector: CallParameterCollector | None = None - ) -> None: - """Move the blind to a specific tilt position.""" - if not self.is_state_change(tilt_position=tilt_position): - return - tilt_level = min(100.0, max(0.0, tilt_position)) / 100.0 - await self._set_level(tilt_level=tilt_level, collector=collector) - - @bind_collector - async def set_combined_position( + async def set_position( self, - position: float, - tilt_position: float, + position: float | None = None, + tilt_position: float | None = None, collector: CallParameterCollector | None = None, ) -> None: """Move the blind to a specific position.""" if not self.is_state_change(position=position, tilt_position=tilt_position): return - level = min(100.0, max(0.0, position)) / 100.0 - tilt_level = min(100.0, max(0.0, tilt_position)) / 100.0 + level = min(100.0, max(0.0, position)) / 100.0 if position is not None else None + tilt_level = ( + min(100.0, max(0.0, tilt_position)) / 100.0 if tilt_position is not None else None + ) await self._set_level(level=level, tilt_level=tilt_level, collector=collector) async def _set_level( @@ -428,9 +423,14 @@ def current_position(self) -> int | None: @bind_collector async def set_position( - self, position: float, collector: CallParameterCollector | None = None + self, + position: float | None = None, + tilt_position: float | None = None, + collector: CallParameterCollector | None = None, ) -> None: """Move the garage door to a specific position.""" + if position is None: + return if 50.0 < position <= 100.0: await self.open(collector=collector) if 10.0 < position <= 50.0: diff --git a/pyproject.toml b/pyproject.toml index caa697cb..48f12b29 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "hahomematic" -version = "2023.8.14" +version = "2023.9.0" license = {text = "MIT License"} description = "Homematic interface for Home Assistant running on Python 3." readme = "README.md" diff --git a/tests/test_cover.py b/tests/test_cover.py index 37496538..1c0d4853 100644 --- a/tests/test_cover.py +++ b/tests/test_cover.py @@ -46,7 +46,7 @@ async def test_cecover(factory: helper.Factory) -> None: assert cover.current_position == 0 assert cover._channel_level == _HM_CLOSED assert cover.is_closed is True - await cover.set_position(81) + await cover.set_position(position=81) assert mock_client.method_calls[-1] == call.set_value( channel_address="VCU8537918:4", paramset_key="VALUES", @@ -96,7 +96,7 @@ async def test_cecover(factory: helper.Factory) -> None: central.event(const.INTERFACE_ID, "VCU8537918:3", "LEVEL", 0.4) call_count = len(mock_client.method_calls) - await cover.set_position(40) + await cover.set_position(position=40) assert call_count == len(mock_client.method_calls) @@ -111,7 +111,7 @@ async def test_ceipblind_dr(factory: helper.Factory) -> None: assert cover._channel_level == _HM_CLOSED assert cover.channel_operation_mode == "SHUTTER" assert cover.is_closed is True - await cover.set_position(81) + await cover.set_position(position=81) assert mock_client.method_calls[-1] == call.set_value( channel_address="VCU7807849:2", paramset_key="VALUES", @@ -162,7 +162,7 @@ async def test_cewindowdrive(factory: helper.Factory) -> None: assert cover.current_position == 0 assert cover._channel_level == _HM_WD_CLOSED assert cover.is_closed is True - await cover.set_position(81) + await cover.set_position(position=81) assert mock_client.method_calls[-1] == call.set_value( channel_address="VCU0000350:1", paramset_key="VALUES", @@ -191,12 +191,12 @@ async def test_cewindowdrive(factory: helper.Factory) -> None: assert cover._channel_level == _HM_WD_CLOSED assert cover.is_closed is True - await cover.set_position(1) + await cover.set_position(position=1) assert cover.current_position == 1 assert cover._channel_level == _HM_CLOSED assert cover.is_closed is False - await cover.set_position(0.0) + await cover.set_position(position=0.0) assert cover.current_position == 0 assert cover._channel_level == _HM_WD_CLOSED assert cover.is_closed is True @@ -211,7 +211,7 @@ async def test_ceblind(factory: helper.Factory) -> None: assert cover.current_position == 0 assert cover.current_tilt_position == 0 - await cover.set_position(81) + await cover.set_position(position=81) assert mock_client.method_calls[-1] == call.set_value( channel_address="VCU0000145:1", paramset_key="VALUES", @@ -255,7 +255,7 @@ async def test_ceblind(factory: helper.Factory) -> None: assert cover.current_position == 0 assert cover.current_tilt_position == 100 - await cover.set_tilt_position(45) + await cover.set_position(tilt_position=45) assert mock_client.method_calls[-1] == call.set_value( channel_address="VCU0000145:1", paramset_key="VALUES", @@ -277,7 +277,7 @@ async def test_ceblind(factory: helper.Factory) -> None: assert cover.current_position == 0 assert cover.current_tilt_position == 0 - await cover.set_combined_position(position=10, tilt_position=20) + await cover.set_position(position=10, tilt_position=20) assert mock_client.method_calls[-1] == call.set_value( channel_address="VCU0000145:1", paramset_key="VALUES", @@ -320,7 +320,7 @@ async def test_ceblind(factory: helper.Factory) -> None: central.event(const.INTERFACE_ID, "VCU0000145:1", "LEVEL_SLATS", 0.4) call_count = len(mock_client.method_calls) - await cover.set_tilt_position(40) + await cover.set_position(tilt_position=40) assert call_count == len(mock_client.method_calls) @@ -333,7 +333,7 @@ async def test_ceipblind(factory: helper.Factory) -> None: assert cover.current_position == 0 assert cover.current_tilt_position == 0 - await cover.set_position(81) + await cover.set_position(position=81) assert mock_client.method_calls[-1] == call.set_value( channel_address="VCU1223813:4", paramset_key="VALUES", @@ -379,7 +379,7 @@ async def test_ceipblind(factory: helper.Factory) -> None: assert cover.current_position == 0 assert cover.current_tilt_position == 100 - await cover.set_tilt_position(45) + await cover.set_position(tilt_position=45) assert mock_client.method_calls[-1] == call.set_value( channel_address="VCU1223813:4", paramset_key="VALUES", @@ -402,7 +402,7 @@ async def test_ceipblind(factory: helper.Factory) -> None: assert cover.current_position == 0 assert cover.current_tilt_position == 0 - await cover.set_combined_position(position=10, tilt_position=20) + await cover.set_position(position=10, tilt_position=20) assert mock_client.method_calls[-1] == call.set_value( channel_address="VCU1223813:4", paramset_key="VALUES", @@ -439,7 +439,7 @@ async def test_cegarageho(factory: helper.Factory) -> None: assert cover.usage == HmEntityUsage.CE_PRIMARY assert cover.current_position is None - await cover.set_position(81) + await cover.set_position(position=81) assert mock_client.method_calls[-1] == call.set_value( channel_address="VCU3574044:1", paramset_key="VALUES", @@ -458,7 +458,7 @@ async def test_cegarageho(factory: helper.Factory) -> None: central.event(const.INTERFACE_ID, "VCU3574044:1", "DOOR_STATE", 0) assert cover.current_position == 0 assert cover.is_closed is True - await cover.set_position(11) + await cover.set_position(position=11) assert mock_client.method_calls[-1] == call.set_value( channel_address="VCU3574044:1", paramset_key="VALUES", @@ -468,7 +468,7 @@ async def test_cegarageho(factory: helper.Factory) -> None: central.event(const.INTERFACE_ID, "VCU3574044:1", "DOOR_STATE", 2) assert cover.current_position == 10 - await cover.set_position(5) + await cover.set_position(position=5) assert mock_client.method_calls[-1] == call.set_value( channel_address="VCU3574044:1", paramset_key="VALUES", @@ -532,7 +532,7 @@ async def test_cegaragetm(factory: helper.Factory) -> None: assert cover.usage == HmEntityUsage.CE_PRIMARY assert cover.current_position is None - await cover.set_position(81) + await cover.set_position(position=81) assert mock_client.method_calls[-1] == call.set_value( channel_address="VCU6166407:1", paramset_key="VALUES", @@ -551,7 +551,7 @@ async def test_cegaragetm(factory: helper.Factory) -> None: central.event(const.INTERFACE_ID, "VCU6166407:1", "DOOR_STATE", 0) assert cover.current_position == 0 assert cover.is_closed is True - await cover.set_position(11) + await cover.set_position(position=11) assert mock_client.method_calls[-1] == call.set_value( channel_address="VCU6166407:1", paramset_key="VALUES", @@ -561,7 +561,7 @@ async def test_cegaragetm(factory: helper.Factory) -> None: central.event(const.INTERFACE_ID, "VCU6166407:1", "DOOR_STATE", 2) assert cover.current_position == 10 - await cover.set_position(5) + await cover.set_position(position=5) assert mock_client.method_calls[-1] == call.set_value( channel_address="VCU6166407:1", paramset_key="VALUES",