Created
September 26, 2023 13:16
-
-
Save lduboeuf/742c94f4af0f7cb46197bcd84ac18d1f to your computer and use it in GitHub Desktop.
LTE to GSM switcher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
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
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