Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refactor to use kwargs for construct_levels_change #53

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading