def setUp(self): self.mock_hid = MockHidapiDevice() self.device = SmartDevice(self.mock_hid, 'Mock Smart Device', speed_channel_count=3, color_channel_count=1) self.device.connect()
def test_kraken2_backwards_modes_are_deprecated(caplog): modes = [ 'backwards-spectrum-wave', 'backwards-marquee-3', 'backwards-marquee-4', 'backwards-marquee-5', 'backwards-marquee-6', 'covering-backwards-marquee', 'backwards-moving-alternating', 'backwards-super-wave' ] from liquidctl.driver.kraken2 import Kraken2 for mode in modes: base_mode = mode.replace('backwards-', '') old = Kraken2(MockHidapiDevice(), 'Mock X62', device_type=Kraken2.DEVICE_KRAKENX) new = Kraken2(MockHidapiDevice(), 'Mock X62', device_type=Kraken2.DEVICE_KRAKENX) colors = [RADICAL_RED, MOUNTAIN_MEADOW] old.set_color('ring', mode, colors) new.set_color('ring', base_mode, colors, direction='backward') assert old.device.sent == new.device.sent, \ f'{mode} != {base_mode} + direction=backward' assert 'deprecated mode' in caplog.text
def test_kraken3_backwards_modes_are_deprecated(caplog): modes = [ 'backwards-spectrum-wave', 'backwards-marquee-3', 'backwards-marquee-4', 'backwards-marquee-5', 'backwards-marquee-6', 'backwards-moving-alternating-3', 'covering-backwards-marquee', 'backwards-moving-alternating-4', 'backwards-moving-alternating-5', 'backwards-moving-alternating-6', 'backwards-rainbow-flow', 'backwards-super-rainbow', 'backwards-rainbow-pulse' ] from liquidctl.driver.kraken3 import KrakenX3 from liquidctl.driver.kraken3 import _COLOR_CHANNELS_KRAKENX from liquidctl.driver.kraken3 import _SPEED_CHANNELS_KRAKENX for mode in modes: base_mode = mode.replace('backwards-', '') old = KrakenX3(MockHidapiDevice(), 'Mock X63', speed_channels=_SPEED_CHANNELS_KRAKENX, color_channels=_COLOR_CHANNELS_KRAKENX) new = KrakenX3(MockHidapiDevice(), 'Mock X63', speed_channels=_SPEED_CHANNELS_KRAKENX, color_channels=_COLOR_CHANNELS_KRAKENX) colors = [RADICAL_RED, MOUNTAIN_MEADOW] old.set_color('ring', mode, colors) new.set_color('ring', base_mode, colors, direction='backward') assert old.device.sent == new.device.sent, \ f'{mode} != {base_mode} + direction=backward' assert 'deprecated mode' in caplog.text
def test_smart_device_v1_backwards_modes_are_deprecated(caplog): modes = [ 'backwards-spectrum-wave', 'backwards-marquee-3', 'backwards-marquee-4', 'backwards-marquee-5', 'backwards-marquee-6', 'covering-backwards-marquee', 'backwards-moving-alternating', 'backwards-super-wave' ] from liquidctl.driver.smart_device import SmartDevice for mode in modes: base_mode = mode.replace('backwards-', '') old = SmartDevice(MockHidapiDevice(), 'Mock Smart Device', speed_channel_count=3, color_channel_count=1) new = SmartDevice(MockHidapiDevice(), 'Mock Smart Device', speed_channel_count=3, color_channel_count=1) colors = [RADICAL_RED, MOUNTAIN_MEADOW] old.set_color('led', mode, colors) new.set_color('led', base_mode, colors, direction='backward') assert old.device.sent == new.device.sent, \ f'{mode} != {base_mode} + direction=backward' assert 'deprecated mode' in caplog.text
def mockDevice(): device = MockHidapiDevice() dev = KrakenTwoDriver(device, 'Mock X62', device_type=KrakenTwoDriver.DEVICE_KRAKENX) dev.connect() return dev
def setUp(self): self.mock_hid = MockHidapiDevice() self.device = KrakenTwoDriver( self.mock_hid, 'Mock X62', device_type=KrakenTwoDriver.DEVICE_KRAKENX) self.device.connect()
def lightingNodeCoreDevice(): device = MockHidapiDevice(vendor_id=0x1b1c, product_id=0x0c1a, address='addr') node = CommanderPro(device, 'Corsair Lighting Node Core', 0, 0, 1) runtime_storage = MockRuntimeStorage(key_prefixes=['testing']) node.connect(runtime_storage=runtime_storage) return node
def commanderProDevice(): device = MockHidapiDevice(vendor_id=0x1b1c, product_id=0x0c10, address='addr') pro = CommanderPro(device, 'Corsair Commander Pro (experimental)', 6, 4, 2) pro.connect() pro._data = MockRuntimeStorage(key_prefixes='testing') return pro
def mockSmartDevice(): device = MockHidapiDevice(vendor_id=0x1e71, product_id=0x1714, address='addr') return SmartDevice(device, 'mock NZXT Smart Device V1', speed_channel_count=3, color_channel_count=1)
def mockRgbFusion2_5702Device(): device = MockHidapiDevice(vendor_id=0x048d, product_id=0x5702, address='addr') dev = RgbFusion2(device, 'mock 5702 Controller') dev.connect() return dev
def lightingNodeProDevice(): device = MockHidapiDevice(vendor_id=0x1b1c, product_id=0x0c0b, address='addr') node = CommanderPro(device, 'Corsair Lighting Node Pro (experimental)', 0, 0, 2) node.connect() node._data = MockRuntimeStorage(key_prefixes='testing') return node
def commanderProDevice(): device = MockHidapiDevice(vendor_id=0x1b1c, product_id=0x0c10, address='addr') pro = CommanderPro(device, 'Corsair Commander Pro', 6, 4, 2) runtime_storage = MockRuntimeStorage(key_prefixes=['testing']) pro.connect(runtime_storage=runtime_storage) return pro
class SmartDeviceTestCase(unittest.TestCase): def setUp(self): self.mock_hid = MockHidapiDevice() self.device = SmartDevice(self.mock_hid, 'Mock Smart Device', speed_channel_count=3, color_channel_count=1) self.device.connect() def tearDown(self): self.device.disconnect() def test_not_totally_broken(self): """A few reasonable example calls do not raise exceptions.""" for i in range(3): self.mock_hid.preload_read(Report(0, bytes(63))) self.device.initialize() status = self.device.get_status() self.device.set_color(channel='led', mode='breathing', colors=iter([[142, 24, 68]]), speed='fastest') self.device.set_fixed_speed(channel='fan3', duty=50)
def emulated_hid_device(): hiddev = MockHidapiDevice() return UsbHidDriver(hiddev, 'Test')
def emulated_usb_device(): usbdev = MockHidapiDevice() # hack, should mock PyUsbDevice dev = UsbDriver(usbdev, 'Test') return dev
def lightingNodeProDeviceUnconnected(): device = MockHidapiDevice(vendor_id=0x1B1C, product_id=0x0C0B, address='addr') return CommanderPro(device, 'Corsair Lighting Node Pro (experimental)', 0, 0, 2)
def commanderProDeviceUnconnected(): device = MockHidapiDevice(vendor_id=0x1b1c, product_id=0x0c10, address='addr') return CommanderPro(device, 'Corsair Commander Pro', 6, 4, 2)
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 lightingNodeProDeviceUnconnected(): device = MockHidapiDevice(vendor_id=0x1b1c, product_id=0x0c0b, address='addr') return CommanderPro(device, 'Corsair Lighting Node Pro', 0, 0, 2)
class Controller5702TestCase(unittest.TestCase): def setUp(self): description = 'Mock 5702 Controller' self.mock_hid = MockHidapiDevice() self.device = RgbFusion2(self.mock_hid, description) self.device.connect() self.report_id = 0xcc def tearDown(self): self.device.disconnect() def test_command_format(self): self.mock_hid.preload_read(_INIT_5702_SAMPLE) self.device.initialize() self.device.set_color(channel='sync', mode='off', colors=[]) self.assertEqual(len(self.mock_hid.sent), 1 + 8 + 1) for i, (report, data) in enumerate(self.mock_hid.sent): self.assertEqual(report, self.report_id) self.assertEqual(len(data), 63) # TODO double check, more likely to be 64 def test_get_status(self): self.assertEqual(self.device.get_status(), []) def test_initialize_status(self): self.mock_hid.preload_read(_INIT_5702_SAMPLE) name, fw_version = self.device.initialize() self.assertEqual(name[1], "IT5702-GIGABYTE V1.0.10.0") self.assertEqual(fw_version[1], '1.0.10.0') def test_off_with_some_channel(self): colors = [[0xff, 0, 0x80]] # should be ignored self.device.set_color(channel='led8', mode='off', colors=iter(colors)) set_color, execute = self.mock_hid.sent self.assertEqual(set_color.data[0:2], [0x27, 0x80], "incorrect channel") self.assertEqual(set_color.data[10], 0x01, "wrong mode value") self.assertEqual(max(set_color.data[13:16]), 0, "incorrect color") self.assertEqual(max(set_color.data[21:27]), 0, "incorrect speed values") def test_fixed_with_some_channel(self): colors = [[0xff, 0, 0x80], [0x30, 0x30, 0x30]] # second color should be ignored self.device.set_color(channel='led7', mode='fixed', colors=iter(colors)) set_color, execute = self.mock_hid.sent self.assertEqual(set_color.data[0:2], [0x26, 0x40], "incorrect channel") self.assertEqual(set_color.data[10], 0x01, "wrong mode value") self.assertEqual(set_color.data[13:16], [0x80, 0x00, 0xff], "incorrect color encoding") self.assertEqual(max(set_color.data[21:27]), 0, "incorrect speed values") def test_pulse_with_some_channel_and_speed(self): colors = [[0xff, 0, 0x80], [0x30, 0x30, 0x30]] # second color should be ignored self.device.set_color(channel='led3', mode='pulse', colors=iter(colors), speed='faster') set_color, execute = self.mock_hid.sent self.assertEqual(set_color.data[0:2], [0x22, 0x04], "incorrect channel") self.assertEqual(set_color.data[10], 0x02, "wrong mode value") self.assertEqual(set_color.data[13:16], [0x80, 0x00, 0xff], "incorrect color encoding") self.assertEqual(set_color.data[21:27], [0xe8, 0x03, 0xe8, 0x03, 0xf4, 0x01], "incorrect speed values") def test_flash_with_some_channel_and_speed(self): colors = [[0xff, 0, 0x80], [0x30, 0x30, 0x30]] # second color should be ignored self.device.set_color(channel='led6', mode='flash', colors=iter(colors), speed='slowest') set_color, execute = self.mock_hid.sent self.assertEqual(set_color.data[0:2], [0x25, 0x20], "incorrect channel") self.assertEqual(set_color.data[10], 0x03, "wrong mode value") self.assertEqual(set_color.data[13:16], [0x80, 0x00, 0xff], "incorrect color encoding") self.assertEqual(set_color.data[21:27], [0x64, 0x00, 0x64, 0x00, 0x60, 0x09], "incorrect speed values") def test_double_flash_with_some_channel_and_speed_and_uppercase(self): colors = [[0xff, 0, 0x80], [0x30, 0x30, 0x30]] # second color should be ignored self.device.set_color(channel='LED5', mode='DOUBLE-FLASH', colors=iter(colors), speed='LUDICROUS') set_color, execute = self.mock_hid.sent self.assertEqual(set_color.data[0:2], [0x24, 0x10], "incorrect channel") self.assertEqual(set_color.data[10], 0x03, "wrong mode value") self.assertEqual(set_color.data[13:16], [0x80, 0x00, 0xff], "incorrect color encoding") self.assertEqual(set_color.data[21:27], [0x64, 0x00, 0x64, 0x00, 0x40, 0x06], "incorrect speed values") def test_color_cycle_with_some_channel_and_speed(self): colors = [[0xff, 0, 0x80]] # should be ignored self.device.set_color(channel='led4', mode='color-cycle', colors=iter(colors), speed='fastest') set_color, execute = self.mock_hid.sent self.assertEqual(set_color.data[0:2], [0x23, 0x08], "incorrect channel") self.assertEqual(set_color.data[10], 0x04, "wrong mode value") self.assertEqual(max(set_color.data[13:16]), 0, "incorrect color") self.assertEqual(set_color.data[21:27], [0x26, 0x02, 0xc2, 0x01, 0x00, 0x00], "incorrect speed values") # TODO brightness def test_common_behavior_in_all_set_color_writes(self): colors = [[0xff, 0, 0x80]] for mode in [ 'off', 'fixed', 'pulse', 'flash', 'double-flash', 'color-cycle' ]: self.mock_hid.sent = deque() self.device.set_color(channel='led1', mode=mode, colors=iter(colors)) set_color, execute = self.mock_hid.sent self.assertEqual(execute.data[0:2], [0x28, 0xff], "incorrect execute payload") self.assertEqual(max(execute.data[2:]), 0, "incorrect execute padding") def test_sync_channel(self): colors = [[0xff, 0, 0x80]] self.device.set_color(channel='sync', mode='fixed', colors=iter(colors)) self.assertEqual(len(self.mock_hid.sent), 8 + 1) # 8 × set + execute def test_reset_all_channels(self): self.device.reset_all_channels() for addr, report in enumerate(self.mock_hid.sent[:-1], 0x20): self.assertEqual(report.data[0:2], [addr, 0], "invalid payload") self.assertEqual(max(report.data[2:]), 0, "invalid padding") execute = self.mock_hid.sent[-1] self.assertEqual(execute.data[0:2], [0x28, 0xff], "incorrect execute payload") self.assertEqual(max(execute.data[2:]), 0, "incorrect execute padding") def test_invalid_set_color_arguments(self): self.assertRaises(Exception, self.device.set_color, channel='invalid', mode='off', colors=[]) self.assertRaises(Exception, self.device.set_color, channel='led1', mode='invalid', colors=[]) self.assertRaises(Exception, self.device.set_color, channel='led1', mode='fixed', colors=[]) self.assertRaises(Exception, self.device.set_color, channel='led1', mode='pulse', colors=[[0xff, 0, 0x80]], speed='invalid')
def setUp(self): description = 'Mock 5702 Controller' self.mock_hid = MockHidapiDevice() self.device = RgbFusion2(self.mock_hid, description) self.device.connect() self.report_id = 0xcc
def commanderProDeviceUnconnected(): device = MockHidapiDevice(vendor_id=0x1B1C, product_id=0x0C10, address='addr') return CommanderPro(device, 'Corsair Commander Pro (experimental)', 6, 4, 2)