pwr-Solaar / Solaar

Linux device manager for Logitech devices
https://pwr-solaar.github.io/Solaar
GNU General Public License v2.0
5.54k stars 410 forks source link

bad key in divert-keys value in config file causes AttributeError #1788

Closed 6e2f61 closed 2 years ago

6e2f61 commented 2 years ago

I have user-defined rules within Solaar Rule Editor for MX Master 2S mouse. Lately my bindings stopped to work (nothing happens after pressing key on mouse).

Defined rules: Rule 1

Rule 2

Unifying receiver version: RQR12.10_B0032, bootloader: BOT01.02_B0015 Python version: 3.10.7 Solaar version: 1.1.5

Debug mode throws only below lines after pressing any of buttons assigned to Rule

ERROR [ReceiverListener:hidraw0] logitech_receiver.settings: invalid choice 0 for 215
WARNING [ReceiverListener:hidraw0] logitech_receiver.settings: divert-keys: error applying value {82: 0, 83: 0, 86: 0, 195: 1, 196: 1, 215: 0, '0': 2} so ignore it (<Device(2,4069,Wireless Mouse MX Master 2S,DB37EDED)>)
ERROR [ReceiverListener:hidraw0] logitech_receiver.listener: processing Notification(11,2,0A,00,00000000000000000000000000000000)
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/logitech_receiver/listener.py", line 188, in run
    self._notifications_callback(n)
  File "/usr/lib/python3.10/site-packages/solaar/listener.py", line 264, in _notifications_handler
    _notifications.process(dev, n)
  File "/usr/lib/python3.10/site-packages/logitech_receiver/notifications.py", line 60, in process
    return _process_device_notification(device, status, notification)
  File "/usr/lib/python3.10/site-packages/logitech_receiver/notifications.py", line 169, in _process_device_notification
    handling_ret = device.handle_notification(n)
  File "/usr/lib/python3.10/site-packages/logitech_receiver/device.py", line 417, in handle_notification
    ret = h(self, n)
  File "/usr/lib/python3.10/site-packages/logitech_receiver/settings.py", line 1431, in handler
    if int(k.key) in cids:  # initiating key that was pressed
AttributeError: 'NoneType' object has no attribute 'key'

Sometimes when I plug out and plug in unifying receiver while Solaar is running everything start to work normally.

How can I help to nail down the issue?

