Repository: pwr-Solaar/Solaar

Issue:
G915 Keyboard causes error in 1.1.12rc1
My G915 Lightspeed Keyboard get not listed in Solaar.

![image](https://github.com/pwr-Solaar/Solaar/assets/43136984/fea19eee-ddf2-41a3-bd20-bbbe531e3a7a)

out put of `solaar -ddd`: 
[test.log](https://github.com/pwr-Solaar/Solaar/files/15041789/test.log)



Discussion:
Did this work in previous versions of Solaar?
yes. I previously used the 1.1.11 without any issues. And with the PRs I reviewed between these versions every thing worked as well.
I found this error in the debuggin messages:
```
2024-04-19 16:29:54,032,032  WARNING [SolaarListener:hidraw14] logitech_receiver.settings: onboard_profiles: error applying 511 so ignore it (<Device(1,407C,G915 WIRELESS RGB MECHANICAL GAMING KEYBOARD,A502B0E1)>): ValueError('invalid choice 511')
2024-04-19 16:29:54,042,042    ERROR [SolaarListener:hidraw14] logitech_receiver.base: (15) device 1 error on feature request {162B}: 2 = invalid argument
2024-04-19 16:29:54,042,042  WARNING [SolaarListener:hidraw14] logitech_receiver.settings: report_rate: error applying 1 so ignore it (<Device(1,407C,G915 WIRELESS RGB MECHANICAL GAMING KEYBOARD,A502B0E1)>): FeatureCallError({'number': 1, 'request': 5675, 'error': 2, 'params': b'\x01'})
2024-04-19 16:29:54,062,062    ERROR [SolaarListener:hidraw14] logitech_receiver.base: (15) device 1 error on feature request {0AED}: 7 = invalid function
2024-04-19 16:29:54,062,062  WARNING [SolaarListener:hidraw14] logitech_receiver.settings: rgb_zone_2: error applying None so ignore it (<Device(1,407C,G915 WIRELESS RGB MECHANICAL GAMING KEYBOARD,A502B0E1)>): FeatureCallError({'number': 1, 'request': 2797, 'error': 7, 'params': b'\x00'})
2024-04-19 16:29:54,072,072    ERROR [SolaarListener:hidraw14] logitech_receiver.base: (15) device 1 error on feature request {0AE9}: 7 = invalid function
2024-04-19 16:29:54,072,072  WARNING [SolaarListener:hidraw14] logitech_receiver.settings: rgb_zone_1: error applying None so ignore it (<Device(1,407C,G915 WIRELESS RGB MECHANICAL GAMING KEYBOARD,A502B0E1)>): FeatureCallError({'number': 1, 'request': 2793, 'error': 7, 'params': b'\x01'})
2024-04-19 16:29:54,298,298    ERROR [SolaarListener:hidraw14] logitech_receiver.listener: processing Notification(10,1,41,11,317C40)
Traceback (most recent call last):
  File "/nix/store/95pf2zw97qin7105z243y1kzsibimbga-solaar-flake-1.1.12rc1/lib/python3.11/site-packages/logitech_receiver/listener.py", line 153, in run
    self._notifications_callback(n)
  File "/nix/store/95pf2zw97qin7105z243y1kzsibimbga-solaar-flake-1.1.12rc1/lib/python3.11/site-packages/solaar/listener.py", line 219, in _notifications_handler
    _notifications.process(dev, n)
  File "/nix/store/95pf2zw97qin7105z243y1kzsibimbga-solaar-flake-1.1.12rc1/lib/python3.11/site-packages/logitech_receiver/notifications.py", line 54, in process
    return _process_device_notification(device, notification)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/95pf2zw97qin7105z243y1kzsibimbga-solaar-flake-1.1.12rc1/lib/python3.11/site-packages/logitech_receiver/notifications.py", line 163, in _process_device_notification
    return _process_hidpp10_notification(device, n)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/95pf2zw97qin7105z243y1kzsibimbga-solaar-flake-1.1.12rc1/lib/python3.11/site-packages/logitech_receiver/notifications.py", line 267, in _process_hidpp10_notification
    device.changed(active=link_established)
  File "/nix/store/95pf2zw97qin7105z243y1kzsibimbga-solaar-flake-1.1.12rc1/lib/python3.11/site-packages/logitech_receiver/device.py", line 417, in changed
    self.read_battery()  # battery information may have changed so try to read it now 
    ^^^^^^^^^^^^^^^^^^^
  File "/nix/store/95pf2zw97qin7105z243y1kzsibimbga-solaar-flake-1.1.12rc1/lib/python3.11/site-packages/logitech_receiver/device.py", line 392, in read_battery
    self.set_battery_info(battery if battery is not None else Battery(None, None, None, None))
  File "/nix/store/95pf2zw97qin7105z243y1kzsibimbga-solaar-flake-1.1.12rc1/lib/python3.11/site-packages/logitech_receiver/device.py", line 385, in set_battery_info
    _hidpp10.set_3leds(self, info.level, charging=info.charging(), warning=bool(alert))
  File "/nix/store/95pf2zw97qin7105z243y1kzsibimbga-solaar-flake-1.1.12rc1/lib/python3.11/site-packages/logitech_receiver/hidpp10.py", line 120, in set_3leds
    if REGISTERS.three_leds not in device.registers:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: argument of type 'NoneType' is not iterable
```
What settings does the keyboard have?   

Please provide the other information asked for in bug reports.
config.yaml:
```yml
- 1.1.12rc1
- _NAME: G915 WIRELESS RGB MECHANICAL GAMING KEYBOARD
  _absent: [hi-res-scroll, lowres-scroll-mode, hires-smooth-invert, hires-smooth-resolution, hires-scroll-mode, scroll-ratchet, smart-shift, thumb-scroll-invert,
    thumb-scroll-mode, report_rate_extended, pointer_speed, dpi, dpi_extended, speed-change, backlight, backlight_level, backlight_duration_hands_out, backlight_duration_hands_in,
    backlight_duration_powered, backlight-timed, led_control, led_zone_, fn-swap, reprogrammable-keys, persistent-remappable-keys, disable-keyboard-keys,
    crown-smooth, divert-crown, multiplatform, gesture2-gestures, gesture2-divert, gesture2-params, sidetone, equalizer, adc_power_management]
  _battery: 4097
  _modelId: B354407CC33E
  _sensitive: {hires-scroll-mode: ignore, hires-smooth-invert: ignore, hires-smooth-resolution: ignore}
  _serial: A502B0E1
  _unitId: A502B0E1
  _wpid: 407C
  brightness_control: 12
  change-host: null
  divert-gkeys: false
  divert-keys: {209: 0, 210: 0}
  m-key-leds: {1: false, 2: false, 4: false}
  mr-key-led: false
  onboard_profiles: 511
  report_rate: 1
  rgb_control: 0
```
solaar 1.1.11:
![image](https://github.com/pwr-Solaar/Solaar/assets/43136984/98449f0f-3c71-4446-afd5-ded56df80fe4)


Resolving patch:
diff --git a/lib/logitech_receiver/device.py b/lib/logitech_receiver/device.py
--- a/lib/logitech_receiver/device.py
+++ b/lib/logitech_receiver/device.py
@@ -101,7 +101,8 @@ def __init__(self, receiver, number, online, pairing_info=None, handle=None, dev
         self._tid_map = None  # map from transports to product identifiers
         self._persister = None  # persister holds settings
         self._led_effects = self._firmware = self._keys = self._remap_keys = self._gestures = None
-        self._profiles = self._backlight = self.registers = self._settings = None
+        self._profiles = self._backlight = self._settings = None
+        self.registers = []
         self.notification_flags = None
         self.battery_info = None
         self.link_encrypted = None
diff --git a/lib/logitech_receiver/settings_templates.py b/lib/logitech_receiver/settings_templates.py
--- a/lib/logitech_receiver/settings_templates.py
+++ b/lib/logitech_receiver/settings_templates.py
@@ -1568,7 +1568,7 @@ def build(cls, setting_class, device):
 class LEDControl(_Setting):
     name = "led_control"
     label = _("LED Control")
-    description = _("Switch control of LEDs between device and Solaar")
+    description = _("Switch control of LED zones between device and Solaar")
     feature = _F.COLOR_LED_EFFECTS
     rw_options = {"read_fnid": 0x70, "write_fnid": 0x80}
     choices_universe = _NamedInts(Device=0, Solaar=1)
@@ -1584,7 +1584,7 @@ class LEDControl(_Setting):
 class LEDZoneSetting(_Setting):
     name = "led_zone_"
     label = _("LED Zone Effects")
-    description = _("Set effect for LED Zone")
+    description = _("Set effect for LED Zone") + "\n" + _("LED Control needs to be set to Solaar to be effective.")
     feature = _F.COLOR_LED_EFFECTS
     color_field = {"name": _LEDP.color, "kind": _KIND.choice, "label": None, "choices": colors}
     speed_field = {"name": _LEDP.speed, "kind": _KIND.range, "label": _("Speed"), "min": 0, "max": 255}
@@ -1619,8 +1619,8 @@ def build(cls, device):
 
 class RGBControl(_Setting):
     name = "rgb_control"
-    label = _("RGB Control")
-    description = _("Switch control of RGB zones between device and Solaar")
+    label = _("LED Control")
+    description = _("Switch control of LED zones between device and Solaar")
     feature = _F.RGB_EFFECTS
     rw_options = {"read_fnid": 0x50, "write_fnid": 0x50}
     choices_universe = _NamedInts(Device=0, Solaar=1)
@@ -1631,7 +1631,7 @@ class RGBControl(_Setting):
 class RGBEffectSetting(LEDZoneSetting):
     name = "rgb_zone_"
     label = _("LED Zone Effects")
-    description = _("Set effect for LED Zone")
+    description = _("Set effect for LED Zone") + "\n" + _("LED Control needs to be set to Solaar to be effective.")
     feature = _F.RGB_EFFECTS
 
     @classmethod


Test patch:
diff --git a/tests/logitech_receiver/test_device.py b/tests/logitech_receiver/test_device.py
--- a/tests/logitech_receiver/test_device.py
+++ b/tests/logitech_receiver/test_device.py
@@ -106,7 +106,7 @@ def test_Device_name(device_info, responses, codename, name, kind, mock_base):
         [None, "Illuminated", "Craft", "G700", "MX Vertical", None],
         [0xFF, 0x0, 0xFF, 0x0, 0xFF, 0xFF],
         [1.0, 1.0, 4.5, 1.0, 4.5, 4.5],
-        [None, [], [], (common.NamedInt(7, "battery status"), common.NamedInt(81, "three leds")), [], None],
+        [[], [], [], (common.NamedInt(7, "battery status"), common.NamedInt(81, "three leds")), [], []],
     ),
 )
 def test_Device_info(device_info, responses, handle, _name, _codename, number, protocol, registers, mock_base):