Add option to control bluetooth

This commit is contained in:
Magnus Walbeck 2024-05-19 12:16:24 +02:00
parent 1b36c9fc7e
commit 1d4eeaf549
Signed by: mwalbeck
SSH key fingerprint: SHA256:LW2enW+zg6O/tGp+u4fVcpo+4Bn9y1qGj9SxUIBdK3s

View file

@ -44,6 +44,7 @@ def on_connect(client, userdata, flags, rc):
logging.info("Connected with result code - %s", rc)
client.publish("speakers/pi-soulra/version", __version__)
client.publish("speakers/pi-soulra/bluetooth", "on")
client.subscribe("speakers/pi-soulra/command")
@ -80,6 +81,16 @@ def on_message(client, userdata, message):
logging.info("Shutting down...")
subprocess.run(["systemctl", "poweroff"], check=False)
elif message.payload == b"bluetooth_on":
logging.info("Turning on bluetooth")
subprocess.run(["bluetoothctl", "power", "on"], check=False)
client.publish("speakers/pi-soulra/bluetooth", "on")
elif message.payload == b"bluetooth_off":
logging.info("Turning off bluetooth")
subprocess.run(["bluetoothctl", "power", "off"], check=False)
client.publish("speakers/pi-soulra/bluetooth", "off")
def send(commands):
for command in commands: