Skip to content

Commit 7d5f9c3

Browse files
authored
clamp effect brightness to ensure it cannot be set above the max value (#437)
clamp brightness to ensure it cannot be set above the max value
1 parent 265864d commit 7d5f9c3

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

flux_led/aiodevice.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ async def async_set_effect(
428428
if effect == EFFECT_RANDOM:
429429
await self.async_set_random()
430430
return
431+
brightness = min(100, max(0, brightness))
431432
if effect == EFFECT_MUSIC:
432433
await self.async_set_music_mode(brightness=brightness)
433434
return

tests/test_aio.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,15 @@ def _updated_callback(*args, **kwargs):
934934
counter_byte = transport.mock_calls[0][1][0][7]
935935
assert counter_byte == 0
936936

937+
transport.reset_mock()
938+
# Verify brightness clamped
939+
await light.async_set_effect("RBM 1", 50, brightness=500)
940+
assert transport.mock_calls[0][0] == "write"
941+
assert (
942+
transport.mock_calls[0][1][0]
943+
== b"\xb0\xb1\xb2\xb3\x00\x01\x01\x01\x00\x05B\x012d\xd9\x80"
944+
)
945+
937946

938947
@pytest.mark.asyncio
939948
async def test_SK6812RGBW(mock_aio_protocol, caplog: pytest.LogCaptureFixture):

0 commit comments

Comments
 (0)