From 05c7f4c1fd642460ff23ea1d3dd1bf5c6a6e6965 Mon Sep 17 00:00:00 2001 From: SukramJ Date: Wed, 3 Jan 2024 21:18:17 +0100 Subject: [PATCH] Add duration=0 when ramp_time used for HmIP-RGBW (#1352) --- changelog.md | 4 ++++ hahomematic/platforms/custom/definition.py | 4 +++- hahomematic/platforms/custom/light.py | 14 ++++++++++++++ pyproject.toml | 2 +- tests/test_light.py | 18 +++++++++++++++++- 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index 926f21ed..c40eea2c 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,7 @@ +# Version 2024.1.0 (2024-01-03) + +- Add duration=0 when ramp_time used for HmIP-RGBW + # Version 2023.12.4 (2023-12-19) - Add HB-LC-Bl1-Velux to cover diff --git a/hahomematic/platforms/custom/definition.py b/hahomematic/platforms/custom/definition.py index e9c06696..d8d21326 100644 --- a/hahomematic/platforms/custom/definition.py +++ b/hahomematic/platforms/custom/definition.py @@ -182,8 +182,10 @@ ED.PRIMARY_CHANNEL: 1, ED.SECONDARY_CHANNELS: (2, 3, 4), ED.REPEATABLE_FIELDS: { - Field.DIRECTION: Parameter.ACTIVITY_STATE, Field.COLOR_TEMPERATURE: Parameter.COLOR_TEMPERATURE, + Field.DIRECTION: Parameter.ACTIVITY_STATE, + Field.ON_TIME_VALUE: Parameter.DURATION_VALUE, + Field.ON_TIME_UNIT: Parameter.DURATION_UNIT, Field.EFFECT: Parameter.EFFECT, Field.HUE: Parameter.HUE, Field.LEVEL: Parameter.LEVEL, diff --git a/hahomematic/platforms/custom/light.py b/hahomematic/platforms/custom/light.py index f9fa03b6..771cccc1 100644 --- a/hahomematic/platforms/custom/light.py +++ b/hahomematic/platforms/custom/light.py @@ -439,6 +439,9 @@ def _init_entity_fields(self) -> None: self._e_device_operation_mode: HmSelect = self._get_entity( field=Field.DEVICE_OPERATION_MODE, entity_type=HmSelect ) + self._e_on_time_unit: HmAction = self._get_entity( + field=Field.ON_TIME_UNIT, entity_type=HmAction + ) self._e_effect: HmAction = self._get_entity(field=Field.EFFECT, entity_type=HmAction) self._e_hue: HmInteger = self._get_entity(field=Field.HUE, entity_type=HmInteger) self._e_ramp_time_to_off_unit: HmAction = self._get_entity( @@ -524,11 +527,22 @@ async def turn_on( await self._e_color_temperature_kelvin.send_value( 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) if self.supports_effects and (effect := kwargs.get("effect")) is not None: await self._e_effect.send_value(value=effect, collector=collector) await super().turn_on(collector=collector, **kwargs) + @bind_collector + async def _set_on_time_value( + self, on_time: float, collector: CallParameterCollector | None = None + ) -> 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) + await self._e_on_time_value.send_value(value=float(on_time), collector=collector) + async def _set_ramp_time_on_value( self, ramp_time: float, collector: CallParameterCollector | None = None ) -> None: diff --git a/pyproject.toml b/pyproject.toml index 9ac332f5..870066f6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "hahomematic" -version = "2023.12.4" +version = "2024.1.0" 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 497559d3..e192dcb7 100644 --- a/tests/test_light.py +++ b/tests/test_light.py @@ -6,7 +6,7 @@ import pytest -from hahomematic.const import EntityUsage +from hahomematic.const import EntityUsage, ParamsetKey from hahomematic.platforms.custom.light import ( CeColorDimmer, CeColorDimmerEffect, @@ -16,6 +16,7 @@ CeIpRGBWLight, ColorBehaviour, FixedColor, + TimeUnit, ) from tests import const, helper @@ -843,3 +844,18 @@ async def test_ceiprgbwlight(factory: helper.Factory) -> None: assert mock_client.method_calls[-1] == call.put_paramset( address="VCU5629873:1", paramset_key="VALUES", value={"EFFECT": 1, "LEVEL": 1.0} ) + + await light.turn_on(hs_color=(44, 66), ramp_time=5) + assert mock_client.method_calls[-1] == call.put_paramset( + address="VCU5629873:1", + paramset_key=ParamsetKey.VALUES, + value={ + "HUE": 44, + "SATURATION": 0.66, + "DURATION_UNIT": TimeUnit.SECONDS, + "DURATION_VALUE": 0, + "RAMP_TIME_UNIT": TimeUnit.SECONDS, + "RAMP_TIME_VALUE": 5, + "LEVEL": 1.0, + }, + )