Skip to content

Instantly share code, notes, and snippets.

@lduboeuf
Created September 26, 2023 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lduboeuf/742c94f4af0f7cb46197bcd84ac18d1f to your computer and use it in GitHub Desktop.
Save lduboeuf/742c94f4af0f7cb46197bcd84ac18d1f to your computer and use it in GitHub Desktop.
LTE to GSM switcher
import os
import dbus
from gi.repository import GLib
from dbus.mainloop.glib import DBusGMainLoop
best_connectivity="lte"
lowest_connectivity="gsm"
sim_slot="/ril_0"
best_connectivity_cmd=f'/usr/share/ofono/scripts/set-tech-preference {sim_slot} {best_connectivity}'
lowest_connectivity_cmd=f'/usr/share/ofono/scripts/set-tech-preference {sim_slot} {lowest_connectivity}'
def signal_handler(*args, **kwargs):
[iface, changed, _invalidated] = args
if 'MobileDataEnabled' in changed:
mobileDataEnabled = changed['MobileDataEnabled']
if mobileDataEnabled:
os.system(best_connectivity_cmd)
else:
os.system(lowest_connectivity_cmd)
DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
bus.add_signal_receiver(signal_handler,signal_name='PropertiesChanged',dbus_interface='org.freedesktop.DBus.Properties',
path='/com/lomiri/connectivity1/Private'
# message_keyword='msg')
)
loop = GLib.MainLoop()
loop.run()
[Unit]
Description=LTE battery saver
Requires=dbus.socket
After=dbus.socket
[Service]
ExecStart=/home/phablet/.local/bin/lte-battery-saver.sh
[Install]
WantedBy=dbus.socket
@lduboeuf
Copy link
Author

from https://forums.ubports.com/topic/6211/howto-alternate-way-of-saving-battery-when-using-4g-lte/70?_=1695711334682
declare systemd service: /home/phablet/.config/systemd/user/lte-battery-saver.service
running the service: systemctl --user enable --now lte-battery-saver

@lduboeuf
Copy link
Author

lduboeuf commented Sep 27, 2023

monitor
dbus-monitor --session "type=signal,path='/com/lomiri/connectivity1/Private',interface='org.freedesktop.DBus.Properties',member='PropertiesChanged'"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment