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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
|
import pytest
from _testutils import MockHidapiDevice, Report
from collections import deque
from liquidctl.error import NotSupportedByDevice, NotSupportedByDriver
from liquidctl.driver.ga2_lcd import GA2LCD, _write_colors
@pytest.fixture
def mockGA2LCD():
device = MockHidapiDevice(vendor_id=0x0416, product_id=0x7395, address="addr")
dev = GA2LCD(device, "mock GA II LCD")
dev.connect()
return dev
def test_ga2_lcd_initialize(mockGA2LCD):
_FW_REPORT_PART1 = bytes.fromhex(
"0186000000324e392c30312c48532c53512c43415f49492d566973696f6e2c56"
"322e30312e3032452c312e340000000000000000000000000000000000000000"
)
_FW_REPORT_PART2 = bytes.fromhex(
"01860000011b4f637420323220323032342c31303a33393a3135000000000000"
"0000000000000000000000000000000000000000000000000000000000000000"
)
mockGA2LCD.device.preload_read(Report(0, _FW_REPORT_PART1))
mockGA2LCD.device.preload_read(Report(0, _FW_REPORT_PART2))
status = mockGA2LCD.initialize() # should perform 3 writes
assert len(mockGA2LCD.device.sent) == 1
inq = mockGA2LCD.device.sent[0]
assert inq[0] == 0x01 # report ID
assert inq.data[0] == 0x86
assert inq.data[1] == 0x00
assert inq.data[2] == 0x00
assert inq.data[3] == 0x00
assert status[0][0] == "Firmware version"
assert status[0][1] == "N9,01,HS,SQ,CA_II-Vision,V2.01.02E,1.4 Oct 22 2024,10:39:15"
def test_ga2_lcd_initialize_bad_version(mockGA2LCD):
mockGA2LCD.device.preload_read(
Report(0, bytes.fromhex("0186000000320000000000000000000000000000000000000000000000000000"))
)
mockGA2LCD.device.preload_read(
Report(0, bytes.fromhex("0186000000320000000000000000000000000000000000000000000000000000"))
)
with pytest.raises(NotSupportedByDriver, match="Device firmware version does not match"):
mockGA2LCD.initialize()
def test_ga2_lcd_initialize_no_response(mockGA2LCD):
with pytest.raises(ValueError, match="Device not responding"):
mockGA2LCD.initialize()
def test_ga2_lcd_initialize_bad_response(mockGA2LCD):
mockGA2LCD.device.preload_read(Report(0, bytes.fromhex("018600")))
with pytest.raises(ValueError, match="Unexpected response from device"):
mockGA2LCD.initialize()
def test_ga2_lcd_get_status(mockGA2LCD):
_STATUS_REPORT = bytes.fromhex(
"01810000000705a00a6e01250800000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000"
)
mockGA2LCD.device.preload_read(Report(0, _STATUS_REPORT))
status = mockGA2LCD.get_status()
inq = mockGA2LCD.device.sent[0]
assert inq[0] == 0x01
assert inq.data[0] == 0x81
assert inq.data[1] == 0x00
assert inq.data[2] == 0x00
assert inq.data[3] == 0x00
assert len(status) == 5
assert status[1][0] == "Fan speed"
assert status[1][1] == 1440
assert status[2][0] == "Fan duty"
assert status[2][1] == pytest.approx(57.1, 57.2)
assert status[3][0] == "Pump speed"
assert status[3][1] == 2670
assert status[0][0] == "Liquid temperature"
assert status[0][1] == 37.8
assert status[4][0] == "Pump duty"
assert status[4][1] == pytest.approx(74.1, 74.2)
def test_ga2_lcd_fan_speed(mockGA2LCD):
mockGA2LCD.set_fixed_speed(channel="fan", duty=50)
report = mockGA2LCD.device.sent[0]
assert report[0] == 0x01 # report ID
assert report.data[0] == 0x8B
assert report.data[1] == 0x00
assert report.data[2] == 0x00
assert report.data[3] == 0x00
assert report.data[4] == 0x02
assert report.data[5] == 0x00
assert report.data[6] == 50
def test_ga2_lcd_fan_speed_out_of_range(mockGA2LCD):
mockGA2LCD.set_fixed_speed(channel="fan", duty=150)
report = mockGA2LCD.device.sent[0]
assert report[0] == 0x01 # report ID
assert report.data[0] == 0x8B
assert report.data[1] == 0x00
assert report.data[2] == 0x00
assert report.data[3] == 0x00
assert report.data[4] == 0x02
assert report.data[5] == 0x00
assert report.data[6] == 100
def test_ga2_lcd_fan_speed_negative(mockGA2LCD):
mockGA2LCD.set_fixed_speed(channel="fan", duty=-5)
report = mockGA2LCD.device.sent[0]
assert report[0] == 0x01 # report ID
assert report.data[0] == 0x8B
assert report.data[1] == 0x00
assert report.data[2] == 0x00
assert report.data[3] == 0x00
assert report.data[4] == 0x02
assert report.data[5] == 0x00
assert report.data[6] == 0
def test_ga2_lcd_pump_speed(mockGA2LCD):
mockGA2LCD.set_fixed_speed(channel="pump", duty=75)
report = mockGA2LCD.device.sent[0]
assert report[0] == 0x01 # report ID
assert report.data[0] == 0x8A
assert report.data[1] == 0x00
assert report.data[2] == 0x00
assert report.data[3] == 0x00
assert report.data[4] == 0x02
assert report.data[5] == 0x00
assert report.data[6] == 75
def test_ga2_lcd_pump_speed_out_of_range(mockGA2LCD):
mockGA2LCD.set_fixed_speed(channel="pump", duty=150)
report = mockGA2LCD.device.sent[0]
assert report[0] == 0x01 # report ID
assert report.data[0] == 0x8A
assert report.data[1] == 0x00
assert report.data[2] == 0x00
assert report.data[3] == 0x00
assert report.data[4] == 0x02
assert report.data[5] == 0x00
assert report.data[6] == 100
def test_ga2_lcd_pump_speed_negative(mockGA2LCD):
mockGA2LCD.set_fixed_speed(channel="pump", duty=-10)
report = mockGA2LCD.device.sent[0]
assert report[0] == 0x01 # report ID
assert report.data[0] == 0x8A
assert report.data[1] == 0x00
assert report.data[2] == 0x00
assert report.data[3] == 0x00
assert report.data[4] == 0x02
assert report.data[5] == 0x00
assert report.data[6] == 0
def test_ga2_lcd_set_pump_lighting_mode(mockGA2LCD):
mockGA2LCD.set_color(
channel="pump",
mode="static",
colors=[(0xFF, 0x00, 0x00), (0x00, 0xFF, 0x00), (0x00, 0x00, 0xFF), (0xFF, 0x00, 0xFF)],
speed="faster",
direction="forward",
)
report = mockGA2LCD.device.sent[0]
assert report[0] == 0x01 # report ID
assert report.data[0] == 0x83
assert report.data[1] == 0x00
assert report.data[2] == 0x00
assert report.data[3] == 0x00
assert report.data[4] == 19
assert report.data[5] == 0x00
assert report.data[6] == 0x03 # static mode
assert report.data[7] == 0x04 # brightness max
assert report.data[8] == 0x03 # faster speed
assert report.data[9] == 0xFF # red
assert report.data[10] == 0x00
assert report.data[11] == 0x00
assert report.data[12] == 0x00 # green
assert report.data[13] == 0xFF
assert report.data[14] == 0x00
assert report.data[15] == 0x00 # blue
assert report.data[16] == 0x00
assert report.data[17] == 0xFF
assert report.data[18] == 0xFF # purple
assert report.data[19] == 0x00
assert report.data[20] == 0xFF
assert report.data[21] == 0x00 # direction
assert report.data[22] == 0x00
assert report.data[23] == 0x00
assert report.data[24] == 0x00
def test_ga2_lcd_set_fan_lighting_mode(mockGA2LCD):
mockGA2LCD.set_color(
channel="fan",
mode="rainbow",
colors=[(0x00, 0x00, 0xFF), (0xFF, 0x00, 0xFF), (0xFF, 0x00, 0x00), (0x00, 0xFF, 0x00)],
speed="slower",
direction="backward",
)
report = mockGA2LCD.device.sent[0]
assert report[0] == 0x01 # report ID
assert report.data[0] == 0x85
assert report.data[1] == 0x00
assert report.data[2] == 0x00
assert report.data[3] == 0x00
assert report.data[4] == 20
assert report.data[5] == 0x05 # static mode
assert report.data[6] == 0x04 # brightness max
assert report.data[7] == 0x01 # slower speed
assert report.data[8] == 0x00 # blue
assert report.data[9] == 0x00
assert report.data[10] == 0xFF
assert report.data[11] == 0xFF # purple
assert report.data[12] == 0x00
assert report.data[13] == 0xFF
assert report.data[14] == 0xFF # red
assert report.data[15] == 0x00
assert report.data[16] == 0x00
assert report.data[17] == 0x00 # green
assert report.data[18] == 0xFF
assert report.data[19] == 0x00
assert report.data[20] == 0x01 # backward
assert report.data[21] == 0x00
assert report.data[22] == 0x00
assert report.data[23] == 0x00
assert report.data[24] == 24
def test_ga2_write_colors_four_twelve():
buffer = [0] * 14
buffer[0] = 0x35
buffer[13] = 0xAB
colors = [(0xFF, 0x00, 0x00), (0x00, 0xFF, 0x00), (0x00, 0x00, 0xFF), (0xFF, 0xFF, 0x00)]
_write_colors(buffer, colors, 1, 12)
assert buffer[0] == 0x35
assert buffer[1] == 0xFF
assert buffer[2] == 0x00
assert buffer[3] == 0x00
assert buffer[4] == 0x00
assert buffer[5] == 0xFF
assert buffer[6] == 0x00
assert buffer[7] == 0x00
assert buffer[8] == 0x00
assert buffer[9] == 0xFF
assert buffer[10] == 0xFF
assert buffer[11] == 0xFF
assert buffer[12] == 0x00
assert buffer[13] == 0xAB
def test_ga2_write_colors_three_twelve():
buffer = [0] * 14
buffer[0] = 0x45
buffer[13] = 0xAE
colors = [(0xFF, 0xFF, 0xFF), (0xFF, 0xFF, 0xFF), (0xFF, 0xFF, 0xFF)]
_write_colors(buffer, colors, 1, 12)
assert buffer[0] == 0x45
assert buffer[1] == 0xFF
assert buffer[2] == 0xFF
assert buffer[3] == 0xFF
assert buffer[4] == 0xFF
assert buffer[5] == 0xFF
assert buffer[6] == 0xFF
assert buffer[7] == 0xFF
assert buffer[8] == 0xFF
assert buffer[9] == 0xFF
assert buffer[10] == 0x00
assert buffer[11] == 0x00
assert buffer[12] == 0x00
assert buffer[13] == 0xAE
def test_ga2_write_colors_two_eight():
buffer = [0] * 10
buffer[0] = 0x55
buffer[9] = 0xAF
colors = [(0xFF, 0xFF, 0xFF), (0xFF, 0xFF, 0xFF)]
_write_colors(buffer, colors, 1, 8)
assert buffer[0] == 0x55
assert buffer[1] == 0xFF
assert buffer[2] == 0xFF
assert buffer[3] == 0xFF
assert buffer[4] == 0xFF
assert buffer[5] == 0xFF
assert buffer[6] == 0xFF
assert buffer[7] == 0x00
assert buffer[8] == 0x00
assert buffer[9] == 0xAF
|