Skip to content

Commit

Permalink
fix: refactor to use kwargs for construct_levels_change
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Dec 11, 2024
1 parent 667c585 commit 8df6b8c
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/led_ble/led_ble.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,15 @@ async def set_rgb(
rgb = self._calculate_brightness(rgb, brightness)
_LOGGER.debug("%s: Set rgb after brightness: %s", self.name, rgb)
assert self._protocol is not None # nosec

r, g, b = rgb
command = self._protocol.construct_levels_change(
True, *rgb, None, None, LevelWriteMode.COLORS
persist=True,
red=r,
green=g,
blue=b,
warm_white=None,
cool_white=None,
write_mode=LevelWriteMode.COLORS,
)
await self._send_command(command)
self._state = replace(
Expand All @@ -216,12 +222,18 @@ async def set_rgbw(
for value in rgbw:
if not 0 <= value <= 255:
raise ValueError("Value {} is outside the valid range of 0-255")
rgbw = rgbw_brightness(rgbw, brightness)
r, g, b, w = rgbw_brightness(rgbw, brightness)
_LOGGER.debug("%s: Set rgbw after brightness: %s", self.name, rgbw)
assert self._protocol is not None # nosec

command = self._protocol.construct_levels_change(
True, *rgbw, None, None, LevelWriteMode.ALL
persist=True,
red=r,
green=g,
blue=b,
warm_white=w,
cool_white=None,
write_mode=LevelWriteMode.ALL,
)
await self._send_command(command)

Expand All @@ -241,7 +253,13 @@ async def set_white(self, brightness: int) -> None:
assert self._protocol is not None # nosec

command = self._protocol.construct_levels_change(
True, 0, 0, 0, brightness, None, LevelWriteMode.WHITES
persist=True,
red=0,
green=0,
blue=0,
warm_white=brightness,
cool_white=None,
write_mode=LevelWriteMode.WHITES,
)
await self._send_command(command)
self._state = replace(
Expand Down

0 comments on commit 8df6b8c

Please sign in to comment.