File: test_aura_led.py

package info (click to toggle)
liquidctl 1.16.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 3,452 kB
  • sloc: python: 15,304; sh: 712; xml: 84; makefile: 4
file content (118 lines) | stat: -rw-r--r-- 5,061 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import pytest
from _testutils import MockHidapiDevice, Report

from liquidctl.driver.aura_led import AuraLed

# Sample data for Aura LED controller from ASUS ProArt Z690-Creator WiFi
_INIT_19AF_FIRMWARE_DATA = bytes.fromhex(
    "ec0241554c41332d415233322d30323037000000000000000000000000000000"
    "000000000000000000000000000000000000000000000000000000000000000000"
)
_INIT_19AF_FIRMWARE = Report(_INIT_19AF_FIRMWARE_DATA[0], _INIT_19AF_FIRMWARE_DATA[1:])

_INIT_19AF_CONFIG_DATA = bytes.fromhex(
    "ec3000001e9f03010000783c00010000783c00010000783c0000000000000001"
    "040201f40000000000000000000000000000000000000000000000000000000000"
)
_INIT_19AF_CONFIG = Report(_INIT_19AF_CONFIG_DATA[0], _INIT_19AF_CONFIG_DATA[1:])


@pytest.fixture
def mockAuraLed_19AFDevice():
    device = MockHidapiDevice(vendor_id=0x0B05, product_id=0x19AF, address="addr")
    dev = AuraLed(device, "mock Aura LED Controller")
    dev.connect()
    return dev


def test_aura_led_19AF_device_command_format(mockAuraLed_19AFDevice):
    mockAuraLed_19AFDevice.device.preload_read(_INIT_19AF_FIRMWARE)
    mockAuraLed_19AFDevice.device.preload_read(_INIT_19AF_CONFIG)
    mockAuraLed_19AFDevice.initialize()  # should perform 3 writes
    mockAuraLed_19AFDevice.set_color(
        channel="sync", mode="off", colors=[]
    )  # should perform 14 writes
    assert len(mockAuraLed_19AFDevice.device.sent) == 2 + 14
    for i, (report, data) in enumerate(mockAuraLed_19AFDevice.device.sent):
        assert report == 0xEC
        assert len(data) == 64


def test_aura_led_19AF_device_get_status(mockAuraLed_19AFDevice):
    mockAuraLed_19AFDevice.device.preload_read(_INIT_19AF_CONFIG)
    assert mockAuraLed_19AFDevice.get_status() != []


def test_aura_led_unexpected_get_status(mockAuraLed_19AFDevice):
    with pytest.raises(AssertionError):
        mockAuraLed_19AFDevice.device.preload_read(Report(bytes(0), _INIT_19AF_CONFIG_DATA[1:]))
        mockAuraLed_19AFDevice.get_status()


def test_aura_led_19AF_device_initialize_status(mockAuraLed_19AFDevice):
    mockAuraLed_19AFDevice.device.preload_read(_INIT_19AF_FIRMWARE)
    mockAuraLed_19AFDevice.device.preload_read(_INIT_19AF_CONFIG)
    status_list = mockAuraLed_19AFDevice.initialize()
    firmware_tuple = status_list[0]
    assert firmware_tuple[1] == "AULA3-AR32-0207"


def test_aura_led_19AF_device_off_with_some_channel(mockAuraLed_19AFDevice):
    colors = [[0xFF, 0, 0x80]]  # should be ignored
    mockAuraLed_19AFDevice.set_color(channel="led2", mode="off", colors=iter(colors))
    assert len(mockAuraLed_19AFDevice.device.sent) == 5
    data1 = mockAuraLed_19AFDevice.device.sent[0].data
    data2 = mockAuraLed_19AFDevice.device.sent[1].data
    assert data1[1] == 0x01  # key for led2
    assert data1[4] == 0x00  # off
    assert data2[2] == 0x02  # channel led2
    assert data2[7:10] == [0x00, 0x00, 0x00]


def test_aura_led_19AF_static_with_some_channel(mockAuraLed_19AFDevice):
    colors = [[0xFF, 0, 0x80], [0x30, 0x30, 0x30]]  # second color should be ignored
    mockAuraLed_19AFDevice.set_color(channel="led2", mode="static", colors=iter(colors))
    assert len(mockAuraLed_19AFDevice.device.sent) == 5
    data1 = mockAuraLed_19AFDevice.device.sent[0].data
    data2 = mockAuraLed_19AFDevice.device.sent[1].data
    assert data1[1] == 0x01  # key for led2
    assert data1[4] == 0x01  # static mode
    assert data2[2] == 0x02  # channel led2
    assert data2[7:10] == [0xFF, 0x00, 0x80]


def test_aura_led_19AF_spectrum_cycle_with_some_channel(mockAuraLed_19AFDevice):
    colors = [[0xFF, 0, 0x80], [0x30, 0x30, 0x30]]  # second color should be ignored
    mockAuraLed_19AFDevice.set_color(channel="led3", mode="spectrum_cycle", colors=iter(colors))
    assert len(mockAuraLed_19AFDevice.device.sent) == 5
    data1 = mockAuraLed_19AFDevice.device.sent[0].data
    data2 = mockAuraLed_19AFDevice.device.sent[1].data
    assert data1[1] == 0x01  # key for led3
    assert data1[4] == 0x04  # spectrum cycle
    assert data2[2] == 0x04  # channel led3
    assert data2[7:10] == [0x00, 0x00, 0x00]


def test_aura_led_19AF_device_sync_channel(mockAuraLed_19AFDevice):
    colors = [[0xFF, 0, 0x80]]
    mockAuraLed_19AFDevice.set_color(channel="sync", mode="static", colors=iter(colors))
    assert len(mockAuraLed_19AFDevice.device.sent) == 14  # 14 writes


def test_aura_led_19AF_device_invalid_set_color_arguments(mockAuraLed_19AFDevice):
    with pytest.raises(KeyError):
        mockAuraLed_19AFDevice.set_color("invalid", "off", [])

    with pytest.raises(KeyError):
        mockAuraLed_19AFDevice.set_color("led2", "invalid", [])

    with pytest.raises(ValueError):
        mockAuraLed_19AFDevice.set_color("led3", "static", [])


def test_aura_led_19AF_device_initialize_status(mockAuraLed_19AFDevice):
    mockAuraLed_19AFDevice.device.preload_read(_INIT_19AF_FIRMWARE)
    mockAuraLed_19AFDevice.device.preload_read(_INIT_19AF_CONFIG)
    status_list = mockAuraLed_19AFDevice.initialize()
    firmware_tuple = status_list[0]
    assert firmware_tuple[1] == "AULA3-AR32-0207"