1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-07 00:57:22 +02:00

fix for missing dB value

This commit is contained in:
Kelly Brazil
2025-03-31 16:50:46 -07:00
parent ed3046bb1b
commit 1182c9f263
2 changed files with 24 additions and 2 deletions

View File

@ -251,10 +251,16 @@ def parse(
channel_data = channel_info.split(" ")
if channel_data[0] == "":
continue
if "dB" in channel_data[3]:
db_value = channel_data[3].strip("[]")
status = channel_data[4].strip("[]")
else:
db_value = "0.0db"
status = channel_data[3].strip("[]")
playback_value = channel_data[1]
percentage = channel_data[2].strip("[]") # Extract percentage e.g., "100%"
db_value = channel_data[3].strip("[]") # Extract db value e.g., "0.00db"
status = channel_data[4].strip("[]") # Extract status e.g., "on" or "off"
# Store channel mapping in the dictionary
mapping[channel_name] = {

View File

@ -49,6 +49,22 @@ class AmixerTests(unittest.TestCase):
quiet=True)
self.assertEqual(amixer_sget_json_processed_map, expected_amixer_sget_processed_json_map)
def test_amixer_missing_db(self):
data = '''Simple mixer control 'Master',0
Capabilities: pvolume pswitch pswitch-joined
Playback channels: Front Left - Front Right
Limits: Playback 0 - 65536
Mono:
Front Left: Playback 55039 [84%] [on]
Front Right: Playback 54383 [83%] [on]
Simple mixer control 'Capture',0
Capabilities: cvolume cswitch cswitch-joined
Capture channels: Front Left - Front Right
Limits: Capture 0 - 65536
Front Left: Capture 24672 [38%] [on]
Front Right: Capture 24672 [38%] [on]'''
expected = {"control_name":"Master","capabilities":["cvolume","cswitch","cswitch-joined"],"playback_channels":["Front Left","Front Right"],"limits":{"playback_min":0,"playback_max":65536},"front_left":{"playback_value":24672,"percentage":38,"db":0.0,"status":True},"front_right":{"playback_value":24672,"percentage":38,"db":0.0,"status":True}}
self.assertEqual(expected, jc.parsers.amixer.parse(data, quiet=True))
if __name__ == '__main__':
unittest.main()