[modules/bluetooth2] quotes

This commit is contained in:
tobi-wan-kenobi 2020-04-29 20:20:04 +02:00
parent 6e5d60d3ae
commit 2028d51e15

View file

@ -29,8 +29,8 @@ class Module(bumblebee.engine.Module):
bumblebee.output.Widget( bumblebee.output.Widget(
full_text=self.status)) full_text=self.status))
self.manager = self.parameter("manager", "blueman-manager") self.manager = self.parameter('manager', 'blueman-manager')
self._status = "Off" self._status = 'Off'
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
self._bus = dbus.SystemBus() self._bus = dbus.SystemBus()
@ -48,12 +48,12 @@ class Module(bumblebee.engine.Module):
state = len(subprocess.run(['bluetoothctl', 'list'], stdout=subprocess.PIPE).stdout) state = len(subprocess.run(['bluetoothctl', 'list'], stdout=subprocess.PIPE).stdout)
if state > 0: if state > 0:
connected_devices = self.get_connected_devices() connected_devices = self.get_connected_devices()
self._status = "On - {}".format(connected_devices) self._status = 'On - {}'.format(connected_devices)
else: else:
self._status = "Off" self._status = 'Off'
adapters_cmd = 'rfkill list | grep Bluetooth' adapters_cmd = 'rfkill list | grep Bluetooth'
if not len(subprocess.run(adapters_cmd, shell=True, stdout=subprocess.PIPE).stdout): if not len(subprocess.run(adapters_cmd, shell=True, stdout=subprocess.PIPE).stdout):
self._status = "No Adapter Found" self._status = 'No Adapter Found'
return return
def manager(self, widget): def manager(self, widget):
@ -62,12 +62,12 @@ class Module(bumblebee.engine.Module):
def _toggle(self, widget=None): def _toggle(self, widget=None):
"""Toggle bluetooth state.""" """Toggle bluetooth state."""
if "On" in self._status: if 'On' in self._status:
state = "false" state = 'false'
else: else:
state = "true" state = 'true'
cmd = "dbus-send --system --print-reply --dest=org.blueman.Mechanism /org/blueman/mechanism org.blueman.Mechanism.SetRfkillState boolean:%s" % state cmd = 'dbus-send --system --print-reply --dest=org.blueman.Mechanism /org/blueman/mechanism org.blueman.Mechanism.SetRfkillState boolean:%s' % state
logging.debug('bt: toggling bluetooth') logging.debug('bt: toggling bluetooth')
bumblebee.util.execute(cmd) bumblebee.util.execute(cmd)
@ -76,29 +76,29 @@ class Module(bumblebee.engine.Module):
"""Get current state.""" """Get current state."""
state = [] state = []
if self._status == "No Adapter Found": if self._status == 'No Adapter Found':
state.append("critical") state.append('critical')
elif self._status == "On - 0": elif self._status == 'On - 0':
state.append("warning") state.append('warning')
elif "On" in self._status and not(self._status == "On - 0"): elif 'On' in self._status and not(self._status == 'On - 0'):
state.append("ON") state.append('ON')
else: else:
state.append("critical") state.append('critical')
return state return state
def get_connected_devices(self): def get_connected_devices(self):
devices = 0 devices = 0
objects = dbus.Interface( objects = dbus.Interface(
self._bus.get_object("org.bluez", "/"), self._bus.get_object('org.bluez', '/'),
"org.freedesktop.DBus.ObjectManager" 'org.freedesktop.DBus.ObjectManager'
).GetManagedObjects() ).GetManagedObjects()
for path, interfaces in objects.items(): for path, interfaces in objects.items():
if "org.bluez.Device1" in interfaces: if 'org.bluez.Device1' in interfaces:
if dbus.Interface( if dbus.Interface(
self._bus.get_object("org.bluez", path), self._bus.get_object('org.bluez', path),
"org.freedesktop.DBus.Properties" 'org.freedesktop.DBus.Properties'
).Get( ).Get(
"org.bluez.Device1", "Connected" 'org.bluez.Device1', 'Connected'
): ):
devices += 1 devices += 1
return devices return devices