Show Bluetooth inputs when BlueZ objects can't be read as JSON

inputs() still used GetManagedObjects on BlueZ to look up names and
silently dropped every Bluetooth input when an Apple device's
advertisement data broke the JSON conversion. Read only Alias per
device and fall back to the address.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jsahn
2026-10-12 22:01:54 +09:00
co-authored by Claude Opus 5.5
parent 7fa372e801
commit 1cd00ae21b
2 changed files with 12 additions and 3 deletions
+4 -3
View File
@@ -114,13 +114,14 @@ def inputs():
result.append({'id':'airplay','name':'AirPlay','kind':'airplay','volume':0,
'muted':False,'playing':False,'available':False})
try:
devices = objects('org.bluez', '/')
for path, props in pcms().items():
if not is_input(props): continue
dev = props['Device']; key = address(dev)
d = devices.get(dev, {}).get('org.bluez.Device1', {})
# A missing name must not hide a working input.
try: name = properties('org.bluez', dev, 'org.bluez.Device1', ['Alias'])['Alias']
except (ValueError, KeyError, subprocess.TimeoutExpired): name = key
volume, muted = decode_volume(int(props['Volume']))
result.append({'id':key,'name':d.get('Alias', key),'kind':'bluetooth','volume':volume,
result.append({'id':key,'name':name,'kind':'bluetooth','volume':volume,
'muted':muted,'playing':bool(props.get('Running')),'available':True})
except (ValueError, KeyError, subprocess.TimeoutExpired): pass
return result