Skip to content

Commit

Permalink
Add duration=111600 when ramp_time used for HmIP-RGBW (#1364)
Browse files Browse the repository at this point in the history
* Add duration=111600 when ramp_time used for HmIP-RGBW

* Update light.py

* Fix test

* Fix test
  • Loading branch information
SukramJ authored Jan 7, 2024
1 parent 634b25f commit 5a8d584
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 17 additions & 7 deletions hahomematic/platforms/custom/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -554,23 +555,28 @@ 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(
self, ramp_time: float, collector: CallParameterCollector | None = None
) -> 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(
self, ramp_time: float, collector: CallParameterCollector | None = None
) -> 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
)
Expand Down Expand Up @@ -641,15 +647,17 @@ 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(
self, ramp_time: float, collector: CallParameterCollector | None = None
) -> 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)


Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 5 additions & 8 deletions tests/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
CeIpRGBWLight,
ColorBehaviour,
FixedColor,
TimeUnit,
)

from tests import const, helper
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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,
},
Expand Down

0 comments on commit 5a8d584

Please sign in to comment.