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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user