Skip to content

Commit

Permalink
Fix effects on v1 0x6,0x7,0x8 controllers (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Dec 16, 2021
1 parent bebeaf1 commit 8e0834f
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 3 deletions.
15 changes: 12 additions & 3 deletions flux_led/models_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@ class LEDENETHardware:
models=["AK001-ZJ100", "AK001-ZJ200", "AK001-ZJ2145", "AK001-ZJ2147"],
description="Controller RGBW",
always_writes_white_and_colors=False, # Formerly rgbwprotocol
protocols=[MinVersionProtocol(0, PROTOCOL_LEDENET_8BYTE_DIMMABLE_EFFECTS)],
protocols=[
MinVersionProtocol(2, PROTOCOL_LEDENET_8BYTE_DIMMABLE_EFFECTS),
MinVersionProtocol(0, PROTOCOL_LEDENET_8BYTE),
],
mode_to_color_mode=GENERIC_RGBW_MAP,
color_modes={COLOR_MODE_RGBW}, # Formerly rgbwcapable
channel_map={},
Expand All @@ -294,7 +297,10 @@ class LEDENETHardware:
models=["AK001-ZJ2146"],
description="Controller RGBCW",
always_writes_white_and_colors=False, # Formerly rgbwprotocol
protocols=[MinVersionProtocol(0, PROTOCOL_LEDENET_9BYTE_DIMMABLE_EFFECTS)],
protocols=[
MinVersionProtocol(2, PROTOCOL_LEDENET_9BYTE_DIMMABLE_EFFECTS),
MinVersionProtocol(0, PROTOCOL_LEDENET_9BYTE),
],
mode_to_color_mode=GENERIC_RGBWW_MAP,
color_modes={COLOR_MODE_RGBWW}, # Formerly rgbwcapable
channel_map={},
Expand All @@ -307,7 +313,10 @@ class LEDENETHardware:
models=["AK001-ZJ2101", "AK001-ZJ2145", "AK001-ZJ2147"],
description="Controller RGB with MIC",
always_writes_white_and_colors=True, # Formerly rgbwprotocol
protocols=[MinVersionProtocol(2, PROTOCOL_LEDENET_8BYTE_DIMMABLE_EFFECTS)],
protocols=[
MinVersionProtocol(2, PROTOCOL_LEDENET_8BYTE_DIMMABLE_EFFECTS),
MinVersionProtocol(0, PROTOCOL_LEDENET_8BYTE),
],
mode_to_color_mode=GENERIC_RGB_MAP,
color_modes={COLOR_MODE_RGB},
channel_map={},
Expand Down
66 changes: 66 additions & 0 deletions tests_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
MultiColorEffects,
)
from flux_led.protocol import (
PROTOCOL_LEDENET_8BYTE,
PROTOCOL_LEDENET_8BYTE_DIMMABLE_EFFECTS,
PROTOCOL_LEDENET_9BYTE,
PROTOCOL_LEDENET_ADDRESSABLE_CHRISTMAS,
PROTOCOL_LEDENET_ORIGINAL,
Expand Down Expand Up @@ -677,8 +679,72 @@ def _updated_callback(*args, **kwargs):
)
await task
assert light.model_num == 0x08
assert light.version_num == 4
assert light.effect == EFFECT_MUSIC
assert light.microphone is True
assert light.protocol == PROTOCOL_LEDENET_8BYTE_DIMMABLE_EFFECTS

transport.reset_mock()
await light.async_set_music_mode()
assert transport.mock_calls[0][0] == "write"
assert transport.mock_calls[0][1][0] == b"s\x01d\x0f\xe7"
assert transport.mock_calls[1][0] == "write"
assert transport.mock_calls[1][1][0] == b"7\x00\x007"


@pytest.mark.asyncio
async def test_async_set_music_mode_0x08_v1_firmware(
mock_aio_protocol, caplog: pytest.LogCaptureFixture
):
"""Test we can set music mode on an 0x08 with v1 firmware."""
light = AIOWifiLedBulb("192.168.1.166")

def _updated_callback(*args, **kwargs):
pass

with patch.object(aiodevice, "COMMAND_SPACING_DELAY", 0):
task = asyncio.create_task(light.async_setup(_updated_callback))
transport, protocol = await mock_aio_protocol()
light._aio_protocol.data_received(
b"\x81\x08\x23\x62\x23\x01\x80\x00\xFF\x00\x01\x00\x00\xB2"
)
await task
assert light.model_num == 0x08
assert light.version_num == 1
assert light.effect == EFFECT_MUSIC
assert light.microphone is True
assert light.protocol == PROTOCOL_LEDENET_8BYTE

transport.reset_mock()
await light.async_set_music_mode()
assert transport.mock_calls[0][0] == "write"
assert transport.mock_calls[0][1][0] == b"s\x01d\x0f\xe7"
assert transport.mock_calls[1][0] == "write"
assert transport.mock_calls[1][1][0] == b"7\x00\x007"


@pytest.mark.asyncio
async def test_async_set_music_mode_0x08_v2_firmware(
mock_aio_protocol, caplog: pytest.LogCaptureFixture
):
"""Test we can set music mode on an 0x08 with v2 firmware."""
light = AIOWifiLedBulb("192.168.1.166")

def _updated_callback(*args, **kwargs):
pass

with patch.object(aiodevice, "COMMAND_SPACING_DELAY", 0):
task = asyncio.create_task(light.async_setup(_updated_callback))
transport, protocol = await mock_aio_protocol()
light._aio_protocol.data_received(
b"\x81\x08\x23\x62\x23\x01\x80\x00\xFF\x00\x02\x00\x00\xB3"
)
await task
assert light.model_num == 0x08
assert light.version_num == 2
assert light.effect == EFFECT_MUSIC
assert light.microphone is True
assert light.protocol == PROTOCOL_LEDENET_8BYTE_DIMMABLE_EFFECTS

transport.reset_mock()
await light.async_set_music_mode()
Expand Down

0 comments on commit 8e0834f

Please sign in to comment.