Config file content Config ```yaml - 1.1.5 - _NAME: Wireless Keyboard K270 (unifying) _absent: [hi-res-scroll, lowres-smooth-scroll, hires-smooth-invert, hires-smooth-resolution, smart-shift, thumb-scroll-mode, thumb-scroll-invert, onboard_profiles, report_rate, pointer_speed, dpi, dpi-sliding, speed-change, mouse-gestures, backlight, backlight-timed, fn-swap, reprogrammable-keys, persistent-remappable-keys, divert-keys, disable-keyboard-keys, divert-crown, crown-smooth, divert-gkeys, m-key-leds, mr-key-led, multiplatform, change-host, gesture2-gestures, gesture2-divert, gesture2-params, lowres-scroll-mode, hires-scroll-mode, sidetone, equalizer] _modelId: '000000000000' _serial: 0F193031 _unitId: '00000000' _wpid: '4003' - _NAME: Wireless Mouse MX Master 2S _modelId: B01E40710000 _serial: 37BB0FCA _unitId: 20FCEF34 _wpid: '4069' divert-keys: {82: 0, 83: 0, 86: 0, 195: 0, 196: 0, 215: 0} dpi: 1000 dpi-sliding: 0 gesture2-gestures: {45: true, 46: true} hires-smooth-invert: false hires-smooth-resolution: true mouse-gestures: 0 reprogrammable-keys: {80: 80, 81: 81, 82: 82, 83: 83, 86: 86, 195: 195, 196: 196} smart-shift: 16 - _NAME: Wireless Mouse MX Master 2S _absent: [hi-res-scroll, lowres-smooth-scroll, thumb-scroll-mode, thumb-scroll-invert, onboard_profiles, report_rate, pointer_speed, speed-change, backlight, backlight-timed, fn-swap, persistent-remappable-keys, disable-keyboard-keys, divert-crown, crown-smooth, divert-gkeys, m-key-leds, mr-key-led, multiplatform, gesture2-params, lowres-scroll-mode, sidetone, equalizer] _battery: 4096 _modelId: B01940690000 _sensitive: {divert-keys: false, dpi: false, gesture2-gestures: false, hires-smooth-invert: false, hires-smooth-resolution: false, mouse-gestures: false, reprogrammable-keys: false, smart-shift: false} _serial: DB37EDED _unitId: 127BEBDC _wpid: '4069' change-host: null divert-keys: {82: 0, 83: 0, 86: 0, 195: 1, 196: 1, 215: 0, '0': 2} dpi: '2500' dpi-sliding: 0 gesture2-divert: {46: false} gesture2-gestures: {45: true, 46: true} hires-scroll-mode: false hires-smooth-invert: false hires-smooth-resolution: true reprogrammable-keys: {80: 80, 81: 81, 82: 82, 83: 83, 86: 86, 195: 195, 196: 196} smart-shift: 12 - _NAME: Wireless Keyboard K375s _absent: [hi-res-scroll, lowres-scroll-mode, hires-smooth-invert, hires-smooth-resolution, hires-scroll-mode, smart-shift, thumb-scroll-invert, thumb-scroll-mode, onboard_profiles, report_rate, pointer_speed, dpi, dpi-sliding, speed-change, mouse-gestures, backlight, backlight-timed, reprogrammable-keys, crown-smooth, divert-crown, divert-gkeys, m-key-leds, mr-key-led, gesture2-gestures, gesture2-divert, gesture2-params, sidetone, equalizer] _modelId: B34C40610000 _serial: 9AE82DDC _unitId: DB5BB00B _wpid: '4061' change-host: null disable-keyboard-keys: {1: false, 2: false, 4: false, 8: false, 16: false} divert-keys: {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 10: 0, 189: 0, 191: 0, 192: 0, 193: 0, 209: 0, 210: 0, 211: 0, 212: 0, 213: 0, 214: 0, 221: 0} fn-swap: true multiplatform: 0 persistent-remappable-keys: null - {_NAME: MX Master 3 Wireless Mouse, _serial: FDAE16EE, _wpid: '4082'} - _NAME: Wireless Keyboard K375s _absent: [hi-res-scroll, lowres-scroll-mode, hires-smooth-invert, hires-smooth-resolution, hires-scroll-mode, smart-shift, thumb-scroll-invert, thumb-scroll-mode, onboard_profiles, report_rate, pointer_speed, dpi, dpi-sliding, speed-change, mouse-gestures, backlight, backlight-timed, reprogrammable-keys, crown-smooth, divert-crown, divert-gkeys, m-key-leds, mr-key-led, gesture2-gestures, gesture2-divert, gesture2-params, sidetone, equalizer] _battery: 4096 _modelId: B34C40610000 _sensitive: {disable-keyboard-keys: false, divert-keys: false, fn-swap: false, multiplatform: false, persistent-remappable-keys: false} _serial: B70E1D61 _unitId: 6CFA7C3F _wpid: '4061' change-host: null disable-keyboard-keys: {1: false, 2: false, 4: true, 8: false, 16: false} divert-keys: {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 10: 0, 189: 0, 191: 0, 192: 0, 193: 0, 209: 0, 210: 0, 211: 0, 212: 0, 213: 0, 214: 0, 221: 0} fn-swap: false multiplatform: 0 persistent-remappable-keys: null ```
pfps commented 2 years ago

Do you have these buttons diverted to mouse gestures or sliding dpi? It looks as if this could be the case based on which function is being called.

Your ~/.config/solaar/config.yaml has an invalid entry in it. You should edit that file and remove the part of the divert-keys value that has a string for the key. You could also remove the entire entry for divert-keys. Then try running Solaar again.

Also provide the version of Solaar you are using.

pfps commented 2 years ago

PR #1789 should remove the error you are encountering. But you should also remove the bad part of your config.yaml file. The easiest way do to this may be to start Solaar, change some setting, and then quit Solaar. Check to ensure that the bad part of config.yaml was actually removed.

To clone and use Solar from its GitHub repository

git clone https://github.com/pwr-Solaar/Solaar.git
cd Solaar

Run Solaar as bin/solaar from this directory.

To run PR #1789, first clone Solaar if you have not already done so and cd to the clone directory. The first time you download the pull request, fetch it into a new branch and checkout that branch, as in:

git fetch origin pull/1789/head:pull_1789
git checkout pull_1789

To download a new version of the pull request, fetch it and then set your pull branch to the new fetch, as in:

git checkout pull_1789
git fetch origin pull/1789/head
git reset --hard FETCH_HEAD
6e2f61 commented 2 years ago

Hi, updated issue description with solaar version and original config content which caused problems.

Thanks for quick response on issue. I just removed config and recreated it from scratch with the same rules. Changing options and trying to save&reboot didn't work in my case.

Below current config which works (no issue, no debug info) for reference:

Config content Config ```yaml - 1.1.5 - _NAME: Wireless Keyboard K375s _absent: [hi-res-scroll, lowres-scroll-mode, hires-smooth-invert, hires-smooth-resolution, hires-scroll-mode, smart-shift, thumb-scroll-invert, thumb-scroll-mode, onboard_profiles, report_rate, pointer_speed, dpi, speed-change, backlight, backlight-timed, reprogrammable-keys, crown-smooth, divert-crown, divert-gkeys, m-key-leds, mr-key-led, gesture2-gestures, gesture2-divert, gesture2-params, sidetone, equalizer] _battery: 4096 _modelId: B34C40610000 _sensitive: {persistent-remappable-keys: false} _serial: B70E1D61 _unitId: 6CFA7C3F _wpid: '4061' change-host: null disable-keyboard-keys: {1: false, 2: false, 4: true, 8: false, 16: false} divert-keys: {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 10: 0, 189: 0, 191: 0, 192: 0, 193: 0, 209: 0, 210: 0, 211: 0, 212: 0, 213: 0, 214: 0, 221: 0} fn-swap: false multiplatform: 0 persistent-remappable-keys: null - _NAME: Wireless Mouse MX Master 2S _absent: [hi-res-scroll, lowres-scroll-mode, thumb-scroll-invert, thumb-scroll-mode, onboard_profiles, report_rate, pointer_speed, speed-change, backlight, backlight-timed, fn-swap, persistent-remappable-keys, disable-keyboard-keys, crown-smooth, divert-crown, divert-gkeys, m-key-leds, mr-key-led, multiplatform, gesture2-params, sidetone, equalizer] _battery: 4096 _modelId: B01940690000 _serial: DB37EDED _unitId: 127BEBDC _wpid: '4069' change-host: null divert-keys: {82: 0, 83: 0, 86: 0, 195: 1, 196: 1} dpi: 2500 gesture2-divert: {46: false} gesture2-gestures: {45: true, 46: true} hires-scroll-mode: false hires-smooth-invert: false hires-smooth-resolution: true reprogrammable-keys: {80: 80, 81: 81, 82: 82, 83: 83, 86: 86, 195: 195, 196: 196} smart-shift: 12 ```
pfps commented 2 years ago

Using Solaar to fix the configuration file would not work, you have to edit or replace the file outside of Solaar. The problem is that the format of the configuration file changed and there were bugs in the code that converted from the old format to the new one. This resulted in data that should have been ignored, as described in:

WARNING [ReceiverListener:hidraw0] logitech_receiver.settings: divert-keys: error applying value {82: 0, 83: 0, 86: 0, 195: 1, 196: 1, 215: 0, '0': 2} so ignore it (<Device(2,4069,Wireless Mouse MX Master 2S,DB37EDED)>)

but actually ended up causing Solaar to think that a non-existent key was supposed to trigger dpi sliding, which ended up causing the error you reported. PR #1789 checks for non-existent keys before setting up triggers thus fixing the crash.

As things are OK for you now, I'm going to close this issue.