"""Test I2C functionality on a FreeWili."""

import pytest

from freewili import FreeWili
from freewili.framing import ResponseFrameType


@pytest.mark.skipif("len(FreeWili.find_all()) == 0")
def test_hw_board_leds() -> None:
    """Test LEDs on a FreeWili."""
    device = FreeWili.find_all()[0]
    device.stay_open = True

    for led_num in range(7):
        response_frame = device.set_board_leds(led_num, 50, 50, 50).expect("Failed to set LED")
        assert response_frame.rf_type == ResponseFrameType.Standard
        # assert response_frame.rf_type_data == r"k\s"
        assert response_frame.timestamp != 0
        assert response_frame.response == "Ok"
        assert response_frame.is_ok()

    for led_num in range(7):
        response_frame = device.set_board_leds(led_num, 0, 0, 0).expect("Failed to set LED")
        assert response_frame.rf_type == ResponseFrameType.Standard
        # assert response_frame.rf_type_data == r"k\s"
        assert response_frame.timestamp != 0
        assert response_frame.response == "Ok"
        assert response_frame.is_ok()

    device.close()


if __name__ == "__main__":
    import pytest

    pytest.main(
        args=[
            __file__,
            "--verbose",
        ]
    )
