Repository: pwr-Solaar/Solaar

Issue:
forgotten removed call in device.py - breaks device enumeration on 27MHz receiver
**Information**
- Solaar version (`solaar --version` or `git describe --tags` if cloned from this repository): solaar 1.1.8+dfsg-2
- Distribution: Debian bullseye/bookworm
- Kernel version (ex. `uname -srmo`): `Linux 6.0.0-0.deb11.6-amd64 x86_64 GNU/Linux`
- Output of `solaar show`:
<details>

```
solaar show
solaar version 1.1.8+dfsg-2

EX100 Receiver 27 Mhz
  Device path  : /dev/hidraw3
  USB id       : 046d:C517
  Serial       : None
  Has 2 paired device(s) out of a maximum of 4.
  Notifications: wireless (0x000100)

```

</details>

- Contents of `~/.config/solaar/config.yaml` (or `~/.config/solaar/config.json` if `~/.config/solaar/config.yaml` not present):

No such file.

- Errors or warrnings from Solaar:
```
solaar -dd
2023-02-06 15:36:15,508,508     INFO [MainThread] root: language fr_FR (UTF-8), translations path None
2023-02-06 15:36:15,803,803     INFO [MainThread] logitech_receiver.diversion: GDK Keymap set up
2023-02-06 15:36:15,848,848     INFO [MainThread] solaar.upower: connected to system dbus, watching for suspend/resume events
2023-02-06 15:36:15,917,917     INFO [MainThread] solaar.ui.notify: starting desktop notifications
2023-02-06 15:36:16,220,220     INFO [MainThread] solaar.listener: starting receiver listening threads
2023-02-06 15:36:16,508,508  WARNING [MainThread] hidapi.udev: Report Descriptor not processed for BID 0003 VID 000017EF PID 0000608C: unpack requires a buffer of 2 bytes
2023-02-06 15:36:16,523,523     INFO [MainThread] hidapi.udev: Found device BID 0003 VID 0000046D PID 0000C517 HID++ True True USB 1 1
2023-02-06 15:36:16,523,523     INFO [MainThread] solaar.listener: receiver event add DeviceInfo(path='/dev/hidraw3', bus_id=3, vendor_id='046D', product_id='C517', interface=1, driver='logitech-djreceiver', manufacturer=None, product=None, serial='', release=None, isDevice=None, hidpp_short=True, hidpp_long=True)
2023-02-06 15:36:16,524,524     INFO [MainThread] logitech_receiver.base: New lock 13
2023-02-06 15:36:16,531,531     INFO [ReceiverListener:hidraw3] logitech_receiver.listener: started with <EX100Receiver27Mhz(/dev/hidraw3,13)> (13)
2023-02-06 15:36:16,531,531     INFO [ReceiverListener:hidraw3] solaar.listener: <EX100Receiver27Mhz(/dev/hidraw3,13)>: notifications listener has started (13)
2023-02-06 15:36:16,531,531     INFO [ReceiverListener:hidraw3] logitech_receiver.base: New lock <_ThreadedHandle(/dev/hidraw3)>
2023-02-06 15:36:16,547,547     INFO [ReceiverListener:hidraw3] logitech_receiver.receiver: <EX100Receiver27Mhz(/dev/hidraw3,13)>: receiver notifications enabled => ('wireless',)
2023-02-06 15:36:16,555,555     INFO [ReceiverListener:hidraw3] solaar.listener: status_changed <EX100Receiver27Mhz(/dev/hidraw3,13)>: present, Aucun périphérique jumelé. (0) 
2023-02-06 15:36:16,572,572    ERROR [ReceiverListener:hidraw3] logitech_receiver.listener: processing Notification(10,1,41,02,012239)
Traceback (most recent call last):
  File "/usr/share/solaar/lib/logitech_receiver/listener.py", line 191, in run
    self._notifications_callback(n)
  File "/usr/share/solaar/lib/solaar/listener.py", line 234, in _notifications_handler
    dev = self.receiver.register_new_device(n.devnumber, n)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/solaar/lib/logitech_receiver/receiver.py", line 241, in register_new_device
    dev = Device(self, number, notification)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/solaar/lib/logitech_receiver/device.py", line 121, in __init__
    kind = self.get_kind_from_index(number, receiver)
           ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Device' object has no attribute 'get_kind_from_index'
2023-02-06 15:36:16,580,580    ERROR [ReceiverListener:hidraw3] logitech_receiver.listener: processing Notification(10,3,41,02,021145)
Traceback (most recent call last):
  File "/usr/share/solaar/lib/logitech_receiver/listener.py", line 191, in run
    self._notifications_callback(n)
  File "/usr/share/solaar/lib/solaar/listener.py", line 234, in _notifications_handler
    dev = self.receiver.register_new_device(n.devnumber, n)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/solaar/lib/logitech_receiver/receiver.py", line 241, in register_new_device
    dev = Device(self, number, notification)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/solaar/lib/logitech_receiver/device.py", line 121, in __init__
    kind = self.get_kind_from_index(number, receiver)
           ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Device' object has no attribute 'get_kind_from_index'
2023-02-06 15:36:24,927,927     INFO [MainThread] solaar.listener: stopping receiver listening threads [<ReceiverListener(ReceiverListener:hidraw3, started daemon 139937519236800)>]
2023-02-06 15:36:25,611,611     INFO [ReceiverListener:hidraw3] solaar.listener: <EX100Receiver27Mhz(/dev/hidraw3,13)>: notifications listener has stopped
2023-02-06 15:36:25,614,614     INFO [MainThread] solaar.ui.notify: stopping desktop notifications
```




**Describe the bug**
The device paired are not shown. The UI tells no device is paired (even though the CLI with "show" tells 2 are paired).

The issue is that in commit 2c3578a "receiver: move receiver pairing information code from device class to receiver class" a call to self.get_kind_from_index in lib/logitech_receiver/device.py class Device, __init__ was left.  This function is not defined anymore.
This call is also in git master.



**To Reproduce**
Steps to reproduce the behavior:
1. start solar -dd with device paired on a 27MHz receiver.
2. See error



Discussion:
PR #1984 should fix your problem.   Please try it out and report back whether it works.

Also please provide the output from `solaar show` when your devices are active so that information about them can be added to the Solaar documentation.

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 #1984, 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/1984/head:pull_1984
git checkout pull_1984
```
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_1984
git fetch origin pull/1984/head
git reset --hard FETCH_HEAD
```


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
@@ -113,8 +113,14 @@ def __init__(
                     self.wpid = '00' + _strhex(link_notification.data[2:3])
                     kind = receiver.get_kind_from_index(number)
                 self._kind = _hidpp10.DEVICE_KIND[kind]
-            else:
-                # Not a notification, force a reading of pairing information
+            elif receiver.receiver_kind == '27Mhz':  # 27 Mhz receiver doesn't have pairing registers
+                self.wpid = _hid.find_paired_node_wpid(receiver.path, number)
+                if not self.wpid:
+                    _log.error('Unable to get wpid from udev for device %d of %s', number, receiver)
+                    raise _base.NoSuchDevice(number=number, receiver=receiver, error='Not present 27Mhz device')
+                kind = receiver.get_kind_from_index(number)
+                self._kind = _hidpp10.DEVICE_KIND[kind]
+            else:  # get information from pairing registers
                 self.online = True
                 self.update_pairing_information()
                 self.update_extended_pairing_information()


Test patch: