nullp0tr / bluew

Bluew is a simple and easy to use bluetooth API for python
MIT License
15 stars 2 forks source link

Fetching device class not working #11

Closed Hoeze closed 6 years ago

Hoeze commented 6 years ago

Hi, I'd like to read the device class of certain devices:

import bluew
devices = bluew.devices()
bluew.read_attribute(devices[0].address, "Class")

However, this either results in segfault or this:

  File "/usr/local/lib/python3.5/dist-packages/bluew/dbusted/interfaces.py", line 198, in connect_device
    self.manager.Connect()
  File "/usr/local/lib/python3.5/dist-packages/dbus/proxies.py", line 70, in __call__
    return self._proxy_method(*args, **keywords)
  File "/usr/local/lib/python3.5/dist-packages/dbus/proxies.py", line 145, in __call__
    **keywords)
  File "/usr/local/lib/python3.5/dist-packages/dbus/connection.py", line 651, in call_blocking
    message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/bluew/dbusted/decorators.py", line 69, in _wrapper
    return func(self, *args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/bluew/dbusted/dbusted.py", line 189, in connect
    deviface.connect_device()
  File "/usr/local/lib/python3.5/dist-packages/bluew/dbusted/interfaces.py", line 200, in connect_device
    self._handle_connect_error(exp)
  File "/usr/local/lib/python3.5/dist-packages/bluew/dbusted/interfaces.py", line 234, in _handle_connect_error
    raise bzerr(bzerr.UNKNOWN_ERROR)
bluew.dbusted.interfaces.BluezInterfaceError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/lib/python3.5/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/bluew/api.py", line 120, in read_attribute
    with Connection(mac, *args, **kwargs) as connection:
  File "/usr/local/lib/python3.5/dist-packages/bluew/connections.py", line 57, in __init__
    self._connect()
  File "/usr/local/lib/python3.5/dist-packages/bluew/connections.py", line 35, in wrapper
    raise exp
  File "/usr/local/lib/python3.5/dist-packages/bluew/connections.py", line 32, in wrapper
    return func(self, *args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/bluew/connections.py", line 66, in _connect
    self.engine.connect(self.mac)
  File "/usr/local/lib/python3.5/dist-packages/bluew/dbusted/decorators.py", line 24, in _wrapper
    return func(self, dev, *args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/bluew/dbusted/decorators.py", line 35, in _wrapper
    return func(self, dev, *args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/bluew/dbusted/decorators.py", line 72, in _wrapper
    self._handle_errors(exp, *args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/bluew/dbusted/dbusted.py", line 452, in _handle_errors
    raise BluewError(BluewError.UNEXPECTED_ERROR)
bluew.errors.BluewError: An unexpected error happened. using:  ver: 
nullp0tr commented 6 years ago

Hey,

read_attribute is for GATT attributes, you have to pass it a UUID string. The segfault might be bluez caused but could also be libdbus. I'll investigate this. Anyways to read 'Class' attribute use devices[0].cls.

Hoeze commented 6 years ago

Thank you for pointing out, cls works great.