Skip to content

Commit

Permalink
Fix A3 white value (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Jan 5, 2022
1 parent f3c3dc0 commit 8c64b0d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions flux_led/base_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,16 @@ def _set_raw_state(
)
return

if isinstance(self._protocol, ProtocolLEDENETAddressableA3):
if updated is not None:
self.raw_state = raw_state
return
# A3 uses a unique scale for warm white
self.raw_state = raw_state._replace(
warm_white=utils.A3WarmWhiteToByte(raw_state.warm_white)
)
return

self.raw_state = raw_state

def __str__(self) -> str: # noqa: C901
Expand Down
4 changes: 4 additions & 0 deletions flux_led/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ def byteToPercent(byte: int) -> int:
def percentToByte(percent: int) -> int:
return int((max(0, min(100, percent)) * 255) / 100)

@staticmethod
def A3WarmWhiteToByte(val: int) -> int:
return round(((min(228, max(128, val)) - 128) * 255) / 100)


def rgbwc_to_rgbcw(
rgbwc_data: Tuple[int, int, int, int, int]
Expand Down
14 changes: 14 additions & 0 deletions tests_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,20 @@ def _updated_callback(*args, **kwargs):
assert transport.mock_calls == [
call.write(bytearray(b"\xb0\xb1\xb2\xb3\x00\x01\x01\x03\x00\x03G\xffFZ"))
]
light._transition_complete_time = 0

light._aio_protocol.data_received(
b"\x81\xA3\x23\x61\x01\x32\x40\x40\x40\x80\x01\x00\x90\xAC"
)
assert light.raw_state.warm_white == 0
light._aio_protocol.data_received(
b"\x81\xA3\x23\x61\x01\x32\x40\x40\x40\xE4\x01\x00\x90\x10"
)
assert light.raw_state.warm_white == 255
light._aio_protocol.data_received(
b"\x81\xA3\x23\x61\x01\x32\x40\x40\x40\xB1\x01\x00\x90\xDD"
)
assert light.raw_state.warm_white == 125


@pytest.mark.asyncio
Expand Down

0 comments on commit 8c64b0d

Please sign in to comment.