[Newm] Add method for displaying connected bluetooth devices
This commit is contained in:
parent
af2c327eb7
commit
1214534726
@ -6,6 +6,7 @@ import time
|
|||||||
import logging
|
import logging
|
||||||
import psutil
|
import psutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import dbus
|
||||||
import docker
|
import docker
|
||||||
|
|
||||||
docker_client = docker.from_env()
|
docker_client = docker.from_env()
|
||||||
@ -249,6 +250,35 @@ def right_text() -> str:
|
|||||||
return " | ".join([unread_emails(), cpu_usage(), mem_usage(), battery_status()])
|
return " | ".join([unread_emails(), cpu_usage(), mem_usage(), battery_status()])
|
||||||
|
|
||||||
|
|
||||||
|
def get_bluetooth_devices() -> str:
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
|
bus = dbus.SystemBus()
|
||||||
|
service_name = "org.bluez"
|
||||||
|
|
||||||
|
# Verify if bluetooth is turned on
|
||||||
|
proxy = bus.get_object(service_name, "/org/bluez/hci0")
|
||||||
|
props = dbus.Interface(proxy, "org.freedesktop.DBus.Properties")
|
||||||
|
if not props.Get("org.bluez.Adapter1", "Powered"):
|
||||||
|
return ""
|
||||||
|
|
||||||
|
# Grab all known devices
|
||||||
|
bt_intro_iface = dbus.Interface(proxy, "org.freedesktop.DBus.Introspectable")
|
||||||
|
bt_intro = str(bt_intro_iface.Introspect())
|
||||||
|
root_node = ET.fromstring(bt_intro)
|
||||||
|
known_devices = [n.get("name") for n in root_node.findall("node")]
|
||||||
|
|
||||||
|
# Check if all devices are connected
|
||||||
|
counter = 0
|
||||||
|
for device in known_devices:
|
||||||
|
object_path = f"/org/bluez/hci0/{device}"
|
||||||
|
proxy = bus.get_object(service_name, object_path)
|
||||||
|
props = dbus.Interface(proxy, "org.freedesktop.DBus.Properties")
|
||||||
|
if props.Get("org.bluez.Device1", "Connected"):
|
||||||
|
counter = counter + 1
|
||||||
|
return f" {counter}"
|
||||||
|
|
||||||
|
|
||||||
def display_docker() -> str:
|
def display_docker() -> str:
|
||||||
containers = docker_client.containers.list(sparse=True)
|
containers = docker_client.containers.list(sparse=True)
|
||||||
return f" {len(containers)}"
|
return f" {len(containers)}"
|
||||||
|
Loading…
Reference in New Issue
Block a user