altdesktop / python-dbus-next

🚌 The next great DBus library for Python with asyncio support
https://python-dbus-next.readthedocs.io/en/latest/
MIT License
191 stars 60 forks source link

Better support for ofono #89

Closed pkcinna01 closed 3 years ago

pkcinna01 commented 3 years ago

Ofono is a popular framework for interacting with cell phones via bluetooth. I could not figure out how to get events for a specific phone or phone call without having access to a proxy object.

#only listen for phone calls on specific phone defined by self.modem_path
self.call_added_sig_receiver = sysBus.add_signal_receiver(self.call_added_cb,
    signal_name="CallAdded",
    bus_name="org.ofono",
    dbus_interface="org.ofono.VoiceCallManager",
    path=self.modem_path)

#only listen to a specific all on a specific phone
self.prop_changed_sig_receiver = sysBus.add_signal_receiver(self.voice_call_prop_change_cb,
    signal_name="PropertyChanged",
    bus_name="org.ofono",
    dbus_interface="org.ofono.VoiceCall",
    path=self.call_path)
acrisci commented 3 years ago

Please read the docs for the low level interface https://python-dbus-next.readthedocs.io/en/latest/low-level-interface/index.html

There's plenty of examples there to show you how to use it.

pkcinna01 commented 3 years ago

Sorry.  I couldn't figure it out with the low level api.  Another problem I was having was ofono creates a lot of objects on the fly defined by a path. With dbus-next, I didn't see a method to get the interface from a proxy object to listen for events on one object. I did find BaseProxyObject.ProxyInterface but could not add listeners with calls like "ProxyInterface.on_call_started". It is easy with dbus with code like this:

self.voice_call_manager = dbus.Interface(sysBus.get_object('org.ofono', self.modem_path), 'org.ofono.VoiceCallManager')

Btw, I tried to use the "Chat" link in the README but it was asking for personal credentials (phone number).

acrisci commented 3 years ago

One useful tip for working with introspected classes like this is to use statements like print(dir(interface)). Other than that i don't know how to help without having a specific question to answer.

pkcinna01 commented 3 years ago

I guess the question is how to convert the code below to the interface for one object defined by modem_path. There will be lots of VoiceCallMangers created dynamically.

modem_interface = dbus.Interface(sysBus.get_object('org.ofono', modem_path),'org.ofono.VoiceCallManager')

With dbus-next, i can get the proxy_object but not clear how to get the interface from there... my hope was calling proxy_object.get_interface() with no arguments would return the interface to keep it simple.