From 8df6b8c89eac585bfe36bf6991fa2a2ff4e29279 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 11 Dec 2024 22:21:10 +0100 Subject: [PATCH] fix: refactor to use kwargs for construct_levels_change --- src/led_ble/led_ble.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/led_ble/led_ble.py b/src/led_ble/led_ble.py index f655769..c7c05f6 100644 --- a/src/led_ble/led_ble.py +++ b/src/led_ble/led_ble.py @@ -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( @@ -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) @@ -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(