Add web toggle for Bluetooth discoverable window
The board stays hidden by default, so new phones could only pair via an SSH session. Add 'radxa-audio discoverable on|off' backed by a transient radxa-bt-pairing unit that auto-approves and trusts devices pairing in the window, expires on its own, and expose it in the web mixer with a countdown. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,9 +6,11 @@ import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
import os
|
||||
import time
|
||||
|
||||
CONFIG = Path('/etc/radxa-audio/mixer.json')
|
||||
MEMORY = Path('/etc/radxa-audio/input-memory.json')
|
||||
PAIRING_UNTIL = Path('/run/radxa-audio/pairing-until')
|
||||
SPS = 'org.gnome.ShairportSync'
|
||||
SPS_PATH = '/org/gnome/ShairportSync'
|
||||
MAC = re.compile(r'(?:[0-9A-F]{2}:){5}[0-9A-F]{2}\Z')
|
||||
@@ -148,6 +150,16 @@ def devices():
|
||||
return result
|
||||
|
||||
|
||||
def pairing():
|
||||
adapter = next((i['org.bluez.Adapter1'] for i in objects('org.bluez', '/').values()
|
||||
if 'org.bluez.Adapter1' in i), {})
|
||||
on = bool(adapter.get('Discoverable'))
|
||||
remaining = 0
|
||||
try: remaining = max(0, round(float(PAIRING_UNTIL.read_text()) - time.time()))
|
||||
except (FileNotFoundError, ValueError): pass
|
||||
return {'discoverable': on, 'remaining': remaining if on else 0, 'alias': adapter.get('Alias', '')}
|
||||
|
||||
|
||||
def dacs():
|
||||
result = []
|
||||
for line in command('aplay','-l').splitlines():
|
||||
@@ -164,4 +176,6 @@ def state():
|
||||
except Exception as e: bluetooth=[]; issues.append(str(e))
|
||||
try: dac = dacs()
|
||||
except Exception as e: dac=[]; issues.append(str(e))
|
||||
return {'config':config,'inputs':inputs(),'bluetooth':bluetooth,'dacs':dac,'issues':issues}
|
||||
try: pair = pairing()
|
||||
except Exception as e: pair={'discoverable':False,'remaining':0,'alias':''}; issues.append(str(e))
|
||||
return {'config':config,'inputs':inputs(),'bluetooth':bluetooth,'dacs':dac,'pairing':pair,'issues':issues}
|
||||
|
||||
Reference in New Issue
Block a user