From 5a8d584bf1178560eadd93f306fc971536b6fa26 Mon Sep 17 00:00:00 2001 From: SukramJ Date: Sun, 7 Jan 2024 20:54:08 +0100 Subject: [PATCH] Add duration=111600 when ramp_time used for HmIP-RGBW (#1364) * Add duration=111600 when ramp_time used for HmIP-RGBW * Update light.py * Fix test * Fix test --- changelog.md | 4 ++++ hahomematic/platforms/custom/light.py | 24 +++++++++++++++++------- pyproject.toml | 2 +- tests/test_light.py | 13 +++++-------- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/changelog.md b/changelog.md index a632266c..efbe504a 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,7 @@ +# Version 2024.1.3 (2024-01-07) + +- Add duration=111600 when ramp_time used for HmIP-RGBW + # Version 2024.1.2 (2024-01-07) - Only consider relevant entities for HmIP-RGBW diff --git a/hahomematic/platforms/custom/light.py b/hahomematic/platforms/custom/light.py index 24a410ec..0dc48691 100644 --- a/hahomematic/platforms/custom/light.py +++ b/hahomematic/platforms/custom/light.py @@ -542,7 +542,8 @@ async def turn_on( value=color_temp_kelvin, collector=collector ) if kwargs.get("on_time") is None and kwargs.get("ramp_time"): - await self._set_on_time_value(on_time=0, collector=collector) + # 111600 is a special value for NOT_USED + await self._set_on_time_value(on_time=111600, collector=collector) if self.supports_effects and (effect := kwargs.get("effect")) is not None: await self._e_effect.send_value(value=effect, collector=collector) @@ -554,7 +555,8 @@ async def _set_on_time_value( ) -> None: """Set the on time value in seconds.""" on_time, on_time_unit = _recalc_unit_timer(time=on_time) - await self._e_on_time_unit.send_value(value=on_time_unit, collector=collector) + if on_time_unit: + await self._e_on_time_unit.send_value(value=on_time_unit, collector=collector) await self._e_on_time_value.send_value(value=float(on_time), collector=collector) async def _set_ramp_time_on_value( @@ -562,7 +564,8 @@ async def _set_ramp_time_on_value( ) -> None: """Set the ramp time value in seconds.""" ramp_time, ramp_time_unit = _recalc_unit_timer(time=ramp_time) - await self._e_ramp_time_unit.send_value(value=ramp_time_unit, collector=collector) + if ramp_time_unit: + await self._e_ramp_time_unit.send_value(value=ramp_time_unit, collector=collector) await self._e_ramp_time_value.send_value(value=float(ramp_time), collector=collector) async def _set_ramp_time_off_value( @@ -570,7 +573,10 @@ async def _set_ramp_time_off_value( ) -> None: """Set the ramp time value in seconds.""" ramp_time, ramp_time_unit = _recalc_unit_timer(time=ramp_time) - await self._e_ramp_time_to_off_unit.send_value(value=ramp_time_unit, collector=collector) + if ramp_time_unit: + await self._e_ramp_time_to_off_unit.send_value( + value=ramp_time_unit, collector=collector + ) await self._e_ramp_time_to_off_value.send_value( value=float(ramp_time), collector=collector ) @@ -641,7 +647,8 @@ async def _set_on_time_value( ) -> None: """Set the on time value in seconds.""" on_time, on_time_unit = _recalc_unit_timer(time=on_time) - await self._e_on_time_unit.send_value(value=on_time_unit, collector=collector) + if on_time_unit: + await self._e_on_time_unit.send_value(value=on_time_unit, collector=collector) await self._e_on_time_value.send_value(value=float(on_time), collector=collector) async def _set_ramp_time_on_value( @@ -649,7 +656,8 @@ async def _set_ramp_time_on_value( ) -> None: """Set the ramp time value in seconds.""" ramp_time, ramp_time_unit = _recalc_unit_timer(time=ramp_time) - await self._e_ramp_time_unit.send_value(value=ramp_time_unit, collector=collector) + if ramp_time_unit: + await self._e_ramp_time_unit.send_value(value=ramp_time_unit, collector=collector) await self._e_ramp_time_value.send_value(value=float(ramp_time), collector=collector) @@ -702,9 +710,11 @@ async def turn_on( await super().turn_on(collector=collector, **kwargs) -def _recalc_unit_timer(time: float) -> tuple[float, int]: +def _recalc_unit_timer(time: float) -> tuple[float, int | None]: """Recalculate unit and value of timer.""" ramp_time_unit = TimeUnit.SECONDS + if time == 111600: + return time, None if time > 16343: time /= 60 ramp_time_unit = TimeUnit.MINUTES diff --git a/pyproject.toml b/pyproject.toml index 6461b978..d67ee782 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "hahomematic" -version = "2024.1.2" +version = "2024.1.3" license = {text = "MIT License"} description = "Homematic interface for Home Assistant running on Python 3." readme = "README.md" diff --git a/tests/test_light.py b/tests/test_light.py index 9bcad719..d61f9b9f 100644 --- a/tests/test_light.py +++ b/tests/test_light.py @@ -16,7 +16,6 @@ CeIpRGBWLight, ColorBehaviour, FixedColor, - TimeUnit, ) from tests import const, helper @@ -459,7 +458,7 @@ async def test_ceipfixedcolorlight(factory: helper.Factory) -> None: assert mock_client.method_calls[-1] == call.put_paramset( address="VCU3716619:8", paramset_key="VALUES", - value={"DURATION_UNIT": 0, "DURATION_VALUE": 18, "LEVEL": 1.0}, + value={"DURATION_VALUE": 18, "LEVEL": 1.0}, ) await light.turn_off() @@ -483,7 +482,7 @@ async def test_ceipfixedcolorlight(factory: helper.Factory) -> None: assert mock_client.method_calls[-1] == call.put_paramset( address="VCU3716619:8", paramset_key="VALUES", - value={"RAMP_TIME_UNIT": 0, "RAMP_TIME_VALUE": 18, "LEVEL": 1.0}, + value={"RAMP_TIME_VALUE": 18, "LEVEL": 1.0}, ) await light.turn_on(ramp_time=17000) @@ -691,7 +690,7 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: assert mock_client.method_calls[-1] == call.put_paramset( address="VCU4704397:8", paramset_key="VALUES", - value={"COLOR_BEHAVIOUR": 6, "DURATION_UNIT": 0, "DURATION_VALUE": 18, "LEVEL": 1.0}, + value={"COLOR_BEHAVIOUR": 6, "DURATION_VALUE": 18, "LEVEL": 1.0}, ) await light.turn_off() @@ -715,7 +714,7 @@ async def test_ceipfixedcolorlightwired(factory: helper.Factory) -> None: assert mock_client.method_calls[-1] == call.put_paramset( address="VCU4704397:8", paramset_key="VALUES", - value={"COLOR_BEHAVIOUR": 6, "RAMP_TIME_UNIT": 0, "RAMP_TIME_VALUE": 18, "LEVEL": 1.0}, + value={"COLOR_BEHAVIOUR": 6, "RAMP_TIME_VALUE": 18, "LEVEL": 1.0}, ) await light.turn_on(ramp_time=17000) @@ -865,9 +864,7 @@ async def test_ceiprgbwlight(factory: helper.Factory) -> None: value={ "HUE": 44, "SATURATION": 0.66, - "DURATION_UNIT": TimeUnit.SECONDS, - "DURATION_VALUE": 0, - "RAMP_TIME_UNIT": TimeUnit.SECONDS, + "DURATION_VALUE": 111600, "RAMP_TIME_VALUE": 5, "LEVEL": 1.0, },