diff --git a/flux_led/models_db.py b/flux_led/models_db.py index 68e47d3b..d9d14de6 100755 --- a/flux_led/models_db.py +++ b/flux_led/models_db.py @@ -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={}, @@ -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={}, @@ -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={}, diff --git a/tests_aio.py b/tests_aio.py index 904c42be..2e0e5a11 100644 --- a/tests_aio.py +++ b/tests_aio.py @@ -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, @@ -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()